diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index 96b892924..d8368283f 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -160,7 +160,7 @@ func (consensus *Consensus) processCommitMessage(payload []byte) { consensus.Log.Debug("Enough commitments received with signatures", "numOfSignatures", len(consensus.commitments)) // Broadcast challenge - msgToSend := consensus.constructChallengeMessage() + msgToSend := consensus.constructChallengeMessage(proto_consensus.CHALLENGE) p2p.BroadcastMessage(consensus.getValidatorPeers(), msgToSend) // Set state to CHALLENGE_DONE diff --git a/consensus/consensus_leader_msg.go b/consensus/consensus_leader_msg.go index 3ff9b3e4f..b31e91d77 100644 --- a/consensus/consensus_leader_msg.go +++ b/consensus/consensus_leader_msg.go @@ -37,7 +37,7 @@ func (consensus *Consensus) constructAnnounceMessage() []byte { } // Construct the challenge message -func (consensus *Consensus) constructChallengeMessage() []byte { +func (consensus *Consensus) constructChallengeMessage(msgType proto_consensus.MessageType) []byte { buffer := bytes.NewBuffer([]byte{}) // 4 byte consensus id @@ -72,7 +72,7 @@ func (consensus *Consensus) constructChallengeMessage() []byte { signature := consensus.signMessage(buffer.Bytes()) buffer.Write(signature) - return proto_consensus.ConstructConsensusMessage(proto_consensus.CHALLENGE, buffer.Bytes()) + return proto_consensus.ConstructConsensusMessage(msgType, buffer.Bytes()) } // Construct the collective signature message diff --git a/consensus/consensus_leader_msg_test.go b/consensus/consensus_leader_msg_test.go index b4139bf97..263422684 100644 --- a/consensus/consensus_leader_msg_test.go +++ b/consensus/consensus_leader_msg_test.go @@ -6,6 +6,7 @@ import ( "github.com/simple-rules/harmony-benchmark/crypto" "github.com/simple-rules/harmony-benchmark/crypto/pki" "github.com/simple-rules/harmony-benchmark/p2p" + consensus_proto "github.com/simple-rules/harmony-benchmark/proto/consensus" ) func TestConstructAnnounceMessage(test *testing.T) { @@ -41,7 +42,7 @@ func TestConstructChallengeMessage(test *testing.T) { consensus.bitmap.SetKey(leaderPubKey, true) consensus.bitmap.SetKey(validatorPubKey, true) - msg := consensus.constructChallengeMessage() + msg := consensus.constructChallengeMessage(consensus_proto.CHALLENGE) if len(msg) != 1+1+1+4+32+2+33+33+32+64 { test.Errorf("Annouce message is not constructed in the correct size: %d", len(msg)) diff --git a/consensus/consensus_validator.go b/consensus/consensus_validator.go index 61bd25bbf..783b86cfb 100644 --- a/consensus/consensus_validator.go +++ b/consensus/consensus_validator.go @@ -234,10 +234,10 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) { response, err := crypto.Response(crypto.Ed25519Curve, consensus.priKey, consensus.secret, receivedChallenge) if err != nil { - log.Error("Failed to generate response", "err", err) + log.Info("Failed to generate response", "err", err) return } - msgToSend := consensus.constructResponseMessage(response) + msgToSend := consensus.constructResponseMessage(proto_consensus.RESPONSE, response) p2p.SendMessage(consensus.leader, msgToSend) diff --git a/consensus/consensus_validator_msg.go b/consensus/consensus_validator_msg.go index c999adcc4..7172d2e8a 100644 --- a/consensus/consensus_validator_msg.go +++ b/consensus/consensus_validator_msg.go @@ -37,7 +37,7 @@ func (consensus *Consensus) constructCommitMessage(msgType proto_consensus.Messa } // Construct the response message to send to leader (assumption the consensus data is already verified) -func (consensus *Consensus) constructResponseMessage(response kyber.Scalar) []byte { +func (consensus *Consensus) constructResponseMessage(msgType proto_consensus.MessageType, response kyber.Scalar) []byte { buffer := bytes.NewBuffer([]byte{}) // 4 byte consensus id @@ -60,5 +60,5 @@ func (consensus *Consensus) constructResponseMessage(response kyber.Scalar) []by signature := consensus.signMessage(buffer.Bytes()) buffer.Write(signature) - return proto_consensus.ConstructConsensusMessage(proto_consensus.RESPONSE, buffer.Bytes()) + return proto_consensus.ConstructConsensusMessage(msgType, buffer.Bytes()) } diff --git a/consensus/consensus_validator_msg_test.go b/consensus/consensus_validator_msg_test.go index 6facaaccc..46430eee4 100644 --- a/consensus/consensus_validator_msg_test.go +++ b/consensus/consensus_validator_msg_test.go @@ -25,7 +25,7 @@ func TestConstructResponseMessage(test *testing.T) { validator := p2p.Peer{Ip: "3", Port: "5"} consensus := NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader) consensus.blockHash = [32]byte{} - msg := consensus.constructResponseMessage(crypto.Ed25519Curve.Scalar()) + msg := consensus.constructResponseMessage(consensus_proto.RESPONSE, crypto.Ed25519Curve.Scalar()) if len(msg) != 1+1+1+4+32+2+32+64 { test.Errorf("Response message is not constructed in the correct size: %d", len(msg))