Skip to content

Commit 7a0c2b9

Browse files
committed
Update tooling and fix new linter errors
1 parent 34f2c2c commit 7a0c2b9

18 files changed

+434
-218
lines changed

.golangci.yml

+359-151
Large diffs are not rendered by default.

Makefile

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ VERSION ?= $(shell git describe --tags)
88
# Flags appended to `go test` command in `make test`
99
TEST_FLAGS ?=
1010

11-
GOLANGCI_LINT_VERSION := v1.56.2
11+
GOLANGCI_LINT_VERSION := v1.57.0
1212
STATICCHECK_VERSION := v0.4.7
1313
GOTESTSUM_VERSION := v1.11.0
1414
GOSCALE_VERSION := v1.1.13
1515

16-
BUF_VERSION := 1.29.0
17-
PROTOC_VERSION = 25.3
16+
BUF_VERSION := 1.30.0
17+
PROTOC_VERSION = 26.0
18+
19+
GRPC_JSON_PROXY_VERSION := v2.19.1
20+
PROTOC_GO_VERSION := v1.33.0
21+
PROTOC_GEN_GO_VERSION := v1.3.0
22+
PROTOC_OPENAPI_VERSION := v2.19.1
1823

1924
# Everything below this line is meant to be static, i.e. only adjust the above variables. ###
2025

@@ -51,13 +56,13 @@ GOLINES := $(GOBIN)/golines
5156
FUZZTIME ?= "10s"
5257

5358
$(GOVULNCHECK):
54-
@go install golang.org/x/vuln/cmd/govulncheck@latest
59+
@go install golang.org/x/vuln/cmd/govulncheck@v1.0.4
5560

5661
$(GOLINES):
5762
@go install github.com/segmentio/[email protected]
5863

5964
$(BIN_DIR)/mockgen:
60-
go install go.uber.org/mock/mockgen@v0.4.0
65+
@go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
6166

6267
install-buf:
6368
@mkdir -p $(BIN_DIR)
@@ -78,10 +83,10 @@ endif
7883

7984
# Download protoc plugins
8085
protoc-plugins:
81-
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.18.0
82-
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.18.0
83-
@go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0
84-
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
86+
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@$(GRPC_JSON_PROXY_VERSION)
87+
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@$(PROTOC_OPENAPI_VERSION)
88+
@go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GO_VERSION)
89+
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_VERSION)
8590
.PHONY: protoc-plugins
8691

8792
all: build

