Merge branch 'master' of github.com:simple-rules/harmony-benchmark

pull/61/head
Alok Kothari 6 years ago
commit 3e1932e5e4
  1. 2
      consensus/consensus_leader.go
  2. 4
      consensus/consensus_leader_msg.go
  3. 3
      consensus/consensus_leader_msg_test.go
  4. 4
      consensus/consensus_validator.go
  5. 4
      consensus/consensus_validator_msg.go
  6. 2
      consensus/consensus_validator_msg_test.go

@ -160,7 +160,7 @@ func (consensus *Consensus) processCommitMessage(payload []byte) {
consensus.Log.Debug("Enough commitments received with signatures", "numOfSignatures", len(consensus.commitments)) consensus.Log.Debug("Enough commitments received with signatures", "numOfSignatures", len(consensus.commitments))
// Broadcast challenge // Broadcast challenge
msgToSend := consensus.constructChallengeMessage() msgToSend := consensus.constructChallengeMessage(proto_consensus.CHALLENGE)
p2p.BroadcastMessage(consensus.getValidatorPeers(), msgToSend) p2p.BroadcastMessage(consensus.getValidatorPeers(), msgToSend)
// Set state to CHALLENGE_DONE // Set state to CHALLENGE_DONE

@ -37,7 +37,7 @@ func (consensus *Consensus) constructAnnounceMessage() []byte {
} }
// Construct the challenge message // Construct the challenge message
func (consensus *Consensus) constructChallengeMessage() []byte { func (consensus *Consensus) constructChallengeMessage(msgType proto_consensus.MessageType) []byte {
buffer := bytes.NewBuffer([]byte{}) buffer := bytes.NewBuffer([]byte{})
// 4 byte consensus id // 4 byte consensus id
@ -72,7 +72,7 @@ func (consensus *Consensus) constructChallengeMessage() []byte {
signature := consensus.signMessage(buffer.Bytes()) signature := consensus.signMessage(buffer.Bytes())
buffer.Write(signature) buffer.Write(signature)
return proto_consensus.ConstructConsensusMessage(proto_consensus.CHALLENGE, buffer.Bytes()) return proto_consensus.ConstructConsensusMessage(msgType, buffer.Bytes())
} }
// Construct the collective signature message // Construct the collective signature message

@ -6,6 +6,7 @@ import (
"github.com/simple-rules/harmony-benchmark/crypto" "github.com/simple-rules/harmony-benchmark/crypto"
"github.com/simple-rules/harmony-benchmark/crypto/pki" "github.com/simple-rules/harmony-benchmark/crypto/pki"
"github.com/simple-rules/harmony-benchmark/p2p" "github.com/simple-rules/harmony-benchmark/p2p"
consensus_proto "github.com/simple-rules/harmony-benchmark/proto/consensus"
) )
func TestConstructAnnounceMessage(test *testing.T) { func TestConstructAnnounceMessage(test *testing.T) {
@ -41,7 +42,7 @@ func TestConstructChallengeMessage(test *testing.T) {
consensus.bitmap.SetKey(leaderPubKey, true) consensus.bitmap.SetKey(leaderPubKey, true)
consensus.bitmap.SetKey(validatorPubKey, 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 { 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)) test.Errorf("Annouce message is not constructed in the correct size: %d", len(msg))

@ -234,10 +234,10 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
response, err := crypto.Response(crypto.Ed25519Curve, consensus.priKey, consensus.secret, receivedChallenge) response, err := crypto.Response(crypto.Ed25519Curve, consensus.priKey, consensus.secret, receivedChallenge)
if err != nil { if err != nil {
log.Error("Failed to generate response", "err", err) log.Info("Failed to generate response", "err", err)
return return
} }
msgToSend := consensus.constructResponseMessage(response) msgToSend := consensus.constructResponseMessage(proto_consensus.RESPONSE, response)
p2p.SendMessage(consensus.leader, msgToSend) 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) // 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{}) buffer := bytes.NewBuffer([]byte{})
// 4 byte consensus id // 4 byte consensus id
@ -60,5 +60,5 @@ func (consensus *Consensus) constructResponseMessage(response kyber.Scalar) []by
signature := consensus.signMessage(buffer.Bytes()) signature := consensus.signMessage(buffer.Bytes())
buffer.Write(signature) 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"} validator := p2p.Peer{Ip: "3", Port: "5"}
consensus := NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader) consensus := NewConsensus("1", "2", "0", []p2p.Peer{leader, validator}, leader)
consensus.blockHash = [32]byte{} 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 { 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)) test.Errorf("Response message is not constructed in the correct size: %d", len(msg))

Loading…
Cancel
Save