Skip to content

Commit

Permalink
do not write on chan under mut protection
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Feb 11, 2025
1 parent ea0b8ef commit 7bf2b24
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions process/block/baseProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2409,24 +2409,28 @@ func (bp *baseProcessor) checkReceivedHeaderAndUpdateMissingAttesting(headerHand
}

bp.mutRequestedAttestingNoncesMap.Lock()
defer bp.mutRequestedAttestingNoncesMap.Unlock()

receivedShard := headerHandler.GetShardID()
prevHash := headerHandler.GetPrevHash()
_, isHeaderWithoutProof := bp.requestedAttestingNoncesMap[string(prevHash)]
if !isHeaderWithoutProof {
log.Debug("received header does not have previous hash any of the requested ones")
bp.mutRequestedAttestingNoncesMap.Unlock()
return
}

if !bp.proofsPool.HasProof(receivedShard, prevHash) {
log.Debug("received next header but proof is still missing", "hash", hex.EncodeToString(prevHash))
bp.mutRequestedAttestingNoncesMap.Unlock()
return
}

delete(bp.requestedAttestingNoncesMap, string(prevHash))

if len(bp.requestedAttestingNoncesMap) == 0 {
allProofsReceived := len(bp.requestedAttestingNoncesMap) == 0
bp.mutRequestedAttestingNoncesMap.Unlock()

if allProofsReceived {
bp.allProofsReceived <- true
}
}

0 comments on commit 7bf2b24

Please sign in to comment.