mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix(stage): merkle checkpoint target (#2512)
This commit is contained in:
@ -6,7 +6,7 @@ use reth_db::{
|
||||
transaction::{DbTx, DbTxMut},
|
||||
};
|
||||
use reth_interfaces::consensus;
|
||||
use reth_primitives::{hex, BlockNumber, MerkleCheckpoint, H256};
|
||||
use reth_primitives::{hex, trie::StoredSubNode, BlockNumber, MerkleCheckpoint, H256};
|
||||
use reth_provider::Transaction;
|
||||
use reth_trie::{IntermediateStateRootState, StateRoot, StateRootProgress};
|
||||
use std::{fmt::Debug, ops::DerefMut};
|
||||
@ -168,7 +168,7 @@ impl<DB: Database> Stage<DB> for MerkleStage {
|
||||
block_root
|
||||
} else if to_block - from_block > threshold || from_block == 1 {
|
||||
// if there are more blocks than threshold it is faster to rebuild the trie
|
||||
if let Some(checkpoint) = &checkpoint {
|
||||
if let Some(checkpoint) = checkpoint.as_ref().filter(|c| c.target_block == to_block) {
|
||||
debug!(
|
||||
target: "sync::stages::merkle::exec",
|
||||
current = ?current_block,
|
||||
@ -182,8 +182,11 @@ impl<DB: Database> Stage<DB> for MerkleStage {
|
||||
target: "sync::stages::merkle::exec",
|
||||
current = ?current_block,
|
||||
target = ?to_block,
|
||||
previous_checkpoint = ?checkpoint,
|
||||
"Rebuilding trie"
|
||||
);
|
||||
// Reset the checkpoint and clear trie tables
|
||||
self.save_execution_checkpoint(tx, None)?;
|
||||
tx.clear::<tables::AccountsTrie>()?;
|
||||
tx.clear::<tables::StoragesTrie>()?;
|
||||
}
|
||||
@ -195,7 +198,14 @@ impl<DB: Database> Stage<DB> for MerkleStage {
|
||||
match progress {
|
||||
StateRootProgress::Progress(state, updates) => {
|
||||
updates.flush(tx.deref_mut())?;
|
||||
self.save_execution_checkpoint(tx, Some((*state).into()))?;
|
||||
let checkpoint = MerkleCheckpoint::new(
|
||||
to_block,
|
||||
state.last_account_key,
|
||||
state.last_walker_key.hex_data,
|
||||
state.walker_stack.into_iter().map(StoredSubNode::from).collect(),
|
||||
state.hash_builder.into(),
|
||||
);
|
||||
self.save_execution_checkpoint(tx, Some(checkpoint))?;
|
||||
return Ok(ExecOutput { stage_progress: input.stage_progress(), done: false })
|
||||
}
|
||||
StateRootProgress::Complete(root, updates) => {
|
||||
|
||||
Reference in New Issue
Block a user