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

Subround endround v2 fixes #6683

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
39 changes: 23 additions & 16 deletions consensus/spos/bls/v2/subroundEndRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func (sr *subroundEndRound) doEndRoundJob(_ context.Context) bool {
return false
}

sr.mutProcessingEndRound.Lock()
defer sr.mutProcessingEndRound.Unlock()

return sr.doEndRoundJobByNode()
}

Expand All @@ -240,14 +243,17 @@ func (sr *subroundEndRound) commitBlock() error {
}

func (sr *subroundEndRound) doEndRoundJobByNode() bool {
if !sr.waitForSignalSync() {
return false
if sr.shouldSendProof() {
if !sr.waitForSignalSync() {
return false
}
}

sr.mutProcessingEndRound.Lock()
defer sr.mutProcessingEndRound.Unlock()
proof, ok := sr.sendProof()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the empty line here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

proof := sr.sendProof()
if !ok {
return false
}

err := sr.commitBlock()
if err != nil {
Expand Down Expand Up @@ -277,41 +283,42 @@ func (sr *subroundEndRound) doEndRoundJobByNode() bool {
return true
}

func (sr *subroundEndRound) sendProof() data.HeaderProofHandler {
func (sr *subroundEndRound) sendProof() (data.HeaderProofHandler, bool) {
if !sr.shouldSendProof() {
return nil
return nil, true
}

bitmap := sr.GenerateBitmap(bls.SrSignature)
err := sr.checkSignaturesValidity(bitmap)
if err != nil {
log.Debug("sendProof.checkSignaturesValidity", "error", err.Error())
return nil
return nil, false
}

// Aggregate signatures, handle invalid signers and send final info if needed
bitmap, sig, err := sr.aggregateSigsAndHandleInvalidSigners(bitmap)
if err != nil {
log.Debug("sendProof.aggregateSigsAndHandleInvalidSigners", "error", err.Error())
return nil
return nil, false
}

ok := sr.ScheduledProcessor().IsProcessedOKWithTimeout()
// placeholder for subroundEndRound.doEndRoundJobByLeader script
if !ok {
return nil
return nil, false
}

roundHandler := sr.RoundHandler()
if roundHandler.RemainingTime(roundHandler.TimeStamp(), roundHandler.TimeDuration()) < 0 {
log.Debug("sendProof: time is out -> cancel broadcasting final info and header",
"round time stamp", roundHandler.TimeStamp(),
"current time", time.Now())
return nil
return nil, false
}

// broadcast header proof
return sr.createAndBroadcastProof(sig, bitmap)
proof, err := sr.createAndBroadcastProof(sig, bitmap)
return proof, err == nil
}

func (sr *subroundEndRound) shouldSendProof() bool {
Expand Down Expand Up @@ -519,7 +526,7 @@ func (sr *subroundEndRound) computeAggSigOnValidNodes() ([]byte, []byte, error)
return bitmap, sig, nil
}

func (sr *subroundEndRound) createAndBroadcastProof(signature []byte, bitmap []byte) *block.HeaderProof {
func (sr *subroundEndRound) createAndBroadcastProof(signature []byte, bitmap []byte) (*block.HeaderProof, error) {
headerProof := &block.HeaderProof{
PubKeysBitmap: bitmap,
AggregatedSignature: signature,
Expand All @@ -531,14 +538,14 @@ func (sr *subroundEndRound) createAndBroadcastProof(signature []byte, bitmap []b

err := sr.BroadcastMessenger().BroadcastEquivalentProof(headerProof, []byte(sr.SelfPubKey()))
if err != nil {
return nil
return nil, err
}

log.Debug("step 3: block header proof has been sent",
"PubKeysBitmap", bitmap,
"AggregateSignature", signature)

return headerProof
return headerProof, nil
}

func (sr *subroundEndRound) createAndBroadcastInvalidSigners(invalidSigners []byte) {
Expand Down Expand Up @@ -710,7 +717,7 @@ func (sr *subroundEndRound) waitForSignalSync() bool {
case <-timerBetweenStatusChecks.C:
if sr.IsSubroundFinished(sr.Current()) {
log.Trace("subround already finished", "subround", sr.Name())
return false
return true
}

if sr.checkReceivedSignatures() {
Expand Down
7 changes: 6 additions & 1 deletion consensus/spos/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,12 @@ func (wrk *Worker) AddReceivedHeaderHandler(handler func(data.HeaderHandler)) {

// ReceivedProof process the received proof, calling each received proof handler registered in worker instance
func (wrk *Worker) ReceivedProof(proofHandler consensus.ProofHandler) {
// TODO: add preliminary checks
if check.IfNilReflect(proofHandler) {
log.Trace("ReceivedProof: nil proof handler")
return
}

log.Trace("ReceivedProof:", "proof header", proofHandler.GetHeaderHash())

wrk.mutReceivedProofHandler.RLock()
for _, handler := range wrk.receivedProofHandlers {
Expand Down
Loading