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_validator_msg.go

60 lines
1.9 KiB

package consensus
import (
"github.com/harmony-one/harmony/api/proto"
msg_pb "github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/internal/utils"
)
6 years ago
// Construct the prepare message to send to leader (assumption the consensus data is already verified)
func (consensus *Consensus) constructPrepareMessage() []byte {
message := &msg_pb.Message{
ServiceType: msg_pb.ServiceType_CONSENSUS,
Type: msg_pb.MessageType_PREPARE,
Request: &msg_pb.Message_Consensus{
Consensus: &msg_pb.ConsensusRequest{},
},
}
consensusMsg := message.GetConsensus()
consensus.populateMessageFields(consensusMsg)
6 years ago
// 48 byte of bls signature
sign := consensus.priKey.SignHash(consensusMsg.BlockHash)
6 years ago
if sign != nil {
consensusMsg.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 := &msg_pb.Message{
ServiceType: msg_pb.ServiceType_CONSENSUS,
Type: msg_pb.MessageType_COMMIT,
Request: &msg_pb.Message_Consensus{
Consensus: &msg_pb.ConsensusRequest{},
},
}
consensusMsg := message.GetConsensus()
consensus.populateMessageFields(consensusMsg)
6 years ago
// 48 byte of bls signature
sign := consensus.priKey.SignHash(multiSigAndBitmap)
6 years ago
if sign != nil {
consensusMsg.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)
}