mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
trie: allow RHS commit
This commit is contained in:
parent
fcd719186c
commit
34faed3cf0
2 changed files with 30 additions and 25 deletions
|
|
@ -2096,7 +2096,7 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
|
||||||
// on the fly to not trash the gluing points
|
// on the fly to not trash the gluing points
|
||||||
if i == len(res.hashes)-1 && res.subTask != nil {
|
if i == len(res.hashes)-1 && res.subTask != nil {
|
||||||
res.subTask.genTrie.AddProof(res.roots[i], res.origin[:], res.proof)
|
res.subTask.genTrie.AddProof(res.roots[i], res.origin[:], res.proof)
|
||||||
res.subTask.genTrie.UpdateAll(res.hashes[i], res.slots[i])
|
res.subTask.genTrie.UpdateAll(res.hashes[i], res.slots[i], res.cont)
|
||||||
}
|
}
|
||||||
// Persist the received storage segments. These flat state maybe
|
// Persist the received storage segments. These flat state maybe
|
||||||
// outdated during the sync, but it can be fixed later during the
|
// outdated during the sync, but it can be fixed later during the
|
||||||
|
|
|
||||||
|
|
@ -421,36 +421,32 @@ type GenerativeTrie struct {
|
||||||
writeFn NodeWriteFunc
|
writeFn NodeWriteFunc
|
||||||
stack *StackTrie
|
stack *StackTrie
|
||||||
|
|
||||||
|
leftHandBorder []byte
|
||||||
rightHandBorder []byte
|
rightHandBorder []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGentrie(origin, end common.Hash, writeFn NodeWriteFunc) *GenerativeTrie {
|
func NewGentrie(origin, end common.Hash, writeFn NodeWriteFunc) *GenerativeTrie {
|
||||||
var g = &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
|
// Wrap the write function
|
||||||
var originBorder = keybytesToHex(origin[:])
|
|
||||||
wrapper := func(path []byte, hash common.Hash, blob []byte) {
|
wrapper := func(path []byte, hash common.Hash, blob []byte) {
|
||||||
if bytes.HasPrefix(originBorder, path) {
|
if g.leftHandBorder != nil && bytes.HasPrefix(g.leftHandBorder, path) {
|
||||||
//fmt.Printf("1. Skipping path %x\n", path)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.HasPrefix(g.rightHandBorder, path) {
|
if g.rightHandBorder != nil && bytes.HasPrefix(g.rightHandBorder, path) {
|
||||||
//fmt.Printf("2. Skipping path %x\n", path)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeFn(path, hash, blob)
|
writeFn(path, hash, blob)
|
||||||
}
|
}
|
||||||
|
// If origin is non-zero, we can set the left hand border right away.
|
||||||
|
if origin != (common.Hash{}) {
|
||||||
|
g.leftHandBorder = keybytesToHex(origin[:])
|
||||||
|
} else {
|
||||||
|
// If origin is zero. then no proof-init will be needed, and we can
|
||||||
|
// set the internal stacktrie.
|
||||||
|
g.stack = NewStackTrie(writeFn)
|
||||||
|
}
|
||||||
g.writeFn = wrapper
|
g.writeFn = wrapper
|
||||||
}
|
|
||||||
|
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -467,15 +463,24 @@ func (g *GenerativeTrie) AddProof(rootHash common.Hash, origin []byte, proof eth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GenerativeTrie) UpdateAll(keys []common.Hash, values [][]byte) error {
|
func (g *GenerativeTrie) UpdateAll(keys []common.Hash, values [][]byte, hasMore bool) error {
|
||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
last := keys[len(keys)-1]
|
||||||
|
// If the trie has more elements, then we can (for now) set the right-hand
|
||||||
|
// border: in case Commit or Hash is called, having the border set prevents
|
||||||
|
// nodes on the boundary from being comitted.
|
||||||
|
if hasMore {
|
||||||
|
g.rightHandBorder = keybytesToHex(last[:])
|
||||||
|
} else {
|
||||||
|
// If we know that all elements have been inserted, we must remove
|
||||||
|
// the border, and let the nodes be comitted.
|
||||||
|
g.rightHandBorder = nil
|
||||||
|
}
|
||||||
for i := 0; i < len(keys); i++ {
|
for i := 0; i < len(keys); i++ {
|
||||||
g.stack.Update(keys[i][:], values[i])
|
g.stack.Update(keys[i][:], values[i])
|
||||||
}
|
}
|
||||||
last := keys[len(keys)-1]
|
|
||||||
g.rightHandBorder = keybytesToHex(last[:])
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue