Skip to content

Commit

Permalink
Merge pull request #114 from relab/fix-lint-issues
Browse files Browse the repository at this point in the history
Fix lint issues that cause GitHub actions to fail
  • Loading branch information
meling authored Mar 9, 2024
2 parents 3176a69 + 4f9471f commit 6c1fcb7
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 67 deletions.
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ linters-settings:
gocyclo:
min-complexity: 15

misspell:
locale: US

revive:
min-confidence: 0.21 # disables package comment warning
rules:
- name: unexported-return
disabled: true
- name: unused-parameter

issues:
exclude-use-default: false
Expand Down
15 changes: 15 additions & 0 deletions .vscode/dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ anypb
Bano
Baudet
BFT's
Bitfield
cerr
chainedhotstuff
checkf
Chursin
Expand All @@ -12,10 +14,12 @@ CODECOV
covermode
coverpkg
coverprofile
cpuprofile
Debugf
durationpb
emptypb
Erevik
eventloop
Fangyu
fasthotstuff
felixge
Expand All @@ -28,32 +32,40 @@ golangci
golint
gomock
gorums
gpool
grpc
Gueta
Hein
hostnames
HOTSTUFF
hotstuffgorums
hotstuffpb
iagotest
ICDCS
iface
Infof
Jalalzai
Jehl
Jianyu
keygen
kilic
latencygen
leaderrotation
Malkhi
Mathieu
Meling
memprofile
mitchellh
mockgen
nolint
orchestrationpb
partitioner
Paulo
perr
pflag
pflags
pkgs
PRECOMMIT
Println
propsed
proto
Expand All @@ -71,11 +83,14 @@ simplehotstuff
Sonnino
SSWU
structs
subconfiguration
testutil
throughputvslatency
timestamppb
TMPDIR
tmpl
Tormod
unexported
unittests
unmarshals
unregisters
Expand Down
2 changes: 1 addition & 1 deletion backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (cfg *subConfig) Timeout(msg hotstuff.TimeoutMsg) {
return
}

// will wait until the second timeout before cancelling
// will wait until the second timeout before canceling
ctx, cancel := synchronizer.TimeoutContext(cfg.eventLoop.Context(), cfg.eventLoop)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type blockChain struct {
pruneHeight hotstuff.View
blocks map[hotstuff.Hash]*hotstuff.Block
blockAtHeight map[hotstuff.View]*hotstuff.Block
pendingFetch map[hotstuff.Hash]context.CancelFunc // allows a pending fetch operation to be cancelled
pendingFetch map[hotstuff.Hash]context.CancelFunc // allows a pending fetch operation to be canceled
}

