mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
trie: fix some issues with storage responses and gentrie
This commit is contained in:
parent
06d1b5299f
commit
fcd719186c
2 changed files with 34 additions and 13 deletions
|
|
@ -750,8 +750,13 @@ func testMultiSync(t *testing.T, scheme string) {
|
|||
func TestSyncWithStorage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("hash", func(t *testing.T) {
|
||||
testSyncWithStorage(t, rawdb.HashScheme)
|
||||
})
|
||||
t.Run("path", func(t *testing.T) {
|
||||
testSyncWithStorage(t, rawdb.PathScheme)
|
||||
})
|
||||
//testSyncWithStorage(t, rawdb.PathScheme)
|
||||
}
|
||||
|
||||
func testSyncWithStorage(t *testing.T, scheme string) {
|
||||
|
|
|
|||
|
|
@ -425,25 +425,41 @@ type GenerativeTrie struct {
|
|||
}
|
||||
|
||||
func NewGentrie(origin, end common.Hash, writeFn NodeWriteFunc) *GenerativeTrie {
|
||||
var g = &GenerativeTrie{}
|
||||
|
||||
if origin == (common.Hash{}) {
|
||||
// This gentrie has zero-origin: this means no right-side proof is used,
|
||||
// and thus we do not need to wrap the write-function.
|
||||
g.writeFn = func(path []byte, hash common.Hash, blob []byte) {
|
||||
writeFn(path, hash, blob)
|
||||
}
|
||||
g.stack = NewStackTrie(g.writeFn)
|
||||
} else {
|
||||
// Wrap the write function
|
||||
var originBorder = keybytesToHex(origin[:])
|
||||
var g = &GenerativeTrie{}
|
||||
wrapper := func(path []byte, hash common.Hash, blob []byte) {
|
||||
if bytes.HasPrefix(originBorder, path) {
|
||||
//fmt.Printf("1. Skipping path %x\n", path)
|
||||
return
|
||||
}
|
||||
if bytes.HasPrefix(g.rightHandBorder, path) {
|
||||
//fmt.Printf("2. Skipping path %x\n", path)
|
||||
return
|
||||
}
|
||||
writeFn(path, hash, blob)
|
||||
}
|
||||
return &GenerativeTrie{writeFn: wrapper}
|
||||
g.writeFn = wrapper
|
||||
}
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GenerativeTrie) AddProof(rootHash common.Hash, origin []byte, proof ethdb.KeyValueReader) {
|
||||
if g.stack == nil {
|
||||
g.proofsSet = true
|
||||
stack, err := newStackTrieFromProof(rootHash, origin[:], proof, g.writeFn)
|
||||
var stack *StackTrie
|
||||
var err error
|
||||
stack, err = newStackTrieFromProof(rootHash, origin[:], proof, g.writeFn)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -459,7 +475,7 @@ func (g *GenerativeTrie) UpdateAll(keys []common.Hash, values [][]byte) error {
|
|||
g.stack.Update(keys[i][:], values[i])
|
||||
}
|
||||
last := keys[len(keys)-1]
|
||||
g.rightHandBorder = last[:]
|
||||
g.rightHandBorder = keybytesToHex(last[:])
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue