diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3567b1c89..ec5dbf047 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,7 @@ jobs: runs-on: ${{matrix.os.name}} strategy: matrix: - os: [{ name: ubuntu-20.04, bin-name: linux }, { name: windows-2022, bin-name: windows }, { name: macos-12, bin-name: darwin }] + os: [{ name: ubuntu-22.04, bin-name: linux }, { name: windows-2022, bin-name: windows }, { name: macos-12, bin-name: darwin }] arch: [amd64, arm64] exclude: - os: { name: windows-2022, bin-name: windows } @@ -53,8 +53,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21' - cache: true + go-version: '1.22' - name: Build CLI run: make build @@ -80,7 +79,7 @@ jobs: build_image: needs: build_cli name: Build and push docker image - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -136,8 +135,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21' - cache: true + go-version: '1.22' - name: Login to DockerHub if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b475320e7..840f75c9c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -86,7 +86,7 @@ jobs: test_cover: name: Coverage - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 env: CGO_ENABLED: 0 @@ -99,7 +99,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' cache: true - name: Write coverage profile @@ -117,25 +117,25 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-2022, macos-12, macos-14] - go_versions: [ '1.19', '1.20', '1.21' ] + os: [ubuntu-22.04, windows-2022, macos-12, macos-14] + go_versions: [ '1.20', '1.21', '1.22' ] exclude: # Only latest Go version for Windows and MacOS. - os: windows-2022 - go_versions: '1.19' + go_versions: '1.20' - os: windows-2022 - go_versions: '1.20' - - os: macos-12 - go_versions: '1.19' - - os: macos-12 - go_versions: '1.20' - - os: macos-14 - go_versions: '1.19' - - os: macos-14 - go_versions: '1.20' - # Exclude latest Go version for Ubuntu as Coverage uses it. - - os: ubuntu-20.04 go_versions: '1.21' + - os: macos-12 + go_versions: '1.20' + - os: macos-12 + go_versions: '1.21' + - os: macos-14 + go_versions: '1.20' + - os: macos-14 + go_versions: '1.21' + # Exclude latest Go version for Ubuntu as Coverage uses it. + - os: ubuntu-22.04 + go_versions: '1.22' fail-fast: false steps: - uses: actions/checkout@v4 @@ -147,7 +147,6 @@ jobs: uses: actions/setup-go@v5 with: go-version: '${{ matrix.go_versions }}' - cache: true - name: Run tests run: go test -v -race ./... diff --git a/Dockerfile b/Dockerfile index 137f07393..c23ada9b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Builder image # Keep go version in sync with Build GA job. -FROM golang:1.21-alpine as builder +FROM golang:1.22-alpine as builder # Display go version for information purposes. RUN go version diff --git a/Dockerfile.wsc b/Dockerfile.wsc index c4d094980..58e09f65a 100644 --- a/Dockerfile.wsc +++ b/Dockerfile.wsc @@ -1,6 +1,6 @@ # Builder image # Keep go version in sync with Build GA job. -FROM golang:1.21.3-windowsservercore-ltsc2022 as builder +FROM golang:1.22.0-windowsservercore-ltsc2022 as builder COPY . /neo-go diff --git a/Makefile b/Makefile index 7fbbdb13d..e8b0c9c02 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ REPONAME = "neo-go" NETMODE ?= "privnet" BINARY=neo-go BINARY_PATH=./bin/$(BINARY)$(shell go env GOEXE) -GO_VERSION ?= 1.19 +GO_VERSION ?= 1.20 DESTDIR = "" SYSCONFIGDIR = "/etc" BINDIR = "/usr/bin" diff --git a/README.md b/README.md index 4a88b0832..a435c83c3 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ NeoGo, `:latest` points to the latest release) or build yourself. ### Building -Building NeoGo requires Go 1.19+ and `make`: +Building NeoGo requires Go 1.20+ and `make`: ``` make diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index de8cb4c49..4d4d10674 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -375,7 +375,7 @@ func initSmartContract(ctx *cli.Context) error { gm := []byte("module " + contractName + ` -go 1.19 +go 1.20 require ( github.com/nspcc-dev/neo-go/pkg/interop ` + ver + ` diff --git a/cli/vm/cli.go b/cli/vm/cli.go index 5de30ecc7..b504a51dd 100644 --- a/cli/vm/cli.go +++ b/cli/vm/cli.go @@ -616,7 +616,7 @@ func getInstructionParameter(c *cli.Context) (int, error) { } n, err := strconv.Atoi(args[0]) if err != nil { - return 0, fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return 0, fmt.Errorf("%w: %w", ErrInvalidParameter, err) } return n, nil } @@ -736,7 +736,7 @@ func handleLoadNEF(c *cli.Context) error { if signersStartOffset != 0 && len(args) > signersStartOffset { signers, err = cmdargs.ParseSigners(c.Args()[signersStartOffset:]) if err != nil { - return fmt.Errorf("%w: failed to parse signers: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: failed to parse signers: %w", ErrInvalidParameter, err) } } err = prepareVM(c, createFakeTransaction(nef.Script, signers)) @@ -767,7 +767,7 @@ func handleLoadBase64(c *cli.Context) error { } b, err := base64.StdEncoding.DecodeString(args[0]) if err != nil { - return fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } var signers []transaction.Signer if len(args) > 1 { @@ -779,7 +779,7 @@ func handleLoadBase64(c *cli.Context) error { } signers, err = cmdargs.ParseSigners(args[2:]) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } } err = prepareVM(c, createFakeTransaction(b, signers)) @@ -807,7 +807,7 @@ func handleLoadHex(c *cli.Context) error { } b, err := hex.DecodeString(args[0]) if err != nil { - return fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } var signers []transaction.Signer if len(args) > 1 { @@ -819,7 +819,7 @@ func handleLoadHex(c *cli.Context) error { } signers, err = cmdargs.ParseSigners(args[2:]) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } } err = prepareVM(c, createFakeTransaction(b, signers)) @@ -859,7 +859,7 @@ func handleLoadGo(c *cli.Context) error { } signers, err = cmdargs.ParseSigners(args[2:]) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } } @@ -962,7 +962,7 @@ func handleLoadDeployed(c *cli.Context) error { } signers, err = cmdargs.ParseSigners(args[2:]) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } } err = prepareVM(c, createFakeTransaction(cs.NEF.Script, signers)) // prepare VM one more time for proper IC initialization. @@ -1074,7 +1074,7 @@ func handleRun(c *cli.Context) error { _, scParams, err := cmdargs.ParseParams(args[1:], true) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } params = make([]stackitem.Item, len(scParams)) for i := range scParams { @@ -1185,7 +1185,7 @@ func handleStep(c *cli.Context) error { if len(args) > 0 { n, err = strconv.Atoi(args[0]) if err != nil { - return fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidParameter, err) } } v.AddBreakPointRel(n) diff --git a/cli/vm/cli_test.go b/cli/vm/cli_test.go index 569513918..81c2d56b0 100644 --- a/cli/vm/cli_test.go +++ b/cli/vm/cli_test.go @@ -347,7 +347,7 @@ require ( github.com/nspcc-dev/neo-go/pkg/interop v0.0.0 ) replace github.com/nspcc-dev/neo-go/pkg/interop => ` + filepath.Join(wd, "../../pkg/interop") + ` -go 1.19`) +go 1.20`) require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm)) return filename } diff --git a/cli/wallet/legacy_test.go b/cli/wallet/legacy_test.go index 8a80ac00c..388d04841 100644 --- a/cli/wallet/legacy_test.go +++ b/cli/wallet/legacy_test.go @@ -1,12 +1,12 @@ package wallet import ( + "bytes" "crypto/elliptic" "encoding/hex" "testing" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/require" ) @@ -36,27 +36,27 @@ func TestParseMultisigContract(t *testing.T) { testParseMultisigContract(t, s, 1, pub) }) t.Run("bad, no check multisig", func(t *testing.T) { - sBad := slice.Copy(s) + sBad := bytes.Clone(s) sBad[len(sBad)-1] ^= 0xFF testParseMultisigContract(t, sBad, 0) }) t.Run("bad, invalid number of keys", func(t *testing.T) { - sBad := slice.Copy(s) + sBad := bytes.Clone(s) sBad[len(sBad)-2] = opPush1 + 1 testParseMultisigContract(t, sBad, 0) }) t.Run("bad, invalid first instruction", func(t *testing.T) { - sBad := slice.Copy(s) + sBad := bytes.Clone(s) sBad[0] = 0xFF testParseMultisigContract(t, sBad, 0) }) t.Run("bad, invalid public key", func(t *testing.T) { - sBad := slice.Copy(s) + sBad := bytes.Clone(s) sBad[2] = 0xFF testParseMultisigContract(t, sBad, 0) }) t.Run("bad, many sigs", func(t *testing.T) { - sBad := slice.Copy(s) + sBad := bytes.Clone(s) sBad[0] = opPush1 + 1 testParseMultisigContract(t, sBad, 0) }) diff --git a/examples/engine/go.mod b/examples/engine/go.mod index 259d8f414..40bd3810a 100644 --- a/examples/engine/go.mod +++ b/examples/engine/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/engine -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/events/go.mod b/examples/events/go.mod index 898e16e49..d52037a51 100644 --- a/examples/events/go.mod +++ b/examples/events/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/events -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/iterator/go.mod b/examples/iterator/go.mod index 87b7e7f71..a71f43e99 100644 --- a/examples/iterator/go.mod +++ b/examples/iterator/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/iterator -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/nft-d/go.mod b/examples/nft-d/go.mod index 8709f571c..a27ef65e1 100644 --- a/examples/nft-d/go.mod +++ b/examples/nft-d/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/nft -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/nft-nd-nns/go.mod b/examples/nft-nd-nns/go.mod index 88ab26274..c4d040cce 100644 --- a/examples/nft-nd-nns/go.mod +++ b/examples/nft-nd-nns/go.mod @@ -1,6 +1,6 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd-nns -go 1.19 +go 1.20 require ( github.com/nspcc-dev/neo-go v0.102.1-0.20231020181554-d89c8801d689 diff --git a/examples/nft-nd/go.mod b/examples/nft-nd/go.mod index 236b605e1..16d3433bc 100644 --- a/examples/nft-nd/go.mod +++ b/examples/nft-nd/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/nft-nd -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/oracle/go.mod b/examples/oracle/go.mod index 0453b08a6..1e30916d3 100644 --- a/examples/oracle/go.mod +++ b/examples/oracle/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/oracle -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/runtime/go.mod b/examples/runtime/go.mod index 440513532..75d947357 100644 --- a/examples/runtime/go.mod +++ b/examples/runtime/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/runtime -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/storage/go.mod b/examples/storage/go.mod index 009c5e290..f9cf20219 100644 --- a/examples/storage/go.mod +++ b/examples/storage/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/storage -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/timer/go.mod b/examples/timer/go.mod index 24c17b59f..388f80a7b 100644 --- a/examples/timer/go.mod +++ b/examples/timer/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/timer -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/token/go.mod b/examples/token/go.mod index cf10146ad..ce074aa12 100644 --- a/examples/token/go.mod +++ b/examples/token/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/token -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/examples/zkp/cubic_circuit/go.mod b/examples/zkp/cubic_circuit/go.mod index 3a7225032..a7cc285de 100644 --- a/examples/zkp/cubic_circuit/go.mod +++ b/examples/zkp/cubic_circuit/go.mod @@ -1,6 +1,6 @@ module github.com/nspcc-dev/neo-go/examples/zkp/cubic -go 1.19 +go 1.20 require ( github.com/consensys/gnark v0.9.1 diff --git a/examples/zkp/xor_compat/go.mod b/examples/zkp/xor_compat/go.mod index b6fb30805..edf86e3a3 100644 --- a/examples/zkp/xor_compat/go.mod +++ b/examples/zkp/xor_compat/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/examples/zkp/xor -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/go.mod b/go.mod index 186803962..001c828a7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/nspcc-dev/neo-go -go 1.19 +go 1.20 require ( github.com/chzyer/readline v1.5.1 diff --git a/internal/contracts/oracle_contract/go.mod b/internal/contracts/oracle_contract/go.mod index fd17f38fe..d5399fb20 100644 --- a/internal/contracts/oracle_contract/go.mod +++ b/internal/contracts/oracle_contract/go.mod @@ -1,5 +1,5 @@ module github.com/nspcc-dev/neo-go/internal/examples/oracle -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 diff --git a/internal/random/random_util.go b/internal/random/random_util.go index 529f6947f..282af57c9 100644 --- a/internal/random/random_util.go +++ b/internal/random/random_util.go @@ -50,5 +50,6 @@ func Uint160() util.Uint160 { } func init() { + //nolint:staticcheck rand.Seed(time.Now().UTC().UnixNano()) } diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index aa1a0f324..05a18a88a 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -36,7 +36,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" @@ -1172,7 +1171,7 @@ func (bc *Blockchain) resetTransfers(cache *dao.Simple, height uint32) error { trInfo = nil removeFollowing = false } else if removeFollowing { - cache.Store.Delete(slice.Copy(k)) + cache.Store.Delete(bytes.Clone(k)) return seekErr == nil } @@ -2511,7 +2510,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool. // really require a chain lock. err := vm.IsScriptCorrect(t.Script, nil) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidScript, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidScript, err) } height := bc.BlockHeight() @@ -2522,7 +2521,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool. // Policying. if err := bc.contracts.Policy.CheckPolicy(bc.dao, t); err != nil { // Only one %w can be used. - return fmt.Errorf("%w: %v", ErrPolicy, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrPolicy, err) } if t.SystemFee > bc.config.MaxBlockSystemFee { return fmt.Errorf("%w: too big system fee (%d > MaxBlockSystemFee %d)", ErrPolicy, t.SystemFee, bc.config.MaxBlockSystemFee) @@ -2566,7 +2565,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool. case errors.Is(err, mempool.ErrOOM): return ErrOOM case errors.Is(err, mempool.ErrConflictsAttribute): - return fmt.Errorf("mempool: %w: %s", ErrHasConflicts, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("mempool: %w: %w", ErrHasConflicts, err) default: return err } @@ -2607,7 +2606,7 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact case transaction.OracleResponseT: h, err := bc.contracts.Oracle.GetScriptHash(bc.dao) if err != nil || h.Equals(util.Uint160{}) { - return fmt.Errorf("%w: %v", ErrInvalidAttribute, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidAttribute, err) } hasOracle := false for i := range tx.Signers { @@ -2627,7 +2626,7 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact resp := tx.Attributes[i].Value.(*transaction.OracleResponse) req, err := bc.contracts.Oracle.GetRequestInternal(bc.dao, resp.ID) if err != nil { - return fmt.Errorf("%w: oracle tx points to invalid request: %v", ErrInvalidAttribute, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: oracle tx points to invalid request: %w", ErrInvalidAttribute, err) } if uint64(tx.NetworkFee+tx.SystemFee) < req.GasForResponse { return fmt.Errorf("%w: oracle tx has insufficient gas", ErrInvalidAttribute) @@ -2638,7 +2637,7 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact if isPartialTx { maxNVBDelta, err := bc.GetMaxNotValidBeforeDelta() if err != nil { - return fmt.Errorf("%w: failed to retrieve MaxNotValidBeforeDelta value from native Notary contract: %v", ErrInvalidAttribute, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: failed to retrieve MaxNotValidBeforeDelta value from native Notary contract: %w", ErrInvalidAttribute, err) } if curHeight+maxNVBDelta < nvb { return fmt.Errorf("%w: NotValidBefore (%d) bigger than MaxNVBDelta (%d) allows at height %d", ErrInvalidAttribute, nvb, maxNVBDelta, curHeight) @@ -2873,7 +2872,7 @@ func (bc *Blockchain) InitVerificationContext(ic *interop.Context, hash util.Uin } err := vm.IsScriptCorrect(witness.VerificationScript, nil) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidVerificationScript, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidVerificationScript, err) } ic.VM.LoadScriptWithHash(witness.VerificationScript, hash, callflag.ReadOnly) } else { @@ -2898,7 +2897,7 @@ func (bc *Blockchain) InitVerificationContext(ic *interop.Context, hash util.Uin if len(witness.InvocationScript) != 0 { err := vm.IsScriptCorrect(witness.InvocationScript, nil) if err != nil { - return fmt.Errorf("%w: %v", ErrInvalidInvocationScript, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidInvocationScript, err) } ic.VM.LoadScript(witness.InvocationScript) } @@ -2930,7 +2929,7 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa } err := interopCtx.Exec() if vm.HasFailed() { - return 0, fmt.Errorf("%w: vm execution has failed: %v", ErrVerificationFailed, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return 0, fmt.Errorf("%w: vm execution has failed: %w", ErrVerificationFailed, err) } estack := vm.Estack() if estack.Len() > 0 { diff --git a/pkg/core/blockchain_core_test.go b/pkg/core/blockchain_core_test.go index 0e7f6bff5..111202829 100644 --- a/pkg/core/blockchain_core_test.go +++ b/pkg/core/blockchain_core_test.go @@ -1,6 +1,7 @@ package core import ( + "bytes" "encoding/binary" "fmt" "strings" @@ -17,7 +18,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -175,9 +175,9 @@ func TestBlockchain_InitWithIncompleteStateJump(t *testing.T) { bPrefix := make([]byte, 1) bPrefix[0] = byte(bcSpout.dao.Version.StoragePrefix) bcSpout.dao.Store.Seek(storage.SeekRange{Prefix: bPrefix}, func(k, v []byte) bool { - key := slice.Copy(k) + key := bytes.Clone(k) key[0] = byte(tempPrefix) - value := slice.Copy(v) + value := bytes.Clone(v) batch.Put(key, value) return true }) diff --git a/pkg/core/dao/dao.go b/pkg/core/dao/dao.go index 61c24c3e8..218be9123 100644 --- a/pkg/core/dao/dao.go +++ b/pkg/core/dao/dao.go @@ -1,6 +1,7 @@ package dao import ( + "bytes" "context" "encoding/binary" "errors" @@ -19,7 +20,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -383,7 +383,7 @@ func (dao *Simple) DeleteStorageItem(id int32, key []byte) { // may not be copied. Seek continues iterating until false is returned from f. A requested prefix // (if any non-empty) is trimmed before passing to f. func (dao *Simple) Seek(id int32, rng storage.SeekRange, f func(k, v []byte) bool) { - rng.Prefix = slice.Copy(dao.makeStorageItemKey(id, rng.Prefix)) // f() can use dao too. + rng.Prefix = bytes.Clone(dao.makeStorageItemKey(id, rng.Prefix)) // f() can use dao too. dao.Store.Seek(rng, func(k, v []byte) bool { return f(k[len(rng.Prefix):], v) }) @@ -393,7 +393,7 @@ func (dao *Simple) Seek(id int32, rng storage.SeekRange, f func(k, v []byte) boo // starting from the point specified) to a channel and returns the channel. // Resulting keys and values may not be copied. func (dao *Simple) SeekAsync(ctx context.Context, id int32, rng storage.SeekRange) chan storage.KeyValue { - rng.Prefix = slice.Copy(dao.makeStorageItemKey(id, rng.Prefix)) + rng.Prefix = bytes.Clone(dao.makeStorageItemKey(id, rng.Prefix)) return dao.Store.SeekAsync(ctx, rng, true) } diff --git a/pkg/core/interop/contract/account_test.go b/pkg/core/interop/contract/account_test.go index e03a4ea1e..cb69de97a 100644 --- a/pkg/core/interop/contract/account_test.go +++ b/pkg/core/interop/contract/account_test.go @@ -1,6 +1,7 @@ package contract_test import ( + "bytes" "math" "math/big" "testing" @@ -15,7 +16,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/stretchr/testify/require" ) @@ -136,13 +136,13 @@ func TestCreateAccount_HFAspidochelone(t *testing.T) { emit.Int(w.BinWriter, int64(2)) emit.Syscall(w.BinWriter, interopnames.SystemContractCreateMultisigAccount) require.NoError(t, w.Err) - multisigScript := slice.Copy(w.Bytes()) + multisigScript := bytes.Clone(w.Bytes()) w.Reset() emit.Bytes(w.BinWriter, pub.Bytes()) emit.Syscall(w.BinWriter, interopnames.SystemContractCreateStandardAccount) require.NoError(t, w.Err) - standardScript := slice.Copy(w.Bytes()) + standardScript := bytes.Clone(w.Bytes()) createAccTx := func(t *testing.T, script []byte) *transaction.Transaction { tx := e.PrepareInvocation(t, script, []neotest.Signer{e.Committee}, bc.BlockHeight()+1) diff --git a/pkg/core/interop/contract/call.go b/pkg/core/interop/contract/call.go index e1b8b72be..712b9e1d9 100644 --- a/pkg/core/interop/contract/call.go +++ b/pkg/core/interop/contract/call.go @@ -165,7 +165,7 @@ func CallFromNative(ic *interop.Context, caller util.Uint160, cs *state.Contract for !ic.VM.HasStopped() && len(ic.VM.Istack()) > startSize { if err := ic.VM.Step(); err != nil { - return fmt.Errorf("%w: %v", ErrNativeCall, err) //nolint:errorlint // non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrNativeCall, err) } } if ic.VM.HasFailed() { diff --git a/pkg/core/interop/storage/find.go b/pkg/core/interop/storage/find.go index 666950e34..dacf5a83f 100644 --- a/pkg/core/interop/storage/find.go +++ b/pkg/core/interop/storage/find.go @@ -1,12 +1,12 @@ package storage import ( + "bytes" "context" "fmt" "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/storage" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -31,6 +31,9 @@ type Iterator struct { curr storage.KeyValue next bool opts int64 + // prefix is the storage item key prefix Find is performed with. It must be + // copied if no FindRemovePrefix option specified since it's shared between all + // iterator items. prefix []byte } @@ -39,7 +42,7 @@ func NewIterator(seekCh chan storage.KeyValue, prefix []byte, opts int64) *Itera return &Iterator{ seekCh: seekCh, opts: opts, - prefix: slice.Copy(prefix), + prefix: bytes.Clone(prefix), } } @@ -58,7 +61,7 @@ func (s *Iterator) Value() stackitem.Item { } key := s.curr.Key if s.opts&FindRemovePrefix == 0 { - key = append(s.prefix, key...) + key = append(bytes.Clone(s.prefix), key...) } if s.opts&FindKeysOnly != 0 { return stackitem.NewByteArray(key) diff --git a/pkg/core/mpt/billet.go b/pkg/core/mpt/billet.go index cba44afa0..10acfdd19 100644 --- a/pkg/core/mpt/billet.go +++ b/pkg/core/mpt/billet.go @@ -9,7 +9,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) var ( @@ -230,7 +229,7 @@ func (b *Billet) traverse(curr Node, path, from []byte, process func(pathToNode return b.traverse(r, path, from, process, ignoreStorageErr, backwards) } if len(from) == 0 { - bytes := slice.Copy(curr.Bytes()) + bytes := bytes.Clone(curr.Bytes()) if process(fromNibbles(path), curr, bytes) { return curr, errStop } diff --git a/pkg/core/mpt/proof.go b/pkg/core/mpt/proof.go index 7a02ebbb9..76b4901a0 100644 --- a/pkg/core/mpt/proof.go +++ b/pkg/core/mpt/proof.go @@ -7,7 +7,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) // GetProof returns a proof that the key belongs to t. @@ -30,11 +29,11 @@ func (t *Trie) getProof(curr Node, path []byte, proofs *[][]byte) (Node, error) switch n := curr.(type) { case *LeafNode: if len(path) == 0 { - *proofs = append(*proofs, slice.Copy(n.Bytes())) + *proofs = append(*proofs, bytes.Clone(n.Bytes())) return n, nil } case *BranchNode: - *proofs = append(*proofs, slice.Copy(n.Bytes())) + *proofs = append(*proofs, bytes.Clone(n.Bytes())) i, path := splitPath(path) r, err := t.getProof(n.Children[i], path, proofs) if err != nil { @@ -44,7 +43,7 @@ func (t *Trie) getProof(curr Node, path []byte, proofs *[][]byte) (Node, error) return n, nil case *ExtensionNode: if bytes.HasPrefix(path, n.key) { - *proofs = append(*proofs, slice.Copy(n.Bytes())) + *proofs = append(*proofs, bytes.Clone(n.Bytes())) r, err := t.getProof(n.next, path[len(n.key):], proofs) if err != nil { return nil, err @@ -75,5 +74,5 @@ func VerifyProof(rh util.Uint256, key []byte, proofs [][]byte) ([]byte, bool) { if err != nil { return nil, false } - return slice.Copy(leaf.(*LeafNode).value), true + return bytes.Clone(leaf.(*LeafNode).value), true } diff --git a/pkg/core/mpt/trie.go b/pkg/core/mpt/trie.go index 046b074fb..8b34bac80 100644 --- a/pkg/core/mpt/trie.go +++ b/pkg/core/mpt/trie.go @@ -9,7 +9,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) // TrieMode is the storage mode of a trie, it affects the DB scheme. @@ -84,7 +83,7 @@ func (t *Trie) Get(key []byte) ([]byte, error) { return nil, err } t.root = r - return slice.Copy(leaf.(*LeafNode).value), nil + return bytes.Clone(leaf.(*LeafNode).value), nil } // getWithPath returns the current node with all hash nodes along the path replaced @@ -221,7 +220,7 @@ func (t *Trie) putIntoExtension(curr *ExtensionNode, path []byte, val Node) (Nod t.addRef(b.Hash(), b.bytes) if lp > 0 { - e := NewExtensionNode(slice.Copy(pref), b) + e := NewExtensionNode(bytes.Clone(pref), b) t.addRef(e.Hash(), e.bytes) return e, nil } @@ -617,8 +616,8 @@ func (t *Trie) Find(prefix, from []byte, max int) ([]storage.KeyValue, error) { if leaf, ok := node.(*LeafNode); ok { if from == nil || !bytes.Equal(pathToNode, from) { // (*Billet).traverse includes `from` path into result if so. Need to filter out manually. res = append(res, storage.KeyValue{ - Key: append(slice.Copy(prefix), pathToNode...), - Value: slice.Copy(leaf.value), + Key: append(bytes.Clone(prefix), pathToNode...), + Value: bytes.Clone(leaf.value), }) count++ } diff --git a/pkg/core/mpt/trie_store.go b/pkg/core/mpt/trie_store.go index b07cc99df..7c7a158fb 100644 --- a/pkg/core/mpt/trie_store.go +++ b/pkg/core/mpt/trie_store.go @@ -7,7 +7,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) // TrieStore is an MPT-based storage implementation for storing and retrieving @@ -101,8 +100,8 @@ func (m *TrieStore) Seek(rng storage.SeekRange, f func(k, v []byte) bool) { if leaf, ok := node.(*LeafNode); ok { // (*Billet).traverse includes `from` path into the result if so. It's OK for Seek, so shouldn't be filtered out. kv := storage.KeyValue{ - Key: append(slice.Copy(rng.Prefix), pathToNode...), // Do not cut prefix. - Value: slice.Copy(leaf.value), + Key: append(bytes.Clone(rng.Prefix), pathToNode...), // Do not cut prefix. + Value: bytes.Clone(leaf.value), } return !f(kv.Key, kv.Value) // Should return whether to stop. } diff --git a/pkg/core/native/oracle.go b/pkg/core/native/oracle.go index d07447eaf..012fc3064 100644 --- a/pkg/core/native/oracle.go +++ b/pkg/core/native/oracle.go @@ -1,6 +1,7 @@ package native import ( + "bytes" "encoding/binary" "errors" "fmt" @@ -25,7 +26,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -160,7 +160,7 @@ func newOracle() *Oracle { // GetOracleResponseScript returns a script for the transaction with an oracle response. func (o *Oracle) GetOracleResponseScript() []byte { - return slice.Copy(o.oracleScript) + return bytes.Clone(o.oracleScript) } // OnPersist implements the Contract interface. @@ -395,7 +395,7 @@ func (o *Oracle) RequestInternal(ic *interop.Context, url string, filter *string if len(data) > maxUserDataLength { return ErrBigArgument } - data = slice.Copy(data) // Serialization context will be used in PutRequestInternal again. + data = bytes.Clone(data) // Serialization context will be used in PutRequestInternal again. var filterNotif stackitem.Item if filter != nil { diff --git a/pkg/core/native/std.go b/pkg/core/native/std.go index 32c17fa62..90d2c579c 100644 --- a/pkg/core/native/std.go +++ b/pkg/core/native/std.go @@ -177,7 +177,7 @@ func (s *Std) serialize(ic *interop.Context, args []stackitem.Item) stackitem.It panic(errors.New("too big item")) } - return stackitem.NewByteArray(slice.Copy(data)) // Serialization context can be reused. + return stackitem.NewByteArray(bytes.Clone(data)) // Serialization context can be reused. } func (s *Std) deserialize(_ *interop.Context, args []stackitem.Item) stackitem.Item { diff --git a/pkg/core/statesync/module_test.go b/pkg/core/statesync/module_test.go index 893dfe07e..3ead29e43 100644 --- a/pkg/core/statesync/module_test.go +++ b/pkg/core/statesync/module_test.go @@ -1,6 +1,7 @@ package statesync import ( + "bytes" "fmt" "testing" @@ -8,7 +9,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/mpt" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" ) @@ -33,8 +33,8 @@ func TestModule_PR2019_discussion_r689629704(t *testing.T) { expectedItems []storage.KeyValue ) expectedStorage.Seek(storage.SeekRange{Prefix: []byte{byte(storage.DataMPT)}}, func(k, v []byte) bool { - key := slice.Copy(k) - value := slice.Copy(v) + key := bytes.Clone(k) + value := bytes.Clone(v) expectedItems = append(expectedItems, storage.KeyValue{ Key: key, Value: value, @@ -97,8 +97,8 @@ func TestModule_PR2019_discussion_r689629704(t *testing.T) { // Compare resulting storage items and refcounts. var actualItems []storage.KeyValue expectedStorage.Seek(storage.SeekRange{Prefix: []byte{byte(storage.DataMPT)}}, func(k, v []byte) bool { - key := slice.Copy(k) - value := slice.Copy(v) + key := bytes.Clone(k) + value := bytes.Clone(v) actualItems = append(actualItems, storage.KeyValue{ Key: key, Value: value, diff --git a/pkg/core/statesync/neotest_test.go b/pkg/core/statesync/neotest_test.go index 47836cc61..d69325a5c 100644 --- a/pkg/core/statesync/neotest_test.go +++ b/pkg/core/statesync/neotest_test.go @@ -1,6 +1,7 @@ package statesync_test import ( + "bytes" "testing" "github.com/nspcc-dev/neo-go/internal/basicchain" @@ -11,7 +12,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/require" ) @@ -230,7 +230,7 @@ func TestStateSyncModule_Init(t *testing.T) { alreadyRequested[unknownHashes[0]] = struct{}{} var callbackCalled bool err := bcSpout.GetStateSyncModule().Traverse(unknownHashes[0], func(node mpt.Node, nodeBytes []byte) bool { - require.NoError(t, module.AddMPTNodes([][]byte{slice.Copy(nodeBytes)})) + require.NoError(t, module.AddMPTNodes([][]byte{bytes.Clone(nodeBytes)})) callbackCalled = true return true // add nodes one-by-one }) @@ -435,8 +435,8 @@ func TestStateSyncModule_RestoreBasicChain(t *testing.T) { fetchStorage := func(ps storage.Store, storagePrefix byte) []storage.KeyValue { var kv []storage.KeyValue ps.Seek(storage.SeekRange{Prefix: []byte{storagePrefix}}, func(k, v []byte) bool { - key := slice.Copy(k) - value := slice.Copy(v) + key := bytes.Clone(k) + value := bytes.Clone(v) if key[0] == byte(storage.STTempStorage) { key[0] = byte(storage.STStorage) } diff --git a/pkg/core/storage/boltdb_store.go b/pkg/core/storage/boltdb_store.go index 80de15a87..f313dcd2e 100644 --- a/pkg/core/storage/boltdb_store.go +++ b/pkg/core/storage/boltdb_store.go @@ -9,7 +9,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" "github.com/nspcc-dev/neo-go/pkg/io" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "go.etcd.io/bbolt" ) @@ -66,7 +65,7 @@ func NewBoltDBStore(cfg dbconfig.BoltDBOptions) (*BoltDBStore, error) { closeErr := db.Close() err = fmt.Errorf("failed to initialize BoltDB instance: %w", err) if closeErr != nil { - err = fmt.Errorf("%w, failed to close BoltDB instance: %v", err, closeErr) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + err = fmt.Errorf("%w, failed to close BoltDB instance: %w", err, closeErr) } return nil, err } @@ -81,7 +80,7 @@ func (s *BoltDBStore) Get(key []byte) (val []byte, err error) { val = b.Get(key) // Value from Get is only valid for the lifetime of transaction, #1482 if val != nil { - val = slice.Copy(val) + val = bytes.Clone(val) } return nil }) diff --git a/pkg/core/storage/memcached_store.go b/pkg/core/storage/memcached_store.go index f91c74fc4..ad476ad3f 100644 --- a/pkg/core/storage/memcached_store.go +++ b/pkg/core/storage/memcached_store.go @@ -6,8 +6,6 @@ import ( "sort" "strings" "sync" - - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) // MemCachedStore is a wrapper around persistent store that caches all changes @@ -107,7 +105,7 @@ func (s *MemCachedStore) Get(key []byte) ([]byte, error) { // Put puts new KV pair into the store. func (s *MemCachedStore) Put(key, value []byte) { newKey := string(key) - vcopy := slice.Copy(value) + vcopy := bytes.Clone(value) s.lock() put(s.chooseMap(key), newKey, vcopy) s.unlock() @@ -259,8 +257,8 @@ func performSeek(ctx context.Context, ps Store, memRes []KeyValueExists, rng See return false } kvPs := KeyValue{ - Key: slice.Copy(k), - Value: slice.Copy(v), + Key: bytes.Clone(k), + Value: bytes.Clone(v), } for { select { diff --git a/pkg/core/storage/memcached_store_test.go b/pkg/core/storage/memcached_store_test.go index 0472c9817..0f2defe65 100644 --- a/pkg/core/storage/memcached_store_test.go +++ b/pkg/core/storage/memcached_store_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/nspcc-dev/neo-go/internal/random" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -420,7 +419,7 @@ func TestCachedSeekSorting(t *testing.T) { } var foundKVs []KeyValue ts.Seek(SeekRange{Prefix: goodPrefix}, func(k, v []byte) bool { - foundKVs = append(foundKVs, KeyValue{Key: slice.Copy(k), Value: slice.Copy(v)}) + foundKVs = append(foundKVs, KeyValue{Key: bytes.Clone(k), Value: bytes.Clone(v)}) return true }) assert.Equal(t, len(foundKVs), len(lowerKVs)+len(updatedKVs)) diff --git a/pkg/core/storage/storeandbatch_test.go b/pkg/core/storage/storeandbatch_test.go index 88724fe10..7c5f64325 100644 --- a/pkg/core/storage/storeandbatch_test.go +++ b/pkg/core/storage/storeandbatch_test.go @@ -7,7 +7,6 @@ import ( "sort" "testing" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -70,8 +69,8 @@ func testStoreSeek(t *testing.T, s Store) { actual := make([]KeyValue, 0, len(goodkvs)) s.Seek(rng, func(k, v []byte) bool { actual = append(actual, KeyValue{ - Key: slice.Copy(k), - Value: slice.Copy(v), + Key: bytes.Clone(k), + Value: bytes.Clone(v), }) if cont == nil { return true diff --git a/pkg/interop/go.mod b/pkg/interop/go.mod index 1dbeee464..0d22c16d4 100644 --- a/pkg/interop/go.mod +++ b/pkg/interop/go.mod @@ -1,3 +1,3 @@ module github.com/nspcc-dev/neo-go/pkg/interop -go 1.19 +go 1.20 diff --git a/pkg/network/fuzz_test.go b/pkg/network/fuzz_test.go index a0e5f5ccb..7a5e89d79 100644 --- a/pkg/network/fuzz_test.go +++ b/pkg/network/fuzz_test.go @@ -11,6 +11,7 @@ import ( func FuzzMessageDecode(f *testing.F) { for i := 0; i < 100; i++ { seed := make([]byte, rand.Uint32()%1000) + //nolint:staticcheck rand.Read(seed) f.Add(seed) } diff --git a/pkg/rpcclient/waiter/waiter.go b/pkg/rpcclient/waiter/waiter.go index 716187fc6..830fe20cf 100644 --- a/pkg/rpcclient/waiter/waiter.go +++ b/pkg/rpcclient/waiter/waiter.go @@ -201,9 +201,9 @@ func (w *PollingBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.U return nil, ErrTxNotAccepted } case <-w.polling.Context().Done(): - return nil, fmt.Errorf("%w: %v", ErrContextDone, w.polling.Context().Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return nil, fmt.Errorf("%w: %w", ErrContextDone, w.polling.Context().Err()) case <-ctx.Done(): - return nil, fmt.Errorf("%w: %v", ErrContextDone, ctx.Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return nil, fmt.Errorf("%w: %w", ErrContextDone, ctx.Err()) } } } @@ -329,9 +329,9 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin } res = aer case <-w.ws.Context().Done(): - waitErr = fmt.Errorf("%w: %v", ErrContextDone, w.ws.Context().Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + waitErr = fmt.Errorf("%w: %w", ErrContextDone, w.ws.Context().Err()) case <-ctx.Done(): - waitErr = fmt.Errorf("%w: %v", ErrContextDone, ctx.Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + waitErr = fmt.Errorf("%w: %w", ErrContextDone, ctx.Err()) } } close(exit) @@ -361,7 +361,7 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin } case unsubErr := <-unsubErrs: if unsubErr != nil { - errFmt := "unsubscription error: %v" + errFmt := "unsubscription error: %w" errArgs := []any{unsubErr} if waitErr != nil { errFmt = "%w; " + errFmt @@ -393,7 +393,7 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin res, waitErr = w.polling.WaitAny(ctx, vub, hashes...) if waitErr != nil { // Wrap the poll-based error, it's more important. - waitErr = fmt.Errorf("event-based error: %v; poll-based waiter error: %w", wsWaitErr, waitErr) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + waitErr = fmt.Errorf("event-based error: %w; poll-based waiter error: %w", wsWaitErr, waitErr) } } return diff --git a/pkg/rpcclient/wsclient.go b/pkg/rpcclient/wsclient.go index 9674766da..3b131f890 100644 --- a/pkg/rpcclient/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -943,7 +943,7 @@ func (c *WSClient) UnsubscribeAll() error { for _, id := range subs { err := c.performUnsubscription(id) if err != nil { - errFmt := "failed to unsubscribe from feed %d: %v" + errFmt := "failed to unsubscribe from feed %d: %w" errArgs := []any{err} if resErr != nil { errFmt = "%w; " + errFmt diff --git a/pkg/services/notary/notary.go b/pkg/services/notary/notary.go index 205891c27..1f75f9e45 100644 --- a/pkg/services/notary/notary.go +++ b/pkg/services/notary/notary.go @@ -20,7 +20,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/wallet" @@ -354,8 +353,8 @@ func safeCopy(tx *transaction.Transaction) *transaction.Transaction { cp.Scripts = make([]transaction.Witness, len(tx.Scripts)) for i := range cp.Scripts { cp.Scripts[i] = transaction.Witness{ - InvocationScript: slice.Copy(tx.Scripts[i].InvocationScript), - VerificationScript: slice.Copy(tx.Scripts[i].VerificationScript), + InvocationScript: bytes.Clone(tx.Scripts[i].InvocationScript), + VerificationScript: bytes.Clone(tx.Scripts[i].VerificationScript), } } return &cp diff --git a/pkg/services/oracle/neofs/neofs.go b/pkg/services/oracle/neofs/neofs.go index a438165f2..27351ba8b 100644 --- a/pkg/services/oracle/neofs/neofs.go +++ b/pkg/services/oracle/neofs/neofs.go @@ -109,12 +109,12 @@ func parseNeoFSURL(u *url.URL) (*oid.Address, []string, error) { var containerID cid.ID if err := containerID.DecodeString(ps[0]); err != nil { - return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return nil, nil, fmt.Errorf("%w: %w", ErrInvalidContainer, err) } var objectID oid.ID if err := objectID.DecodeString(ps[1]); err != nil { - return nil, nil, fmt.Errorf("%w: %v", ErrInvalidObject, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return nil, nil, fmt.Errorf("%w: %w", ErrInvalidObject, err) } var objAddr = new(oid.Address) objAddr.SetContainer(containerID) diff --git a/pkg/services/oracle/network.go b/pkg/services/oracle/network.go index 9b69edfda..4af62d440 100644 --- a/pkg/services/oracle/network.go +++ b/pkg/services/oracle/network.go @@ -65,7 +65,7 @@ func getDefaultClient(cfg config.OracleConfiguration) *http.Client { d.Control = func(network, address string, c syscall.RawConn) error { host, _, err := net.SplitHostPort(address) if err != nil { - return fmt.Errorf("%w: failed to split address %s: %s", ErrRestrictedRedirect, address, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: failed to split address %s: %w", ErrRestrictedRedirect, address, err) } ip := net.ParseIP(host) if ip == nil { diff --git a/pkg/services/oracle/oracle.go b/pkg/services/oracle/oracle.go index b9612f4a0..0868adeda 100644 --- a/pkg/services/oracle/oracle.go +++ b/pkg/services/oracle/oracle.go @@ -1,6 +1,7 @@ package oracle import ( + "bytes" "errors" "net/http" "sync" @@ -16,7 +17,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/wallet" "go.uber.org/zap" ) @@ -277,8 +277,8 @@ drain: // UpdateNativeContract updates native oracle contract info for tx verification. func (o *Oracle) UpdateNativeContract(script, resp []byte, h util.Uint160, verifyOffset int) { - o.oracleScript = slice.Copy(script) - o.oracleResponse = slice.Copy(resp) + o.oracleScript = bytes.Clone(script) + o.oracleResponse = bytes.Clone(resp) o.oracleHash = h o.verifyOffset = verifyOffset diff --git a/pkg/services/oracle/oracle_test.go b/pkg/services/oracle/oracle_test.go index 74b33f4cf..28017ef33 100644 --- a/pkg/services/oracle/oracle_test.go +++ b/pkg/services/oracle/oracle_test.go @@ -30,7 +30,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/services/oracle" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/assert" @@ -163,8 +162,8 @@ func TestOracle(t *testing.T) { md := nativeOracleState.Manifest.ABI.GetMethod(manifest.MethodVerify, -1) require.NotNil(t, md) oracleRespScript := native.CreateOracleResponseScript(nativeOracleH) - orc1.UpdateNativeContract(nativeOracleState.NEF.Script, slice.Copy(oracleRespScript), nativeOracleH, md.Offset) - orc2.UpdateNativeContract(nativeOracleState.NEF.Script, slice.Copy(oracleRespScript), nativeOracleH, md.Offset) + orc1.UpdateNativeContract(nativeOracleState.NEF.Script, bytes.Clone(oracleRespScript), nativeOracleH, md.Offset) + orc2.UpdateNativeContract(nativeOracleState.NEF.Script, bytes.Clone(oracleRespScript), nativeOracleH, md.Offset) cs := contracts.GetOracleContractState(t, pathToInternalContracts, validator.ScriptHash(), 0) rawManifest, err := json.Marshal(cs.Manifest) diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 87db5b440..6430a2ffe 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -52,7 +52,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest/standard" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" @@ -1760,7 +1759,7 @@ func (s *Server) findStorageInternal(id int32, prefix []byte, start, take int, s } if i < end { res.Results = append(res.Results, result.KeyValue{ - Key: slice.Copy(append(prefix, k...)), // Don't strip prefix, as it is done in C#. + Key: bytes.Clone(append(prefix, k...)), // Don't strip prefix, as it is done in C#. Value: v, }) i++ diff --git a/pkg/smartcontract/zkpbinding/binding.go b/pkg/smartcontract/zkpbinding/binding.go index 4cca65fbd..91ab10ba1 100644 --- a/pkg/smartcontract/zkpbinding/binding.go +++ b/pkg/smartcontract/zkpbinding/binding.go @@ -165,7 +165,7 @@ supportedstandards: []` // and dependency packages version needed for smart contract compilation. verifyGomod = `module verify -go 1.19 +go 1.20 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231004150345-8849ccde2524 ` diff --git a/pkg/util/slice/array.go b/pkg/util/slice/array.go index d6e13f9f9..9be387e45 100644 --- a/pkg/util/slice/array.go +++ b/pkg/util/slice/array.go @@ -22,13 +22,6 @@ func reverse(dst []byte, src []byte) { } } -// Copy copies the byte slice into new slice (make/copy). -func Copy(b []byte) []byte { - d := make([]byte, len(b)) - copy(d, b) - return d -} - // Clean wipes the data in b by filling it with zeros. func Clean(b []byte) { for i := range b { diff --git a/pkg/util/slice/array_test.go b/pkg/util/slice/array_test.go index a5b8f54d6..ae7ccd162 100644 --- a/pkg/util/slice/array_test.go +++ b/pkg/util/slice/array_test.go @@ -1,6 +1,7 @@ package slice import ( + "bytes" "testing" "github.com/stretchr/testify/require" @@ -30,7 +31,7 @@ var testCases = []struct { func TestCopyReverse(t *testing.T) { for _, tc := range testCases { - arg := Copy(tc.arr) + arg := bytes.Clone(tc.arr) require.Equal(t, tc.arr, arg) have := CopyReverse(arg) @@ -52,7 +53,7 @@ func TestCopyReverse(t *testing.T) { func TestClean(t *testing.T) { for _, tc := range testCases[1:] { // Empty one will be equal. - cp := Copy(tc.arr) + cp := bytes.Clone(tc.arr) Clean(cp) require.NotEqual(t, tc.arr, cp) } diff --git a/pkg/vm/stackitem/item.go b/pkg/vm/stackitem/item.go index 6f0f1d02b..33ff664bf 100644 --- a/pkg/vm/stackitem/item.go +++ b/pkg/vm/stackitem/item.go @@ -14,7 +14,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/encoding/bigint" "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/util/slice" ) const ( @@ -197,7 +196,7 @@ func convertPrimitive(item Item, typ Type) (Item, error) { return nil, err } if typ == BufferT { - return NewBuffer(slice.Copy(b)), nil + return NewBuffer(bytes.Clone(b)), nil } // ByteArray can't really be changed, so it's OK to reuse `b`. return NewByteArray(b), nil @@ -687,7 +686,7 @@ func (i *ByteArray) equalsLimited(s Item, limit *int) bool { // Dup implements the Item interface. func (i *ByteArray) Dup() Item { - ba := slice.Copy(*i) + ba := bytes.Clone(*i) return (*ByteArray)(&ba) } @@ -1186,7 +1185,7 @@ func (i *Buffer) Convert(typ Type) (Item, error) { case BufferT: return i, nil case ByteArrayT: - return NewByteArray(slice.Copy(*i)), nil + return NewByteArray(bytes.Clone(*i)), nil case IntegerT: if len(*i) > MaxBigIntegerSizeBits/8 { return nil, errTooBigInteger @@ -1248,12 +1247,12 @@ func deepCopy(item Item, seen map[Item]Item, asImmutable bool) Item { bi := new(big.Int).Set(it.Big()) return (*BigInteger)(bi) case *ByteArray: - return NewByteArray(slice.Copy(*it)) + return NewByteArray(bytes.Clone(*it)) case *Buffer: if asImmutable { - return NewByteArray(slice.Copy(*it)) + return NewByteArray(bytes.Clone(*it)) } - return NewBuffer(slice.Copy(*it)) + return NewBuffer(bytes.Clone(*it)) case Bool: return it case *Pointer: diff --git a/pkg/vm/stackitem/json.go b/pkg/vm/stackitem/json.go index c18ef002d..ef9ab6515 100644 --- a/pkg/vm/stackitem/json.go +++ b/pkg/vm/stackitem/json.go @@ -449,7 +449,7 @@ type ( ) func mkErrValue(err error) error { - return fmt.Errorf("%w: %v", ErrInvalidValue, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors + return fmt.Errorf("%w: %w", ErrInvalidValue, err) } // FromJSONWithTypes deserializes an item from typed-json representation. diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index b175998a9..c48d993ec 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -3,7 +3,6 @@ package vm import ( "crypto/elliptic" "encoding/binary" - "encoding/hex" "encoding/json" "errors" "fmt" @@ -223,7 +222,7 @@ func (v *VM) PrintOps(out io.Writer) { // if the parameter is a 20-byte value. u, err := util.Uint160DecodeBytesBE(parameter) if err == nil { - desc = fmt.Sprintf("%x (%q, %q)", parameter, address.Uint160ToString(u), "0x"+hex.EncodeToString(slice.CopyReverse(parameter))) + desc = fmt.Sprintf("%x (%q, %q)", parameter, address.Uint160ToString(u), "0x"+u.StringLE()) } else { desc = fmt.Sprintf("%x", parameter) }