mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-14 19:01:36 +00:00
Master added (via PR #34754) a dirty bool to InternalNode/StemNode plus a CollectNodes short-circuit that skips clean subtrees — the arena branch diverged before that landed. Port the semantics onto the arena shape: - Add dirty bool to InternalNode and StemNode. - Wire dirty=true alongside every existing mustRecompute=true setter in node_store.go (newInternalRef, newStemRef) and store_ops.go (8 mutation sites across InsertSingle/insertSingleInternal/InsertValuesAtStem/ insertValuesAtStem/splitStemInsert/splitStemValuesInsert). - Add 'if !node.dirty { return nil }' gate at the top of CollectNodes for both KindInternal and KindStem; clear dirty after flushfn runs. - Plumb a dirty parameter through deserializeNode; DeserializeNode passes dirty=true (safe default), DeserializeNodeWithHash passes dirty=false (loaded from disk, blob matches). The arena test in trie_test.go that was auto-merged from master used master-shape struct literals (tr.root, NewBinaryNode) that don't exist on arena; delete those and replace with TestCommitSkipCleanSubtrees, an arena-native version that asserts first-Commit flushes all nodes, no-op Commit flushes none, and single-leaf Commit flushes only the root-to-leaf path.
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
// Copyright 2025 go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package bintrie
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
)
|
|
|
|
func keyToPath(depth int, key []byte) ([]byte, error) {
|
|
if depth >= 31*8 {
|
|
return nil, errors.New("node too deep")
|
|
}
|
|
path := make([]byte, 0, depth+1)
|
|
for i := range depth + 1 {
|
|
bit := key[i/8] >> (7 - (i % 8)) & 1
|
|
path = append(path, bit)
|
|
}
|
|
return path, nil
|
|
}
|
|
|
|
// Invariant: dirty=false implies mustRecompute=false. Every mutation that
|
|
// invalidates the cached hash MUST also mark the blob for re-flush.
|
|
type InternalNode struct {
|
|
left, right NodeRef
|
|
depth uint8
|
|
mustRecompute bool // hash is stale (cleared by Hash)
|
|
dirty bool // on-disk blob is stale (cleared by CollectNodes)
|
|
hash common.Hash
|
|
}
|