Skip to main content

reth_trie_common/
constants.rs

1/// The maximum size of RLP encoded trie account in bytes.
2/// 2 (header) + 4 * 1 (field lens) + 8 (nonce) + 32 * 3 (balance, storage root, code hash)
3pub const TRIE_ACCOUNT_RLP_MAX_SIZE: usize = 110;
4
5#[cfg(test)]
6mod tests {
7    use super::*;
8    use crate::TrieAccount;
9    use alloy_primitives::{B256, U256};
10    use alloy_rlp::Encodable;
11
12    #[test]
13    #[allow(clippy::needless_update)]
14    fn account_rlp_max_size() {
15        let account = TrieAccount {
16            nonce: u64::MAX,
17            balance: U256::MAX,
18            storage_root: B256::from_slice(&[u8::MAX; 32]),
19            code_hash: B256::from_slice(&[u8::MAX; 32]),
20            ..Default::default()
21        };
22        let mut encoded = Vec::new();
23        account.encode(&mut encoded);
24        assert_eq!(encoded.len(), TRIE_ACCOUNT_RLP_MAX_SIZE);
25    }
26}