Refactor constructResponseMessage to support final response

pull/61/head
Rongjian Lan 6 years ago
parent 8dc7448e82
commit c519f495ca
  1. 2
      consensus/consensus_validator.go
  2. 4
      consensus/consensus_validator_msg.go
  3. 2
      consensus/consensus_validator_msg_test.go

@ -237,7 +237,7 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
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)

@ -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())
}

@ -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))

Loading…
Cancel
Save