go-ethereum/trie
CPerezz 437a53bbe0
triedb/pathdb: implement bintrieFlatCodec + stem blob helpers
Introduce the codec and on-disk blob format for the bintrie flat-state
layer. This commit only defines the types; the codec is NOT wired into
pathdb.Database.New yet (that happens in a later commit once the
leaf-production hook in binaryHasher and the stateUpdate wiring are in
place).

Three pieces:

1. trie/bintrie/pack.go

   Canonical PackBasicData / UnpackBasicData helpers that encode an
   account's (codeSize, nonce, balance) into the 32-byte BasicData leaf
   defined by EIP-7864. Preserves the existing BinaryTrie.UpdateAccount
   layout byte-for-byte (4-byte code_size at offset 4 rather than the
   spec's 3-byte field at offset 5 — any realistic code size has byte 4
   always zero and the two encodings are bit-equivalent in practice).

   BinaryTrie.UpdateAccount is refactored to delegate to PackBasicData
   so the flat-state codec can produce a bit-identical BasicData
   encoding without duplicating the layout logic.

2. triedb/pathdb/stem_blob.go

   Packed encoding of the populated (offset, value) pairs at a bintrie
   stem. A stem can hold up to 256 offsets per EIP-7864 but in practice
   only a handful are set; the layout is a 32-byte bitmap followed by
   N 32-byte values in ascending offset order, where N = popcount.
   Empty stems encode to nil so the caller knows to delete the on-disk
   key rather than write a zero-length value.

   Provides encodeStemBlob / decodeStemBlob / extractStemOffset /
   mergeStemBlob and a stemBuilder type for accumulating writes. The
   tombstone convention (32 zero bytes = "present with zero" as used
   by DeleteStorage) is preserved.

   11 unit tests cover: empty blob, BasicData+CodeHash roundtrip, all
   256 offsets populated, sparse high offsets, set/clear roundtrip,
   load-from-existing-blob RMW, merge helper, merge-to-empty, tombstone
   zero bytes, malformed input detection, bitmap rank sanity.

3. triedb/pathdb/flat_codec_bintrie.go

   bintrieFlatCodec implements flatStateCodec over the stem-blob layout.
   Unlike merkleFlatCodec it is stateful: it holds a ethdb.KeyValueReader
   reference used by applyWrites to read the existing stem blob before
   merging in new writes. ethdb.Batch is write-only so the batch passed
   to Write* cannot be used to fetch current state.

   Pre-aggregation requirement is documented explicitly: within a single
   flush, the caller must NOT issue two Write* calls targeting the same
   stem, because the RMW read comes from the store (not the in-flight
   batch). Commit 8 of the bintrie flat-state plan restructures
   writeStates to pre-aggregate per-stem writes so callers don't have
   to handle this manually.

   Cache keys are prefix-disambiguated with a one-byte 0x01 to keep
   bintrie stem lookups disjoint from merkle 32-byte account keys and
   64-byte storage keys in the shared clean-state fastcache.

   SplitMarker is a single-tier (stem-only) format, not the merkle
   two-tier (account, account+storage) format.

   7 unit tests cover: account roundtrip, storage roundtrip, multiple
   writes to the same stem, DeleteAccount preserving unrelated offsets,
   DeleteStorage removing the final offset collapsing the key, cache
   key disjointness from merkle, SplitMarker semantics.

The codec is not dispatched by anything yet; MPT continues through the
merkle codec and bintrie mode still runs on the (soon-to-be-replaced)
keccak-shaped path until Commit 10 wires things up.
2026-04-15 15:00:40 +02:00
..
bintrie triedb/pathdb: implement bintrieFlatCodec + stem blob helpers 2026-04-15 15:00:40 +02:00
transitiontrie 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
trienode core/state: build hasher skeleton 2026-04-15 15:00:38 +02:00
bytepool.go core/types, trie: reduce allocations in derivesha (#30747) 2025-10-01 10:05:49 +02:00
committer.go trie/bintrie: add eip7864 binary trees and run its tests (#32365) 2025-09-01 21:06:51 +08:00
database_test.go trie: no need to store preimage if not enabled (#32012) 2025-06-13 15:04:24 +08:00
encoding.go trie: reduce allocations in stacktrie (#30743) 2025-01-23 10:17:12 +01:00
encoding_test.go trie: reduce allocs in recHash (#27770) 2023-08-18 22:41:19 +02:00
errors.go all: fix various typos (#29600) 2024-04-23 13:09:42 +03:00
hasher.go trie: reduce the memory allocation in trie hashing (#31902) 2025-08-01 10:23:23 +08:00
inspect.go cmd/geth: add inspect trie tool to analysis trie storage (#28892) 2026-02-24 10:56:00 -07:00
inspect_test.go cmd/geth: add inspect trie tool to analysis trie storage (#28892) 2026-02-24 10:56:00 -07:00
iterator.go trie: add sub-trie iterator support (#32520) 2025-09-17 22:07:02 +08:00
iterator_test.go trie: align AllFFPrefix test assertion and message (#32719) 2025-09-24 10:36:56 +08:00
levelstats.go core, miner, trie: relocate witness stats (#34106) 2026-03-27 17:06:46 +01:00
levelstats_test.go cmd/geth: add inspect trie tool to analysis trie storage (#28892) 2026-02-24 10:56:00 -07:00
list_hasher.go core/types, trie: reduce allocations in derivesha (#30747) 2025-10-01 10:05:49 +02:00
node.go rlp: add back Iterator.Count, with fixes (#33841) 2026-02-13 23:53:42 +01:00
node_enc.go trie: reduce the memory allocation in trie hashing (#31902) 2025-08-01 10:23:23 +08:00
node_test.go trie: fix flaky test (#33711) 2026-01-29 17:22:15 +08:00
proof.go trie: error out for unexpected key-value pairs preceding the range (#33898) 2026-02-26 23:00:02 +08:00
proof_test.go trie: fix TestOneElementProof expected value message (#32738) 2025-09-24 18:57:01 -06:00
secure_trie.go trie: preallocate slice capacity (#33689) 2026-01-27 12:04:12 +08:00
secure_trie_test.go core/state, eth/protocols, trie, triedb/pathdb: remove unused error from trie Commit (#29869) 2024-06-12 12:23:16 +03:00
stacktrie.go core/types, trie: reduce allocations in derivesha (#30747) 2025-10-01 10:05:49 +02:00
stacktrie_fuzzer_test.go trie: do not expect ordering in stacktrie during fuzzing (#31170) 2025-02-18 10:48:42 +08:00
stacktrie_test.go trie: reduce allocations in stacktrie (#30743) 2025-01-23 10:17:12 +01:00
sync.go trie: cleaner array concatenation (#32756) 2025-10-02 17:32:20 +02:00
sync_test.go core, trie, triedb: minor changes from snapshot integration (#30599) 2024-10-18 17:06:31 +02:00
tracer.go trie/bintrie: add eip7864 binary trees and run its tests (#32365) 2025-09-01 21:06:51 +08:00
tracer_test.go trie, core/state: introduce trie Prefetch for optimizing preload (#32134) 2025-08-20 21:45:27 +08:00
trie.go core/types, trie: reduce allocations in derivesha (#30747) 2025-10-01 10:05:49 +02:00
trie_id.go all: update license comments and AUTHORS (#31133) 2025-02-05 23:01:17 +01:00
trie_reader.go trie/bintrie: add eip7864 binary trees and run its tests (#32365) 2025-09-01 21:06:51 +08:00
trie_test.go core, ethdb, triedb: add batch close (#33708) 2026-03-04 11:17:47 +01:00