mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 09:51:36 +00:00
Addresses review finding C2 (+ I5, S5, T2, T3, T12).
Before this commit, bintrieFlatCodec.ReadAccount returned the FULL
variable-length stem blob from disk while the in-memory diff-layer
buffer stored per-offset 32-byte values. The consumer,
bintrieFlatReader.Account, enforced len(basicBlob)!=32 → error, so
every disk-layer hit produced "bintrie BasicData leaf invalid length"
in production the moment the write buffer flushed. TestBintrieFlatReaderEndToEnd
did not catch this because it never forced a buffer → disk flush.
Fix: make bintrieFlatCodec.ReadAccount extract the offset from the
stem blob (mirroring ReadStorage), so the disk path and the buffer
path return the same 32-byte per-offset shape. Update
AccountCacheKey/StorageCacheKey to embed the full 32-byte key
(prefix + 31-byte stem + 1-byte offset), since caching under a
stem-only key would collapse BasicData and CodeHash into the same
slot and return the wrong value on the second hit. Update
Flush's cache-update loop to store per-offset entries from the
aggregated write set.
Design note: I considered the alternative of introducing a new
StemBlob(stem) interface method that returns the full blob synthesized
from a stem-level lookup index. Rejected because (a) the index is a
new data structure with its own consistency invariants, (b) the
per-offset approach is strictly local to the codec + reader, and (c)
the "1 Pebble read per Account" locality benefit is preserved at the
OS page cache level — both offsets at the same stem live in the same
Pebble block, so the second read is effectively free.
bintrieFlatReader.Account still does two AccountRLP lookups; the
torn-read hazard is gated by a new load-bearing invariant test,
TestBinaryHasherWritesBothBasicAndCodeHash, which asserts that
binaryHasher.updateAccount always emits both BasicData and CodeHash
leaves together. A future code-only update that broke this invariant
would fail the test.
Tests added:
* TestBintrieFlatReaderEndToEndAfterFlush — explicitly flushes via
tdb.Commit(root, false) and re-reads through a fresh StateReader.
This is the smoking-gun regression for C2.
* TestBintrieFlatReaderMultipleOffsetsPerStem — multiple offsets at
the same stem (BasicData, CodeHash, header storage slots) all
round-trip post-flush.
* TestBintrieCodecCrossFlushRMW — two Flush calls to the same stem
from different "blocks" correctly merge on disk, with prior
offsets preserved.
* TestBinaryHasherWritesBothBasicAndCodeHash — locks down the hasher
co-write invariant that bintrieFlatReader.Account relies on.
Existing tests updated to match the new per-offset ReadAccount
semantics:
* TestBintrieCodecAccountRoundTrip, TestBintrieCodecMultipleWritesSameStem,
TestBintrieCodecDeleteAccount — now read per-offset rather than
calling extractStemOffset on the raw blob.
* TestBintrieCodecCacheKeysDisjoint — additionally verifies two
offsets at the same stem produce distinct cache keys.
Error messages in bintrieFlatReader now include address and length
context (S5).
|
||
|---|---|---|
| .. | ||
| filtermaps | ||
| forkid | ||
| history | ||
| overlay | ||
| rawdb | ||
| state | ||
| stateless | ||
| tracing | ||
| txpool | ||
| types | ||
| vm | ||
| .gitignore | ||
| bench_test.go | ||
| bintrie_witness_test.go | ||
| block_validator.go | ||
| block_validator_test.go | ||
| blockchain.go | ||
| blockchain_insert.go | ||
| blockchain_reader.go | ||
| blockchain_repair_test.go | ||
| blockchain_sethead_test.go | ||
| blockchain_snapshot_test.go | ||
| blockchain_stats.go | ||
| blockchain_test.go | ||
| chain_makers.go | ||
| chain_makers_test.go | ||
| dao_test.go | ||
| error.go | ||
| eth_transfer_logs_test.go | ||
| events.go | ||
| evm.go | ||
| gaspool.go | ||
| gen_genesis.go | ||
| genesis.go | ||
| genesis_alloc.go | ||
| genesis_test.go | ||
| headerchain.go | ||
| headerchain_test.go | ||
| mkalloc.go | ||
| rlp_test.go | ||
| sender_cacher.go | ||
| state_prefetcher.go | ||
| state_processor.go | ||
| state_processor_test.go | ||
| state_transition.go | ||
| stateless.go | ||
| txindexer.go | ||
| txindexer_test.go | ||
| types.go | ||