From 32605ab49e746065f4b5a68301ce080d1576c6ef Mon Sep 17 00:00:00 2001 From: yahtoo Date: Tue, 16 Jul 2019 14:34:11 +0800 Subject: [PATCH] Del BlockSignatureMsg unused Height field (#293) --- netsync/consensusmgr/consensus_msg.go | 7 +++---- netsync/consensusmgr/consensus_msg_test.go | 8 +++----- netsync/consensusmgr/handle.go | 10 ++-------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/netsync/consensusmgr/consensus_msg.go b/netsync/consensusmgr/consensus_msg.go index 0015cca9..33fee3d1 100644 --- a/netsync/consensusmgr/consensus_msg.go +++ b/netsync/consensusmgr/consensus_msg.go @@ -46,19 +46,18 @@ func decodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) { // BlockSignatureMsg block signature message transferred between nodes. type BlockSignatureMsg struct { BlockHash [32]byte - Height uint64 Signature []byte PubKey []byte } //NewBlockSignatureMsg create new block signature msg. -func NewBlockSignatureMsg(blockHash bc.Hash, height uint64, signature, pubKey []byte) ConsensusMessage { +func NewBlockSignatureMsg(blockHash bc.Hash, signature, pubKey []byte) ConsensusMessage { hash := blockHash.Byte32() - return &BlockSignatureMsg{BlockHash: hash, Height: height, Signature: signature, PubKey: pubKey} + return &BlockSignatureMsg{BlockHash: hash, Signature: signature, PubKey: pubKey} } func (bs *BlockSignatureMsg) String() string { - return fmt.Sprintf("{block_hash: %s,block_height:%d,signature:%s,pubkey:%s}", hex.EncodeToString(bs.BlockHash[:]), bs.Height, hex.EncodeToString(bs.Signature), hex.EncodeToString(bs.PubKey[:])) + return fmt.Sprintf("{block_hash: %s,signature:%s,pubkey:%s}", hex.EncodeToString(bs.BlockHash[:]), hex.EncodeToString(bs.Signature), hex.EncodeToString(bs.PubKey[:])) } // BroadcastMarkSendRecord mark send message record to prevent messages from being sent repeatedly. diff --git a/netsync/consensusmgr/consensus_msg_test.go b/netsync/consensusmgr/consensus_msg_test.go index f4299169..d00c93bb 100644 --- a/netsync/consensusmgr/consensus_msg_test.go +++ b/netsync/consensusmgr/consensus_msg_test.go @@ -55,11 +55,10 @@ func TestDecodeMessage(t *testing.T) { func TestBlockSignBroadcastMsg(t *testing.T) { blockSignMsg := &BlockSignatureMsg{ BlockHash: [32]byte{0x01}, - Height: 100, Signature: []byte{0x00}, PubKey: []byte{0x01}, } - signatureBroadcastMsg := NewBroadcastMsg(NewBlockSignatureMsg(bc.NewHash(blockSignMsg.BlockHash), blockSignMsg.Height, blockSignMsg.Signature, blockSignMsg.PubKey), consensusChannel) + signatureBroadcastMsg := NewBroadcastMsg(NewBlockSignatureMsg(bc.NewHash(blockSignMsg.BlockHash), blockSignMsg.Signature, blockSignMsg.PubKey), consensusChannel) binMsg := wire.BinaryBytes(signatureBroadcastMsg.GetMsg()) gotMsgType, gotMsg, err := decodeMessage(binMsg) @@ -139,16 +138,15 @@ func TestBlockProposeMsg(t *testing.T) { func TestBlockSignatureMsg(t *testing.T) { msg := &BlockSignatureMsg{ BlockHash: [32]byte{0x01}, - Height: 100, Signature: []byte{0x00}, PubKey: []byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, } - gotMsg := NewBlockSignatureMsg(bc.NewHash(msg.BlockHash), msg.Height, msg.Signature, msg.PubKey) + gotMsg := NewBlockSignatureMsg(bc.NewHash(msg.BlockHash), 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:01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000}" + wantString := "{block_hash: 0100000000000000000000000000000000000000000000000000000000000000,signature:00,pubkey:01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000}" if gotMsg.String() != wantString { t.Fatalf("test block signature message err. got string:%s\n want string:%s", gotMsg.String(), wantString) } diff --git a/netsync/consensusmgr/handle.go b/netsync/consensusmgr/handle.go index 9c8642e4..702df720 100644 --- a/netsync/consensusmgr/handle.go +++ b/netsync/consensusmgr/handle.go @@ -162,16 +162,10 @@ func (m *Manager) blockSignatureMsgBroadcastLoop() { continue } - blockHeader, err := m.chain.GetHeaderByHash(&ev.BlockHash) - if err != nil { - logrus.WithFields(logrus.Fields{"module": logModule, "err": err}).Error("failed on get header by hash from chain.") - return - } - - blockSignatureMsg := NewBroadcastMsg(NewBlockSignatureMsg(ev.BlockHash, blockHeader.Height, ev.Signature, ev.XPub), consensusChannel) + blockSignatureMsg := NewBroadcastMsg(NewBlockSignatureMsg(ev.BlockHash, 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 + continue } case <-m.quit: -- 2.11.0