feat(trie): SparseStateTrie::update_account (#12954)

This commit is contained in:
Roman Krasiuk
2024-11-28 13:00:18 +01:00
committed by GitHub
parent cbcf79a18e
commit e9a6e4525e
6 changed files with 67 additions and 11 deletions

View File

@ -0,0 +1,24 @@
/// The maximum size of RLP encoded trie account in bytes.
/// 2 (header) + 4 * 1 (field lens) + 8 (nonce) + 32 * 3 (balance, storage root, code hash)
pub const TRIE_ACCOUNT_RLP_MAX_SIZE: usize = 110;
#[cfg(test)]
mod tests {
use super::*;
use crate::TrieAccount;
use alloy_primitives::{B256, U256};
use alloy_rlp::Encodable;
#[test]
fn account_rlp_max_size() {
let account = TrieAccount {
nonce: u64::MAX,
balance: U256::MAX,
storage_root: B256::from_slice(&[u8::MAX; 32]),
code_hash: B256::from_slice(&[u8::MAX; 32]),
};
let mut encoded = Vec::new();
account.encode(&mut encoded);
assert_eq!(encoded.len(), TRIE_ACCOUNT_RLP_MAX_SIZE);
}
}

View File

@ -11,6 +11,10 @@
/// The implementation of hash builder.
pub mod hash_builder;
/// Constants related to the trie computation.
mod constants;
pub use constants::*;
mod account;
pub use account::TrieAccount;