mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Update sync.go
This commit is contained in:
parent
5342dd54e5
commit
4c30df6075
1 changed files with 16 additions and 17 deletions
33
trie/sync.go
33
trie/sync.go
|
|
@ -259,15 +259,14 @@ func (s *Sync) AddSubTrie(root common.Hash, path []byte, parent common.Hash, par
|
||||||
// Short circuit if the trie is empty.
|
// Short circuit if the trie is empty.
|
||||||
if root == types.EmptyRootHash {
|
if root == types.EmptyRootHash {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Short circuit if the trie is already known.
|
|
||||||
owner, inner := ResolvePath(path)
|
owner, inner := ResolvePath(path)
|
||||||
exist, mismatch := s.hasNode(owner, inner, root)
|
exist, inconsistent := s.hasNode(owner, inner, root)
|
||||||
if exist {
|
if exist {
|
||||||
|
// The entire subtrie is already present in the database.
|
||||||
return
|
return
|
||||||
}
|
} else if inconsistent {
|
||||||
if mismatch {
|
// There is a pre-existing node with the wrong hash in DB, remove it.
|
||||||
// The node is inconsistent with and needs to be removed.
|
|
||||||
s.membatch.delNode(owner, inner)
|
s.membatch.delNode(owner, inner)
|
||||||
}
|
}
|
||||||
// Assemble the new sub-trie sync request
|
// Assemble the new sub-trie sync request
|
||||||
|
|
@ -593,22 +592,22 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the child references another node, resolve or schedule
|
// If the child references another node, resolve or schedule.
|
||||||
|
// We check all children concurrently.
|
||||||
if node, ok := (child.node).(hashNode); ok {
|
if node, ok := (child.node).(hashNode); ok {
|
||||||
// Check the presence of children concurrently
|
path := child.path
|
||||||
|
hash := common.BytesToHash(node)
|
||||||
pending.Add(1)
|
pending.Add(1)
|
||||||
go func(path []byte, hash common.Hash) {
|
go func() {
|
||||||
defer pending.Done()
|
defer pending.Done()
|
||||||
|
|
||||||
// Short circuit if the child node is already known.
|
|
||||||
owner, inner := ResolvePath(path)
|
owner, inner := ResolvePath(path)
|
||||||
exist, mismatch := s.hasNode(owner, inner, hash)
|
exist, inconsistent := s.hasNode(owner, inner, hash)
|
||||||
if exist {
|
if exist {
|
||||||
return
|
return
|
||||||
}
|
} else if inconsistent {
|
||||||
if mismatch {
|
// There is a pre-existing node with the wrong hash in DB, remove it.
|
||||||
batchMu.Lock()
|
batchMu.Lock()
|
||||||
s.membatch.delNode(owner, inner) // remove the inconsistent node
|
s.membatch.delNode(owner, inner)
|
||||||
batchMu.Unlock()
|
batchMu.Unlock()
|
||||||
}
|
}
|
||||||
// Locally unknown node, schedule for retrieval
|
// Locally unknown node, schedule for retrieval
|
||||||
|
|
@ -618,7 +617,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
|
||||||
parent: req,
|
parent: req,
|
||||||
callback: req.callback,
|
callback: req.callback,
|
||||||
}
|
}
|
||||||
}(child.path, common.BytesToHash(node))
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pending.Wait()
|
pending.Wait()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue