44 "bytes"
55 "context"
66 "encoding/hex"
7+ "sync"
78 "time"
89
910 "github.com/multiversx/mx-chain-core-go/core"
@@ -25,6 +26,7 @@ type subroundBlock struct {
2526
2627 processingThresholdPercentage int
2728 worker spos.WorkerHandler
29+ mutBlockProcessing sync.Mutex
2830}
2931
3032// NewSubroundBlock creates a subroundBlock object
@@ -555,10 +557,13 @@ func (sr *subroundBlock) receivedBlockHeader(headerHandler data.HeaderHandler) {
555557
556558// CanProcessReceivedHeader method returns true if the received header can be processed and false otherwise
557559func (sr * subroundBlock ) CanProcessReceivedHeader (headerLeader string ) bool {
560+ return sr .shouldProcessBlock (headerLeader )
561+ }
562+
563+ func (sr * subroundBlock ) shouldProcessBlock (headerLeader string ) bool {
558564 if sr .IsNodeSelf (headerLeader ) {
559565 return false
560566 }
561-
562567 if sr .IsJobDone (headerLeader , sr .Current ()) {
563568 return false
564569 }
@@ -582,6 +587,9 @@ func (sr *subroundBlock) processReceivedBlock(
582587 return false
583588 }
584589
590+ sr .mutBlockProcessing .Lock ()
591+ defer sr .mutBlockProcessing .Unlock ()
592+
585593 defer func () {
586594 sr .SetProcessingBlock (false )
587595 }()
@@ -599,6 +607,11 @@ func (sr *subroundBlock) processReceivedBlock(
599607 return false
600608 }
601609
610+ // check again under critical section to avoid double execution
611+ if ! sr .shouldProcessBlock (string (senderPK )) {
612+ return false
613+ }
614+
602615 return sr .processBlock (ctx , round , senderPK )
603616}
604617
0 commit comments