fix(stages): add commit threshold to merkle stage v2 (#1656)

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
joshieDo
2023-03-14 12:47:16 +08:00
committed by GitHub
parent c5cd236e1a
commit 5b90cbc411
12 changed files with 476 additions and 180 deletions

View File

@ -44,10 +44,7 @@ pub(crate) async fn dump_merkle_stage<DB: Database>(
unwind_and_copy::<DB>(db_tool, (from, to), tip_block_number, &output_db).await?;
if should_run {
println!(
"\n# Merkle stage does not support dry run, so it will actually be committing changes."
);
run(output_db, to, from).await?;
dry_run(output_db, to, from).await?;
}
Ok(())
@ -113,7 +110,7 @@ async fn unwind_and_copy<DB: Database>(
}
/// Try to re-execute the stage straightaway
async fn run(
async fn dry_run(
output_db: reth_db::mdbx::Env<reth_db::mdbx::WriteMap>,
to: u64,
from: u64,
@ -121,18 +118,24 @@ async fn run(
info!(target: "reth::cli", "Executing stage.");
let mut tx = Transaction::new(&output_db)?;
MerkleStage::Execution {
clean_threshold: u64::MAX, // Forces updating the root instead of calculating from scratch
let mut exec_output = false;
while !exec_output {
exec_output = MerkleStage::Execution {
clean_threshold: u64::MAX, /* Forces updating the root instead of calculating from
* scratch */
}
.execute(
&mut tx,
reth_stages::ExecInput {
previous_stage: Some((StageId("Another"), to)),
stage_progress: Some(from),
},
)
.await?
.done;
}
.execute(
&mut tx,
reth_stages::ExecInput {
previous_stage: Some((StageId("Another"), to)),
stage_progress: Some(from),
},
)
.await?;
tx.drop()?;
info!(target: "reth::cli", "Success.");