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

Update AvalancheGo dep to include latest + ACP-118 #1961

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
12 changes: 6 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ run:
# By default, it isn't set.
modules-download-mode: readonly

output:
# Make issues output unique by line.
# Default: true
uniq-by-line: false

issues:
# Maximum issues count per one linter.
# Set to 0 to disable.
Expand All @@ -36,6 +31,10 @@ issues:
# Default: true
exclude-dirs-use-default: false

# Make issues output unique by line.
# Default: true
uniq-by-line: false
Comment on lines +34 to +36
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


linters:
disable-all: true
enable:
Expand All @@ -45,7 +44,7 @@ linters:
- dupword
- errcheck
- errorlint
- exportloopref
- copyloopvar
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as of go1.23

- forbidigo
- gci
- goconst
Expand Down Expand Up @@ -121,6 +120,7 @@ linters-settings:
gosec:
excludes:
- G107 # Url provided to HTTP request as taint input https://securego.io/docs/rules/g107
- G115 # TODO Enable this ruleset in a follow-up PR
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable majority of newly introduced linting errors with the golangci / golang version bump

importas:
# Do not allow unaliased imports of aliased packages.
no-unaliased: false
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ARG AVALANCHEGO_NODE_IMAGE="invalid-image" # This value is not intended to be used but silences a warning

# ============= Compilation Stage ================
FROM --platform=$BUILDPLATFORM golang:1.22.12-bullseye AS builder
FROM --platform=$BUILDPLATFORM golang:1.23.7-bullseye AS builder

WORKDIR /build

Expand Down
6 changes: 3 additions & 3 deletions api/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,14 @@ func (w *WebSocketServer) expireTx(txID ids.ID) {
// [expiringTxs] will be cleared eventually (does not support removal)
}

func (w *WebSocketServer) setMinTx(t int64) error {
func (w *WebSocketServer) setMinTx(t int64) {
expired := w.expiringTxs.SetMin(t)
for _, id := range expired {
w.expireTx(id)
}
if exp := len(expired); exp > 0 {
w.logger.Debug("expired listeners", zap.Int("count", exp))
}
return nil
}

func (w *WebSocketServer) AcceptBlock(_ context.Context, b *chain.ExecutedBlock) error {
Expand Down Expand Up @@ -194,7 +193,8 @@ func (w *WebSocketServer) AcceptBlock(_ context.Context, b *chain.ExecutedBlock)
delete(w.txListeners, txID)
// [expiringTxs] will be cleared eventually (does not support removal)
}
return w.setMinTx(b.Block.Tmstmp)
w.setMinTx(b.Block.Tmstmp)
return nil
}

