Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Feb 11, 2025
1 parent a69c70f commit bf92b84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
27 changes: 14 additions & 13 deletions process/block/baseProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ func (bp *baseProcessor) requestNextHeader(currentHeaderHash []byte, nonce uint6
}
}

func (bp *baseProcessor) waitAllMissingProofs() error {
func (bp *baseProcessor) waitAllMissingProofs(waitTime time.Duration) error {
bp.mutRequestedAttestingNoncesMap.RLock()
isWaitingForProofs := len(bp.requestedAttestingNoncesMap) > 0
bp.mutRequestedAttestingNoncesMap.RUnlock()
Expand All @@ -2381,7 +2381,7 @@ func (bp *baseProcessor) waitAllMissingProofs() error {
select {
case <-bp.allProofsReceived:
return nil
case <-time.After(bp.extraDelayRequestBlockInfo):
case <-time.After(waitTime):
bp.mutRequestedAttestingNoncesMap.RLock()
defer bp.mutRequestedAttestingNoncesMap.RUnlock()

Expand All @@ -2396,7 +2396,7 @@ func (bp *baseProcessor) waitAllMissingProofs() error {
}
}

func (bp *baseProcessor) checkReceivedHeaderAndUpdateMissingAttesting(headerHandler data.HeaderHandler) {
func (bp *baseProcessor) checkReceivedHeaderIfAttestingIsNeeded(headerHandler data.HeaderHandler) {
if !common.ShouldBlockHavePrevProof(headerHandler, bp.enableEpochsHandler, common.EquivalentMessagesFlag) {
return
}
Expand All @@ -2408,29 +2408,30 @@ func (bp *baseProcessor) checkReceivedHeaderAndUpdateMissingAttesting(headerHand
return
}

allProofsReceived := bp.checkReceivedHeaderAndUpdateMissingAttesting(headerHandler)
if allProofsReceived {
bp.allProofsReceived <- true
}
}

func (bp *baseProcessor) checkReceivedHeaderAndUpdateMissingAttesting(headerHandler data.HeaderHandler) bool {
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
return len(bp.requestedAttestingNoncesMap) == 0
}

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

delete(bp.requestedAttestingNoncesMap, string(prevHash))

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

if allProofsReceived {
bp.allProofsReceived <- true
}
return len(bp.requestedAttestingNoncesMap) == 0
}
10 changes: 5 additions & 5 deletions process/block/metablock.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (mp *metaProcessor) ProcessBlock(
}
}

err = mp.checkProofsForShardData(header)
err = mp.checkProofsForShardData(header, haveTime())
if err != nil {
return err
}
Expand Down Expand Up @@ -418,15 +418,15 @@ func (mp *metaProcessor) ProcessBlock(
return nil
}

func (mp *metaProcessor) checkProofsForShardData(header *block.MetaBlock) error {
func (mp *metaProcessor) checkProofsForShardData(header *block.MetaBlock, waitTime time.Duration) error {
if !(mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, header.Epoch) && header.GetNonce() > 1) {
return nil
}

mp.mutRequestedAttestingNoncesMap.Lock()
mp.requestedAttestingNoncesMap = make(map[string]uint64)
_ = core.EmptyChannel(mp.allProofsReceived)
mp.mutRequestedAttestingNoncesMap.Unlock()
_ = core.EmptyChannel(mp.allProofsReceived)

for _, shardData := range header.ShardInfo {
// TODO: consider the validation of the proof:
Expand Down Expand Up @@ -466,7 +466,7 @@ func (mp *metaProcessor) checkProofsForShardData(header *block.MetaBlock) error
}
}

return mp.waitAllMissingProofs()
return mp.waitAllMissingProofs(waitTime)
}

func (mp *metaProcessor) processEpochStartMetaBlock(
Expand Down Expand Up @@ -2075,7 +2075,7 @@ func (mp *metaProcessor) receivedShardHeader(headerHandler data.HeaderHandler, s
"hash", shardHeaderHash,
)

mp.checkReceivedHeaderAndUpdateMissingAttesting(headerHandler)
mp.checkReceivedHeaderIfAttestingIsNeeded(headerHandler)

mp.hdrsForCurrBlock.mutHdrsForBlock.Lock()

Expand Down
6 changes: 3 additions & 3 deletions process/block/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ func (sp *shardProcessor) ProcessBlock(

sp.mutRequestedAttestingNoncesMap.Lock()
sp.requestedAttestingNoncesMap = make(map[string]uint64)
_ = core.EmptyChannel(sp.allProofsReceived)
sp.mutRequestedAttestingNoncesMap.Unlock()
_ = core.EmptyChannel(sp.allProofsReceived)

// check proofs for cross notarized metablocks
for _, metaBlockHash := range header.GetMetaBlockHashes() {
Expand All @@ -312,7 +312,7 @@ func (sp *shardProcessor) ProcessBlock(
sp.checkProofRequestingNextHeaderIfMissing(core.MetachainShardId, metaBlockHash, hInfo.hdr.GetNonce())
}

err = sp.waitAllMissingProofs()
err = sp.waitAllMissingProofs(haveTime())
if err != nil {
return err
}
Expand Down Expand Up @@ -1763,7 +1763,7 @@ func (sp *shardProcessor) receivedMetaBlock(headerHandler data.HeaderHandler, me
"hash", metaBlockHash,
)

sp.checkReceivedHeaderAndUpdateMissingAttesting(headerHandler)
sp.checkReceivedHeaderIfAttestingIsNeeded(headerHandler)

sp.hdrsForCurrBlock.mutHdrsForBlock.Lock()

Expand Down

0 comments on commit bf92b84

Please sign in to comment.