Skip to content

Commit

Permalink
Try #4864:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Aug 16, 2023
2 parents 00b8792 + f4ad73b commit 6ce64d3
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 74 deletions.
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 @@ func (h *Handler) handleAtx(ctx context.Context, expHash types.Hash32, peer p2p.
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)
}

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 @@ func (nb *NIPostBuilder) BuildNIPost(ctx context.Context, challenge *types.NIPos
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)
}
if err := nb.validator.Post(
ctx,
Expand All @@ -269,7 +269,7 @@ func (nb *NIPostBuilder) BuildNIPost(ctx context.Context, challenge *types.NIPos
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)
}
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 consumeEvents[T any](ctx context.Context, subscription event.Subscription)

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))
}
}
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 @@ func checkpointDB(ctx context.Context, db *sql.Database, snapshot types.LayerID,

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)
}
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 @@ func (db *CachedDB) getAndCacheHeader(id types.ATXID) (*types.ActivationTxHeader

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)
}

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 @@ func (c *Context) Spawn(args scale.Encodable) error {
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)
}
_, err = instance.EncodeScale(scale.NewEncoder(buf))
if err != nil {
return fmt.Errorf("%w: %s", ErrInternal, err)
return fmt.Errorf("%w: %w", ErrInternal, err)
}
account.State = buf.Bytes()
account.TemplateAddress = &c.Header.TemplateAddress
Expand Down Expand Up @@ -160,7 +160,7 @@ func (c *Context) Relay(remoteTemplate, address Address, call func(Host) error)
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)
}
account.State = buf.Bytes()
c.change(account)
Expand Down Expand Up @@ -188,12 +188,12 @@ func (c *Context) Consume(gas uint64) (err error) {
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)
}
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)
}
}
return nil
Expand Down Expand Up @@ -228,7 +228,7 @@ func (c *Context) load(address types.Address) (*Account, error) {
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)
}
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,11 +62,11 @@ func (v *VM) addRewards(lctx ApplyContext, ss *core.StagedCache, fees uint64, bl
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)
}
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)
}
transferred += totalReward.Uint64()
}
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 @@ func (h *handler) Load(state []byte) (core.Template, error) {
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)
}
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 @@ type handler struct{}
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 @@ func (*handler) Load(state []byte) (core.Template, error) {
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)
}
return &wallet, nil
}
Expand Down

0 comments on commit 6ce64d3

Please sign in to comment.