Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix base buffer concurrent read/write race #88

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
owen-reorg marked this conversation as resolved.
Show resolved Hide resolved
w.nf.baseMux.RUnlock()
if err != nil {
return nil, err
}
Expand Down
Loading