Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provider): add a local bedrock DA provider #836

Closed
wants to merge 1 commit into from

Conversation

dancoombs
Copy link
Collaborator

@dancoombs dancoombs commented Oct 9, 2024

Related to #744

Proposed Changes

  • Add a local DA provider for optimism bedrock chains. This requires a single network call per block to calculate the required DA gas for every user operation.
  • The DA provider contains an LRU cache to ensure that we only issue 1 network call update per block.
  • Compression happens locally now, via a fastlz binding at a specific commit. This commit is specifically the same used by LibZip.sol, which is used by the optimism DA oracle contract.

TODO:

  • Utilize a helper contract to get all of the BlockDAData in a single eth_call
  • Consider the implications of running the fastlz compression on each block for each user operation. Its highly likely we need the following:
  • Cache the result of the fastlz compressed size for each UO by hash. This only needs to be done once.
  • Consider moving the fastlz compression to a specific threadpool for blocking operations.

async fn get_block_da_data(&self, block: BlockHashOrNumber) -> ProviderResult<BlockDAData> {
assert!(self.is_fjord().await);

let base_fee_scalar = self
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use a helper contract to make this 1 network call.


fn fjord_l1_fee(data: Bytes, block_da_data: &BlockDAData) -> u128 {
let mut buf = vec![0; data.len() * 2];
let compressed = rundler_bindings_fastlz::compress(&data, &mut buf);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: consider doing this on a specific blocking thread pool

fn fjord_l1_fee(data: Bytes, block_da_data: &BlockDAData) -> u128 {
let mut buf = vec![0; data.len() * 2];
let compressed = rundler_bindings_fastlz::compress(&data, &mut buf);
let compressed_length = compressed.len() as u64;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: cache this value.

@dancoombs dancoombs force-pushed the danc/local-bedrock branch 2 times, most recently from ce9b0ef to 0d5b477 Compare October 9, 2024 16:14
// This test may begin to fail if an optimism sepolia fork changes how the L1 gas oracle works.
// If that happens, we should update the local bedrock oracle to match the new fork logic in
// a backwards compatible way based on the fork booleans in the contract.
#[tokio::test]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely have to set these tests to #[ignore] due to the flakey-ness of the RPC endpoint.

Base automatically changed from danc/da-block-id to feat/v0.4 October 9, 2024 17:57
Comment on lines +25 to +35
sol! {
#[sol(rpc)]
interface GasPriceOracle {
bool public isFjord;

function baseFeeScalar() public view returns (uint32);
function l1BaseFee() public view returns (uint32);
function blobBaseFeeScalar() public view returns (uint32);
function blobBaseFee() public view returns (uint32);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when react! {...} so we can do everything in rust XD

this is really cool

gas_price: u128,
) -> ProviderResult<u128> {
let block_da_data = {
let mut cache = self.block_da_data_cache.lock().await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol these names are amazing "block da data cache" "estimate da gas" -- "do da thing".

ok I'm done these comments are not at all helpful

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol I read it the same way. Got 50 cent stuck in my head writing this

@dancoombs dancoombs closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants