fix nil block (#2638)

This commit is contained in:
Raul Jordan 2019-05-17 21:31:28 -04:00 committed by GitHub
parent 85ef099360
commit d43ea74244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,19 +278,21 @@ func (c *ChainService) runStateTransition(
}
// Prune the block cache on every new finalized epoch.
if newState.FinalizedEpoch > finalizedEpoch {
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {
return nil, err
if block != nil {
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {
return nil, err
}
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
return nil, err
}
c.p2p.Broadcast(ctx, &pb.FinalizedStateAnnounce{
BlockRoot: blockRoot[:],
StateRoot: stateRoot[:],
Slot: beaconState.Slot,
})
}
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
return nil, err
}
c.p2p.Broadcast(ctx, &pb.FinalizedStateAnnounce{
BlockRoot: blockRoot[:],
StateRoot: stateRoot[:],
Slot: beaconState.Slot,
})
c.beaconDB.ClearBlockCache()
}
log.WithField(