Skip to content

Commit 693d9cc

Browse files
authored
trie: more node iterator improvements (ethereum#14615)
* ethdb: remove Set Set deadlocks immediately and isn't part of the Database interface. * trie: add Err to Iterator This is useful for testing because the underlying NodeIterator doesn't need to be kept in a separate variable just to get the error. * trie: add LeafKey to iterator, panic when not at leaf LeafKey is useful for callers that can't interpret Path. * trie: retry failed seek/peek in iterator Next Instead of failing iteration irrecoverably, make it so Next retries the pending seek or peek every time. Smaller changes in this commit make this easier to test: * The iterator previously returned from Next on encountering a hash node. This caused it to visit the same path twice. * Path returned nibbles with terminator symbol for valueNode attached to fullNode, but removed it for valueNode attached to shortNode. Now the terminator is always present. This makes Path unique to each node and simplifies Leaf. * trie: add Path to MissingNodeError The light client trie iterator needs to know the path of the node that's missing so it can retrieve a proof for it. NodeIterator.Path is not sufficient because it is updated when the node is resolved and actually visited by the iterator. Also remove unused fields. They were added a long time ago before we knew which fields would be needed for the light client.
1 parent 431cf2a commit 693d9cc

File tree

7 files changed

+288
-172
lines changed

7 files changed

+288
-172
lines changed

ethdb/memory_database.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ func (db *MemDatabase) Put(key []byte, value []byte) error {
4545
return nil
4646
}
4747

48-
func (db *MemDatabase) Set(key []byte, value []byte) {
49-
db.lock.Lock()
50-
defer db.lock.Unlock()
51-
52-
db.Put(key, value)
53-
}
54-
5548
func (db *MemDatabase) Get(key []byte) ([]byte, error) {
5649
db.lock.RLock()
5750
defer db.lock.RUnlock()

trie/errors.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,13 @@ import (
2323
)
2424

2525
// MissingNodeError is returned by the trie functions (TryGet, TryUpdate, TryDelete)
26-
// in the case where a trie node is not present in the local database. Contains
27-
// information necessary for retrieving the missing node through an ODR service.
28-
//
29-
// NodeHash is the hash of the missing node
30-
//
31-
// RootHash is the original root of the trie that contains the node
32-
//
33-
// PrefixLen is the nibble length of the key prefix that leads from the root to
34-
// the missing node
35-
//
36-
// SuffixLen is the nibble length of the remaining part of the key that hints on
37-
// which further nodes should also be retrieved (can be zero when there are no
38-
// such hints in the error message)
26+
// in the case where a trie node is not present in the local database. It contains
27+
// information necessary for retrieving the missing node.
3928
type MissingNodeError struct {
40-
RootHash, NodeHash common.Hash
41-
PrefixLen, SuffixLen int
29+
NodeHash common.Hash // hash of the missing node
30+
Path []byte // hex-encoded path to the missing node
4231
}
4332

4433
func (err *MissingNodeError) Error() string {
45-
return fmt.Sprintf("Missing trie node %064x", err.NodeHash)
34+
return fmt.Sprintf("missing trie node %x (path %x)", err.NodeHash, err.Path)
4635
}

0 commit comments

Comments
 (0)