hash/hash_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ import (
99

1010
func TestGenLabelHashFunc(t *testing.T) {
1111
t.Parallel()
12-
r := require.New(t)
1312

1413
aChallenge, bChallenge := []byte("a"), []byte("b")
1514
data, other := []byte("data"), []byte("other")
1615

1716
// same challenge and data -> same hash
18-
r.Equal(GenLabelHashFunc(aChallenge)(data), GenLabelHashFunc(aChallenge)(data))
17+
aHash := GenLabelHashFunc(aChallenge)(data)
18+
require.Equal(t, aHash, GenLabelHashFunc(aChallenge)(data))
1919

2020
// different challenge -> different hash
21-
r.NotEqual(GenLabelHashFunc(aChallenge)(data), GenLabelHashFunc(bChallenge)(data))
21+
require.NotEqual(t, aHash, GenLabelHashFunc(bChallenge)(data))
2222

2323
// different data -> different hash
24-
r.NotEqual(GenLabelHashFunc(aChallenge)(data), GenLabelHashFunc(aChallenge)(other))
24+
require.NotEqual(t, aHash, GenLabelHashFunc(aChallenge)(other))
2525
}
2626

2727
func TestGenMerkleHashFunc(t *testing.T) {
2828
t.Parallel()
29-
r := require.New(t)
3029

3130
aChallenge, bChallenge := []byte("a"), []byte("b")
3231
lChild, rChild := []byte("l"), []byte("r")
3332

3433
// same challenge and children -> same hash
35-
r.Equal(GenMerkleHashFunc(aChallenge)(nil, lChild, rChild), GenMerkleHashFunc(aChallenge)(nil, lChild, rChild))
34+
aHash := GenMerkleHashFunc(aChallenge)(nil, lChild, rChild)
35+
require.Equal(t, aHash, GenMerkleHashFunc(aChallenge)(nil, lChild, rChild))
3636

3737
// different challenge -> different hash
38-
r.NotEqual(GenMerkleHashFunc(aChallenge)(nil, lChild, rChild), GenMerkleHashFunc(bChallenge)(nil, lChild, rChild))
38+
require.NotEqual(t, aHash, GenMerkleHashFunc(bChallenge)(nil, lChild, rChild))
3939

4040
// different children (e.g. different order) -> different hash
41-
r.NotEqual(GenMerkleHashFunc(aChallenge)(nil, lChild, rChild), GenMerkleHashFunc(aChallenge)(nil, rChild, lChild))
41+
require.NotEqual(t, aHash, GenMerkleHashFunc(aChallenge)(nil, rChild, lChild))
4242
}
4343

4444
func TestGenLabelHashFuncHash(t *testing.T) {

poetcore_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211

1312
"github.com/spacemeshos/poet/hash"
@@ -67,7 +66,7 @@ func TestNip(t *testing.T) {
6766
time.Now().Add(1*time.Second),
6867
securityParam,
6968
)
70-
assert.NoError(t, err)
69+
require.NoError(t, err)
7170
fmt.Printf("Dag root label: %x\n", merkleProof.Root)
7271

7372
err = verifier.Validate(
@@ -77,15 +76,15 @@ func TestNip(t *testing.T) {
7776
numLeaves,
7877
securityParam,
7978
)
80-
assert.NoError(t, err, "failed to verify proof")
79+
require.NoError(t, err, "failed to verify proof")
8180
}
8281

8382
func BenchmarkProofEx(t *testing.B) {
8483
for j := 0; j < 10; j++ {
8584
// generate random commitment
8685
challenge := make([]byte, 32)
8786
_, err := rand.Read(challenge)
88-
assert.NoError(t, err)
87+
require.NoError(t, err)
8988

9089
securityParam := shared.T
9190

@@ -97,7 +96,7 @@ func BenchmarkProofEx(t *testing.B) {
9796
time.Now().Add(time.Second),
9897
securityParam,
9998
)
100-
assert.NoError(t, err)
99+
require.NoError(t, err)
101100
fmt.Printf("Dag root label: %x\n", merkleProof.Root)
102101

103102
err = verifier.Validate(
@@ -107,6 +106,6 @@ func BenchmarkProofEx(t *testing.B) {
107106
numLeaves,
108107
securityParam,
109108
)
110-
assert.NoError(t, err, "failed to verify proof")
109+
require.NoError(t, err, "failed to verify proof")
111110
}
112111
}

prover/prover.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func makeRecoveryProofTree(
164164

165165
// Validate that layer 0 exists.
166166
if _, ok := layersFiles[0]; !ok {
167-
return nil, nil, fmt.Errorf("layer 0 cache file is missing")
167+
return nil, nil, errors.New("layer 0 cache file is missing")
168168
}
169169

170170
var topLayer uint
@@ -245,8 +245,8 @@ func makeRecoveryProofTree(
245245
}
246246
parkedNodes = append(parkedNodes, memCachedParkedNodes...)
247247

248-
logging.FromContext(ctx).
249-
Debug("recovered parked nodes", zap.Array("nodes", zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error {
248+
logging.FromContext(ctx).Debug("recovered parked nodes",
249+
zap.Array("nodes", zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error {
250250
for _, node := range parkedNodes {
251251
enc.AppendString(fmt.Sprintf("%X", node))
252252
}

registration/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func DefaultConfig() Config {
1515
}
1616
}
1717

18+
//nolint:lll
1819
type Config struct {
1920
// FIXME: remove deprecated PoW
2021
PowDifficulty uint `long:"pow-difficulty" description:"(DEPRECATED) PoW difficulty (in the number of leading zero bits)"`

registration/doc.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ Package registration provides functionality for registering PoET challenges, sch
33
44
Each round starts by being open for receiving challenges (byte arrays) from miners.
55
Once finalized (according to the configured duration), a hash digest is created from the received challenges,
6-
and is used as the input for the proof generation. The hash is the root of a merkle tree constructed from registered challenges
7-
sorted lexicographically.
8-
The proof generation is done by a worker, which can be a separate process that communicates with the registration service.
6+
and is used as the input for the proof generation. The hash is the root of a merkle tree constructed from registered
7+
challenges sorted lexicographically.
8+
The proof generation is done by a worker, which can be a separate process that communicates with the registration
9+
service.
910
1011
Once completed, the proof is stored in a database and available for nodes via a GRPC query.
1112
In addition to the PoET, the proof also contains the list of received challenges, so that the membership

registration/pow_verifier.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type PowVerifier interface {
2222
// PoW hash is ripemd256(powChallenge || nodeID || poetChallenge || nonce)
2323
Verify(poetChallenge, nodeID []byte, nonce uint64) error
2424
Params() PowParams
25-
SetParams(PowParams)
25+
SetParams(params PowParams)
2626
}
2727

2828
type PowParams struct {

registration/registration.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,11 @@ func (r *Registration) closeRound(ctx context.Context) error {
183183
if err != nil {
184184
return fmt.Errorf("calculating membership root: %w", err)
185185
}
186-
logging.FromContext(ctx).
187-
Info("closing round", zap.Uint("epoch", r.openRound.epoch), zap.Binary("root", root), zap.Int("members", r.openRound.members))
186+
logging.FromContext(ctx).Info("closing round",
187+
zap.Uint("epoch", r.openRound.epoch),
188+
zap.Binary("root", root),
189+
zap.Int("members", r.openRound.members),
190+
)
188191

189192
if err := r.openRound.Close(); err != nil {
190193
logging.FromContext(ctx).Error("failed to close the open round", zap.Error(err))
@@ -375,7 +378,7 @@ func (r *Registration) Submit(
375378
}
376379
}
377380
case errors.Is(err, ErrChallengeAlreadySubmitted):
378-
case err != nil:
381+
default: // err != nil
379382
return 0, time.Time{}, err
380383
}
381384

registration/round.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ func (r *round) submit(ctx context.Context, key, challenge []byte) (<-chan error
182182
if r.batch.Len() >= r.maxBatchSize {
183183
r.flushPendingSubmitsLocked()
184184
} else if r.batch.Len() == 1 {
185-
logging.FromContext(ctx).Debug("scheduling flush of pending submits", zap.Uint("round", r.epoch), zap.Duration("interval", r.flushInterval))
185+
logging.FromContext(ctx).Debug(
186+
"scheduling flush of pending submits",
187+
zap.Uint("round", r.epoch),
188+
zap.Duration("interval", r.flushInterval),
189+
)
186190
time.AfterFunc(r.flushInterval, r.flushPendingSubmits)
187191
}
188192

release/proto/go/rpc/api/v1/api.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/proto/go/rpc/api/v1/api.pb.gw.go

+2-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/proto/openapiv2/rpc/api/v1/api.swagger.json

+17-17
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@
149149
}
150150
}
151151
},
152+
"apiv1PowParams": {
153+
"type": "object",
154+
"properties": {
155+
"difficulty": {
156+
"type": "integer",
157+
"format": "int64",
158+
"title": "Difficulty of the PoW challenge (in terms of leading zero bits in the hash)"
159+
},
160+
"challenge": {
161+
"type": "string",
162+
"format": "byte",
163+
"title": "The challenge to be used for the PoW"
164+
}
165+
}
166+
},
152167
"protobufAny": {
153168
"type": "object",
154169
"properties": {
@@ -237,26 +252,11 @@
237252
}
238253
}
239254
},
240-
"v1PowParams": {
241-
"type": "object",
242-
"properties": {
243-
"difficulty": {
244-
"type": "integer",
245-
"format": "int64",
246-
"title": "Difficulty of the PoW challenge (in terms of leading zero bits in the hash)"
247-
},
248-
"challenge": {
249-
"type": "string",
250-
"format": "byte",
251-
"title": "The challenge to be used for the PoW"
252-
}
253-
}
254-
},
255255
"v1PowParamsResponse": {
256256
"type": "object",
257257
"properties": {
258258
"powParams": {
259-
"$ref": "#/definitions/v1PowParams"
259+
"$ref": "#/definitions/apiv1PowParams"
260260
}
261261
}
262262
},
@@ -281,7 +281,7 @@
281281
"title": "Proof of Work nonce\ndeprecated - use certificate instead"
282282
},
283283
"powParams": {
284-
"$ref": "#/definitions/v1PowParams",
284+
"$ref": "#/definitions/apiv1PowParams",
285285
"title": "Proof of Work parameters that were used to generate the nonce\ndeprecated - use certificate instead"
286286
},
287287
"prefix": {

rpc/rpcserver_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Test_Submit_DoesNotPanicOnMissingPubKey(t *testing.T) {
2727
// Assert
2828
require.Nil(t, out)
2929
require.Error(t, err)
30-
require.Equal(t, status.Code(err), codes.InvalidArgument)
30+
require.Equal(t, codes.InvalidArgument, status.Code(err))
3131
require.ErrorContains(t, err, "invalid public key")
3232
}
3333

@@ -48,6 +48,6 @@ func Test_Submit_DoesNotPanicOnMissingSignature(t *testing.T) {
4848
// Assert
4949
require.Nil(t, out)
5050
require.Error(t, err)
51-
require.Equal(t, status.Code(err), codes.InvalidArgument)
51+
require.Equal(t, codes.InvalidArgument, status.Code(err))
5252
require.ErrorContains(t, err, "invalid signature")
5353
}

server/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
defaultCycleGap = 10 * time.Second
3131
)
3232

33+
//nolint:lll
3334
type Config struct {
3435
Genesis Genesis `long:"genesis-time" description:"Genesis timestamp in RFC3339 format"`
3536
PoetDir string `long:"poetdir" description:"The base directory that contains poet's data, logs, configuration file, etc."`

service/config.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package service
22

33
const (
4-
defaultMemoryLayers = 26 // Up to (1 << 26) * 2 - 1 Merkle tree cache nodes (32 bytes each) will be held in-memory
4+
// Up to (1 << 26) * 2 - 1 Merkle tree cache nodes (32 bytes each) will be held in-memory.
5+
defaultMemoryLayers = 26
56
defaultTreeFileBufferSize = 4096
67
defaultEstimatedLeavesPerSecond = 78000
78
)
89

10+
//nolint:lll
911
type Config struct {
1012
// Merkle-Tree related configuration:
1113
EstimatedLeavesPerSecond uint `long:"lps" description:"Estimated number of leaves generated per second"`

shared/shared.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func MakeLabelFunc() func(hash LabelHash, labelID uint64, leftSiblings [][]byte)
7676
// Scale encoding is implemented by hand to be able to limit [][]byte slices to a maximum size (inner and outer slices).
7777
type MerkleProof struct {
7878
Root []byte `scale:"max=32"`
79-
ProvenLeaves [][]byte `scale:"max=150"` // the max. size of this slice is T (security param), and each element is exactly 32 bytes
79+
ProvenLeaves [][]byte `scale:"max=150"` // max. size is T (security param), and each element is exactly 32 bytes
8080
ProofNodes [][]byte `scale:"max=5400"` // 36 nodes per leaf and each node is exactly 32 bytes
8181
}
8282

shared/shared_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestFiatShamir(t *testing.T) {
3434
deviationFromExpected := float64(int(occurrences[uint64(i)])-expectedIndicesPerBucket) /
3535
float64(expectedIndicesPerBucket)
3636
// fmt.Printf("%d %d %+0.3f%%\n", i, occurrences[uint64(i)], 100*deviationFromExpected)
37-
assert.True(t, math.Abs(deviationFromExpected) < 0.005,
37+
assert.Less(t, math.Abs(deviationFromExpected), 0.005,
3838
"deviation from expected cannot exceed 0.5%% (for bucket %d it was %+0.3f%%)", i,
3939
100*deviationFromExpected)
4040
}

0 commit comments

Comments
 (0)