Skip to content

Commit

Permalink
fix: fix base buffer concurrent read/write race (#88)
Browse files Browse the repository at this point in the history
Co-authored-by: will@2012 <xibaow2020@qq.com>
  • Loading branch information
will-2012 and will@2012 authored Apr 23, 2024
1 parent 0b1f3ed commit d04dda4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions trie/triedb/pathdb/nodebufferlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func newNodeBufferList(
// node retrieves the trie node with given node info.
func (nf *nodebufferlist) node(owner common.Hash, path []byte, hash common.Hash) (node *trienode.Node, err error) {
nf.mux.RLock()
defer nf.mux.RUnlock()
find := func(nc *multiDifflayer) bool {
subset, ok := nc.nodes[owner]
if !ok {
Expand All @@ -141,14 +142,11 @@ func (nf *nodebufferlist) node(owner common.Hash, path []byte, hash common.Hash)
}
nf.traverse(find)
if err != nil {
nf.mux.RUnlock()
return nil, err
}
if node != nil {
nf.mux.RUnlock()
return node, nil
}
nf.mux.RUnlock()

nf.baseMux.RLock()
node, err = nf.base.node(owner, path, hash)
Expand Down Expand Up @@ -602,7 +600,9 @@ func (w *proposedBlockReader) Node(owner common.Hash, path []byte, hash common.H
current = current.next
}

w.nf.baseMux.RLock()
node, err := w.nf.base.node(owner, path, hash)
w.nf.baseMux.RUnlock()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d04dda4

Please sign in to comment.