Compare commits

...

1 Commits

Author SHA1 Message Date
frozen a1c39a9b00
Get only valid blocks. 9 months ago
  1. 13
      consensus/fbft_log.go
  2. 4
      consensus/view_change_msg.go

@ -222,11 +222,20 @@ func (log *FBFTLog) GetMessagesByTypeSeqViewHash(typ msg_pb.MessageType, blockNu
return found
}
func (log *FBFTLog) all(filters []func(*FBFTMessage, *FBFTLog) bool, value *FBFTMessage) bool {
for _, filter := range filters {
if !filter(value, log) {
return false
}
}
return true
}
// GetMessagesByTypeSeq returns pbft messages with matching type, blockNum
func (log *FBFTLog) GetMessagesByTypeSeq(typ msg_pb.MessageType, blockNum uint64) []*FBFTMessage {
func (log *FBFTLog) GetMessagesByTypeSeq(typ msg_pb.MessageType, blockNum uint64, filters ...func(message *FBFTMessage, log *FBFTLog) bool) []*FBFTMessage {
var found []*FBFTMessage
for _, msg := range log.messages {
if msg.MessageType == typ && msg.BlockNum == blockNum && msg.Verified {
if msg.MessageType == typ && msg.BlockNum == blockNum && msg.Verified && log.all(filters, msg) {
found = append(found, msg)
}
}

@ -33,7 +33,9 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra
}
preparedMsgs := consensus.fBFTLog.GetMessagesByTypeSeq(
msg_pb.MessageType_PREPARED, consensus.getBlockNum(),
msg_pb.MessageType_PREPARED, consensus.getBlockNum(), func(message *FBFTMessage, log *FBFTLog) bool {
return log.IsBlockVerified(message.BlockHash)
},
)
preparedMsg := consensus.fBFTLog.FindMessageByMaxViewID(preparedMsgs)

Loading…
Cancel
Save