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.
47 lines
1.6 KiB
47 lines
1.6 KiB
package consensus
|
|
|
|
import (
|
|
consensus_proto "github.com/harmony-one/harmony/api/consensus"
|
|
"github.com/harmony-one/harmony/api/proto"
|
|
"github.com/harmony-one/harmony/internal/utils"
|
|
)
|
|
|
|
// Construct the prepare message to send to leader (assumption the consensus data is already verified)
|
|
func (consensus *Consensus) constructPrepareMessage() []byte {
|
|
message := consensus_proto.Message{}
|
|
message.Type = consensus_proto.MessageType_PREPARE
|
|
|
|
consensus.populateMessageFields(&message)
|
|
|
|
// 48 byte of bls signature
|
|
sign := consensus.priKey.SignHash(message.BlockHash)
|
|
if sign != nil {
|
|
message.Payload = sign.Serialize()
|
|
}
|
|
|
|
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message)
|
|
if err != nil {
|
|
utils.GetLogInstance().Error("Failed to sign and marshal the Prepare message", "error", err)
|
|
}
|
|
return proto.ConstructConsensusMessage(marshaledMessage)
|
|
}
|
|
|
|
// Construct the commit message which contains the signature on the multi-sig of prepare phase.
|
|
func (consensus *Consensus) constructCommitMessage(multiSigAndBitmap []byte) []byte {
|
|
message := consensus_proto.Message{}
|
|
message.Type = consensus_proto.MessageType_COMMIT
|
|
|
|
consensus.populateMessageFields(&message)
|
|
|
|
// 48 byte of bls signature
|
|
sign := consensus.priKey.SignHash(multiSigAndBitmap)
|
|
if sign != nil {
|
|
message.Payload = sign.Serialize()
|
|
}
|
|
|
|
marshaledMessage, err := consensus.signAndMarshalConsensusMessage(&message)
|
|
if err != nil {
|
|
utils.GetLogInstance().Error("Failed to sign and marshal the Commit message", "error", err)
|
|
}
|
|
return proto.ConstructConsensusMessage(marshaledMessage)
|
|
}
|
|
|