|
|
|
@ -3,7 +3,6 @@ package consensus |
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
|
|
|
|
|
protobuf "github.com/golang/protobuf/proto" |
|
|
|
|
"github.com/harmony-one/bls/ffi/go/bls" |
|
|
|
|
consensus_proto "github.com/harmony-one/harmony/api/consensus" |
|
|
|
|
"github.com/harmony-one/harmony/api/proto" |
|
|
|
@ -16,26 +15,14 @@ func (consensus *Consensus) constructAnnounceMessage() []byte { |
|
|
|
|
message := consensus_proto.Message{} |
|
|
|
|
message.Type = consensus_proto.MessageType_ANNOUNCE |
|
|
|
|
|
|
|
|
|
// 4 byte consensus id
|
|
|
|
|
message.ConsensusId = consensus.consensusID |
|
|
|
|
|
|
|
|
|
// 32 byte block hash
|
|
|
|
|
message.BlockHash = consensus.blockHash[:] |
|
|
|
|
|
|
|
|
|
// 4 byte sender id
|
|
|
|
|
message.SenderId = uint32(consensus.nodeID) |
|
|
|
|
consensus.populateMessageFields(&message) |
|
|
|
|
|
|
|
|
|
// n byte of block header
|
|
|
|
|
message.Payload = consensus.block // TODO: send only block header in the announce phase.
|
|
|
|
|
|
|
|
|
|
err := consensus.signConsensusMessage(&message) |
|
|
|
|
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Debug("Failed to sign the Announce message", "error", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
marshaledMessage, err := protobuf.Marshal(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Debug("Failed to marshal the Announce message", "error", err) |
|
|
|
|
utils.GetLogInstance().Error("Failed to sign and marshal the Announce message", "error", err) |
|
|
|
|
} |
|
|
|
|
return proto.ConstructConsensusMessage(marshaledMessage) |
|
|
|
|
} |
|
|
|
@ -45,14 +32,7 @@ func (consensus *Consensus) constructPreparedMessage() ([]byte, *bls.Sign) { |
|
|
|
|
message := consensus_proto.Message{} |
|
|
|
|
message.Type = consensus_proto.MessageType_PREPARED |
|
|
|
|
|
|
|
|
|
// 4 byte consensus id
|
|
|
|
|
message.ConsensusId = consensus.consensusID |
|
|
|
|
|
|
|
|
|
// 32 byte block hash
|
|
|
|
|
message.BlockHash = consensus.blockHash[:] |
|
|
|
|
|
|
|
|
|
// 4 byte sender id
|
|
|
|
|
message.SenderId = uint32(consensus.nodeID) |
|
|
|
|
consensus.populateMessageFields(&message) |
|
|
|
|
|
|
|
|
|
//// Payload
|
|
|
|
|
buffer := bytes.NewBuffer([]byte{}) |
|
|
|
@ -67,14 +47,9 @@ func (consensus *Consensus) constructPreparedMessage() ([]byte, *bls.Sign) { |
|
|
|
|
message.Payload = buffer.Bytes() |
|
|
|
|
//// END Payload
|
|
|
|
|
|
|
|
|
|
err := consensus.signConsensusMessage(&message) |
|
|
|
|
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Debug("Failed to sign the Prepared message", "error", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
marshaledMessage, err := protobuf.Marshal(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Debug("Failed to marshal the Prepared message", "error", err) |
|
|
|
|
utils.GetLogInstance().Error("Failed to sign and marshal the Prepared message", "error", err) |
|
|
|
|
} |
|
|
|
|
return proto.ConstructConsensusMessage(marshaledMessage), aggSig |
|
|
|
|
} |
|
|
|
@ -83,14 +58,8 @@ func (consensus *Consensus) constructPreparedMessage() ([]byte, *bls.Sign) { |
|
|
|
|
func (consensus *Consensus) constructCommittedMessage() ([]byte, *bls.Sign) { |
|
|
|
|
message := consensus_proto.Message{} |
|
|
|
|
message.Type = consensus_proto.MessageType_COMMITTED |
|
|
|
|
// 4 byte consensus id
|
|
|
|
|
message.ConsensusId = consensus.consensusID |
|
|
|
|
|
|
|
|
|
// 32 byte block hash
|
|
|
|
|
message.BlockHash = consensus.blockHash[:] |
|
|
|
|
|
|
|
|
|
// 4 byte sender id
|
|
|
|
|
message.SenderId = uint32(consensus.nodeID) |
|
|
|
|
consensus.populateMessageFields(&message) |
|
|
|
|
|
|
|
|
|
//// Payload
|
|
|
|
|
buffer := bytes.NewBuffer([]byte{}) |
|
|
|
@ -105,14 +74,9 @@ func (consensus *Consensus) constructCommittedMessage() ([]byte, *bls.Sign) { |
|
|
|
|
message.Payload = buffer.Bytes() |
|
|
|
|
//// END Payload
|
|
|
|
|
|
|
|
|
|
err := consensus.signConsensusMessage(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Debug("Failed to sign the Committed message", "error", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
marshaledMessage, err := protobuf.Marshal(&message) |
|
|
|
|
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message) |
|
|
|
|
if err != nil { |
|
|
|
|
utils.GetLogInstance().Debug("Failed to marshal the Committed message", "error", err) |
|
|
|
|
utils.GetLogInstance().Error("Failed to sign and marshal the Committed message", "error", err) |
|
|
|
|
} |
|
|
|
|
return proto.ConstructConsensusMessage(marshaledMessage), aggSig |
|
|
|
|
} |
|
|
|
|