mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: move hashed state and trie writing to provider (#9636)
This commit is contained in:
@ -73,6 +73,6 @@ similar-asserts.workspace = true
|
||||
criterion.workspace = true
|
||||
|
||||
[features]
|
||||
metrics = ["reth-metrics", "dep:metrics"]
|
||||
metrics = ["reth-metrics", "reth-trie/metrics", "dep:metrics"]
|
||||
serde = ["dep:serde"]
|
||||
test-utils = ["triehash", "reth-trie-common/test-utils"]
|
||||
|
||||
@ -4,7 +4,9 @@ use reth_db_api::database::Database;
|
||||
use reth_primitives::{
|
||||
constants::EMPTY_ROOT_HASH, keccak256, Account, Address, Bytes, StorageEntry, B256, U256,
|
||||
};
|
||||
use reth_provider::{test_utils::create_test_provider_factory, HashingWriter, ProviderFactory};
|
||||
use reth_provider::{
|
||||
test_utils::create_test_provider_factory, HashingWriter, ProviderFactory, TrieWriter,
|
||||
};
|
||||
use reth_storage_errors::provider::ProviderResult;
|
||||
use reth_trie::{proof::Proof, Nibbles, StateRoot};
|
||||
use reth_trie_common::{AccountProof, StorageProof};
|
||||
@ -40,7 +42,7 @@ fn insert_genesis<DB: Database>(
|
||||
provider_factory: &ProviderFactory<DB>,
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
) -> ProviderResult<B256> {
|
||||
let mut provider = provider_factory.provider_rw()?;
|
||||
let provider = provider_factory.provider_rw()?;
|
||||
|
||||
// Hash accounts and insert them into hashing table.
|
||||
let genesis = chain_spec.genesis();
|
||||
@ -64,7 +66,7 @@ fn insert_genesis<DB: Database>(
|
||||
let (root, updates) = StateRoot::from_tx(provider.tx_ref())
|
||||
.root_with_updates()
|
||||
.map_err(Into::<reth_db::DatabaseError>::into)?;
|
||||
updates.write_to_database(provider.tx_mut())?;
|
||||
provider.write_trie_updates(&updates).unwrap();
|
||||
|
||||
provider.commit()?;
|
||||
|
||||
|
||||
@ -6,7 +6,9 @@ use reth_db_api::{
|
||||
transaction::DbTxMut,
|
||||
};
|
||||
use reth_primitives::{hex_literal::hex, Account, StorageEntry, U256};
|
||||
use reth_provider::{test_utils::create_test_provider_factory, DatabaseProviderRW};
|
||||
use reth_provider::{
|
||||
test_utils::create_test_provider_factory, DatabaseProviderRW, StorageTrieWriter, TrieWriter,
|
||||
};
|
||||
use reth_trie::{
|
||||
prefix_set::PrefixSetMut,
|
||||
test_utils::{state_root, state_root_prehashed, storage_root, storage_root_prehashed},
|
||||
@ -82,7 +84,7 @@ fn incremental_vs_full_root(inputs: &[&str], modified: &str) {
|
||||
let modified_root = loader.root().unwrap();
|
||||
|
||||
// Update the intermediate roots table so that we can run the incremental verification
|
||||
trie_updates.write_to_database(tx.tx_ref(), hashed_address).unwrap();
|
||||
tx.write_individual_storage_trie_updates(hashed_address, &trie_updates).unwrap();
|
||||
|
||||
// 3. Calculate the incremental root
|
||||
let mut storage_changes = PrefixSetMut::default();
|
||||
@ -637,7 +639,7 @@ fn account_trie_around_extension_node_with_dbtrie() {
|
||||
|
||||
let (got, updates) = StateRoot::from_tx(tx.tx_ref()).root_with_updates().unwrap();
|
||||
assert_eq!(expected, got);
|
||||
updates.write_to_database(tx.tx_ref()).unwrap();
|
||||
tx.write_trie_updates(&updates).unwrap();
|
||||
|
||||
// read the account updates from the db
|
||||
let mut accounts_trie = tx.tx_ref().cursor_read::<tables::AccountsTrie>().unwrap();
|
||||
@ -684,7 +686,7 @@ proptest! {
|
||||
state.iter().map(|(&key, &balance)| (key, (Account { balance, ..Default::default() }, std::iter::empty())))
|
||||
);
|
||||
assert_eq!(expected_root, state_root);
|
||||
trie_updates.write_to_database(tx.tx_ref()).unwrap();
|
||||
tx.write_trie_updates(&trie_updates).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user