Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Message struct to IbftMessage #97

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ type MessageConstructor interface {
rawProposal []byte,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message
) *proto.IbftMessage

// BuildPrepareMessage builds a PREPARE message based on the passed in view and proposal hash
BuildPrepareMessage(proposalHash []byte, view *proto.View) *proto.Message
BuildPrepareMessage(proposalHash []byte, view *proto.View) *proto.IbftMessage

// BuildCommitMessage builds a COMMIT message based on the passed in view and proposal hash
// Must create a committed seal for proposal hash and include it into the message
BuildCommitMessage(proposalHash []byte, view *proto.View) *proto.Message
BuildCommitMessage(proposalHash []byte, view *proto.View) *proto.IbftMessage

// BuildRoundChangeMessage builds a ROUND_CHANGE message based on the passed in view,
// latest prepared proposal, and latest prepared certificate
BuildRoundChangeMessage(
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message
) *proto.IbftMessage
}

// Verifier defines the verifier interface
Expand All @@ -42,7 +42,7 @@ type Verifier interface {
// Must check the following things:
// (1) recover the signature and the signer matches from address in message
// (2) the signer address is one of the validators at the height in message
IsValidValidator(msg *proto.Message) bool
IsValidValidator(msg *proto.IbftMessage) bool

// IsProposer checks if the passed in ID is the Proposer for current view (sequence, round)
IsProposer(id []byte, height, round uint64) bool
Expand Down
10 changes: 5 additions & 5 deletions core/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func TestByzantineBehaviour(t *testing.T) {
func createBadRoundRoundChangeFn(node *node) buildRoundChangeMessageDelegate {
return func(proposal *proto.Proposal,
rcc *proto.PreparedCertificate,
view *proto.View) *proto.Message {
view *proto.View) *proto.IbftMessage {
if node.byzantine {
view.Round++
}
Expand All @@ -312,7 +312,7 @@ func createBadRoundPrePrepareMessageFn(node *node) buildPrePrepareMessageDelegat
proposal []byte,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
if node.byzantine {
view.Round++
}
Expand All @@ -330,7 +330,7 @@ func createBadRoundPrePrepareMessageFn(node *node) buildPrePrepareMessageDelegat
func createBadHashPrePrepareMessageFn(node *node) buildPrePrepareMessageDelegate {
return func(proposal []byte,
rcc *proto.RoundChangeCertificate,
view *proto.View) *proto.Message {
view *proto.View) *proto.IbftMessage {
proposalHash := validProposalHash
if node.byzantine {
proposalHash = []byte("invalid proposal hash")
Expand All @@ -347,7 +347,7 @@ func createBadHashPrePrepareMessageFn(node *node) buildPrePrepareMessageDelegate
}

func createBadHashPrepareMessageFn(node *node) buildPrepareMessageDelegate {
return func(_ []byte, view *proto.View) *proto.Message {
return func(_ []byte, view *proto.View) *proto.IbftMessage {
proposalHash := validProposalHash
if node.byzantine {
proposalHash = []byte("invalid proposal hash")
Expand Down Expand Up @@ -375,7 +375,7 @@ func createForcedRCProposerFn(c *cluster) isProposerDelegate {
}

func createBadCommitMessageFn(node *node) buildCommitMessageDelegate {
return func(_ []byte, view *proto.View) *proto.Message {
return func(_ []byte, view *proto.View) *proto.IbftMessage {
committedSeal := validCommittedSeal
if node.byzantine {
committedSeal = []byte("invalid committed seal")
Expand Down
50 changes: 25 additions & 25 deletions core/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func buildBasicPreprepareMessage(
certificate *proto.RoundChangeCertificate,
from []byte,
view *proto.View,
) *proto.Message {
return &proto.Message{
) *proto.IbftMessage {
return &proto.IbftMessage{
View: view,
From: from,
Type: proto.MessageType_PREPREPARE,
Payload: &proto.Message_PreprepareData{
Payload: &proto.IbftMessage_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.Proposal{
RawProposal: rawProposal,
Expand All @@ -54,12 +54,12 @@ func buildBasicPrepareMessage(
proposalHash,
from []byte,
view *proto.View,
) *proto.Message {
return &proto.Message{
) *proto.IbftMessage {
return &proto.IbftMessage{
View: view,
From: from,
Type: proto.MessageType_PREPARE,
Payload: &proto.Message_PrepareData{
Payload: &proto.IbftMessage_PrepareData{
PrepareData: &proto.PrepareMessage{
ProposalHash: proposalHash,
},
Expand All @@ -73,12 +73,12 @@ func buildBasicCommitMessage(
committedSeal,
from []byte,
view *proto.View,
) *proto.Message {
return &proto.Message{
) *proto.IbftMessage {
return &proto.IbftMessage{
View: view,
From: from,
Type: proto.MessageType_COMMIT,
Payload: &proto.Message_CommitData{
Payload: &proto.IbftMessage_CommitData{
CommitData: &proto.CommitMessage{
ProposalHash: proposalHash,
CommittedSeal: committedSeal,
Expand All @@ -93,12 +93,12 @@ func buildBasicRoundChangeMessage(
certificate *proto.PreparedCertificate,
view *proto.View,
from []byte,
) *proto.Message {
return &proto.Message{
) *proto.IbftMessage {
return &proto.IbftMessage{
View: view,
From: from,
Type: proto.MessageType_ROUND_CHANGE,
Payload: &proto.Message_RoundChangeData{
Payload: &proto.IbftMessage_RoundChangeData{
RoundChangeData: &proto.RoundChangeMessage{
LastPreparedProposal: proposal,
LatestPreparedCertificate: certificate,
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestConsensus_ValidFlow(t *testing.T) {
t.Parallel()

var (
multicastFn func(message *proto.Message)
multicastFn func(message *proto.IbftMessage)

numNodes = uint64(4)
nodes = generateNodeAddresses(numNodes)
Expand All @@ -144,7 +144,7 @@ func TestConsensus_ValidFlow(t *testing.T) {
// commonTransportCallback is the common method modification
// required for Transport, for all nodes
commonTransportCallback := func(transport *mockTransport, _ int) {
transport.multicastFn = func(message *proto.Message) {
transport.multicastFn = func(message *proto.IbftMessage) {
multicastFn(message)
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestConsensus_ValidFlow(t *testing.T) {
rawProposal []byte,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicPreprepareMessage(
rawProposal,
correctRoundMessage.hash,
Expand All @@ -192,12 +192,12 @@ func TestConsensus_ValidFlow(t *testing.T) {
}

// Make sure the prepare message is built correctly
backend.buildPrepareMessageFn = func(proposal []byte, view *proto.View) *proto.Message {
backend.buildPrepareMessageFn = func(proposal []byte, view *proto.View) *proto.IbftMessage {
return buildBasicPrepareMessage(correctRoundMessage.hash, nodes[nodeIndex], view)
}

// Make sure the commit message is built correctly
backend.buildCommitMessageFn = func(proposal []byte, view *proto.View) *proto.Message {
backend.buildCommitMessageFn = func(proposal []byte, view *proto.View) *proto.IbftMessage {
return buildBasicCommitMessage(correctRoundMessage.hash, correctRoundMessage.seal, nodes[nodeIndex], view)
}

Expand All @@ -206,7 +206,7 @@ func TestConsensus_ValidFlow(t *testing.T) {
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicRoundChangeMessage(proposal, certificate, view, nodes[nodeIndex])
}

Expand All @@ -231,7 +231,7 @@ func TestConsensus_ValidFlow(t *testing.T) {

// Set the multicast callback to relay the message
// to the entire cluster
multicastFn = func(message *proto.Message) {
multicastFn = func(message *proto.IbftMessage) {
cluster.pushMessage(message)
}

Expand Down Expand Up @@ -260,7 +260,7 @@ func TestConsensus_ValidFlow(t *testing.T) {
func TestConsensus_InvalidBlock(t *testing.T) {
t.Parallel()

var multicastFn func(message *proto.Message)
var multicastFn func(message *proto.IbftMessage)

proposals := [][]byte{
[]byte("proposal 1"), // proposed by node 0
Expand All @@ -279,7 +279,7 @@ func TestConsensus_InvalidBlock(t *testing.T) {
// commonTransportCallback is the common method modification
// required for Transport, for all nodes
commonTransportCallback := func(transport *mockTransport, _ int) {
transport.multicastFn = func(message *proto.Message) {
transport.multicastFn = func(message *proto.IbftMessage) {
multicastFn(message)
}
}
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestConsensus_InvalidBlock(t *testing.T) {
rawProposal []byte,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicPreprepareMessage(
rawProposal,
proposalHashes[view.Round],
Expand All @@ -334,12 +334,12 @@ func TestConsensus_InvalidBlock(t *testing.T) {
}

// Make sure the prepare message is built correctly
backend.buildPrepareMessageFn = func(proposal []byte, view *proto.View) *proto.Message {
backend.buildPrepareMessageFn = func(proposal []byte, view *proto.View) *proto.IbftMessage {
return buildBasicPrepareMessage(proposalHashes[view.Round], nodes[nodeIndex], view)
}

// Make sure the commit message is built correctly
backend.buildCommitMessageFn = func(proposal []byte, view *proto.View) *proto.Message {
backend.buildCommitMessageFn = func(proposal []byte, view *proto.View) *proto.IbftMessage {
return buildBasicCommitMessage(proposalHashes[view.Round], committedSeal, nodes[nodeIndex], view)
}

Expand All @@ -348,7 +348,7 @@ func TestConsensus_InvalidBlock(t *testing.T) {
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicRoundChangeMessage(proposal, certificate, view, nodes[nodeIndex])
}

Expand Down
6 changes: 3 additions & 3 deletions core/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestDropAllAndRecover(t *testing.T) {
},
getVotingPowerFn: testCommonGetVotingPowertFnForNodes(c.nodes),
},
&mockTransport{multicastFn: func(message *proto.Message) {
&mockTransport{multicastFn: func(message *proto.IbftMessage) {
if currentNode.offline {
return
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestMaxFaultyDroppingMessages(t *testing.T) {
insertProposalFn: nil,
getVotingPowerFn: testCommonGetVotingPowertFnForNodes(c.nodes),
},
&mockTransport{multicastFn: func(message *proto.Message) {
&mockTransport{multicastFn: func(message *proto.IbftMessage) {
if currentNode.faulty && rand.Intn(100) < 50 {
return
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestAllFailAndGraduallyRecover(t *testing.T) {
},
getVotingPowerFn: testCommonGetVotingPowertFnForNodes(c.nodes),
},
&mockTransport{multicastFn: func(msg *proto.Message) {
&mockTransport{multicastFn: func(msg *proto.IbftMessage) {
if !currentNode.offline {
for _, node := range c.nodes {
node.core.AddMessage(msg)
Expand Down
12 changes: 6 additions & 6 deletions core/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *node) buildPrePrepare(
rawProposal []byte,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicPreprepareMessage(
rawProposal,
validProposalHash,
Expand All @@ -65,7 +65,7 @@ func (n *node) buildPrePrepare(
func (n *node) buildPrepare(
_ []byte,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicPrepareMessage(
validProposalHash,
n.address,
Expand All @@ -76,7 +76,7 @@ func (n *node) buildPrepare(
func (n *node) buildCommit(
_ []byte,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicCommitMessage(
validProposalHash,
validCommittedSeal,
Expand All @@ -89,7 +89,7 @@ func (n *node) buildRoundChange(
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message {
) *proto.IbftMessage {
return buildBasicRoundChangeMessage(
proposal,
certificate,
Expand Down Expand Up @@ -184,7 +184,7 @@ func (c *cluster) runSequences(ctx context.Context, height uint64) error {
// wait for the worker threads to return
<-sequenceDone

return errors.New("timeout")
return errors.New("timeout") //nolint:err113
}
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func (c *cluster) isProposer(
)
}

func (c *cluster) gossip(msg *proto.Message) {
func (c *cluster) gossip(msg *proto.IbftMessage) {
for _, node := range c.nodes {
node.core.AddMessage(msg)
}
Expand Down
Loading
Loading