go-ethereum/triedb
CPerezz 0d16a41887
triedb/pathdb: fix lookup sentinel collision with zero disk layer root
lookup.accountTip and storageTip used common.Hash{} as the "state is
stale" sentinel while ALSO returning common.Hash{} when the disk layer
itself happened to be keyed by the zero hash. lookupAccount/Storage
then blindly compared the returned value against common.Hash{} and
misreported a legitimate disk-layer fallback as errSnapshotStale.

For a merkle path database this sentinel collision is invisible: an
empty merkle trie hashes to types.EmptyRootHash which is a concrete
non-zero keccak, so the disk layer's root never equals common.Hash{}.
The collision only shows up once the disk layer root can legitimately
be zero — for example, a fresh verkle/bintrie database where the empty
binary trie hashes to EmptyVerkleHash = common.Hash{}. In that
configuration, any Account/Storage lookup for a key that has never
been written ends up taking the disk-layer fallback branch, which
correctly returns base=common.Hash{}, which lookupAccount then
misreads as "stale" and bubbles an error up to the caller.

Fix: change accountTip/storageTip to return (common.Hash, bool) so the
"found the tip" signal is carried out of band from the hash value.
lookupAccount/Storage now consult the boolean rather than comparing
the returned hash to zero. The returned hash itself may still be zero
(that is a valid disk-layer root on the bintrie path) and callers
must not treat it as a sentinel.

Noticed while wiring the bintrie flat-state reader in a separate
branch; the fix is scheme-agnostic and lands here so it can flow into
master independently of that work.
2026-04-08 00:18:51 +02:00
..
database trie: optimize memory allocation (#30932) 2025-03-25 14:59:44 +01:00
hashdb core, miner, tests: introduce codedb and simplify cachingDB (#33816) 2026-03-10 08:29:21 +01:00
internal triedb, triedb/internal, triedb/pathdb: add GenerateTrie + extract shared pipeline into triedb/internal (#34654) 2026-04-07 14:36:53 +08:00
pathdb triedb/pathdb: fix lookup sentinel collision with zero disk layer root 2026-04-08 00:18:51 +02:00
database.go core, eth, ethclient, triedb: report trienode index progress (#34633) 2026-04-04 21:00:07 +08:00
generate.go triedb, triedb/internal, triedb/pathdb: add GenerateTrie + extract shared pipeline into triedb/internal (#34654) 2026-04-07 14:36:53 +08:00
generate_test.go triedb, triedb/internal, triedb/pathdb: add GenerateTrie + extract shared pipeline into triedb/internal (#34654) 2026-04-07 14:36:53 +08:00
history.go cmd, triedb: implement history inspection (#29267) 2024-03-22 20:12:10 +08:00
preimages.go all: remove the dependency from trie to triedb (#28824) 2024-02-13 14:49:53 +01:00
preimages_test.go triedb: add test suite for preimage store (#31574) 2025-05-05 14:01:53 +08:00
states.go all: update license comments and AUTHORS (#31133) 2025-02-05 23:01:17 +01:00