func (chain *blockChain) InitModule(mods *modules.Core) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestVote(t *testing.T) {

ok := false
ctx, cancel := context.WithCancel(context.Background())
eventLoop.RegisterObserver(hotstuff.NewViewMsg{}, func(event any) {
eventLoop.RegisterObserver(hotstuff.NewViewMsg{}, func(_ any) {
ok = true
cancel()
})
Expand Down
2 changes: 1 addition & 1 deletion crypto/bitfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func BitfieldFromBytes(b []byte) Bitfield {
len: 0,
}
l := 0
bf.ForEach(func(i hotstuff.ID) {
bf.ForEach(func(_ hotstuff.ID) {
l++
})
bf.len = l
Expand Down
2 changes: 1 addition & 1 deletion crypto/bitfield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestBitfieldForEach(t *testing.T) {

// first check that the bitfield is empty
count := 0
bm.ForEach(func(i hotstuff.ID) {
bm.ForEach(func(_ hotstuff.ID) {
count++
})

Expand Down
24 changes: 12 additions & 12 deletions crypto/keygen/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ func GenerateTLSCert(id hotstuff.ID, hosts []string, parent *x509.Certificate, s
// PrivateKeyToPEM encodes the private key in PEM format.
func PrivateKeyToPEM(key hotstuff.PrivateKey) ([]byte, error) {
var (
marshalled []byte
keyType string
err error
marshaled []byte
keyType string
err error
)
switch k := key.(type) {
case *ecdsa.PrivateKey:
marshalled, err = x509.MarshalECPrivateKey(k)
marshaled, err = x509.MarshalECPrivateKey(k)
if err != nil {
return nil, err
}
keyType = ecdsacrypto.PrivateKeyFileType
case *bls12.PrivateKey:
marshalled = k.ToBytes()
marshaled = k.ToBytes()
keyType = bls12.PrivateKeyFileType
}
b := &pem.Block{
Type: keyType,
Bytes: marshalled,
Bytes: marshaled,
}
return pem.EncodeToMemory(b), nil
}
Expand Down Expand Up @@ -136,25 +136,25 @@ func WritePrivateKeyFile(key hotstuff.PrivateKey, filePath string) (err error) {
// PublicKeyToPEM encodes the public key in PEM format.
func PublicKeyToPEM(key hotstuff.PublicKey) ([]byte, error) {
var (
marshalled []byte
keyType string
err error
marshaled []byte
keyType string
err error
)
switch k := key.(type) {
case *ecdsa.PublicKey:
marshalled, err = x509.MarshalPKIXPublicKey(k)
marshaled, err = x509.MarshalPKIXPublicKey(k)
if err != nil {
return nil, err
}
keyType = ecdsacrypto.PublicKeyFileType
case *bls12.PublicKey:
marshalled = k.ToBytes()
marshaled = k.ToBytes()
keyType = bls12.PublicKeyFileType
}

b := &pem.Block{
Type: keyType,
Bytes: marshalled,
Bytes: marshaled,
}

return pem.EncodeToMemory(b), nil
Expand Down
2 changes: 1 addition & 1 deletion eventloop/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ loop:
el.processEvent(event, false)
}

// HACK: when we get cancelled, we will handle the events that were in the queue at that time before quitting.
// HACK: when we get canceled, we will handle the events that were in the queue at that time before quitting.
l := el.eventQ.len()
for i := 0; i < l; i++ {
event, _ := el.eventQ.pop()
Expand Down
2 changes: 1 addition & 1 deletion eventloop/eventloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestTicker(t *testing.T) {
go el.Run(ctx)

rate := 100 * time.Millisecond
id := el.AddTicker(rate, func(tick time.Time) (event any) { return testEvent(1) })
id := el.AddTicker(rate, func(_ time.Time) (_ any) { return testEvent(1) })

// sleep a little less than 1 second to ensure we get the expected amount of ticks
time.Sleep(time.Second - rate/4)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ run the experiment, and fetch the experiment results.
To run an experiment, use the 'hotstuff run' command.
By default, this command will run a small configuration of replicas locally.
use 'hotstuff help run' to view all possible parameters for this command.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
if !listModules {
return cmd.Usage()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ It is also required that the host keys for all remote machines are present in a
Then, you must use the '--ssh-config' parameter to specify the location of your 'ssh_config' file
(or omit it to use ~/.ssh/config). Then, you must specify the list of remote machines to connect to
using the '--host' parameter. This should be a comma separated list of hostnames or ip addresses.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
runController()
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var workerCmd = &cobra.Command{
Short: "Run a worker.",
Long: `Starts a worker that reads commands from stdin and writes responses to stdout.
This is only intended to be used by a controller (hotstuff run).`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
runWorker()
},
}
Expand Down
13 changes: 5 additions & 8 deletions internal/orchestration/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ func Deploy(g iago.Group, cfg DeployConfig) (workers map[string]WorkerSession, e
}

g.Run("Create temporary directory",
func(ctx context.Context, host iago.Host) (err error) {
func(_ context.Context, host iago.Host) error {
tmpDir := "hotstuff." + randString(8)
testDir := strings.TrimPrefix(tempDirPath(host, tmpDir), "/")
dataDir := testDir + "/data"
host.SetVar("test-dir", testDir)
host.SetVar("data-dir", dataDir)
err = fs.MkdirAll(host.GetFS(), dataDir, 0o755)
return err
return fs.MkdirAll(host.GetFS(), dataDir, 0o755)
})

g.Run(
"Upload hotstuff binary",
g.Run("Upload hotstuff binary",
func(ctx context.Context, host iago.Host) (err error) {
dest, err := iago.NewPath("/", iago.GetStringVar(host, "test-dir")+"/hotstuff")
if err != nil {
Expand Down Expand Up @@ -122,9 +120,8 @@ func FetchData(g iago.Group, dest string) (err error) {
}

g.Run("Remove test directory",
func(ctx context.Context, host iago.Host) (err error) {
err = fs.RemoveAll(host.GetFS(), iago.GetStringVar(host, "test-dir"))
return err
func(_ context.Context, host iago.Host) error {
return fs.RemoveAll(host.GetFS(), iago.GetStringVar(host, "test-dir"))
})

return nil
Expand Down
34 changes: 17 additions & 17 deletions internal/orchestration/orchestration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
)

func TestOrchestration(t *testing.T) {
run := func(consensusImpl string, crypto string, mods []string, byzantine string) {
run := func(t *testing.T, consensusImpl string, crypto string, mods []string, byzantine string) {
t.Helper()
controllerStream, workerStream := net.Pipe()

workerProxy := orchestration.NewRemoteWorker(protostream.NewWriter(controllerStream), protostream.NewReader(controllerStream))
Expand Down Expand Up @@ -72,25 +73,25 @@ func TestOrchestration(t *testing.T) {
}
}

t.Run("ChainedHotStuff+ECDSA", func(t *testing.T) { run("chainedhotstuff", "ecdsa", nil, "") })
t.Run("ChainedHotStuff+BLS12", func(t *testing.T) { run("chainedhotstuff", "bls12", nil, "") })
t.Run("Fast-HotStuff+ECDSA", func(t *testing.T) { run("fasthotstuff", "ecdsa", nil, "") })
t.Run("Fast-HotStuff+BLS12", func(t *testing.T) { run("fasthotstuff", "bls12", nil, "") })
t.Run("Simple-HotStuff+ECDSA", func(t *testing.T) { run("simplehotstuff", "ecdsa", nil, "") })
t.Run("Simple-HotStuff+BLS12", func(t *testing.T) { run("simplehotstuff", "bls12", nil, "") })
t.Run("ChainedHotStuff+ECDSA", func(t *testing.T) { run(t, "chainedhotstuff", "ecdsa", nil, "") })
t.Run("ChainedHotStuff+BLS12", func(t *testing.T) { run(t, "chainedhotstuff", "bls12", nil, "") })
t.Run("Fast-HotStuff+ECDSA", func(t *testing.T) { run(t, "fasthotstuff", "ecdsa", nil, "") })
t.Run("Fast-HotStuff+BLS12", func(t *testing.T) { run(t, "fasthotstuff", "bls12", nil, "") })
t.Run("Simple-HotStuff+ECDSA", func(t *testing.T) { run(t, "simplehotstuff", "ecdsa", nil, "") })
t.Run("Simple-HotStuff+BLS12", func(t *testing.T) { run(t, "simplehotstuff", "bls12", nil, "") })

// handel
mods := []string{"handel"}
t.Run("ChainedHotStuff+ECDSA+Handel", func(t *testing.T) { run("chainedhotstuff", "ecdsa", mods, "") })
t.Run("ChainedHotStuff+BLS12+Handel", func(t *testing.T) { run("chainedhotstuff", "bls12", mods, "") })
t.Run("Fast-HotStuff+ECDSA+Handel", func(t *testing.T) { run("fasthotstuff", "ecdsa", mods, "") })
t.Run("Fast-HotStuff+BLS12+Handel", func(t *testing.T) { run("fasthotstuff", "bls12", mods, "") })
t.Run("Simple-HotStuff+ECDSA+Handel", func(t *testing.T) { run("simplehotstuff", "ecdsa", mods, "") })
t.Run("Simple-HotStuff+BLS12+Handel", func(t *testing.T) { run("simplehotstuff", "bls12", mods, "") })
t.Run("ChainedHotStuff+ECDSA+Handel", func(t *testing.T) { run(t, "chainedhotstuff", "ecdsa", mods, "") })
t.Run("ChainedHotStuff+BLS12+Handel", func(t *testing.T) { run(t, "chainedhotstuff", "bls12", mods, "") })
t.Run("Fast-HotStuff+ECDSA+Handel", func(t *testing.T) { run(t, "fasthotstuff", "ecdsa", mods, "") })
t.Run("Fast-HotStuff+BLS12+Handel", func(t *testing.T) { run(t, "fasthotstuff", "bls12", mods, "") })
t.Run("Simple-HotStuff+ECDSA+Handel", func(t *testing.T) { run(t, "simplehotstuff", "ecdsa", mods, "") })
t.Run("Simple-HotStuff+BLS12+Handel", func(t *testing.T) { run(t, "simplehotstuff", "bls12", mods, "") })

// byzantine
t.Run("ChainedHotStuff+Fork", func(t *testing.T) { run("chainedhotstuff", "ecdsa", nil, "fork:1") })
t.Run("ChainedHotStuff+Silence", func(t *testing.T) { run("chainedhotstuff", "ecdsa", nil, "silence:1") })
t.Run("ChainedHotStuff+Fork", func(t *testing.T) { run(t, "chainedhotstuff", "ecdsa", nil, "fork:1") })
t.Run("ChainedHotStuff+Silence", func(t *testing.T) { run(t, "chainedhotstuff", "ecdsa", nil, "silence:1") })
}

func TestDeployment(t *testing.T) {
Expand Down Expand Up @@ -144,8 +145,7 @@ func TestDeployment(t *testing.T) {
wg.Done()
}(session)
}
err = experiment.Run()
if err != nil {
if err = experiment.Run(); err != nil {
t.Fatal(err)
}
wg.Wait()
Expand Down
2 changes: 1 addition & 1 deletion modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// CommandQueue is a queue of commands to be proposed.
type CommandQueue interface {
// Get returns the next command to be proposed.
// It may run until the context is cancelled.
// It may run until the context is canceled.
// If no command is available, the 'ok' return value should be false.
Get(ctx context.Context) (cmd hotstuff.Command, ok bool)
}
Expand Down
2 changes: 1 addition & 1 deletion replica/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (srv *Replica) Stop() {
srv.Close()
}

// Run runs the replica until the context is cancelled.
// Run runs the replica until the context is canceled.
func (srv *Replica) Run(ctx context.Context) {
var (
synchronizer modules.Synchronizer
Expand Down
8 changes: 4 additions & 4 deletions synchronizer/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// This file provides several functions for creating contexts with lifespans that are tied to synchronizer events.

// ViewContext returns a context that is cancelled at the end of view.
// If view is nil or less than or equal to the current view, the context will be cancelled at the next view change.
// ViewContext returns a context that is canceled at the end of view.
// If view is nil or less than or equal to the current view, the context will be canceled at the next view change.
func ViewContext(parent context.Context, eventLoop *eventloop.EventLoop, view *hotstuff.View) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(parent)

Expand All @@ -26,12 +26,12 @@ func ViewContext(parent context.Context, eventLoop *eventloop.EventLoop, view *h
}
}

// TimeoutContext returns a context that is cancelled either when a timeout occurs, or when the view changes.
// TimeoutContext returns a context that is canceled either when a timeout occurs, or when the view changes.
func TimeoutContext(parent context.Context, eventLoop *eventloop.EventLoop) (context.Context, context.CancelFunc) {
// ViewContext handles view-change case.
ctx, cancel := ViewContext(parent, eventLoop, nil)

id := eventLoop.RegisterHandler(TimeoutEvent{}, func(event any) {
id := eventLoop.RegisterHandler(TimeoutEvent{}, func(_ any) {
cancel()
}, eventloop.Prioritize(), eventloop.UnsafeRunInAddEvent())

Expand Down
Loading

0 comments on commit 6c1fcb7

Please sign in to comment.