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

[Merged by Bors] - Update to go 1.20 #4864

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ run:
# Define the Go version limit.
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18
# go: '1.19'
# go: '1.20'

# output configuration options
output:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

FROM golang:1.19 as builder
FROM golang:1.20 as builder
RUN set -ex \
&& apt-get update --fix-missing \
&& apt-get install -qy --no-install-recommends \
Expand Down
4 changes: 2 additions & 2 deletions Makefile-libs.Inc
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ $(BINDIR_POSTRS_SETUP_LIBS): $(PROJ_DIR)$(POSTRS_SETUP_ZIP)
touch $@

$(PROJ_DIR)$(POSTRS_SETUP_ZIP):
curl -sSL --retry 5 --retry-max-time 60 $(POSTRS_SETUP_URL_ZIP) -o $(PROJ_DIR)$(POSTRS_SETUP_ZIP)
curl -sSL --retry 10 --retry-max-time 120 --retry-all-errors $(POSTRS_SETUP_URL_ZIP) -o $(PROJ_DIR)$(POSTRS_SETUP_ZIP)

$(BIN_DIR)$(POSTRS_PROFILER_BIN):
curl -sSL --retry 5 --retry-max-time 60 $(POSTRS_PROFILER_URL) -o $(PROJ_DIR)$(POSTRS_PROFILER_ZIP)
curl -sSL --retry 10 --retry-max-time 120 --retry-all-errors $(POSTRS_PROFILER_URL) -o $(PROJ_DIR)$(POSTRS_PROFILER_ZIP)
unzip -o -j $(PROJ_DIR)$(POSTRS_PROFILER_ZIP) -d $(BIN_DIR)

get-postrs-lib: $(PROJ_DIR)$(POSTRS_SETUP_ZIP) $(BINDIR_POSTRS_SETUP_LIBS)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Since the project uses Go Modules it is best to place the code **outside** your

Building is supported on OS X, Linux, FreeBSD, and Windows.

