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) {
|
func TestSyncWithStorage(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
testSyncWithStorage(t, rawdb.HashScheme)
|
t.Run("hash", func(t *testing.T) {
|
||||||
testSyncWithStorage(t, rawdb.PathScheme)
|
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) {
|
func testSyncWithStorage(t *testing.T, scheme string) {
|
||||||
|
|
|
||||||
|
|
@ -425,25 +425,41 @@ type GenerativeTrie struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGentrie(origin, end common.Hash, writeFn NodeWriteFunc) *GenerativeTrie {
|
func NewGentrie(origin, end common.Hash, writeFn NodeWriteFunc) *GenerativeTrie {
|
||||||
// Wrap the write function
|
|
||||||
var originBorder = keybytesToHex(origin[:])
|
|
||||||
var g = &GenerativeTrie{}
|
var g = &GenerativeTrie{}
|
||||||
wrapper := func(path []byte, hash common.Hash, blob []byte) {
|
|
||||||
if bytes.HasPrefix(originBorder, path) {
|
if origin == (common.Hash{}) {
|
||||||
return
|
// 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)
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix(g.rightHandBorder, path) {
|
g.stack = NewStackTrie(g.writeFn)
|
||||||
return
|
} else {
|
||||||
|
// Wrap the write function
|
||||||
|
var originBorder = keybytesToHex(origin[:])
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
writeFn(path, hash, blob)
|
g.writeFn = wrapper
|
||||||
}
|
}
|
||||||
return &GenerativeTrie{writeFn: wrapper}
|
|
||||||
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GenerativeTrie) AddProof(rootHash common.Hash, origin []byte, proof ethdb.KeyValueReader) {
|
func (g *GenerativeTrie) AddProof(rootHash common.Hash, origin []byte, proof ethdb.KeyValueReader) {
|
||||||
if g.stack == nil {
|
if g.stack == nil {
|
||||||
g.proofsSet = true
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -459,7 +475,7 @@ func (g *GenerativeTrie) UpdateAll(keys []common.Hash, values [][]byte) error {
|
||||||
g.stack.Update(keys[i][:], values[i])
|
g.stack.Update(keys[i][:], values[i])
|
||||||
}
|
}
|
||||||
last := keys[len(keys)-1]
|
last := keys[len(keys)-1]
|
||||||
g.rightHandBorder = last[:]
|
g.rightHandBorder = keybytesToHex(last[:])
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue