add HasSingleSender func

pull/3374/head
Rongjian Lan 4 years ago
parent 8885eb45e0
commit 1851d7eea5
  1. 4
      consensus/checks.go
  2. 2
      consensus/consensus_service.go
  3. 2
      consensus/consensus_v2.go
  4. 7
      consensus/fbft_log.go
  5. 2
      consensus/fbft_log_test.go
  6. 4
      consensus/leader.go
  7. 2
      consensus/view_change.go
  8. 4
      consensus/view_change_construct.go

@ -72,7 +72,7 @@ func (consensus *Consensus) onAnnounceSanityChecks(recvMsg *FBFTMessage) bool {
msg_pb.MessageType_ANNOUNCE, recvMsg.BlockNum, recvMsg.ViewID,
)
if len(logMsgs) > 0 {
if len(logMsgs[0].SenderPubkeys) != 1 || len(recvMsg.SenderPubkeys) != 1 {
if !logMsgs[0].HasSingleSender() || !recvMsg.HasSingleSender() {
consensus.getLogger().Warn().
Str("logMsgs[0]", logMsgs[0].String()).
Str("recvMsg", recvMsg.String()).
@ -174,7 +174,7 @@ func (consensus *Consensus) onViewChangeSanityCheck(recvMsg *FBFTMessage) bool {
return false
}
if len(recvMsg.SenderPubkeys) != 1 {
if !recvMsg.HasSingleSender() {
consensus.getLogger().Error().Msg("[onViewChangeSanityCheck] zero or multiple signers in view change message.")
return false
}

@ -200,7 +200,7 @@ func (consensus *Consensus) checkViewID(msg *FBFTMessage) error {
//so only set mode to normal when new node enters consensus and need checking viewID
consensus.current.SetMode(Normal)
consensus.SetViewIDs(msg.ViewID)
if len(msg.SenderPubkeys) != 1 {
if !msg.HasSingleSender() {
return errors.New("Leader message can not have multiple sender keys")
}
consensus.LeaderPubKey = msg.SenderPubkeys[0]

@ -520,7 +520,7 @@ func (consensus *Consensus) commitBlock(blk *types.Block, committedMsg *FBFTMess
if err := consensus.OnConsensusDone(blk); err != nil {
return err
}
if len(committedMsg.SenderPubkeys) != 1 {
if !committedMsg.HasSingleSender() {
consensus.getLogger().Error().Msg("[TryCatchup] Leader message can not have multiple sender keys")
}

@ -60,6 +60,11 @@ func (m *FBFTMessage) String() string {
)
}
// HasSingleSender returns whether the message has only a single sender
func (m *FBFTMessage) HasSingleSender() bool {
return len(m.SenderPubkeys) == 1
}
const (
idTypeBytes = 4
idViewIDBytes = 8
@ -82,7 +87,7 @@ func (m *FBFTMessage) id() fbftMsgID {
binary.LittleEndian.PutUint64(id[idTypeBytes:], m.ViewID)
copy(id[idTypeBytes+idViewIDBytes:], m.BlockHash[:])
if len(m.SenderPubkeys) == 1 {
if m.HasSingleSender() {
copy(id[idTypeBytes+idViewIDBytes+idHashBytes:], m.SenderPubkeys[0].Bytes[:])
} else {
copy(id[idTypeBytes+idViewIDBytes+idHashBytes:], m.SenderPubkeyBitmap[:])

@ -39,7 +39,7 @@ func TestFBFTLog_id(t *testing.T) {
if !bytes.Equal(id[idTypeBytes+idViewIDBytes:idTypeBytes+idViewIDBytes+idHashBytes], msg.BlockHash[:]) {
t.Errorf("block hash not expected")
}
if len(msg.SenderPubkeys) != 1 {
if !msg.HasSingleSender() {
if !bytes.Equal(id[idTypeBytes+idViewIDBytes+idHashBytes:idTypeBytes+idViewIDBytes+idHashBytes+len(msg.SenderPubkeyBitmap)], msg.SenderPubkeyBitmap[:]) {
t.Errorf("sender key expected to be the bitmap when key list is not size 1")
}

@ -155,7 +155,7 @@ func (consensus *Consensus) onPrepare(msg *msg_pb.Message) {
return
}
signerPubKey := &bls_core.PublicKey{}
if len(recvMsg.SenderPubkeys) == 1 {
if recvMsg.HasSingleSender() {
signerPubKey = recvMsg.SenderPubkeys[0].Object
} else {
for _, pubKey := range recvMsg.SenderPubkeys {
@ -250,7 +250,7 @@ func (consensus *Consensus) onCommit(msg *msg_pb.Message) {
Logger()
signerPubKey := &bls_core.PublicKey{}
if len(recvMsg.SenderPubkeys) == 1 {
if recvMsg.HasSingleSender() {
signerPubKey = recvMsg.SenderPubkeys[0].Object
} else {
for _, pubKey := range recvMsg.SenderPubkeys {

@ -323,7 +323,7 @@ func (consensus *Consensus) onNewView(msg *msg_pb.Message) {
return
}
if len(recvMsg.SenderPubkeys) != 1 {
if !recvMsg.HasSingleSender() {
consensus.getLogger().Error().Msg("[onNewView] multiple signers in view change message.")
return
}

@ -254,8 +254,8 @@ func (vc *viewChange) ProcessViewChangeMsg(
defer vc.vcLock.Unlock()
preparedBlock := &types.Block{}
if len(recvMsg.SenderPubkeys) != 1 {
return errNoQuorum
if !recvMsg.HasSingleSender() {
return errIncorrectSender
}
senderKey := recvMsg.SenderPubkeys[0]
senderKeyStr := senderKey.Bytes.Hex()

Loading…
Cancel
Save