Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit cc490b6

Browse files
authored
fix: accurately track account and code weighs (paradigmxyz#19091)
1 parent 5887a15 commit cc490b6

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

crates/engine/tree/src/tree/cached_state.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ impl ExecutionCacheBuilder {
474474
.build_with_hasher(DefaultHashBuilder::default());
475475

476476
let account_cache = CacheBuilder::new(self.account_cache_entries)
477-
.weigher(|_key: &Address, _value: &Option<Account>| -> u32 {
477+
.weigher(|_key: &Address, value: &Option<Account>| -> u32 {
478478
// Account has a fixed size (none, balance,code_hash)
479-
size_of::<Option<Account>>() as u32
479+
20 + size_of_val(value) as u32
480480
})
481481
.max_capacity(account_cache_size)
482482
.time_to_live(EXPIRY_TIME)
@@ -485,13 +485,19 @@ impl ExecutionCacheBuilder {
485485

486486
let code_cache = CacheBuilder::new(self.code_cache_entries)
487487
.weigher(|_key: &B256, value: &Option<Bytecode>| -> u32 {
488-
match value {
488+
let code_size = match value {
489489
Some(bytecode) => {
490-
// base weight + actual bytecode size
491-
(40 + bytecode.len()) as u32
490+
// base weight + actual (padded) bytecode size + size of the jump table
491+
(size_of_val(value) +
492+
bytecode.bytecode().len() +
493+
bytecode
494+
.legacy_jump_table()
495+
.map(|table| table.as_slice().len())
496+
.unwrap_or_default()) as u32
492497
}
493-
None => 8, // size of None variant
494-
}
498+
None => size_of_val(value) as u32,
499+
};
500+
32 + code_size
495501
})
496502
.max_capacity(code_cache_size)
497503
.time_to_live(EXPIRY_TIME)

0 commit comments

Comments
 (0)