The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/consensus/consensus_leader_msg.go

83 lines
2.5 KiB

package consensus
import (
"bytes"
6 years ago
6 years ago
"github.com/harmony-one/bls/ffi/go/bls"
consensus_proto "github.com/harmony-one/harmony/api/consensus"
6 years ago
"github.com/harmony-one/harmony/api/proto"
6 years ago
bls_cosi "github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/utils"
)
// Constructs the announce message
func (consensus *Consensus) constructAnnounceMessage() []byte {
message := consensus_proto.Message{}
message.Type = consensus_proto.MessageType_ANNOUNCE
consensus.populateMessageFields(&message)
// n byte of block header
message.Payload = consensus.block // TODO: send only block header in the announce phase.
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message)
if err != nil {
utils.GetLogInstance().Error("Failed to sign and marshal the Announce message", "error", err)
}
return proto.ConstructConsensusMessage(marshaledMessage)
}
6 years ago
// Construct the prepared message, returning prepared message in bytes.
func (consensus *Consensus) constructPreparedMessage() ([]byte, *bls.Sign) {
message := consensus_proto.Message{}
6 years ago
message.Type = consensus_proto.MessageType_PREPARED
consensus.populateMessageFields(&message)
//// Payload
buffer := bytes.NewBuffer([]byte{})
6 years ago
// 48 bytes aggregated signature
aggSig := bls_cosi.AggregateSig(consensus.GetPrepareSigsArray())
buffer.Write(aggSig.Serialize())
6 years ago
// Bitmap
buffer.Write(consensus.prepareBitmap.Bitmap)
message.Payload = buffer.Bytes()
//// END Payload
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message)
if err != nil {
utils.GetLogInstance().Error("Failed to sign and marshal the Prepared message", "error", err)
}
6 years ago
return proto.ConstructConsensusMessage(marshaledMessage), aggSig
}
6 years ago
// Construct the committed message, returning committed message in bytes.
func (consensus *Consensus) constructCommittedMessage() ([]byte, *bls.Sign) {
message := consensus_proto.Message{}
6 years ago
message.Type = consensus_proto.MessageType_COMMITTED
consensus.populateMessageFields(&message)
//// Payload
buffer := bytes.NewBuffer([]byte{})
6 years ago
// 48 bytes aggregated signature
aggSig := bls_cosi.AggregateSig(consensus.GetCommitSigsArray())
buffer.Write(aggSig.Serialize())
6 years ago
// Bitmap
buffer.Write(consensus.commitBitmap.Bitmap)
message.Payload = buffer.Bytes()
//// END Payload
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message)
if err != nil {
utils.GetLogInstance().Error("Failed to sign and marshal the Committed message", "error", err)
}
6 years ago
return proto.ConstructConsensusMessage(marshaledMessage), aggSig
}