go-ethereum/core/state
CPerezz 519a450c43
core/state: skip redundant trie Commit for Verkle in stateObject.commit (#34021)
## Summary

**Bug fix.** In Verkle mode, all state objects share a single unified
trie (`OpenStorageTrie` returns `self`). During `stateDB.commit()`, the
main account trie is committed via `s.trie.Commit(true)`, which calls
`CollectNodes` to traverse and serialize the entire tree. However, each
dirty account's `obj.commit()` also calls `s.trie.Commit(false)` on the
**same trie object**, redundantly traversing and serializing the full
tree once per dirty account.

With N dirty accounts per block, this causes **N+1 full-tree
traversals** instead of 1. On a write-heavy workload (2250 SSTOREs),
this produces ~131 GB of allocations per block from duplicate NodeSet
creation and serialization. It also causes a latent data race from N+1
goroutines concurrently calling `CollectNodes` on shared `InternalNode`
objects.

This commit adds an `IsVerkle()` early return in `stateObject.commit()`
to skip the redundant `trie.Commit()` call.

## Benchmark (AMD EPYC 48-core, 500K entries, `--benchtime=10s
--count=3`)

| Metric | Baseline | Fixed | Delta |
|--------|----------|-------|-------|
| Approve (Mgas/s) | 4.16 ± 0.37 | **220.2 ± 10.1** | **+5190%** |
| BalanceOf (Mgas/s) | 966.2 ± 8.1 | 971.0 ± 3.0 | +0.5% |
| Allocs/op (approve) | 136.4M | 792K | **-99.4%** |

Resolves the TODO in statedb.go about the account trie commit being
"very heavy" and "something's wonky".

---------

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2026-03-17 12:27:29 +01:00
..
pruner all: improve ETA calculation across all progress indicators (#32521) 2025-09-01 13:47:02 +08:00
snapshot crypto/keccak: vendor in golang.org/x/crypto/sha3 (#33323) 2026-02-03 14:55:27 -07:00
access_events.go trie, go.mod: remove all references to go-verkle and go-ipa (#33461) 2025-12-30 20:44:04 +08:00
access_events_test.go trie, go.mod: remove all references to go-verkle and go-ipa (#33461) 2025-12-30 20:44:04 +08:00
access_list.go core/state: improve accessList copy (#33024) 2025-10-26 16:13:59 +08:00
database.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
database_code.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
database_history.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
dump.go cmd/evm/internal/t8ntool, trie: support for verkle-at-genesis, use UBT, and move the transition tree to its own package (#32445) 2025-11-14 15:25:30 +01:00
iterator.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
iterator_test.go core/state: state reader abstraction (#29761) 2024-09-05 13:10:47 +03:00
journal.go core: miner: reduce allocations in block building (#33375) 2026-02-03 08:19:16 +01:00
metrics.go core/rawdb,state: add preimage miss metric (#31295) 2025-03-07 11:23:19 +01:00
reader.go core/state: avoid Bytes() allocation in flatReader hash computations (#34025) 2026-03-17 11:42:42 +01:00
reader_stater.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
state_object.go core/state: skip redundant trie Commit for Verkle in stateObject.commit (#34021) 2026-03-17 12:27:29 +01:00
state_object_test.go core/state: using testing.B.Loop (#32658) 2025-09-19 16:57:43 -06:00
state_sizer.go core/state: add bounds check in heap eviction loop (#33712) 2026-01-29 21:08:04 +08:00
state_sizer_test.go core/state: fix incorrect contract code state metrics (#33376) 2025-12-10 11:33:59 +08:00
state_test.go core, consensus/beacon: defer trie resolution (#31725) 2025-06-25 09:42:11 +08:00
statedb.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
statedb_fuzz_test.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
statedb_hooked.go core/state: ensure deterministic hook emission order in Finalise (#33644) 2026-01-20 20:36:07 +08:00
statedb_hooked_test.go core: invoke selfdestruct tracer hooks during finalisation (#32919) 2026-01-16 15:10:08 -07:00
statedb_test.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
stateupdate.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
sync.go core,eth,internal: fix typo (#29024) 2024-02-20 19:42:48 +08:00
sync_test.go core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
transient_storage.go core/state: improve PrettyPrint function (#32293) 2025-07-30 10:39:03 +08:00
trie_prefetcher.go trie, core/state: introduce trie Prefetch for optimizing preload (#32134) 2025-08-20 21:45:27 +08:00
trie_prefetcher_test.go core/tracing: add code change reason (#32525) 2025-09-02 12:44:47 +02:00