aboutsummaryrefslogtreecommitdiffstats
path: root/light
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-04-18 19:08:17 +0800
committerFelix Lange <fjl@twurst.com>2017-04-18 20:52:11 +0800
commita31d268b76ff13df8e7d060163a842b8ed569793 (patch)
tree3660c31af1e6fc226e99b1b2767c8fe551f40681 /light
parentc7a4d9cf8ae307a94d16dd8197824eecd320cdf7 (diff)
downloaddexon-a31d268b76ff13df8e7d060163a842b8ed569793.tar
dexon-a31d268b76ff13df8e7d060163a842b8ed569793.tar.gz
dexon-a31d268b76ff13df8e7d060163a842b8ed569793.tar.bz2
dexon-a31d268b76ff13df8e7d060163a842b8ed569793.tar.lz
dexon-a31d268b76ff13df8e7d060163a842b8ed569793.tar.xz
dexon-a31d268b76ff13df8e7d060163a842b8ed569793.tar.zst
dexon-a31d268b76ff13df8e7d060163a842b8ed569793.zip
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.
Diffstat (limited to 'light')
-rw-r--r--light/trie.go15
1 files changed, 4 insertions, 11 deletions
diff --git a/light/trie.go b/light/trie.go
index 1440f2fbf..2988a16cf 100644
--- a/light/trie.go
+++ b/light/trie.go
@@ -19,6 +19,7 @@ package light
import (
"context"
+ "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
)
@@ -46,26 +47,18 @@ func NewLightTrie(id *TrieID, odr OdrBackend, useFakeMap bool) *LightTrie {
// retrieveKey retrieves a single key, returns true and stores nodes in local
// database if successful
func (t *LightTrie) retrieveKey(ctx context.Context, key []byte) bool {
- r := &TrieRequest{Id: t.id, Key: key}
+ r := &TrieRequest{Id: t.id, Key: crypto.Keccak256(key)}
return t.odr.Retrieve(ctx, r) == nil
}
// do tries and retries to execute a function until it returns with no error or
// an error type other than MissingNodeError
-func (t *LightTrie) do(ctx context.Context, fallbackKey []byte, fn func() error) error {
+func (t *LightTrie) do(ctx context.Context, key []byte, fn func() error) error {
err := fn()
for err != nil {
- mn, ok := err.(*trie.MissingNodeError)
- if !ok {
+ if _, ok := err.(*trie.MissingNodeError); !ok {
return err
}
-
- var key []byte
- if mn.PrefixLen+mn.SuffixLen > 0 {
- key = mn.Key
- } else {
- key = fallbackKey
- }
if !t.retrieveKey(ctx, key) {
break
}