feat(trie): read-only root calculation (#2233)

This commit is contained in:
Roman Krasiuk
2023-04-21 12:36:48 +03:00
committed by GitHub
parent 9452b3658b
commit ec418d924d
25 changed files with 1279 additions and 494 deletions

View 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),
}
}
}