fix: check for nil bcastDict (#10646)
Also hold the lock when checking the length of the blocks in the bcastDict.
This commit is contained in:
parent
0befed7200
commit
e945c0d6f2
@ -151,16 +151,22 @@ func (cb *ConsistentBCast) RcvBlock(ctx context.Context, blk *types.BlockMsg) {
|
|||||||
// be held off for a bit more time.
|
// be held off for a bit more time.
|
||||||
func (cb *ConsistentBCast) WaitForDelivery(bh *types.BlockHeader) error {
|
func (cb *ConsistentBCast) WaitForDelivery(bh *types.BlockHeader) error {
|
||||||
cb.lk.RLock()
|
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)
|
key := BCastKey(bh)
|
||||||
bInfo, ok := bcastDict.load(key)
|
bInfo, ok := bcastDict.load(key)
|
||||||
cb.lk.RUnlock()
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return xerrors.Errorf("something went wrong, unknown block with Epoch + VRFProof (cid=%s) in consistent broadcast storage", key)
|
return xerrors.Errorf("something went wrong, unknown block with Epoch + VRFProof (cid=%s) in consistent broadcast storage", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the timeout
|
// Wait for the timeout
|
||||||
|
cb.lk.RUnlock()
|
||||||
<-bInfo.ctx.Done()
|
<-bInfo.ctx.Done()
|
||||||
|
cb.lk.RLock()
|
||||||
if bcastDict.blkLen(key) > 1 {
|
if bcastDict.blkLen(key) > 1 {
|
||||||
return xerrors.Errorf("equivocation detected for epoch %d. Two blocks being broadcast with same VRFProof", bh.Height)
|
return xerrors.Errorf("equivocation detected for epoch %d. Two blocks being broadcast with same VRFProof", bh.Height)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user