Install [Go 1.19 or later](https://golang.org/dl/) for your platform, if you haven't already.
Install [Go 1.20 or later](https://golang.org/dl/) for your platform, if you haven't already.

On Windows you need to install `make` via [msys2](https://www.msys2.org/), [MingGW-w64](http://mingw-w64.org/doku.php) or [mingw](https://chocolatey.org/packages/mingw)

Expand Down
2 changes: 1 addition & 1 deletion activation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@
receivedTime := time.Now()
var atx types.ActivationTx
if err := codec.Decode(msg, &atx); err != nil {
return fmt.Errorf("%w: %v", errMalformedData, err)
return fmt.Errorf("%w: %w", errMalformedData, err)

Check warning on line 503 in activation/handler.go

View check run for this annotation

Codecov / codecov/patch

activation/handler.go#L503

Added line #L503 was not covered by tests
}

epochStart := h.clock.LayerToTime(atx.PublishEpoch.FirstLayer())
Expand Down
6 changes: 3 additions & 3 deletions activation/nipost.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@
proof, proofMetadata, err := nb.postSetupProvider.GenerateProof(ctx, nb.state.PoetProofRef[:], proving.WithPowCreator(nb.nodeID.Bytes()))
if err != nil {
events.EmitPostFailure()
return nil, 0, fmt.Errorf("failed to generate Post: %v", err)
return nil, 0, fmt.Errorf("failed to generate Post: %w", err)
}
commitmentAtxId, err := nb.postSetupProvider.CommitmentAtx()
if err != nil {
return nil, 0, fmt.Errorf("failed to get commitment ATX: %v", err)
return nil, 0, fmt.Errorf("failed to get commitment ATX: %w", err)

Check warning on line 259 in activation/nipost.go

View check run for this annotation

Codecov / codecov/patch

activation/nipost.go#L259

Added line #L259 was not covered by tests
}
if err := nb.validator.Post(
ctx,
Expand All @@ -269,7 +269,7 @@
verifying.WithLabelScryptParams(nb.postSetupProvider.LastOpts().Scrypt),
); err != nil {
events.EmitInvalidPostProof()
return nil, 0, fmt.Errorf("failed to verify Post: %v", err)
return nil, 0, fmt.Errorf("failed to verify Post: %w", err)

Check warning on line 272 in activation/nipost.go

View check run for this annotation

Codecov / codecov/patch

activation/nipost.go#L272

Added line #L272 was not covered by tests
}
events.EmitPostComplete(nb.state.PoetProofRef[:])
postGenDuration = time.Since(startTime)
Expand Down
2 changes: 1 addition & 1 deletion activation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (v *Validator) NIPost(ctx context.Context, publishEpoch types.EpochID, node
}

if err := v.Post(ctx, publishEpoch, nodeId, commitmentAtxId, nipost.Post, nipost.PostMetadata, numUnits, opts...); err != nil {
return 0, fmt.Errorf("invalid Post: %v", err)
return 0, fmt.Errorf("invalid Post: %w", err)
}

var ref types.PoetProofRef
Expand Down
2 changes: 1 addition & 1 deletion api/grpcserver/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@

func closeSubscription(accountSubscription event.Subscription) {
if err := accountSubscription.Close(); err != nil {
log.With().Panic("Failed to close account subscription: " + err.Error())
log.With().Panic("Failed to close account subscription", log.Err(err))

Check warning on line 54 in api/grpcserver/events.go

View check run for this annotation

Codecov / codecov/patch

api/grpcserver/events.go#L54

Added line #L54 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"math"
"math/big"
"math/rand"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -46,7 +47,6 @@ import (
"github.com/spacemeshos/go-spacemesh/log/logtest"
"github.com/spacemeshos/go-spacemesh/p2p"
pubsubmocks "github.com/spacemeshos/go-spacemesh/p2p/pubsub/mocks"
"github.com/spacemeshos/go-spacemesh/rand"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/accounts"
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clone_folder: c:\gopath\src\github.com\spacemeshos\go-spacemesh\
environment:
GOPATH: c:\gopath

stack: go 1.19
stack: go 1.20

before_build:
- choco install make
Expand Down
2 changes: 1 addition & 1 deletion blocks/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (h *Handler) HandleSyncedBlock(ctx context.Context, expHash types.Hash32, p
}

if err := ValidateRewards(b.Rewards); err != nil {
return fmt.Errorf("%w: %s", errInvalidRewards, err.Error())
return fmt.Errorf("%w: %w", errInvalidRewards, err)
}

logger = logger.WithFields(b.ID(), b.LayerIndex)
Expand Down
2 changes: 1 addition & 1 deletion blocks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func getProposalMetadata(
}
mtx, err := transactions.Get(cdb, tid)
if err != nil {
return nil, fmt.Errorf("%w: get proposal tx: %v", errProposalTxMissing, err.Error())
return nil, fmt.Errorf("%w: get proposal tx: %w", errProposalTxMissing, err)
}
if mtx.TxHeader == nil {
return nil, fmt.Errorf("%w: inconsistent state: tx %s is missing header", errProposalTxHdrMissing, mtx.ID)
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as builder
FROM golang:1.20 as builder

WORKDIR /src

Expand Down
2 changes: 1 addition & 1 deletion checkpoint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

tx, err := db.Tx(ctx)
if err != nil {
return nil, fmt.Errorf("create db tx: %s", err)
return nil, fmt.Errorf("create db tx: %w", err)

Check warning on line 48 in checkpoint/runner.go

View check run for this annotation

Codecov / codecov/patch

checkpoint/runner.go#L48

Added line #L48 was not covered by tests
}
defer tx.Release()

Expand Down
2 changes: 1 addition & 1 deletion common/types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func StringToAddress(src string) (Address, error) {
var addr Address
hrp, data, err := bech32.DecodeNoLimit(src)
if err != nil {
return addr, fmt.Errorf("%s: %w", ErrDecodeBech32, err)
return addr, fmt.Errorf("%w: %w", ErrDecodeBech32, err)
}

// for encoding bech32 uses slice of 5-bit unsigned integers. convert it back it 8-bit uints.
Expand Down
19 changes: 3 additions & 16 deletions common/types/address_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package types_test

import (
"math/rand"
"testing"
"time"

"github.com/spacemeshos/go-scale/tester"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -62,7 +60,7 @@ func TestAddress_NewAddress(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
_, err := types.StringToAddress(testCase.src)
if testCase.err != nil {
require.ErrorContains(t, err, testCase.err.Error())
require.ErrorIs(t, err, testCase.err)
} else {
require.NoError(t, err)
}
Expand Down Expand Up @@ -102,7 +100,7 @@ func TestAddress_SetBytes(t *testing.T) {
func TestAddress_GenerateAddress(t *testing.T) {
t.Parallel()
t.Run("generate from public key", func(t *testing.T) {
srcAddr := types.GenerateAddress(RandomBytes(32))
srcAddr := types.GenerateAddress(types.RandomBytes(32))
newAddr, err := types.StringToAddress(srcAddr.String())
require.NoError(t, err)
checkAddressesEqual(t, srcAddr, newAddr)
Expand All @@ -117,7 +115,7 @@ func TestAddress_GenerateAddress(t *testing.T) {

func TestAddress_ReservedBytesOnTop(t *testing.T) {
for i := 0; i < 100; i++ {
addr := types.GenerateAddress(RandomBytes(i))
addr := types.GenerateAddress(types.RandomBytes(i))
for j := 0; j < types.AddressReservedSpace; j++ {
require.Zero(t, addr.Bytes()[j])
}
Expand All @@ -130,17 +128,6 @@ func checkAddressesEqual(t *testing.T, addrA, addrB types.Address) {
require.Equal(t, addrA.IsEmpty(), addrB.IsEmpty())
}

// RandomBytes generates random data in bytes for testing.
func RandomBytes(size int) []byte {
rand.Seed(time.Now().UnixNano())
b := make([]byte, size)
_, err := rand.Read(b)
if err != nil {
return nil
}
return b
}

func FuzzAddressConsistency(f *testing.F) {
tester.FuzzConsistency[types.Address](f)
}
Expand Down
2 changes: 1 addition & 1 deletion common/types/testutil.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"math/rand"
"crypto/rand"
)

// RandomBytes generates random data in bytes for testing.
Expand Down
2 changes: 1 addition & 1 deletion datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@

atxHeader, gotIt := db.atxHdrCache.Get(id)
if !gotIt {
return nil, fmt.Errorf("inconsistent state: failed to get atx header: %v", err)
return nil, fmt.Errorf("inconsistent state: failed to get atx header: %w", err)

Check warning on line 191 in datastore/store.go

View check run for this annotation

Codecov / codecov/patch

datastore/store.go#L191

Added line #L191 was not covered by tests
}

return atxHeader, nil
Expand Down
15 changes: 11 additions & 4 deletions fetch/mesh_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"errors"
"fmt"
"sync"

"github.com/hashicorp/go-multierror"
"golang.org/x/sync/errgroup"

"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/codec"
Expand All @@ -30,7 +31,9 @@ func (f *Fetch) GetAtxs(ctx context.Context, ids []types.ATXID) error {
type dataReceiver func(context.Context, types.Hash32, p2p.Peer, []byte) error

func (f *Fetch) getHashes(ctx context.Context, hashes []types.Hash32, hint datastore.Hint, receiver dataReceiver) error {
var eg multierror.Group
var eg errgroup.Group
var errs error
var mu sync.Mutex
for _, hash := range hashes {
p, err := f.getHash(ctx, hash, hint, receiver)
if err != nil {
Expand All @@ -48,14 +51,18 @@ func (f *Fetch) getHashes(ctx context.Context, hashes []types.Hash32, hint datas
return ctx.Err()
case <-p.completed:
if p.err != nil {
return fmt.Errorf("hint: %v, hash: %v, err: %w", hint, h.String(), p.err)
mu.Lock()
defer mu.Unlock()
err := fmt.Errorf("hint: %v, hash: %v, err: %w", hint, h.String(), p.err)
errs = errors.Join(errs, err)
}
return nil
}
})
}

return eg.Wait().ErrorOrNil()
err := eg.Wait()
return errors.Join(errs, err)
}

// GetMalfeasanceProofs gets malfeasance proofs for the specified NodeIDs and validates them.
Expand Down
12 changes: 6 additions & 6 deletions genvm/core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@
buf := bytes.NewBuffer(nil)
instance, err := handler.New(args)
if err != nil {
return fmt.Errorf("%w: %s", ErrMalformed, err.Error())
return fmt.Errorf("%w: %w", ErrMalformed, err)

Check warning on line 87 in genvm/core/context.go

View check run for this annotation

Codecov / codecov/patch

genvm/core/context.go#L87

Added line #L87 was not covered by tests
}
_, err = instance.EncodeScale(scale.NewEncoder(buf))
if err != nil {
return fmt.Errorf("%w: %s", ErrInternal, err)
return fmt.Errorf("%w: %w", ErrInternal, err)

Check warning on line 91 in genvm/core/context.go

View check run for this annotation

Codecov / codecov/patch

genvm/core/context.go#L91

Added line #L91 was not covered by tests
}
account.State = buf.Bytes()
account.TemplateAddress = &c.Header.TemplateAddress
Expand Down Expand Up @@ -160,7 +160,7 @@
buf := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buf)
if _, err := template.EncodeScale(encoder); err != nil {
return fmt.Errorf("%w: %s", ErrInternal, err.Error())
return fmt.Errorf("%w: %w", ErrInternal, err)

Check warning on line 163 in genvm/core/context.go

View check run for this annotation

Codecov / codecov/patch

genvm/core/context.go#L163

Added line #L163 was not covered by tests
}
account.State = buf.Bytes()
c.change(account)
Expand Down Expand Up @@ -188,12 +188,12 @@
func (c *Context) Apply(updater AccountUpdater) error {
c.PrincipalAccount.NextNonce = c.Header.Nonce + 1
if err := updater.Update(c.PrincipalAccount); err != nil {
return fmt.Errorf("%w: %s", ErrInternal, err.Error())
return fmt.Errorf("%w: %w", ErrInternal, err)

Check warning on line 191 in genvm/core/context.go

View check run for this annotation

Codecov / codecov/patch

genvm/core/context.go#L191

Added line #L191 was not covered by tests
}
for _, address := range c.touched {
account := c.changed[address]
if err := updater.Update(*account); err != nil {
return fmt.Errorf("%w: %s", ErrInternal, err.Error())
return fmt.Errorf("%w: %w", ErrInternal, err)

Check warning on line 196 in genvm/core/context.go

View check run for this annotation

Codecov / codecov/patch

genvm/core/context.go#L196

Added line #L196 was not covered by tests
}
}
return nil
Expand Down Expand Up @@ -228,7 +228,7 @@
if !exist {
loaded, err := c.Loader.Get(address)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrInternal, err.Error())
return nil, fmt.Errorf("%w: %w", ErrInternal, err)

Check warning on line 231 in genvm/core/context.go

View check run for this annotation

Codecov / codecov/patch

genvm/core/context.go#L231

Added line #L231 was not covered by tests
}
account = &loaded
}
Expand Down
4 changes: 2 additions & 2 deletions genvm/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
result = append(result, reward)
account, err := ss.Get(blockReward.Coinbase)
if err != nil {
return nil, fmt.Errorf("%w: %s", core.ErrInternal, err.Error())
return nil, fmt.Errorf("%w: %w", core.ErrInternal, err)

Check warning on line 65 in genvm/rewards.go

View check run for this annotation

Codecov / codecov/patch

genvm/rewards.go#L65

Added line #L65 was not covered by tests
}
account.Balance += reward.TotalReward
if err := ss.Update(account); err != nil {
return nil, fmt.Errorf("%w: %s", core.ErrInternal, err.Error())
return nil, fmt.Errorf("%w: %w", core.ErrInternal, err)
}

Check warning on line 70 in genvm/rewards.go

View check run for this annotation

Codecov / codecov/patch

genvm/rewards.go#L69-L70

Added lines #L69 - L70 were not covered by tests
transferred += totalReward.Uint64()
}
v.logger.With().Debug("rewards for layer",
Expand Down
4 changes: 2 additions & 2 deletions genvm/templates/multisig/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type handler struct {
func (h *handler) Parse(host core.Host, method uint8, decoder *scale.Decoder) (output core.ParseOutput, err error) {
var p core.Payload
if _, err = p.DecodeScale(decoder); err != nil {
err = fmt.Errorf("%w: %s", core.ErrMalformed, err.Error())
err = fmt.Errorf("%w: %w", core.ErrMalformed, err)
return
}
output.GasPrice = p.GasPrice
Expand Down Expand Up @@ -67,7 +67,7 @@ func (h *handler) Load(state []byte) (core.Template, error) {
decoder := scale.NewDecoder(bytes.NewReader(state))
var ms MultiSig
if _, err := ms.DecodeScale(decoder); err != nil {
return nil, fmt.Errorf("%w: malformed state %s", core.ErrInternal, err.Error())
return nil, fmt.Errorf("%w: malformed state %w", core.ErrInternal, err)
}
return &ms, nil
}
Expand Down
2 changes: 1 addition & 1 deletion genvm/templates/vault/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
dec := scale.NewDecoder(bytes.NewBuffer(state))
vault := &Vault{}
if _, err := vault.DecodeScale(dec); err != nil {
return nil, fmt.Errorf("%w: %s", core.ErrInternal, err)
return nil, fmt.Errorf("%w: %w", core.ErrInternal, err)

Check warning on line 56 in genvm/templates/vault/handler.go

View check run for this annotation

Codecov / codecov/patch

genvm/templates/vault/handler.go#L56

Added line #L56 was not covered by tests
}
return vault, nil
}
Expand Down
4 changes: 2 additions & 2 deletions genvm/templates/wallet/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
func (*handler) Parse(host core.Host, method uint8, decoder *scale.Decoder) (output core.ParseOutput, err error) {
var p core.Payload
if _, err = p.DecodeScale(decoder); err != nil {
err = fmt.Errorf("%w: %s", core.ErrMalformed, err.Error())
err = fmt.Errorf("%w: %w", core.ErrMalformed, err)
return
}
output.GasPrice = p.GasPrice
Expand All @@ -49,7 +49,7 @@
decoder := scale.NewDecoder(bytes.NewReader(state))
var wallet Wallet
if _, err := wallet.DecodeScale(decoder); err != nil {
return nil, fmt.Errorf("%w: malformed state %s", core.ErrInternal, err.Error())
return nil, fmt.Errorf("%w: malformed state %w", core.ErrInternal, err)

Check warning on line 52 in genvm/templates/wallet/handler.go

View check run for this annotation

Codecov / codecov/patch

genvm/templates/wallet/handler.go#L52

Added line #L52 was not covered by tests
}
return &wallet, nil
}
Expand Down