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

Audit #10

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.21.x

- name: Checkout code
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.21.x

- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.21.x

- name: Checkout code
uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ gofumpt:
fixalign:
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
fieldalignment -fix $(filter-out $@,$(MAKECMDGOALS)) # the full package name (not path!)

.PHONY: protoc
protoc:
protoc --go_out=./ --go-grpc_out=./ messages/proto/*.proto
6 changes: 3 additions & 3 deletions core/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type MessageConstructor interface {
// BuildPrePrepareMessage builds a PREPREPARE message based on the passed in proposal
BuildPrePrepareMessage(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message
Expand All @@ -22,7 +22,7 @@ type MessageConstructor interface {

// BuildRoundChangeMessage builds a ROUND_CHANGE message based on the passed in proposal
BuildRoundChangeMessage(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message
Expand Down Expand Up @@ -56,7 +56,7 @@ type Backend interface {
BuildProposal(blockNumber uint64) []byte

// InsertBlock inserts a proposal with the specified committed seals
InsertBlock(proposal []byte, committedSeals []*messages.CommittedSeal)
InsertBlock(proposal *proto.Proposal, committedSeals []*messages.CommittedSeal)

// ID returns the validator's ID
ID() []byte
Expand Down
34 changes: 17 additions & 17 deletions core/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func generateNodeAddresses(count uint64) [][]byte {

// buildBasicPreprepareMessage builds a simple preprepare message
func buildBasicPreprepareMessage(
proposal []byte,
proposal *proto.Proposal,
proposalHash []byte,
certificate *proto.RoundChangeCertificate,
from []byte,
Expand Down Expand Up @@ -85,7 +85,7 @@ func buildBasicCommitMessage(

// buildBasicRoundChangeMessage builds a simple round change message
func buildBasicRoundChangeMessage(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
from []byte,
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestConsensus_ValidFlow(t *testing.T) {
committedSeal := []byte("seal")
numNodes := uint64(4)
nodes := generateNodeAddresses(numNodes)
insertedBlocks := make([][]byte, numNodes)
insertedBlocks := make([]*proto.Proposal, numNodes)

// commonTransportCallback is the common method modification
// required for Transport, for all nodes
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestConsensus_ValidFlow(t *testing.T) {

// Make sure the preprepare message is built correctly
backend.buildPrePrepareMessageFn = func(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message {
Expand All @@ -189,26 +189,26 @@ 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(_ []byte, view *proto.View) *proto.Message {
return buildBasicPrepareMessage(proposalHash, nodes[nodeIndex], view)
}

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

// Make sure the round change message is built correctly
backend.buildRoundChangeMessageFn = func(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message {
return buildBasicRoundChangeMessage(proposal, certificate, view, nodes[nodeIndex])
}

// Make sure the inserted proposal is noted
backend.insertBlockFn = func(proposal []byte, _ []*messages.CommittedSeal) {
backend.insertBlockFn = func(proposal *proto.Proposal, _ []*messages.CommittedSeal) {
insertedBlocks[nodeIndex] = proposal
}
}
Expand All @@ -221,7 +221,7 @@ func TestConsensus_ValidFlow(t *testing.T) {

// Set the proposal creation method for node 0, since
// they are the proposer
backend.buildProposalFn = func(u uint64) []byte {
backend.buildProposalFn = func(_ uint64) []byte {
return proposal
}
},
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestConsensus_ValidFlow(t *testing.T) {

// Make sure the inserted blocks match what node 0 proposed
for _, block := range insertedBlocks {
assert.True(t, bytes.Equal(block, proposal))
assert.True(t, bytes.Equal(block.Block, proposal))
}
}

Expand Down Expand Up @@ -296,7 +296,7 @@ func TestConsensus_InvalidBlock(t *testing.T) {
committedSeal := []byte("seal")
numNodes := uint64(4)
nodes := generateNodeAddresses(numNodes)
insertedBlocks := make([][]byte, numNodes)
insertedBlocks := make([]*proto.Proposal, numNodes)

// commonTransportCallback is the common method modification
// required for Transport, for all nodes
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestConsensus_InvalidBlock(t *testing.T) {

// Make sure the preprepare message is built correctly
backend.buildPrePrepareMessageFn = func(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.RoundChangeCertificate,
view *proto.View,
) *proto.Message {
Expand All @@ -363,26 +363,26 @@ 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(_ []byte, view *proto.View) *proto.Message {
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(_ []byte, view *proto.View) *proto.Message {
return buildBasicCommitMessage(proposalHashes[view.Round], committedSeal, nodes[nodeIndex], view)
}

// Make sure the round change message is built correctly
backend.buildRoundChangeMessageFn = func(
proposal []byte,
proposal *proto.Proposal,
certificate *proto.PreparedCertificate,
view *proto.View,
) *proto.Message {
return buildBasicRoundChangeMessage(proposal, certificate, view, nodes[nodeIndex])
}

// Make sure the inserted proposal is noted
backend.insertBlockFn = func(proposal []byte, _ []*messages.CommittedSeal) {
backend.insertBlockFn = func(proposal *proto.Proposal, _ []*messages.CommittedSeal) {
insertedBlocks[nodeIndex] = proposal
}
}
Expand Down Expand Up @@ -446,6 +446,6 @@ func TestConsensus_InvalidBlock(t *testing.T) {

// Make sure the inserted blocks match what node 1 proposed
for _, block := range insertedBlocks {
assert.True(t, bytes.Equal(block, proposals[1]))
assert.True(t, bytes.Equal(block.Block, proposals[1]))
}
}
Loading
Loading