Skip to content

Commit

Permalink
fix: check for nil bcastDict (#10646)
Browse files Browse the repository at this point in the history
Also hold the lock when checking the length of the blocks in the
bcastDict.
  • Loading branch information
Stebalien authored Apr 18, 2023
1 parent 0befed7 commit e945c0d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions chain/sub/bcast/consistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,22 @@ func (cb *ConsistentBCast) RcvBlock(ctx context.Context, blk *types.BlockMsg) {
// be held off for a bit more time.
func (cb *ConsistentBCast) WaitForDelivery(bh *types.BlockHeader) error {
cb.lk.RLock()
bcastDict := cb.m[bh.Height]
defer cb.lk.RUnlock()

bcastDict, ok := cb.m[bh.Height]
if !ok {
return xerrors.Errorf("block at height %d garbage collected before it could be processed", bh.Height)
}
key := BCastKey(bh)
bInfo, ok := bcastDict.load(key)
cb.lk.RUnlock()
if !ok {
return xerrors.Errorf("something went wrong, unknown block with Epoch + VRFProof (cid=%s) in consistent broadcast storage", key)
}

// Wait for the timeout
cb.lk.RUnlock()
<-bInfo.ctx.Done()
cb.lk.RLock()
if bcastDict.blkLen(key) > 1 {
return xerrors.Errorf("equivocation detected for epoch %d. Two blocks being broadcast with same VRFProof", bh.Height)
}
Expand Down

0 comments on commit e945c0d

Please sign in to comment.