Skip to content
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
34 changes: 14 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,30 @@ jobs:
go mod vendor
git diff --exit-code

- name: go fmt
run: |
go fmt ./...
git diff --exit-code

- name: goimports
run: |
go install golang.org/x/tools/cmd/goimports@latest
goimports -l -w `find . -name '*.go' | grep -v vendor | grep -v 'pb.go'`
git diff --exit-code

- name: check protobuf
run: |
go -C tools install github.com/bufbuild/buf/cmd/buf google.golang.org/protobuf/cmd/protoc-gen-go
PATH="$(go env GOPATH)/bin:$PATH" buf generate
git diff --exit-code

- name: golangci-lint
run: |
go -C tools install github.com/golangci/golangci-lint/v2/cmd/golangci-lint
PATH="$(go env GOPATH)/bin:$PATH" golangci-lint run ./...

build:
needs:
- validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
name: Checkout Code
- uses: actions/checkout@v7
name: Checkout Code

- name: Install Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Install Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod

- name: Test
run: |
go test -count 1 -race ./...
- name: Test
run: |
go test -count 1 -race ./...
103 changes: 103 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# SPDX-License-Identifier: Apache-2.0
version: "2"
run:
timeout: 5m
exclude-dirs:
- vendor

formatters:
enable:
- gci
- gofumpt
- gofmt
- goimports

linters:
default: none
enable:
- asciicheck
- bodyclose
- contextcheck
- copyloopvar
- decorder
- depguard
- dogsled
- dupword
- durationcheck
- errname
- errorlint
- fatcontext
- gocheckcompilerdirectives
- gocritic
- goheader
- gomodguard_v2
- goprintffuncname
- govet
- grouper
- iface
- ineffassign
- interfacebloat
- loggercheck
- misspell
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- promlinter
- reassign
- recvcheck
- sloglint
- spancheck
- staticcheck
- testableexamples
- tparallel
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
settings:
depguard:
rules:
main:
deny:
- pkg: "golang.org/x/net/context"
desc: "use 'context' from stdlib instead"
- pkg: "github.com/gogo/protobuf"
desc: "use 'github.com/golang/protobuf' instead"
govet:
settings:
printf:
funcs:
- Debug
- Debugf
- Print
- Printf
- Info
- Infof
- Warning
- Warningf
- Error
- Errorf
- Critical
- Criticalf
- Sprint
- Sprintf
- Log
- Logf
- Panic
- Panicf
- Fatal
- Fatalf
- Notice
- Noticef
- Wrap
- Wrapf
- WithMessage
staticcheck:
checks: ["all", "-SA1019", "-ST1000", "-ST1003", "-ST1005", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]

issues:
max-issues-per-linter: 0
max-same-issues: 0
uniq-by-line: false
6 changes: 3 additions & 3 deletions internal/bft/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (c *Controller) OnRequestTimeout(request []byte, info types.RequestInfo) {
}

c.Logger.Infof("Request %s timeout expired, forwarding request to leader: %d", info, leaderID)
c.Comm.SendTransaction(leaderID, request)
c.SendTransaction(leaderID, request)
}

// OnLeaderFwdRequestTimeout is called when the leader-forward timeout expires, and complains about the leader.
Expand Down Expand Up @@ -365,7 +365,7 @@ func (c *Controller) respondToStateTransferRequest(sender uint64) {
},
},
}
c.Comm.SendConsensus(sender, msg)
c.SendConsensus(sender, msg)
}