func (w *WebSocketServer) MessageCallback() pubsub.Callback {
Expand Down
6 changes: 5 additions & 1 deletion auth/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ func NewBLSFactory(priv *bls.PrivateKey) *BLSFactory {
}

func (b *BLSFactory) Sign(msg []byte) (chain.Auth, error) {
return &BLS{Signer: bls.PublicFromPrivateKey(b.priv), Signature: bls.Sign(msg, b.priv)}, nil
signature, err := bls.Sign(msg, b.priv)
if err != nil {
return nil, err
}
return &BLS{Signer: bls.PublicFromPrivateKey(b.priv), Signature: signature}, nil
}

func (*BLSFactory) MaxUnits() (uint64, uint64) {
Expand Down
6 changes: 3 additions & 3 deletions chain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *Builder) BuildBlock(ctx context.Context, pChainCtx *block.Context, pare
c.metrics.clearedMempool.Inc()
break
}
ctx, executeSpan := c.tracer.Start(ctx, "Chain.BuildBlock.Execute") //nolint:spancheck
ctx, executeSpan := c.tracer.Start(ctx, "Chain.BuildBlock.Execute")

// Perform a batch repeat check
// IsRepeat only returns an error if we fail to fetch the full validity window of blocks.
Expand Down Expand Up @@ -276,7 +276,7 @@ func (c *Builder) BuildBlock(ctx context.Context, pChainCtx *block.Context, pare
// Ignore the error and drop the transaction.
// We don't need to rollback [tsv] here because it will never
// be committed.
return nil //nolint:nilerr
return nil
}
result, err := tx.Execute(
ctx,
Expand Down Expand Up @@ -371,7 +371,7 @@ func (c *Builder) BuildBlock(ctx context.Context, pChainCtx *block.Context, pare
// Perform basic validity checks to make sure the block is well-formatted
if len(blockTransactions) == 0 {
if nextTime < parent.Tmstmp+r.GetMinEmptyBlockGap() {
return nil, nil, fmt.Errorf("%w: allowed in %d ms", ErrNoTxs, parent.Tmstmp+r.GetMinEmptyBlockGap()-nextTime) //nolint:spancheck
return nil, nil, fmt.Errorf("%w: allowed in %d ms", ErrNoTxs, parent.Tmstmp+r.GetMinEmptyBlockGap()-nextTime)
}
c.metrics.emptyBlockBuilt.Inc()
}
Expand Down
6 changes: 3 additions & 3 deletions cli/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func (h *Handler) Balance(checkAllChains bool) error {
return err
}

max := len(uris)
maxURIs := len(uris)
if !checkAllChains {
max = 1
maxURIs = 1
}
for _, uri := range uris[:max] {
for _, uri := range uris[:maxURIs] {
utils.Outf("{{yellow}}uri:{{/}} %s\n", uri)
balance, err := h.c.LookupBalance(addr, uris[0])
if err != nil {
Expand Down
42 changes: 21 additions & 21 deletions cli/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func Address(label string) (codec.Address, error) {
return codec.StringToAddress(recipient)
}

func String(label string, min int, max int) (string, error) {
func String(label string, minLen int, maxLen int) (string, error) {
promptText := promptui.Prompt{
Label: label,
Validate: func(input string) error {
if len(input) < min {
if len(input) < minLen {
return ErrInputEmpty
}
if len(input) > max {
if len(input) > maxLen {
return ErrInputTooLarge
}
return nil
Expand Down Expand Up @@ -151,9 +151,9 @@ func Amount(

func Int(
label string,
max int,
maxValue int,
) (int, error) {
stringToInt := func(input string, max int) (int, error) {
stringToInt := func(input string, maxValue int) (int, error) {
input = strings.TrimSpace(input)

if len(input) == 0 {
Expand All @@ -166,31 +166,31 @@ func Int(
if amount <= 0 {
return 0, fmt.Errorf("%d must be > 0", amount)
}
if amount > max {
return 0, fmt.Errorf("%d must be <= %d", amount, max)
if amount > maxValue {
return 0, fmt.Errorf("%d must be <= %d", amount, maxValue)
}
return amount, nil
}

promptText := promptui.Prompt{
Label: label,
Validate: func(input string) error {
_, err := stringToInt(input, max)
_, err := stringToInt(input, maxValue)
return err
},
}
rawAmount, err := promptText.Run()
if err != nil {
return 0, err
}
return stringToInt(rawAmount, max)
return stringToInt(rawAmount, maxValue)
}

func Uint(
label string,
max uint,
maxValue uint,
) (uint, error) {
stringToUint := func(input string, max uint) (uint, error) {
stringToUint := func(input string, maxValue uint) (uint, error) {
input = strings.TrimSpace(input)

if len(input) == 0 {
Expand All @@ -203,29 +203,29 @@ func Uint(
if amount > math.MaxUint {
return 0, fmt.Errorf("%d exceeds the maximum value for uint", amount)
}
if uint(amount) > max {
return 0, fmt.Errorf("%d must be <= %d", amount, max)
if uint(amount) > maxValue {
return 0, fmt.Errorf("%d must be <= %d", amount, maxValue)
}
return uint(amount), nil
}

promptText := promptui.Prompt{
Label: label,
Validate: func(input string) error {
_, err := stringToUint(input, max)
_, err := stringToUint(input, maxValue)
return err
},
}
rawAmount, err := promptText.Run()
if err != nil {
return 0, err
}
return stringToUint(rawAmount, max)
return stringToUint(rawAmount, maxValue)
}

func Float(
label string,
max float64,
maxValue float64,
) (float64, error) {
promptText := promptui.Prompt{
Label: label,
Expand All @@ -240,8 +240,8 @@ func Float(
if amount <= 0 {
return fmt.Errorf("%f must be > 0", amount)
}
if amount > max {
return fmt.Errorf("%f must be <= %f", amount, max)
if amount > maxValue {
return fmt.Errorf("%f must be <= %f", amount, maxValue)
}
return nil
},
Expand All @@ -254,8 +254,8 @@ func Float(
return strconv.ParseFloat(rawAmount, 64)
}

func Choice(label string, max int) (int, error) {
if max == 1 {
func Choice(label string, maxChoice int) (int, error) {
if maxChoice == 1 {
utils.Outf("{{yellow}}%s:{{/}} 0 [auto-selected]\n", label)
return 0, nil
}
Expand All @@ -269,7 +269,7 @@ func Choice(label string, max int) (int, error) {
if err != nil {
return err
}
if index >= max || index < 0 {
if index >= maxChoice || index < 0 {
return ErrIndexOutOfRange
}
return nil
Expand Down
3 changes: 2 additions & 1 deletion crypto/bls/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package bls
import (
"errors"

"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner"

blst "github.com/supranational/blst/bindings/go"
Expand Down Expand Up @@ -37,6 +38,6 @@ func PublicFromPrivateKey(pk *PrivateKey) *PublicKey {
return pk.PublicKey()
}

func Sign(msg []byte, pk *PrivateKey) *Signature {
func Sign(msg []byte, pk *PrivateKey) (*bls.Signature, error) {
return pk.Sign(msg)
}
6 changes: 4 additions & 2 deletions crypto/bls/private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ func TestPrivateKeyBytes(t *testing.T) {

sk, err := GeneratePrivateKey()
require.NoError(err)
sig := Sign(msg, sk)
sig, err := Sign(msg, sk)
require.NoError(err)
skBytes := PrivateKeyToBytes(sk)

sk2, err := PrivateKeyFromBytes(skBytes)
require.NoError(err)
sig2 := Sign(msg, sk2)
sig2, err := Sign(msg, sk2)
require.NoError(err)
sk2Bytes := PrivateKeyToBytes(sk2)

require.Equal(sk, sk2)
Expand Down
6 changes: 4 additions & 2 deletions crypto/bls/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ func TestAggregatePublicKeys(t *testing.T) {
require.NoError(err)

// Aggregates 2 signatures
sig1 := Sign(msg, sk1)
sig2 := Sign(msg, sk2)
sig1, err := Sign(msg, sk1)
require.NoError(err)
sig2, err := Sign(msg, sk2)
require.NoError(err)
aggSigs, err := AggregateSignatures([]*Signature{sig1, sig2})
require.NoError(err)

Expand Down
6 changes: 4 additions & 2 deletions crypto/bls/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func TestSignatureBytes(t *testing.T) {

sk, err := GeneratePrivateKey()
require.NoError(err)
sig := Sign(msg, sk)
sig, err := Sign(msg, sk)
require.NoError(err)
sigBytes := SignatureToBytes(sig)

sig2, err := SignatureFromBytes(sigBytes)
Expand All @@ -36,7 +37,8 @@ func TestAggregateSignaturesNoop(t *testing.T) {
sk, err := GeneratePrivateKey()
require.NoError(err)

sig := Sign(msg, sk)
sig, err := Sign(msg, sk)
require.NoError(err)
sigBytes := SignatureToBytes(sig)

aggSig, err := AggregateSignatures([]*Signature{sig})
Expand Down
4 changes: 1 addition & 3 deletions examples/morpheusvm/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linters:
- depguard
- errcheck
- errorlint
- exportloopref
- copyloopvar
- goconst
- gocritic
- gofmt
Expand All @@ -45,11 +45,9 @@ linters:
- whitespace
- staticcheck
- bodyclose
- structcheck
# - lll
# - gomnd
- goprintffuncname
- interfacer
Comment on lines -48 to -52
Copy link
Collaborator Author

@aaronbuchwald aaronbuchwald Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer supported

- typecheck
# - goerr113
- noctx
Expand Down
4 changes: 2 additions & 2 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var setChainCmd = &cobra.Command{

var importAvalancheCliChainCmd = &cobra.Command{
Use: "import-cli [path]",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return ErrInvalidArgs
}
Expand All @@ -50,7 +50,7 @@ var chainInfoCmd = &cobra.Command{

var watchChainCmd = &cobra.Command{
Use: "watch",
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return handler.Root().WatchChain(hideTxs)
},
}
2 changes: 1 addition & 1 deletion examples/morpheusvm/cmd/morpheus-cli/cmd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var prometheusCmd = &cobra.Command{

var generatePrometheusCmd = &cobra.Command{
Use: "generate",
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, _ []string) error {
return handler.Root().GeneratePrometheus(prometheusBaseURI, prometheusOpenBrowser, startPrometheus, prometheusFile, prometheusData)
},
}
Loading
Loading