BlockHash [32]byte
Height uint64
Signature []byte
- PubKey [32]byte
+ PubKey []byte
}
//NewBlockSignatureMsg create new block signature msg.
-func NewBlockSignatureMsg(blockHash bc.Hash, height uint64, signature []byte, pubKey [32]byte) ConsensusMessage {
+func NewBlockSignatureMsg(blockHash bc.Hash, height uint64, signature []byte, pubKey []byte) ConsensusMessage {
hash := blockHash.Byte32()
return &BlockSignatureMsg{BlockHash: hash, Height: height, Signature: signature, PubKey: pubKey}
}
msg: &BlockSignatureMsg{
BlockHash: [32]byte{0x01},
Signature: []byte{0x00},
- PubKey: [32]byte{0x01},
+ PubKey: []byte{0x01},
},
msgType: blockSignatureByte,
},
BlockHash: [32]byte{0x01},
Height: 100,
Signature: []byte{0x00},
- PubKey: [32]byte{0x01},
+ PubKey: []byte{0x01},
}
signatureBroadcastMsg := NewBroadcastMsg(NewBlockSignatureMsg(bc.NewHash(blockSignMsg.BlockHash), blockSignMsg.Height, blockSignMsg.Signature, blockSignMsg.PubKey), consensusChannel)
BlockHash: [32]byte{0x01},
Height: 100,
Signature: []byte{0x00},
- PubKey: [32]byte{0x01},
+ PubKey: []byte{0x01},
}
gotMsg := NewBlockSignatureMsg(bc.NewHash(msg.BlockHash), msg.Height, msg.Signature, msg.PubKey)
if !reflect.DeepEqual(gotMsg, msg) {
t.Fatalf("test block signature message err. got:%s\n want:%s", spew.Sdump(gotMsg), spew.Sdump(msg))
}
- wantString := "{block_hash: 0100000000000000000000000000000000000000000000000000000000000000,block_height:100,signature:00,pubkey:0100000000000000000000000000000000000000000000000000000000000000}"
+ wantString := "{block_hash: 0100000000000000000000000000000000000000000000000000000000000000,block_height:100,signature:00,pubkey:01}"
if gotMsg.String() != wantString {
t.Fatalf("test block signature message err. got string:%s\n want string:%s", gotMsg.String(), wantString)
}
func (m *Manager) handleBlockSignatureMsg(peerID string, msg *BlockSignatureMsg) {
blockHash := bc.NewHash(msg.BlockHash)
- if err := m.chain.ProcessBlockSignature(msg.Signature, msg.PubKey[:], msg.Height, &blockHash); err != nil {
+ if err := m.chain.ProcessBlockSignature(msg.Signature, msg.PubKey, msg.Height, &blockHash); err != nil {
m.peers.AddBanScore(peerID, 20, 0, err.Error())
return
}
return
}
- blockSignatureMsg := NewBroadcastMsg(NewBlockSignatureMsg(ev.BlockHash, blockHeader.Height, ev.Signature, m.sw.ID()), consensusChannel)
+ blockSignatureMsg := NewBroadcastMsg(NewBlockSignatureMsg(ev.BlockHash, blockHeader.Height, ev.Signature, ev.XPub[:]), consensusChannel)
if err := m.peers.BroadcastMsg(blockSignatureMsg); err != nil {
logrus.WithFields(logrus.Fields{"module": logModule, "err": err}).Error("failed on broadcast BlockSignBroadcastMsg.")
return