mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
feat(trie): read-only root calculation (#2233)
This commit is contained in:
47
crates/trie/src/progress.rs
Normal file
47
crates/trie/src/progress.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use crate::{cursor::CursorSubNode, hash_builder::HashBuilder, updates::TrieUpdates, Nibbles};
|
||||
use reth_primitives::{trie::StoredSubNode, MerkleCheckpoint, H256};
|
||||
|
||||
/// The progress of the state root computation.
|
||||
#[derive(Debug)]
|
||||
pub enum StateRootProgress {
|
||||
/// The complete state root computation with updates and computed root.
|
||||
Complete(H256, TrieUpdates),
|
||||
/// The intermediate progress of state root computation.
|
||||
/// Contains the walker stack, the hash builder and the trie updates.
|
||||
Progress(IntermediateStateRootState, TrieUpdates),
|
||||
}
|
||||
|
||||
/// The intermediate state of the state root computation.
|
||||
#[derive(Debug)]
|
||||
pub struct IntermediateStateRootState {
|
||||
/// Previously constructed hash builder.
|
||||
pub hash_builder: HashBuilder,
|
||||
/// Previously recorded walker stack.
|
||||
pub walker_stack: Vec<CursorSubNode>,
|
||||
/// The last hashed account key processed.
|
||||
pub last_account_key: H256,
|
||||
/// The last walker key processed.
|
||||
pub last_walker_key: Nibbles,
|
||||
}
|
||||
|
||||
impl From<IntermediateStateRootState> for MerkleCheckpoint {
|
||||
fn from(value: IntermediateStateRootState) -> Self {
|
||||
Self {
|
||||
last_account_key: value.last_account_key,
|
||||
last_walker_key: value.last_walker_key.hex_data,
|
||||
walker_stack: value.walker_stack.into_iter().map(StoredSubNode::from).collect(),
|
||||
state: value.hash_builder.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MerkleCheckpoint> for IntermediateStateRootState {
|
||||
fn from(value: MerkleCheckpoint) -> Self {
|
||||
Self {
|
||||
hash_builder: HashBuilder::from(value.state),
|
||||
walker_stack: value.walker_stack.into_iter().map(CursorSubNode::from).collect(),
|
||||
last_account_key: value.last_account_key,
|
||||
last_walker_key: Nibbles::from(value.last_walker_key),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user