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    fn account_rlp_max_size() {
14        let account = TrieAccount {
15            nonce: u64::MAX,
16            balance: U256::MAX,
17            storage_root: B256::from_slice(&[u8::MAX; 32]),
18            code_hash: B256::from_slice(&[u8::MAX; 32]),
19        };
20        let mut encoded = Vec::new();
21        account.encode(&mut encoded);
22        assert_eq!(encoded.len(), TRIE_ACCOUNT_RLP_MAX_SIZE);
23    }
24}