feat(ress): max witness window (#15029)

This commit is contained in:
Roman Krasiuk
2025-03-13 22:39:38 +01:00
committed by GitHub
parent eeaa65a668
commit c10b0dd7fb
4 changed files with 30 additions and 5 deletions

View File

@@ -41,9 +41,10 @@ where
provider,
block_executor,
Box::new(task_executor.clone()),
pending_state,
args.max_witness_window,
args.witness_max_parallel,
args.witness_cache_size,
pending_state,
)?;
network.add_rlpx_sub_protocol(
RessProtocolHandler {

View File

@@ -730,6 +730,11 @@ Ress:
[default: 5]
--ress.max-witness-window <MAX_WITNESS_WINDOW>
The maximum witness lookback window
[default: 1024]
--ress.witness-max-parallel <WITNESS_MAX_PARALLEL>
The maximum number of witnesses to generate in parallel

View File

@@ -3,6 +3,9 @@ use clap::Args;
/// The default number of maximum active connections.
const MAX_ACTIVE_CONNECTIONS_DEFAULT: u64 = 5;
/// The default maximum witness lookback window.
const MAX_WITNESS_WINDOW_DEFAULT: u64 = 1024;
/// The default maximum number of witnesses to generate in parallel.
const WITNESS_MAX_PARALLEL_DEFAULT: usize = 5;
@@ -21,6 +24,10 @@ pub struct RessArgs {
#[arg(long = "ress.max-active-connections", default_value_t = MAX_ACTIVE_CONNECTIONS_DEFAULT)]
pub max_active_connections: u64,
/// The maximum witness lookback window.
#[arg(long = "ress.max-witness-window", default_value_t = MAX_WITNESS_WINDOW_DEFAULT)]
pub max_witness_window: u64,
/// The maximum number of witnesses to generate in parallel.
#[arg(long = "ress.witness-max-parallel", default_value_t = WITNESS_MAX_PARALLEL_DEFAULT)]
pub witness_max_parallel: usize,
@@ -35,6 +42,7 @@ impl Default for RessArgs {
Self {
enabled: false,
max_active_connections: MAX_ACTIVE_CONNECTIONS_DEFAULT,
max_witness_window: MAX_WITNESS_WINDOW_DEFAULT,
witness_max_parallel: WITNESS_MAX_PARALLEL_DEFAULT,
witness_cache_size: WITNESS_CACHE_SIZE_DEFAULT,
}

View File

@@ -31,9 +31,10 @@ pub struct RethRessProtocolProvider<P, E> {
provider: P,
block_executor: E,
task_spawner: Box<dyn TaskSpawner>,
pending_state: PendingState<EthPrimitives>,
max_witness_window: u64,
witness_semaphore: Arc<Semaphore>,
witness_cache: Arc<Mutex<LruMap<B256, Arc<Vec<Bytes>>>>>,
pending_state: PendingState<EthPrimitives>,
}
impl<P: Clone, E: Clone> Clone for RethRessProtocolProvider<P, E> {
@@ -42,9 +43,10 @@ impl<P: Clone, E: Clone> Clone for RethRessProtocolProvider<P, E> {
provider: self.provider.clone(),
block_executor: self.block_executor.clone(),
task_spawner: self.task_spawner.clone(),
pending_state: self.pending_state.clone(),
max_witness_window: self.max_witness_window,
witness_semaphore: self.witness_semaphore.clone(),
witness_cache: self.witness_cache.clone(),
pending_state: self.pending_state.clone(),
}
}
}
@@ -59,17 +61,19 @@ where
provider: P,
block_executor: E,
task_spawner: Box<dyn TaskSpawner>,
pending_state: PendingState<EthPrimitives>,
max_witness_window: u64,
witness_max_parallel: usize,
cache_size: u32,
pending_state: PendingState<EthPrimitives>,
) -> eyre::Result<Self> {
Ok(Self {
provider,
block_executor,
task_spawner,
pending_state,
max_witness_window,
witness_semaphore: Arc::new(Semaphore::new(witness_max_parallel)),
witness_cache: Arc::new(Mutex::new(LruMap::new(ByLength::new(cache_size)))),
pending_state,
})
}
@@ -103,6 +107,13 @@ where
let block =
self.block_by_hash(block_hash)?.ok_or(ProviderError::BlockHashNotFound(block_hash))?;
let best_block_number = self.provider.best_block_number()?;
if best_block_number.saturating_sub(block.number()) > self.max_witness_window {
return Err(ProviderError::TrieWitnessError(
"witness target block exceeds maximum witness window".to_owned(),
))
}
let mut executed_ancestors = Vec::new();
let mut ancestor_hash = block.parent_hash();
let historical = 'sp: loop {