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

mpool: fix: data race when adding messages #10771

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,11 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {

//ensures computations are cached without holding lock
_, _ = mp.api.GetActorAfter(m.Message.From, tmpCurTs)

//Lock is required for getStateNonce to resolve addresses
mp.curTsLk.RLock()
_, _ = mp.getStateNonce(ctx, m.Message.From, tmpCurTs)
mp.curTsLk.RUnlock()

mp.curTsLk.Lock()
if tmpCurTs == mp.curTs {
Expand All @@ -780,8 +784,14 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {
tmpCurTs = mp.curTs
//we want to release the lock, cache the computations then grab it again
mp.curTsLk.Unlock()

_, _ = mp.api.GetActorAfter(m.Message.From, tmpCurTs)

//Lock is required for getStateNonce to resolve addresses
mp.curTsLk.RLock()
_, _ = mp.getStateNonce(ctx, m.Message.From, tmpCurTs)
mp.curTsLk.RUnlock()

mp.curTsLk.Lock()
//now that we have the lock, we continue, we could do this as a loop forever, but that's bad to loop forever, and this was added as an optimization and it seems once is enough because the computation < block time
}
Expand Down