Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions crates/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{fs, path::PathBuf, sync::Arc};

use alloy_chains::NamedChain;
use alloy_primitives::{hex, Address, U128};
use alloy_provider::{Provider, ProviderBuilder};
use alloy_provider::{layers::CacheLayer, Provider, ProviderBuilder};
use alloy_rpc_client::RpcClient;
use alloy_signer::Signer;
use alloy_signer_aws::AwsSigner;
Expand Down Expand Up @@ -191,16 +191,22 @@ impl ScrollRollupNodeConfig {

// Get a provider
let l1_provider = self.l1_provider_args.url.clone().map(|url| {
let L1ProviderArgs { max_retries, initial_backoff, compute_units_per_second, .. } =
self.l1_provider_args;
let L1ProviderArgs {
max_retries,
initial_backoff,
compute_units_per_second,
cache_max_items,
..
} = self.l1_provider_args;
let client = RpcClient::builder()
.layer(RetryBackoffLayer::new(
max_retries,
initial_backoff,
compute_units_per_second,
))
.http(url);
ProviderBuilder::new().connect_client(client)
let cache_layer = CacheLayer::new(cache_max_items);
ProviderBuilder::new().layer(cache_layer).connect_client(client)
});

// Init a retry provider to the execution layer.
Expand All @@ -217,7 +223,9 @@ impl ScrollRollupNodeConfig {
.parse()
.expect("invalid l2 rpc url"),
);
let l2_provider = ProviderBuilder::<_, _, Scroll>::default().connect_client(client);
let l2_provider = ProviderBuilder::<_, _, Scroll>::default()
.layer(CacheLayer::new(constants::L2_PROVIDER_CACHE_MAX_ITEMS))
.connect_client(client);
let l2_provider = Arc::new(l2_provider);

// Fetch the database from the hydrated config.
Expand Down Expand Up @@ -634,6 +642,9 @@ pub struct L1ProviderArgs {
/// The logs query block range.
#[arg(long = "l1.query-range", id = "l1_query_range", value_name = "L1_QUERY_RANGE", default_value_t = constants::LOGS_QUERY_BLOCK_RANGE)]
pub logs_query_block_range: u64,
/// The maximum number of items to be stored in the cache layer.
#[arg(long = "l1.cache-max-items", id = "l1_cache_max_items", value_name = "L1_CACHE_MAX_ITEMS", default_value_t = constants::L1_PROVIDER_CACHE_MAX_ITEMS)]
pub cache_max_items: u32,
}

/// The arguments for the Beacon provider.
Expand Down
6 changes: 6 additions & 0 deletions crates/node/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub(crate) const L1_PROVIDER_MAX_RETRIES: u32 = 10;
/// The initial backoff for the L1 provider.
pub(crate) const L1_PROVIDER_INITIAL_BACKOFF: u64 = 100;

/// The maximum number of items to store in L1 provider's cache layer.
pub(crate) const L1_PROVIDER_CACHE_MAX_ITEMS: u32 = 100;

/// The block range used to fetch L1 logs.
pub(crate) const LOGS_QUERY_BLOCK_RANGE: u64 = 500;

Expand All @@ -17,6 +20,9 @@ pub(crate) const L2_PROVIDER_MAX_RETRIES: u32 = u32::MAX;
/// The initial backoff for the L2 provider.
pub(crate) const L2_PROVIDER_INITIAL_BACKOFF: u64 = 50;

/// The maximum number of items to store in L2 provider's cache layer.
pub(crate) const L2_PROVIDER_CACHE_MAX_ITEMS: u32 = 100;

/// The default provider compute units per second.
pub(crate) const PROVIDER_COMPUTE_UNITS_PER_SECOND: u64 = 10000;

Expand Down
1 change: 1 addition & 0 deletions crates/node/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async fn test_should_consolidate_to_block_15k() -> eyre::Result<()> {
max_retries: 10,
initial_backoff: 100,
logs_query_block_range: 500,
cache_max_items: 100,
},
engine_driver_args: EngineDriverArgs { sync_at_startup: false },
sequencer_args: SequencerArgs {
Expand Down
Loading