add concurrent waitgroup ops#7895
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feat/testnet-fixes #7895 +/- ##
===================================================
Coverage 77.68% 77.68%
===================================================
Files 885 885
Lines 125916 125940 +24
===================================================
+ Hits 97812 97841 +29
+ Misses 21624 21617 -7
- Partials 6480 6482 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends the SPoS consensus state API to support safer concurrent operations by adding (1) an atomic “set once” data setter and (2) a wait-group operation that applies Add() under the consensus state lock and returns the exact wait-group instance used. It then updates the BLS v2 subround block flow to use these APIs, adds tests, and introduces a panic-recovery guard in Worker.ReceivedHeader.
Changes:
- Add
SetDataIfNotSet([]byte) boolandSignaturesWaitGroupAdd(delta int) *sync.WaitGroupto theConsensusStateHandlerAPI and implement them inConsensusState. - Update BLS v2
subroundBlockto use the new wait-group add API and to avoid overwriting consensus data if it is already set. - Add unit tests covering the new consensus state methods; add a
recover()guard inWorker.ReceivedHeader.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| testscommon/consensus/consensusStateMock.go | Extends consensus state mock with new interface methods. |
| consensus/spos/worker.go | Adds panic recovery wrapper to Worker.ReceivedHeader. |
| consensus/spos/interface.go | Extends ConsensusStateHandler with two new methods. |
| consensus/spos/consensusState.go | Implements atomic data set and locked wait-group add returning the applied instance. |
| consensus/spos/consensusState_test.go | Adds tests for SetDataIfNotSet and SignaturesWaitGroupAdd. |
| consensus/spos/bls/v2/subroundBlock.go | Switches to new wait-group add API; avoids double-setting consensus data on received header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // SetDataIfNotSet - | ||
| func (cnsm *ConsensusStateMock) SetDataIfNotSet(data []byte) bool { | ||
| if cnsm.SetDataIfNotSetCalled != nil { | ||
| return cnsm.SetDataIfNotSetCalled(data) | ||
| } | ||
|
|
||
| return true | ||
| } |
Reasoning behind the pull request
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?