Skip to content
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
15 changes: 14 additions & 1 deletion consensus/spos/bls/v2/subroundBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/hex"
"sync"
"time"

"github.com/multiversx/mx-chain-core-go/core"
Expand All @@ -25,6 +26,7 @@ type subroundBlock struct {

processingThresholdPercentage int
worker spos.WorkerHandler
mutBlockProcessing sync.Mutex
}

// NewSubroundBlock creates a subroundBlock object
Expand Down Expand Up @@ -555,10 +557,13 @@ func (sr *subroundBlock) receivedBlockHeader(headerHandler data.HeaderHandler) {

// CanProcessReceivedHeader method returns true if the received header can be processed and false otherwise
func (sr *subroundBlock) CanProcessReceivedHeader(headerLeader string) bool {
return sr.shouldProcessBlock(headerLeader)
}

func (sr *subroundBlock) shouldProcessBlock(headerLeader string) bool {
if sr.IsNodeSelf(headerLeader) {
return false
}

if sr.IsJobDone(headerLeader, sr.Current()) {
return false
}
Expand All @@ -582,6 +587,9 @@ func (sr *subroundBlock) processReceivedBlock(
return false
}

sr.mutBlockProcessing.Lock()
defer sr.mutBlockProcessing.Unlock()

defer func() {
sr.SetProcessingBlock(false)
}()
Expand All @@ -599,6 +607,11 @@ func (sr *subroundBlock) processReceivedBlock(
return false
}

// check again under critical section to avoid double execution
if !sr.shouldProcessBlock(string(senderPK)) {
return false
}

return sr.processBlock(ctx, round, senderPK)
}

Expand Down