From 7cc69d52c6017eeb4348c824a9f5369400e331d1 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Thu, 8 Jun 2023 13:34:25 +0400 Subject: [PATCH] feat(stages): remove changeset commit threshold in Execution (#3050) --- bin/reth/src/chain/import.rs | 1 - bin/reth/src/debug_cmd/execution.rs | 6 +---- bin/reth/src/debug_cmd/merkle.rs | 6 +---- bin/reth/src/node/mod.rs | 1 - bin/reth/src/stage/dump/merkle.rs | 6 +---- bin/reth/src/stage/run.rs | 1 - crates/config/src/config.rs | 12 +-------- crates/stages/src/stages/execution.rs | 35 ++------------------------- 8 files changed, 6 insertions(+), 62 deletions(-) diff --git a/bin/reth/src/chain/import.rs b/bin/reth/src/chain/import.rs index cdfb741ec..6233eca86 100644 --- a/bin/reth/src/chain/import.rs +++ b/bin/reth/src/chain/import.rs @@ -174,7 +174,6 @@ impl ImportCommand { ExecutionStageThresholds { max_blocks: config.stages.execution.max_blocks, max_changes: config.stages.execution.max_changes, - max_changesets: config.stages.execution.max_changesets, }, )), ) diff --git a/bin/reth/src/debug_cmd/execution.rs b/bin/reth/src/debug_cmd/execution.rs index e2211804a..0e1db2ab9 100644 --- a/bin/reth/src/debug_cmd/execution.rs +++ b/bin/reth/src/debug_cmd/execution.rs @@ -143,11 +143,7 @@ impl Command { }) .set(ExecutionStage::new( factory, - ExecutionStageThresholds { - max_blocks: None, - max_changes: None, - max_changesets: None, - }, + ExecutionStageThresholds { max_blocks: None, max_changes: None }, )), ) .build(db); diff --git a/bin/reth/src/debug_cmd/merkle.rs b/bin/reth/src/debug_cmd/merkle.rs index 668b9ea08..df428156e 100644 --- a/bin/reth/src/debug_cmd/merkle.rs +++ b/bin/reth/src/debug_cmd/merkle.rs @@ -91,11 +91,7 @@ impl Command { let factory = reth_revm::Factory::new(self.chain.clone()); let mut execution_stage = ExecutionStage::new( factory, - ExecutionStageThresholds { - max_blocks: Some(1), - max_changes: None, - max_changesets: None, - }, + ExecutionStageThresholds { max_blocks: Some(1), max_changes: None }, ); let mut account_hashing_stage = AccountHashingStage::default(); diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index cbf57dde3..af4df8885 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -691,7 +691,6 @@ impl Command { ExecutionStageThresholds { max_blocks: stage_conf.execution.max_blocks, max_changes: stage_conf.execution.max_changes, - max_changesets: stage_conf.execution.max_changesets, }, )), ) diff --git a/bin/reth/src/stage/dump/merkle.rs b/bin/reth/src/stage/dump/merkle.rs index 2350e5cfa..b0447c248 100644 --- a/bin/reth/src/stage/dump/merkle.rs +++ b/bin/reth/src/stage/dump/merkle.rs @@ -71,11 +71,7 @@ async fn unwind_and_copy( // Bring Plainstate to TO (hashing stage execution requires it) let mut exec_stage = ExecutionStage::new( reth_revm::Factory::new(Arc::new(MAINNET.clone())), - ExecutionStageThresholds { - max_blocks: Some(u64::MAX), - max_changes: None, - max_changesets: None, - }, + ExecutionStageThresholds { max_blocks: Some(u64::MAX), max_changes: None }, ); exec_stage diff --git a/bin/reth/src/stage/run.rs b/bin/reth/src/stage/run.rs index 21a8732c9..4a2a638ca 100644 --- a/bin/reth/src/stage/run.rs +++ b/bin/reth/src/stage/run.rs @@ -190,7 +190,6 @@ impl Command { ExecutionStageThresholds { max_blocks: Some(batch_size), max_changes: None, - max_changesets: None, }, )), None, diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index a8faafaf7..cd8751e34 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -196,21 +196,11 @@ pub struct ExecutionConfig { pub max_blocks: Option, /// The maximum amount of state changes to keep in memory before the execution stage commits. pub max_changes: Option, - /// The maximum amount of changesets to keep in memory before they are written to the pending - /// database transaction. - /// - /// If this is lower than `max_gas`, then history is periodically flushed to the database - /// transaction, which frees up memory. - pub max_changesets: Option, } impl Default for ExecutionConfig { fn default() -> Self { - Self { - max_blocks: Some(500_000), - max_changes: Some(5_000_000), - max_changesets: Some(1_000_000), - } + Self { max_blocks: Some(500_000), max_changes: Some(5_000_000) } } } diff --git a/crates/stages/src/stages/execution.rs b/crates/stages/src/stages/execution.rs index 63bb89efd..1a8cc2ea1 100644 --- a/crates/stages/src/stages/execution.rs +++ b/crates/stages/src/stages/execution.rs @@ -176,14 +176,6 @@ impl ExecutionStage { stage_progress = block_number; stage_checkpoint.progress.processed += block.gas_used; - // Write history periodically to free up memory - if self.thresholds.should_write_history(state.changeset_size_hint() as u64) { - info!(target: "sync::stages::execution", ?block_number, "Writing history."); - state.write_history_to_db(&**tx)?; - info!(target: "sync::stages::execution", ?block_number, "Wrote history."); - // gas_since_history_write = 0; - } - // Check if we should commit now if self.thresholds.is_end_of_batch(block_number - start_block, state.size_hint() as u64) { @@ -431,30 +423,17 @@ impl Stage for ExecutionStage { /// /// If either of the thresholds (`max_blocks` and `max_changes`) are hit, then the execution stage /// commits all pending changes to the database. -/// -/// A third threshold, `max_changesets`, can be set to periodically write changesets to the -/// current database transaction, which frees up memory. #[derive(Debug)] pub struct ExecutionStageThresholds { /// The maximum number of blocks to process before the execution stage commits. pub max_blocks: Option, /// The maximum amount of state changes to keep in memory before the execution stage commits. pub max_changes: Option, - /// The maximum amount of changesets to keep in memory before they are written to the pending - /// database transaction. - /// - /// If this is lower than `max_changes`, then history is periodically flushed to the database - /// transaction, which frees up memory. - pub max_changesets: Option, } impl Default for ExecutionStageThresholds { fn default() -> Self { - Self { - max_blocks: Some(500_000), - max_changes: Some(5_000_000), - max_changesets: Some(1_000_000), - } + Self { max_blocks: Some(500_000), max_changes: Some(5_000_000) } } } @@ -465,12 +444,6 @@ impl ExecutionStageThresholds { blocks_processed >= self.max_blocks.unwrap_or(u64::MAX) || changes_processed >= self.max_changes.unwrap_or(u64::MAX) } - - /// Check if the history write threshold has been hit. - #[inline] - pub fn should_write_history(&self, history_changes: u64) -> bool { - history_changes >= self.max_changesets.unwrap_or(u64::MAX) - } } #[cfg(test)] @@ -499,11 +472,7 @@ mod tests { Factory::new(Arc::new(ChainSpecBuilder::mainnet().berlin_activated().build())); ExecutionStage::new( factory, - ExecutionStageThresholds { - max_blocks: Some(100), - max_changes: None, - max_changesets: None, - }, + ExecutionStageThresholds { max_blocks: Some(100), max_changes: None }, ) }