func (c *Controller) convertViewMessageToHeartbeat(m *protos.Message) *protos.Message {
Expand Down Expand Up @@ -927,7 +927,7 @@ func (c *Controller) BroadcastConsensus(m *protos.Message) {
if c.ID == node {
continue
}
c.Comm.SendConsensus(node, m)
c.SendConsensus(node, m)
}

if m.GetPrePrepare() != nil || m.GetPrepare() != nil || m.GetCommit() != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/bft/heartbeatmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (hm *HeartbeatMonitor) sendHeartBeatResponse(target uint64) {
hm.logger.Debugf("Sent HeartBeatResponse view: %d; to %d", hm.view, target)
}

func (hm *HeartbeatMonitor) viewActive(hbMsg *smartbftprotos.HeartBeat) (bool, uint64) {
func (hm *HeartbeatMonitor) viewActive(_ *smartbftprotos.HeartBeat) (bool, uint64) {
vs := hm.viewSequences.Load()
// View isn't initialized
if vs == nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/bft/heartbeatmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func TestHeartbeatMonitorFollower(t *testing.T) {

start = start.Add(incrementUnit).Add(time.Second)

for i := time.Duration(1); i <= heartbeatCount*2; i++ {
elapsed := start.Add(incrementUnit*i + time.Millisecond)
for i := 1; i <= heartbeatCount*2; i++ {
elapsed := start.Add(time.Duration(i)*incrementUnit + time.Millisecond)
scheduler <- elapsed
hm.ProcessMsg(testCase.sender, testCase.heartbeatMessage)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/bft/requestpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (rp *Pool) RemoveRequest(requestInfo types.RequestInfo) error {
if !exist {
rp.moveToDelSlice(requestInfo)
errStr := fmt.Sprintf("request %s is not in the pool at remove time", requestInfo)
rp.logger.Debugf(errStr)
rp.logger.Debugf("%s", errStr)
return errors.New(errStr)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/bft/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ func (t *Task) isStopped() bool {

type backingHeap []*Task

func (h backingHeap) Len() int {
return len(h)
func (h *backingHeap) Len() int {
return len(*h)
}

func (h backingHeap) Less(i, j int) bool {
return h[i].Deadline.Before(h[j].Deadline)
func (h *backingHeap) Less(i, j int) bool {
return (*h)[i].Deadline.Before((*h)[j].Deadline)
}

func (h backingHeap) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
func (h *backingHeap) Swap(i, j int) {
(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}

func (h *backingHeap) Push(o any) {
Expand Down
6 changes: 1 addition & 5 deletions internal/bft/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package bft

import (
"github.com/hyperledger/SmartBFT/pkg/api"
"github.com/hyperledger/SmartBFT/smartbftprotos"
)

// Generate mocks for a collection of interfaces that are defined in api/dependencies.go
Expand Down Expand Up @@ -36,10 +35,7 @@ type ApplicationMock interface {
// CommMock mock for the Comm interface
//
//go:generate mockery -dir . -name CommMock -case underscore -output ./mocks/
type CommMock interface {
api.Comm
BroadcastConsensus(m *smartbftprotos.Message)
}
type CommMock = Comm

// SynchronizerMock mock for the Synchronizer interface
//
Expand Down
1 change: 0 additions & 1 deletion internal/bft/viewchanger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,6 @@ func TestCommitWhileHavingInFlight(t *testing.T) {
vc.HandleMessage(2, msg2)

reasonAboutInFlightLowerThanLatestDecision.Wait()

}

func TestDontCommitInFlight(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ func TestFollowerStateTransfer(t *testing.T) {
}

func TestLeaderModifiesPreprepare(t *testing.T) {
t.Parallel()
for _, test := range []struct {
description string
mutatingFunc func(target uint64, m *smartbftprotos.Message)
Expand Down Expand Up @@ -1811,7 +1812,7 @@ func TestRotateAndViewChange(t *testing.T) {
}
}

func TestMigrateToBlacklistAndBackAgain(t *testing.T) {
func TestMigrateToBlacklistAndBackAgain(t *testing.T) { //nolint:tparallel // subtests are sequential phases sharing the same nodes
t.Parallel()
network := NewNetwork()
defer network.Shutdown()
Expand Down
2 changes: 1 addition & 1 deletion test/view_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func TestNodeOneSequenceBehindRejoins(t *testing.T) {

// Node 1 leads view 0, so it stays in view 0 while cut off: a leader never starts a view
// change of its own. The other six install view 1, led by node 2.
nodes[1-1].Disconnect()
nodes[0].Disconnect()
if !viewsReached(t, vt, ids[1:], 1, 60*time.Second, "the group that moved on did not start view 1") {
t.Fatalf("the group that moved on did not start view 1:%s", vt.describe(ids))
}
Expand Down
Loading
Loading