Skip to content

Commit a31d268

Browse files
committed
trie: remove Key in MissingNodeError
The key was constructed from nibbles, which isn't possible for all nodes. Remove the only use of Key in LightTrie by always retrying with the original key that was looked up.
1 parent c7a4d9c commit a31d268

File tree

3 files changed

+4
-17
lines changed

3 files changed

+4
-17
lines changed

light/trie.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package light
1919
import (
2020
"context"
2121

22+
"github.com/ethereum/go-ethereum/crypto"
2223
"github.com/ethereum/go-ethereum/ethdb"
2324
"github.com/ethereum/go-ethereum/trie"
2425
)
@@ -46,26 +47,18 @@ func NewLightTrie(id *TrieID, odr OdrBackend, useFakeMap bool) *LightTrie {
4647
// retrieveKey retrieves a single key, returns true and stores nodes in local
4748
// database if successful
4849
func (t *LightTrie) retrieveKey(ctx context.Context, key []byte) bool {
49-
r := &TrieRequest{Id: t.id, Key: key}
50+
r := &TrieRequest{Id: t.id, Key: crypto.Keccak256(key)}
5051
return t.odr.Retrieve(ctx, r) == nil
5152
}
5253

5354
// do tries and retries to execute a function until it returns with no error or
5455
// an error type other than MissingNodeError
55-
func (t *LightTrie) do(ctx context.Context, fallbackKey []byte, fn func() error) error {
56+
func (t *LightTrie) do(ctx context.Context, key []byte, fn func() error) error {
5657
err := fn()
5758
for err != nil {
58-
mn, ok := err.(*trie.MissingNodeError)
59-
if !ok {
59+
if _, ok := err.(*trie.MissingNodeError); !ok {
6060
return err
6161
}
62-
63-
var key []byte
64-
if mn.PrefixLen+mn.SuffixLen > 0 {
65-
key = mn.Key
66-
} else {
67-
key = fallbackKey
68-
}
6962
if !t.retrieveKey(ctx, key) {
7063
break
7164
}

trie/errors.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ import (
3030
//
3131
// RootHash is the original root of the trie that contains the node
3232
//
33-
// Key is a binary-encoded key that contains the prefix that leads to the first
34-
// missing node and optionally a suffix that hints on which further nodes should
35-
// also be retrieved
36-
//
3733
// PrefixLen is the nibble length of the key prefix that leads from the root to
3834
// the missing node
3935
//
@@ -42,7 +38,6 @@ import (
4238
// such hints in the error message)
4339
type MissingNodeError struct {
4440
RootHash, NodeHash common.Hash
45-
Key []byte
4641
PrefixLen, SuffixLen int
4742
}
4843

trie/trie.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
450450
return nil, &MissingNodeError{
451451
RootHash: t.originalRoot,
452452
NodeHash: common.BytesToHash(n),
453-
Key: compactHexEncode(append(prefix, suffix...)),
454453
PrefixLen: len(prefix),
455454
SuffixLen: len(suffix),
456455
}

0 commit comments

Comments
 (0)