From 091c5499bac9e58a6eb929d31d04b5a346004989 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 16 Dec 2024 03:57:02 +0100 Subject: [PATCH] chore: replace TrieAccount with alloy's (#13397) --- Cargo.lock | 2 +- crates/blockchain-tree/src/blockchain_tree.rs | 17 +-- crates/chain-state/src/test_utils.rs | 15 +-- crates/primitives-traits/Cargo.toml | 10 +- crates/primitives-traits/src/account.rs | 12 ++ .../storage/provider/src/test_utils/blocks.rs | 17 +-- crates/trie/common/Cargo.toml | 5 +- crates/trie/common/src/account.rs | 122 +++--------------- crates/trie/common/src/proofs.rs | 7 +- crates/trie/db/tests/trie.rs | 4 +- crates/trie/parallel/src/proof.rs | 4 +- crates/trie/parallel/src/root.rs | 4 +- crates/trie/sparse/src/state.rs | 10 +- crates/trie/sparse/src/trie.rs | 24 ++-- crates/trie/trie/src/proof/mod.rs | 3 +- crates/trie/trie/src/test_utils.rs | 6 +- crates/trie/trie/src/trie.rs | 4 +- 17 files changed, 93 insertions(+), 173 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed4ffde9304d..6dbc8a706e9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8792,6 +8792,7 @@ dependencies = [ "alloy-genesis", "alloy-primitives", "alloy-rlp", + "alloy-trie", "arbitrary", "auto_impl", "bincode", @@ -9593,7 +9594,6 @@ dependencies = [ "proptest-arbitrary-interop", "reth-codecs", "reth-primitives-traits", - "revm-primitives", "serde", "serde_json", "serde_with", diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 5fde2fcbd34a..64bff767126a 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1399,7 +1399,6 @@ mod tests { }, ProviderFactory, StorageLocation, }; - use reth_revm::primitives::AccountInfo; use reth_stages_api::StageCheckpoint; use reth_trie::{root::state_root_unhashed, StateRoot}; use std::collections::HashMap; @@ -1624,15 +1623,13 @@ mod tests { receipts_root, state_root: state_root_unhashed(HashMap::from([( signer, - ( - AccountInfo { - balance: initial_signer_balance - - (single_tx_cost * U256::from(num_of_signer_txs)), - nonce: num_of_signer_txs, - ..Default::default() - }, - EMPTY_ROOT_HASH, - ), + Account { + balance: initial_signer_balance - + (single_tx_cost * U256::from(num_of_signer_txs)), + nonce: num_of_signer_txs, + ..Default::default() + } + .into_trie_account(EMPTY_ROOT_HASH), )])), ..Default::default() }; diff --git a/crates/chain-state/src/test_utils.rs b/crates/chain-state/src/test_utils.rs index a5c0133f59f3..0741e958db45 100644 --- a/crates/chain-state/src/test_utils.rs +++ b/crates/chain-state/src/test_utils.rs @@ -20,6 +20,7 @@ use reth_primitives::{ BlockBody, EthPrimitives, NodePrimitives, Receipt, Receipts, RecoveredTx, SealedBlock, SealedBlockWithSenders, SealedHeader, Transaction, TransactionSigned, }; +use reth_primitives_traits::Account; use reth_storage_api::NodePrimitivesProvider; use reth_trie::{root::state_root_unhashed, updates::TrieUpdates, HashedPostState}; use revm::{db::BundleState, primitives::AccountInfo}; @@ -150,14 +151,12 @@ impl TestBlockBuilder { beneficiary: Address::random(), state_root: state_root_unhashed(HashMap::from([( self.signer, - ( - AccountInfo { - balance: initial_signer_balance - signer_balance_decrease, - nonce: num_txs, - ..Default::default() - }, - EMPTY_ROOT_HASH, - ), + Account { + balance: initial_signer_balance - signer_balance_decrease, + nonce: num_txs, + ..Default::default() + } + .into_trie_account(EMPTY_ROOT_HASH), )])), // use the number as the timestamp so it is monotonically increasing timestamp: number + diff --git a/crates/primitives-traits/Cargo.toml b/crates/primitives-traits/Cargo.toml index 447dcdad6653..917fee952419 100644 --- a/crates/primitives-traits/Cargo.toml +++ b/crates/primitives-traits/Cargo.toml @@ -21,6 +21,7 @@ alloy-eips.workspace = true alloy-genesis.workspace = true alloy-primitives.workspace = true alloy-rlp.workspace = true +alloy-trie.workspace = true revm-primitives.workspace = true # op @@ -80,7 +81,8 @@ std = [ "bytes/std", "derive_more/std", "k256/std", - "secp256k1?/std" + "secp256k1?/std", + "alloy-trie/std" ] secp256k1 = ["dep:secp256k1"] test-utils = [ @@ -99,7 +101,8 @@ arbitrary = [ "reth-codecs?/arbitrary", "secp256k1?/global-context", "secp256k1?/rand", - "op-alloy-consensus?/arbitrary" + "op-alloy-consensus?/arbitrary", + "alloy-trie/arbitrary" ] serde-bincode-compat = [ "serde", @@ -120,7 +123,8 @@ serde = [ "revm-primitives/serde", "op-alloy-consensus?/serde", "k256/serde", - "secp256k1?/serde" + "secp256k1?/serde", + "alloy-trie/serde" ] reth-codec = [ "dep:reth-codecs", diff --git a/crates/primitives-traits/src/account.rs b/crates/primitives-traits/src/account.rs index 17f7f6f58cad..7ea618315fd9 100644 --- a/crates/primitives-traits/src/account.rs +++ b/crates/primitives-traits/src/account.rs @@ -1,6 +1,7 @@ use alloy_consensus::constants::KECCAK_EMPTY; use alloy_genesis::GenesisAccount; use alloy_primitives::{keccak256, Bytes, B256, U256}; +use alloy_trie::TrieAccount; use derive_more::Deref; use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, BytecodeDecodeError}; @@ -57,6 +58,17 @@ impl Account { pub fn get_bytecode_hash(&self) -> B256 { self.bytecode_hash.unwrap_or(KECCAK_EMPTY) } + + /// Converts the account into a trie account with the given storage root. + pub fn into_trie_account(self, storage_root: B256) -> TrieAccount { + let Self { nonce, balance, bytecode_hash } = self; + TrieAccount { + nonce, + balance, + storage_root, + code_hash: bytecode_hash.unwrap_or(KECCAK_EMPTY), + } + } } /// Bytecode for an account. diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index 7f357aa186f7..8d81e98e9619 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -170,16 +170,13 @@ fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 { account.info.as_ref().map(|info| { ( address, - ( - Account::from(info), - storage_root_unhashed( - account - .storage - .iter() - .filter(|(_, value)| !value.present_value.is_zero()) - .map(|(slot, value)| ((*slot).into(), value.present_value)), - ), - ), + Account::from(info).into_trie_account(storage_root_unhashed( + account + .storage + .iter() + .filter(|(_, value)| !value.present_value.is_zero()) + .map(|(slot, value)| ((*slot).into(), value.present_value)), + )), ) }) }, diff --git a/crates/trie/common/Cargo.toml b/crates/trie/common/Cargo.toml index eadbb3176b55..acebc2a7d77c 100644 --- a/crates/trie/common/Cargo.toml +++ b/crates/trie/common/Cargo.toml @@ -19,9 +19,7 @@ alloy-trie.workspace = true alloy-consensus.workspace = true reth-primitives-traits.workspace = true reth-codecs = { workspace = true, optional = true } -revm-primitives.workspace = true -alloy-genesis.workspace = true alloy-rpc-types-eth = { workspace = true, optional = true } alloy-serde = { workspace = true, optional = true } @@ -43,6 +41,7 @@ arbitrary = { workspace = true, features = ["derive"], optional = true } [dev-dependencies] reth-primitives-traits = { workspace = true, features = ["serde"] } reth-codecs.workspace = true +alloy-genesis.workspace = true alloy-primitives = { workspace = true, features = ["getrandom"] } alloy-trie = { workspace = true, features = ["arbitrary", "serde"] } @@ -71,7 +70,6 @@ serde = [ "alloy-consensus/serde", "alloy-trie/serde", "alloy-rpc-types-eth?/serde", - "revm-primitives/serde", "reth-primitives-traits/serde", "reth-codecs?/serde" ] @@ -101,7 +99,6 @@ arbitrary = [ "alloy-consensus/arbitrary", "alloy-primitives/arbitrary", "nybbles/arbitrary", - "revm-primitives/arbitrary", "reth-codecs/arbitrary", "alloy-rpc-types-eth?/arbitrary" ] diff --git a/crates/trie/common/src/account.rs b/crates/trie/common/src/account.rs index 60dc44d4ee18..b8a86907a1e8 100644 --- a/crates/trie/common/src/account.rs +++ b/crates/trie/common/src/account.rs @@ -1,83 +1,18 @@ -use crate::root::storage_root_unhashed; -use alloy_consensus::constants::KECCAK_EMPTY; -use alloy_genesis::GenesisAccount; -use alloy_primitives::{keccak256, B256, U256}; -use alloy_rlp::{RlpDecodable, RlpEncodable}; -use alloy_trie::EMPTY_ROOT_HASH; -use reth_primitives_traits::Account; -use revm_primitives::AccountInfo; - -/// An Ethereum account as represented in the trie. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] -pub struct TrieAccount { - /// Account nonce. - pub nonce: u64, - /// Account balance. - pub balance: U256, - /// Account's storage root. - pub storage_root: B256, - /// Hash of the account's bytecode. - pub code_hash: B256, -} - -impl TrieAccount { - /// Get account's storage root. - pub const fn storage_root(&self) -> B256 { - self.storage_root - } -} - -impl From for TrieAccount { - fn from(account: GenesisAccount) -> Self { - let storage_root = account - .storage - .map(|storage| { - storage_root_unhashed( - storage - .into_iter() - .filter(|(_, value)| !value.is_zero()) - .map(|(slot, value)| (slot, U256::from_be_bytes(*value))), - ) - }) - .unwrap_or(EMPTY_ROOT_HASH); - - Self { - nonce: account.nonce.unwrap_or_default(), - balance: account.balance, - storage_root, - code_hash: account.code.map_or(KECCAK_EMPTY, keccak256), - } - } -} - -impl From<(Account, B256)> for TrieAccount { - fn from((account, storage_root): (Account, B256)) -> Self { - Self { - nonce: account.nonce, - balance: account.balance, - storage_root, - code_hash: account.bytecode_hash.unwrap_or(KECCAK_EMPTY), - } - } -} - -impl From<(AccountInfo, B256)> for TrieAccount { - fn from((account, storage_root): (AccountInfo, B256)) -> Self { - Self { - nonce: account.nonce, - balance: account.balance, - storage_root, - code_hash: account.code_hash, - } - } -} +/// Re-export for convenience. +pub use alloy_trie::TrieAccount; #[cfg(test)] mod tests { use super::*; - use alloy_primitives::Bytes; + use crate::root::storage_root_unhashed; + use alloy_consensus::constants::KECCAK_EMPTY; + use alloy_genesis::GenesisAccount; + use alloy_primitives::{keccak256, Bytes, B256, U256}; use std::collections::BTreeMap; + use alloy_trie::EMPTY_ROOT_HASH; + use reth_primitives_traits::Account; + #[test] fn test_from_genesis_account_with_default_values() { let genesis_account = GenesisAccount::default(); @@ -88,14 +23,11 @@ mod tests { // Check the fields are properly set. assert_eq!(trie_account.nonce, 0); assert_eq!(trie_account.balance, U256::default()); - assert_eq!(trie_account.storage_root(), EMPTY_ROOT_HASH); + assert_eq!(trie_account.storage_root, EMPTY_ROOT_HASH); assert_eq!(trie_account.code_hash, KECCAK_EMPTY); // Check that the default Account converts to the same TrieAccount - assert_eq!(TrieAccount::from((Account::default(), EMPTY_ROOT_HASH)), trie_account); - - // Check that the default AccountInfo converts to the same TrieAccount - assert_eq!(TrieAccount::from((AccountInfo::default(), EMPTY_ROOT_HASH)), trie_account); + assert_eq!(Account::default().into_trie_account(EMPTY_ROOT_HASH), trie_account); } #[test] @@ -123,33 +55,17 @@ mod tests { // Check that the fields are properly set. assert_eq!(trie_account.nonce, 10); assert_eq!(trie_account.balance, U256::from(1000)); - assert_eq!(trie_account.storage_root(), expected_storage_root); + assert_eq!(trie_account.storage_root, expected_storage_root); assert_eq!(trie_account.code_hash, keccak256([0x60, 0x61])); // Check that the Account converts to the same TrieAccount assert_eq!( - TrieAccount::from(( - Account { - nonce: 10, - balance: U256::from(1000), - bytecode_hash: Some(keccak256([0x60, 0x61])) - }, - expected_storage_root - )), - trie_account - ); - - // Check that the AccountInfo converts to the same TrieAccount - assert_eq!( - TrieAccount::from(( - AccountInfo { - nonce: 10, - balance: U256::from(1000), - code_hash: keccak256([0x60, 0x61]), - ..Default::default() - }, - expected_storage_root - )), + Account { + nonce: 10, + balance: U256::from(1000), + bytecode_hash: Some(keccak256([0x60, 0x61])) + } + .into_trie_account(expected_storage_root), trie_account ); } @@ -174,7 +90,7 @@ mod tests { assert_eq!(trie_account.nonce, 3); assert_eq!(trie_account.balance, U256::from(300)); // Zero values in storage should result in EMPTY_ROOT_HASH - assert_eq!(trie_account.storage_root(), EMPTY_ROOT_HASH); + assert_eq!(trie_account.storage_root, EMPTY_ROOT_HASH); // No code provided, so code hash should be KECCAK_EMPTY assert_eq!(trie_account.code_hash, KECCAK_EMPTY); } diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index eb3626d90ea2..12419ec62180 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -258,10 +258,9 @@ impl AccountProof { let expected = if self.info.is_none() && self.storage_root == EMPTY_ROOT_HASH { None } else { - Some(alloy_rlp::encode(TrieAccount::from(( - self.info.unwrap_or_default(), - self.storage_root, - )))) + Some(alloy_rlp::encode( + self.info.unwrap_or_default().into_trie_account(self.storage_root), + )) }; let nibbles = Nibbles::unpack(keccak256(self.address)); verify_proof(root, nibbles, expected, &self.proof) diff --git a/crates/trie/db/tests/trie.rs b/crates/trie/db/tests/trie.rs index 4c614d83be6c..45c72ffd51d6 100644 --- a/crates/trie/db/tests/trie.rs +++ b/crates/trie/db/tests/trie.rs @@ -21,7 +21,7 @@ use reth_trie::{ triehash::KeccakHasher, updates::StorageTrieUpdates, BranchNodeCompact, HashBuilder, IntermediateStateRootState, Nibbles, StateRoot, - StateRootProgress, StorageRoot, TrieAccount, TrieMask, + StateRootProgress, StorageRoot, TrieMask, }; use reth_trie_db::{DatabaseStateRoot, DatabaseStorageRoot}; use std::{collections::BTreeMap, ops::Mul, str::FromStr, sync::Arc}; @@ -284,7 +284,7 @@ fn test_state_root_with_state(state: State) { } fn encode_account(account: Account, storage_root: Option) -> Vec { - let account = TrieAccount::from((account, storage_root.unwrap_or(EMPTY_ROOT_HASH))); + let account = account.into_trie_account(storage_root.unwrap_or(EMPTY_ROOT_HASH)); let mut account_rlp = Vec::with_capacity(account.length()); account.encode(&mut account_rlp); account_rlp diff --git a/crates/trie/parallel/src/proof.rs b/crates/trie/parallel/src/proof.rs index cabd9c7e0669..1d9daff5c920 100644 --- a/crates/trie/parallel/src/proof.rs +++ b/crates/trie/parallel/src/proof.rs @@ -20,7 +20,7 @@ use reth_trie::{ updates::TrieUpdatesSorted, walker::TrieWalker, HashBuilder, HashedPostStateSorted, MultiProof, MultiProofTargets, Nibbles, StorageMultiProof, - TrieAccount, TRIE_ACCOUNT_RLP_MAX_SIZE, + TRIE_ACCOUNT_RLP_MAX_SIZE, }; use reth_trie_common::proof::ProofRetainer; use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory}; @@ -229,7 +229,7 @@ where // Encode account account_rlp.clear(); - let account = TrieAccount::from((account, storage_multiproof.root)); + let account = account.into_trie_account(storage_multiproof.root); account.encode(&mut account_rlp as &mut dyn BufMut); hash_builder.add_leaf(Nibbles::unpack(hashed_address), &account_rlp); diff --git a/crates/trie/parallel/src/root.rs b/crates/trie/parallel/src/root.rs index 2aace02ed9b8..1ae1a6026c8f 100644 --- a/crates/trie/parallel/src/root.rs +++ b/crates/trie/parallel/src/root.rs @@ -16,7 +16,7 @@ use reth_trie::{ trie_cursor::{InMemoryTrieCursorFactory, TrieCursorFactory}, updates::TrieUpdates, walker::TrieWalker, - HashBuilder, Nibbles, StorageRoot, TrieAccount, TrieInput, TRIE_ACCOUNT_RLP_MAX_SIZE, + HashBuilder, Nibbles, StorageRoot, TrieInput, TRIE_ACCOUNT_RLP_MAX_SIZE, }; use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory}; use std::{collections::HashMap, sync::Arc}; @@ -192,7 +192,7 @@ where } account_rlp.clear(); - let account = TrieAccount::from((account, storage_root)); + let account = account.into_trie_account(storage_root); account.encode(&mut account_rlp as &mut dyn BufMut); hash_builder.add_leaf(Nibbles::unpack(hashed_address), &account_rlp); } diff --git a/crates/trie/sparse/src/state.rs b/crates/trie/sparse/src/state.rs index c6c741e002be..07264cbc728b 100644 --- a/crates/trie/sparse/src/state.rs +++ b/crates/trie/sparse/src/state.rs @@ -402,7 +402,7 @@ where } else { trace!(target: "trie::sparse", ?address, "Updating account"); self.account_rlp_buf.clear(); - TrieAccount::from((account, storage_root)).encode(&mut self.account_rlp_buf); + account.into_trie_account(storage_root).encode(&mut self.account_rlp_buf); self.update_account_leaf(nibbles, self.account_rlp_buf.clone()) } } @@ -438,7 +438,7 @@ mod tests { use assert_matches::assert_matches; use rand::{rngs::StdRng, Rng, SeedableRng}; use reth_primitives_traits::Account; - use reth_trie::{updates::StorageTrieUpdates, HashBuilder, TrieAccount, EMPTY_ROOT_HASH}; + use reth_trie::{updates::StorageTrieUpdates, HashBuilder, EMPTY_ROOT_HASH}; use reth_trie_common::{proof::ProofRetainer, StorageMultiProof, TrieMask}; #[test] @@ -537,11 +537,11 @@ mod tests { let address_1 = b256!("1000000000000000000000000000000000000000000000000000000000000000"); let address_path_1 = Nibbles::unpack(address_1); let account_1 = Account::arbitrary(&mut arbitrary::Unstructured::new(&bytes)).unwrap(); - let mut trie_account_1 = TrieAccount::from((account_1, storage_root)); + let mut trie_account_1 = account_1.into_trie_account(storage_root); let address_2 = b256!("1100000000000000000000000000000000000000000000000000000000000000"); let address_path_2 = Nibbles::unpack(address_2); let account_2 = Account::arbitrary(&mut arbitrary::Unstructured::new(&bytes)).unwrap(); - let mut trie_account_2 = TrieAccount::from((account_2, EMPTY_ROOT_HASH)); + let mut trie_account_2 = account_2.into_trie_account(EMPTY_ROOT_HASH); let mut hash_builder = HashBuilder::default().with_proof_retainer(ProofRetainer::from_iter([ @@ -594,7 +594,7 @@ mod tests { let address_3 = b256!("2000000000000000000000000000000000000000000000000000000000000000"); let address_path_3 = Nibbles::unpack(address_3); let account_3 = Account { nonce: account_1.nonce + 1, ..account_1 }; - let trie_account_3 = TrieAccount::from((account_3, EMPTY_ROOT_HASH)); + let trie_account_3 = account_3.into_trie_account(EMPTY_ROOT_HASH); sparse.update_account_leaf(address_path_3, alloy_rlp::encode(trie_account_3)).unwrap(); diff --git a/crates/trie/sparse/src/trie.rs b/crates/trie/sparse/src/trie.rs index 3f2d6f58bd2e..cae03892bf05 100644 --- a/crates/trie/sparse/src/trie.rs +++ b/crates/trie/sparse/src/trie.rs @@ -1297,7 +1297,7 @@ mod tests { trie_cursor::noop::NoopAccountTrieCursor, updates::TrieUpdates, walker::TrieWalker, - BranchNode, ExtensionNode, HashedPostState, LeafNode, TrieAccount, + BranchNode, ExtensionNode, HashedPostState, LeafNode, }; use reth_trie_common::{ proof::{ProofNodes, ProofRetainer}, @@ -1357,7 +1357,7 @@ mod tests { hash_builder.add_branch(branch.key, branch.value, branch.children_are_in_trie); } TrieElement::Leaf(key, account) => { - let account = TrieAccount::from((account, EMPTY_ROOT_HASH)); + let account = account.into_trie_account(EMPTY_ROOT_HASH); account.encode(&mut account_rlp); hash_builder.add_leaf(Nibbles::unpack(key), &account_rlp); @@ -1437,7 +1437,7 @@ mod tests { let value = || Account::default(); let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -1462,7 +1462,7 @@ mod tests { let value = || Account::default(); let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -1491,7 +1491,7 @@ mod tests { let value = || Account::default(); let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -1528,7 +1528,7 @@ mod tests { let value = || Account::default(); let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -1560,13 +1560,13 @@ mod tests { let old_value = Account { nonce: 1, ..Default::default() }; let old_value_encoded = { let mut account_rlp = Vec::new(); - TrieAccount::from((old_value, EMPTY_ROOT_HASH)).encode(&mut account_rlp); + old_value.into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; let new_value = Account { nonce: 2, ..Default::default() }; let new_value_encoded = { let mut account_rlp = Vec::new(); - TrieAccount::from((new_value, EMPTY_ROOT_HASH)).encode(&mut account_rlp); + new_value.into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -1928,7 +1928,7 @@ mod tests { for (update, keys_to_delete) in updates { // Insert state updates into the sparse trie and calculate the root for (key, account) in update.clone() { - let account = TrieAccount::from((account, EMPTY_ROOT_HASH)); + let account = account.into_trie_account(EMPTY_ROOT_HASH); let mut account_rlp = Vec::new(); account.encode(&mut account_rlp); sparse.update_leaf(key, account_rlp).unwrap(); @@ -2049,7 +2049,7 @@ mod tests { let value = || Account::default(); let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -2205,7 +2205,7 @@ mod tests { let value = || Account::default(); let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; @@ -2332,7 +2332,7 @@ mod tests { let value = || Account { bytecode_hash: Some(B256::repeat_byte(1)), ..Default::default() }; let value_encoded = || { let mut account_rlp = Vec::new(); - TrieAccount::from((value(), EMPTY_ROOT_HASH)).encode(&mut account_rlp); + value().into_trie_account(EMPTY_ROOT_HASH).encode(&mut account_rlp); account_rlp }; diff --git a/crates/trie/trie/src/proof/mod.rs b/crates/trie/trie/src/proof/mod.rs index 7467785cc885..165c27c82e2e 100644 --- a/crates/trie/trie/src/proof/mod.rs +++ b/crates/trie/trie/src/proof/mod.rs @@ -15,7 +15,6 @@ use alloy_rlp::{BufMut, Encodable}; use reth_execution_errors::trie::StateProofError; use reth_trie_common::{ proof::ProofRetainer, AccountProof, MultiProof, MultiProofTargets, StorageMultiProof, - TrieAccount, }; mod blinded; @@ -150,7 +149,7 @@ where // Encode account account_rlp.clear(); - let account = TrieAccount::from((account, storage_multiproof.root)); + let account = account.into_trie_account(storage_multiproof.root); account.encode(&mut account_rlp as &mut dyn BufMut); hash_builder.add_leaf(Nibbles::unpack(hashed_address), &account_rlp); diff --git a/crates/trie/trie/src/test_utils.rs b/crates/trie/trie/src/test_utils.rs index 0d0462be90f2..7fa224ab4bb0 100644 --- a/crates/trie/trie/src/test_utils.rs +++ b/crates/trie/trie/src/test_utils.rs @@ -1,7 +1,7 @@ use alloy_primitives::{Address, B256, U256}; use alloy_rlp::encode_fixed_size; use reth_primitives::Account; -use reth_trie_common::{triehash::KeccakHasher, TrieAccount}; +use reth_trie_common::triehash::KeccakHasher; /// Re-export of [triehash]. pub use triehash; @@ -14,7 +14,7 @@ where { let encoded_accounts = accounts.into_iter().map(|(address, (account, storage))| { let storage_root = storage_root(storage); - let account = TrieAccount::from((account, storage_root)); + let account = account.into_trie_account(storage_root); (address, alloy_rlp::encode(account)) }); triehash::sec_trie_root::(encoded_accounts) @@ -35,7 +35,7 @@ where { let encoded_accounts = accounts.into_iter().map(|(address, (account, storage))| { let storage_root = storage_root_prehashed(storage); - let account = TrieAccount::from((account, storage_root)); + let account = account.into_trie_account(storage_root); (address, alloy_rlp::encode(account)) }); diff --git a/crates/trie/trie/src/trie.rs b/crates/trie/trie/src/trie.rs index 953b8d31fc4f..31e1f7a8db9d 100644 --- a/crates/trie/trie/src/trie.rs +++ b/crates/trie/trie/src/trie.rs @@ -7,7 +7,7 @@ use crate::{ trie_cursor::TrieCursorFactory, updates::{StorageTrieUpdates, TrieUpdates}, walker::TrieWalker, - HashBuilder, Nibbles, TrieAccount, TRIE_ACCOUNT_RLP_MAX_SIZE, + HashBuilder, Nibbles, TRIE_ACCOUNT_RLP_MAX_SIZE, }; use alloy_consensus::EMPTY_ROOT_HASH; use alloy_primitives::{keccak256, Address, B256}; @@ -224,7 +224,7 @@ where }; account_rlp.clear(); - let account = TrieAccount::from((account, storage_root)); + let account = account.into_trie_account(storage_root); account.encode(&mut account_rlp as &mut dyn BufMut); hash_builder.add_leaf(Nibbles::unpack(hashed_address), &account_rlp);