[viewchange] simplify GetPreparedBlock function

Signed-off-by: Leo Chen <leo@harmony.one>
pull/3388/head
Leo Chen 4 years ago
parent 72735d3a37
commit 537ec78636
  1. 21
      consensus/view_change_construct.go

@ -113,18 +113,19 @@ func (vc *viewChange) GetPreparedBlock(fbftlog *FBFTLog, hash [32]byte) ([]byte,
vc.vcLock.RLock()
defer vc.vcLock.RUnlock()
if !vc.isM1PayloadEmpty() {
block := fbftlog.GetBlockByHash(hash)
if block != nil {
encodedBlock, err := rlp.EncodeToBytes(block)
if err != nil || len(encodedBlock) == 0 {
vc.getLogger().Err(err).Msg("[GetPreparedBlock] Failed encoding prepared block")
return vc.m1Payload, nil
}
return vc.m1Payload, encodedBlock
if vc.isM1PayloadEmpty() {
return nil, nil
}
if block := fbftlog.GetBlockByHash(hash); block != nil {
encodedBlock, err := rlp.EncodeToBytes(block)
if err != nil || len(encodedBlock) == 0 {
return nil, nil
}
return vc.m1Payload, encodedBlock
}
return vc.m1Payload, nil
return nil, nil
}
// GetM2Bitmap returns the nilBitmap as M2Bitmap

Loading…
Cancel
Save