Skip to content

Commit

Permalink
delete race condition (hyperledger-labs#566) (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Fedor Partanskiy <[email protected]>
Co-authored-by: pfi79 <[email protected]>
  • Loading branch information
HagarMeir and pfi79 authored Feb 14, 2024
1 parent a126c0e commit 22f356d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/bft/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Controller struct {
decisionChan chan decision
deliverChan chan struct{}
leaderToken chan struct{}
verificationSequence uint64
verificationSequence atomic.Uint64

controllerDone sync.WaitGroup

Expand Down Expand Up @@ -629,7 +629,7 @@ func (c *Controller) sync() (viewNum uint64, seq uint64, decisions uint64) {
c.Logger.Infof("Synchronizer returned with sequence %d while the controller is at sequence %d", latestDecisionSeq, controllerSequence)
c.Logger.Debugf("Node %d is setting the checkpoint after sync returned with view %d and seq %d", c.ID, latestDecisionViewNum, latestDecisionSeq)
c.Checkpoint.Set(latestDecision.Proposal, latestDecision.Signatures)
c.verificationSequence = uint64(latestDecision.Proposal.VerificationSequence)
c.verificationSequence.Store(uint64(latestDecision.Proposal.VerificationSequence))
newProposalSequence = latestDecisionSeq + 1
newDecisionsInView = latestDecisionDecisions + 1
}
Expand Down Expand Up @@ -733,12 +733,12 @@ func (c *Controller) relinquishSyncToken() {

// MaybePruneRevokedRequests prunes requests with different verification sequence
func (c *Controller) MaybePruneRevokedRequests() {
oldVerSqn := c.verificationSequence
oldVerSqn := c.verificationSequence.Load()
newVerSqn := c.Verifier.VerificationSequence()
if newVerSqn == oldVerSqn {
return
}
c.verificationSequence = newVerSqn
c.verificationSequence.Store(newVerSqn)

c.Logger.Infof("Verification sequence changed: %d --> %d", oldVerSqn, newVerSqn)
c.RequestPool.Prune(func(req []byte) error {
Expand Down Expand Up @@ -796,7 +796,7 @@ func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64,
c.Logger.Debugf("The number of nodes (N) is %d, F is %d, and the quorum size is %d", c.N, F, Q)
c.quorum = Q

c.verificationSequence = c.Verifier.VerificationSequence()
c.verificationSequence.Store(c.Verifier.VerificationSequence())

if syncOnStart {
startViewNumber, startProposalSequence, startDecisionsInView = c.syncOnStart(startViewNumber, startProposalSequence, startDecisionsInView)
Expand Down

0 comments on commit 22f356d

Please sign in to comment.