From 5dfa34f65e8cc41412f4039867850f73e81f2675 Mon Sep 17 00:00:00 2001 From: aaronbuchwald Date: Fri, 3 Feb 2023 14:17:22 -0800 Subject: [PATCH 1/8] Add documentation section to PR template (#484) --- .github/pull_request_template.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 8200c0597f..119cac2eb9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -3,3 +3,5 @@ ## How this works ## How this was tested + +## How is this documented From 7aa90d019391f9eb2521b36a6214bbdf3b699271 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Sun, 5 Feb 2023 07:20:44 +0300 Subject: [PATCH 2/8] remove current rules (#481) Co-authored-by: Darioush Jalali --- plugin/evm/vm.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index cc08501e2b..5a9e80cf8d 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -8,7 +8,6 @@ import ( "encoding/json" "errors" "fmt" - "math/big" "os" "path/filepath" "strings" @@ -852,12 +851,6 @@ func (vm *VM) GetCurrentNonce(address common.Address) (uint64, error) { return state.GetNonce(address), nil } -// currentRules returns the chain rules for the current block. -func (vm *VM) currentRules() params.Rules { - header := vm.eth.APIBackend.CurrentHeader() - return vm.chainConfig.AvalancheRules(header.Number, big.NewInt(int64(header.Time))) -} - func (vm *VM) startContinuousProfiler() { // If the profiler directory is empty, return immediately // without creating or starting a continuous profiler. From 7887607df856ea7ffb15e179d934da4e21e4dc33 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Mon, 6 Feb 2023 08:50:22 -0800 Subject: [PATCH 3/8] add documentation guidelines (#486) * add documentation guidelines * fix --- .github/CONTRIBUTING.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 5381269fcb..d0c9fae378 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,13 +14,12 @@ well as our review and merge procedures quick and simple. ## Coding guidelines -Please make sure your contributions adhere to our coding guidelines: +Please make sure your contributions adhere to our coding and documentation +guidelines: - Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). -- Code must be documented adhering to the official Go - [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. - Pull requests need to be based on and opened against the `master` branch. - Pull reuqests should include a detailed description - Commits are required to be signed. See [here](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) @@ -28,6 +27,18 @@ Please make sure your contributions adhere to our coding guidelines: - Commit messages should be prefixed with the package(s) they modify. - E.g. "eth, rpc: make trace configs optional" +## Documentation guidelines + +- Code should be well commented, so it is easier to read and maintain. + Any complex sections or invariants should be documented explicitly. +- Code must be documented adhering to the official Go + [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. +- Changes with user facing impact (e.g., addition or modification of flags and + options) should be accompanied by a link to a pull request to the [avalanche-docs](https://github.com/ava-labs/avalanche-docs) + repository. [example](https://github.com/ava-labs/avalanche-docs/pull/1119/files). +- Changes that modify a package significantly or add new features should + either update the existing or include a new `README.md` file in that package. + ## Can I have feature X Before you submit a feature request, please check and make sure that it isn't From c667f95add504871ab88c8a832d77f6ad448eee6 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 7 Feb 2023 02:34:09 +0300 Subject: [PATCH 4/8] parseInt from ENV var (#491) --- contract-examples/hardhat.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contract-examples/hardhat.config.ts b/contract-examples/hardhat.config.ts index be74e1ecb4..1e4c995b7d 100644 --- a/contract-examples/hardhat.config.ts +++ b/contract-examples/hardhat.config.ts @@ -4,7 +4,7 @@ import "./tasks.ts" // HardHat users must populate these environment variables in order to connect to their subnet-evm instance // Since the blockchainID is not known in advance, there's no good default to use and we use the C-Chain here. var local_rpc_uri = process.env.RPC_URI || "http://127.0.0.1:9650/ext/bc/C/rpc" -var local_chain_id = process.env.CHAIN_ID || 99999 +var local_chain_id = parseInt(process.env.CHAIN_ID,10) || 99999 export default { solidity: { From 50da2fd667c9bf68f8148f57dfe8a0ec5eb6a8df Mon Sep 17 00:00:00 2001 From: aaronbuchwald Date: Mon, 6 Feb 2023 15:40:30 -0800 Subject: [PATCH 5/8] Add generate precompile script to fix CGO flags issue (#489) --- scripts/generate_precompile.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 scripts/generate_precompile.sh diff --git a/scripts/generate_precompile.sh b/scripts/generate_precompile.sh new file mode 100755 index 0000000000..8876880659 --- /dev/null +++ b/scripts/generate_precompile.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +# This script generates a Stateful Precompile stub based off of a Solidity ABI file. +# It first sets the necessary CGO_FLAGs for the BLST library used in AvalancheGo and +# then runs PrecompileGen. +if ! [[ "$0" =~ scripts/generate_precompile.sh ]]; then + echo "must be run from repository root, but got $0" + exit 255 +fi + +# Load the versions +SUBNET_EVM_PATH=$( + cd "$(dirname "${BASH_SOURCE[0]}")" + cd .. && pwd +) + +# Load the constants +source "$SUBNET_EVM_PATH"/scripts/constants.sh + +go run ./cmd/precompilegen/main.go $@ From fe5e55c68a98c0624450681d3d654301985b4100 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Tue, 7 Feb 2023 16:43:11 -0800 Subject: [PATCH 6/8] try to fix lint job (#499) --- .github/workflows/lint-tests-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-tests-release.yml b/.github/workflows/lint-tests-release.yml index a478938e62..5862ddfc2f 100644 --- a/.github/workflows/lint-tests-release.yml +++ b/.github/workflows/lint-tests-release.yml @@ -11,7 +11,7 @@ on: jobs: lint_test: name: Lint - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - run: ./scripts/lint_allowed_geth_imports.sh From 40c5212a07808e747d52e41871d76a7776693f59 Mon Sep 17 00:00:00 2001 From: cam-schultz <78878559+cam-schultz@users.noreply.github.com> Date: Tue, 7 Feb 2023 23:08:42 -0500 Subject: [PATCH 7/8] build with avago v1.9.8 (#498) * build with avago v1.9.8 * add indirect deps * build fix * another build fix * try to fix lint job --- go.mod | 5 +++-- go.sum | 10 ++++++---- plugin/evm/gossiper.go | 4 ++-- plugin/evm/warp/backend.go | 8 ++++---- scripts/versions.sh | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index fb7fb410a9..72b82932ec 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.9.7 + github.com/ava-labs/avalanchego v1.9.8 github.com/cespare/cp v0.1.0 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 @@ -27,7 +27,7 @@ require ( github.com/onsi/gomega v1.24.2 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_model v0.3.0 - github.com/rjeczalik/notify v0.9.2 + github.com/rjeczalik/notify v0.9.3 github.com/shirou/gopsutil v3.21.11+incompatible github.com/spf13/cast v1.5.0 github.com/spf13/pflag v1.0.5 @@ -94,6 +94,7 @@ require ( github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect + github.com/pires/go-proxyproto v0.6.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/common v0.37.0 // indirect diff --git a/go.sum b/go.sum index eac7c26609..0b4e002aee 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0= -github.com/ava-labs/avalanchego v1.9.7 h1:f2vS8jUBZmrqPcfU5NEa7dSHXbKfTB0EyjcCyvqxqPw= -github.com/ava-labs/avalanchego v1.9.7/go.mod h1:ckdSQHeoRN6PmQ3TLgWAe6Kh9tFpU4Lu6MgDW4GrU/Q= +github.com/ava-labs/avalanchego v1.9.8 h1:5SHKqkWpBn9Pqxg2qpzDZ7FQqYFapzaCZwArapBdqAA= +github.com/ava-labs/avalanchego v1.9.8/go.mod h1:t9+R55TgRJxYCekRf/EicIjHBeeEQT04TQxpaF98+yM= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -465,6 +465,8 @@ github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQm github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pires/go-proxyproto v0.6.2 h1:KAZ7UteSOt6urjme6ZldyFm4wDe/z0ZUP0Yv0Dos0d8= +github.com/pires/go-proxyproto v0.6.2/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -503,8 +505,8 @@ github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0ua github.com/prometheus/tsdb v0.10.0 h1:If5rVCMTp6W2SiRAQFlbpJNgVlgMEd+U2GZckwK38ic= github.com/prometheus/tsdb v0.10.0/go.mod h1:oi49uRhEe9dPUTlS3JRZOwJuVi6tmh10QSgwXEyGCt4= github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= -github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8= -github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM= +github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY= +github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= diff --git a/plugin/evm/gossiper.go b/plugin/evm/gossiper.go index 300958b78d..bc19021ebf 100644 --- a/plugin/evm/gossiper.go +++ b/plugin/evm/gossiper.go @@ -62,7 +62,7 @@ type pushGossiper struct { // [recentTxs] prevent us from over-gossiping the // same transaction in a short period of time. - recentTxs *cache.LRU + recentTxs *cache.LRU[common.Hash, interface{}] codec codec.Manager signer types.Signer @@ -86,7 +86,7 @@ func (vm *VM) createGossiper(stats GossipStats) Gossiper { txsToGossip: make(map[common.Hash]*types.Transaction), shutdownChan: vm.shutdownChan, shutdownWg: &vm.shutdownWg, - recentTxs: &cache.LRU{Size: recentCacheSize}, + recentTxs: &cache.LRU[common.Hash, interface{}]{Size: recentCacheSize}, codec: vm.networkCodec, signer: types.LatestSigner(vm.blockChain.Config()), stats: stats, diff --git a/plugin/evm/warp/backend.go b/plugin/evm/warp/backend.go index ac865daf51..7e973105ab 100644 --- a/plugin/evm/warp/backend.go +++ b/plugin/evm/warp/backend.go @@ -31,7 +31,7 @@ type WarpBackend interface { type warpBackend struct { db database.Database snowCtx *snow.Context - signatureCache *cache.LRU + signatureCache *cache.LRU[ids.ID, []byte] } // NewWarpBackend creates a new WarpBackend, and initializes the signature cache and message tracking database. @@ -39,7 +39,7 @@ func NewWarpBackend(snowCtx *snow.Context, db database.Database, signatureCacheS return &warpBackend{ db: db, snowCtx: snowCtx, - signatureCache: &cache.LRU{Size: signatureCacheSize}, + signatureCache: &cache.LRU[ids.ID, []byte]{Size: signatureCacheSize}, } } @@ -64,7 +64,7 @@ func (w *warpBackend) AddMessage(ctx context.Context, unsignedMessage *teleporte func (w *warpBackend) GetSignature(ctx context.Context, messageID ids.ID) ([]byte, error) { if sig, ok := w.signatureCache.Get(messageID); ok { - return sig.([]byte), nil + return sig, nil } unsignedMessageBytes, err := w.db.Get(messageID[:]) @@ -82,6 +82,6 @@ func (w *warpBackend) GetSignature(ctx context.Context, messageID ids.ID) ([]byt return nil, fmt.Errorf("failed to sign warp message: %w", err) } - w.signatureCache.Put(messageID[:], signature) + w.signatureCache.Put(messageID, signature) return signature, nil } diff --git a/scripts/versions.sh b/scripts/versions.sh index 4572877092..708a8c549a 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -3,7 +3,7 @@ # Set up the versions to be used - populate ENV variables only if they are not already populated SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-'v0.4.9'} # Don't export them as they're used in the context of other calls -AVALANCHEGO_VERSION=${AVALANCHE_VERSION:-'v1.9.7'} +AVALANCHEGO_VERSION=${AVALANCHE_VERSION:-'v1.9.8'} GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'} # This won't be used, but it's here to make code syncs easier From ab08276e97c88b5a47e8c0e03ea56b97b642cf9b Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 8 Feb 2023 16:38:18 -0800 Subject: [PATCH 8/8] nits for get-signature-endpoint --- plugin/evm/{snowman_service.go => service.go} | 2 +- plugin/evm/vm.go | 18 ++++++++++-------- plugin/evm/warp_client.go | 6 ++---- plugin/evm/warp_service.go | 7 +++++-- 4 files changed, 18 insertions(+), 15 deletions(-) rename plugin/evm/{snowman_service.go => service.go} (95%) diff --git a/plugin/evm/snowman_service.go b/plugin/evm/service.go similarity index 95% rename from plugin/evm/snowman_service.go rename to plugin/evm/service.go index d4113ce203..54b5021a45 100644 --- a/plugin/evm/snowman_service.go +++ b/plugin/evm/service.go @@ -1,4 +1,4 @@ -// (c) 2019-2023, Ava Labs, Inc. All rights reserved. +// (c) 2019-2020, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package evm diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 10f3fc9924..a3ddc87ef9 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -83,10 +83,10 @@ const ( // and fail verification maxFutureBlockTime = 10 * time.Second - decidedCacheSize = 100 - missingCacheSize = 50 - unverifiedCacheSize = 50 - signatureCacheSize = 500 + decidedCacheSize = 100 + missingCacheSize = 50 + unverifiedCacheSize = 50 + warpSignatureCacheSize = 500 // Prefixes for metrics gatherers ethMetricsPrefix = "eth" @@ -182,6 +182,7 @@ type VM struct { acceptedBlockDB database.Database // [warpDB] is used to store warp message signatures + // set to a prefixDB with the prefix [warpPrefix] warpDB database.Database toEngine chan<- commonEng.Message @@ -214,8 +215,9 @@ type VM struct { StateSyncServer StateSyncClient - // AWM backend - backend warp.WarpBackend + // Avalanche Warp Messaging backend + // Used to serve BLS signatures of warp messages over RPC + warpBackend warp.WarpBackend } /* @@ -427,7 +429,7 @@ func (vm *VM) Initialize( vm.client = peer.NewNetworkClient(vm.Network) // initialize warp backend - vm.backend = warp.NewWarpBackend(vm.ctx, vm.warpDB, signatureCacheSize) + vm.warpBackend = warp.NewWarpBackend(vm.ctx, vm.warpDB, warpSignatureCacheSize) if err := vm.initializeChain(lastAcceptedHash, vm.ethConfig); err != nil { return err @@ -810,7 +812,7 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]*commonEng.HTTPHandler } if vm.config.WarpAPIEnabled { - if err := handler.RegisterName("warp", &WarpAPI{vm}); err != nil { + if err := handler.RegisterName("warp", &WarpAPI{vm.warpBackend}); err != nil { return nil, err } enabledAPIs = append(enabledAPIs, "warp") diff --git a/plugin/evm/warp_client.go b/plugin/evm/warp_client.go index 874ce5073d..42fd1c262e 100644 --- a/plugin/evm/warp_client.go +++ b/plugin/evm/warp_client.go @@ -7,14 +7,12 @@ import ( "context" "fmt" - "github.com/ava-labs/subnet-evm/rpc" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ava-labs/avalanchego/utils/cb58" "github.com/ava-labs/subnet-evm/plugin/evm/message" + "github.com/ava-labs/subnet-evm/rpc" + "github.com/ethereum/go-ethereum/common/hexutil" ) -// Interface compliance var _ WarpClient = (*warpClient)(nil) type WarpClient interface { diff --git a/plugin/evm/warp_service.go b/plugin/evm/warp_service.go index 36264008d6..3ee4823cea 100644 --- a/plugin/evm/warp_service.go +++ b/plugin/evm/warp_service.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/subnet-evm/plugin/evm/warp" "github.com/ethereum/go-ethereum/common/hexutil" ) @@ -16,11 +17,13 @@ type SignatureResponse struct { } // WarpAPI introduces snowman specific functionality to the evm -type WarpAPI struct{ vm *VM } +type WarpAPI struct { + backend warp.WarpBackend +} // GetSignature returns the BLS signature associated with a messageID. In the raw request, [messageID] should be cb58 encoded func (api *WarpAPI) GetSignature(ctx context.Context, messageID ids.ID) (*SignatureResponse, error) { - signature, err := api.vm.backend.GetSignature(ctx, messageID) + signature, err := api.backend.GetSignature(ctx, messageID) if err != nil { return nil, fmt.Errorf("failed to get signature for with error %w", err) }