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

nits for get-signature-endpoint #502

Merged
merged 9 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,31 @@ 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)
for information on signing commits.
- 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
Expand Down
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
## How this works

## How this was tested

## How is this documented
2 changes: 1 addition & 1 deletion .github/workflows/lint-tests-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contract-examples/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/snowman_service.go → plugin/evm/service.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 10 additions & 15 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -83,10 +82,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"
Expand Down Expand Up @@ -182,6 +181,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
Expand Down Expand Up @@ -214,8 +214,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
}

/*
Expand Down Expand Up @@ -427,7 +428,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
Expand Down Expand Up @@ -810,7 +811,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")
Expand Down Expand Up @@ -867,12 +868,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.
Expand Down
8 changes: 4 additions & 4 deletions plugin/evm/warp/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ type WarpBackend interface {
type warpBackend struct {
db database.Database
snowCtx *snow.Context
signatureCache *cache.LRU
signatureCache *cache.LRU[ids.ID, [bls.SignatureLen]byte]
}

// NewWarpBackend creates a new WarpBackend, and initializes the signature cache and message tracking database.
func NewWarpBackend(snowCtx *snow.Context, db database.Database, signatureCacheSize int) WarpBackend {
return &warpBackend{
db: db,
snowCtx: snowCtx,
signatureCache: &cache.LRU{Size: signatureCacheSize},
signatureCache: &cache.LRU[ids.ID, [bls.SignatureLen]byte]{Size: signatureCacheSize},
}
}

Expand All @@ -71,7 +71,7 @@ func (w *warpBackend) AddMessage(ctx context.Context, unsignedMessage *teleporte

func (w *warpBackend) GetSignature(ctx context.Context, messageID ids.ID) ([bls.SignatureLen]byte, error) {
if sig, ok := w.signatureCache.Get(messageID); ok {
return sig.([bls.SignatureLen]byte), nil
return sig, nil
}

unsignedMessageBytes, err := w.db.Get(messageID[:])
Expand All @@ -91,6 +91,6 @@ func (w *warpBackend) GetSignature(ctx context.Context, messageID ids.ID) ([bls.
}

copy(signature[:], sig)
w.signatureCache.Put(messageID[:], signature)
w.signatureCache.Put(messageID, signature)
return signature, nil
}
6 changes: 2 additions & 4 deletions plugin/evm/warp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions plugin/evm/warp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
Expand Down
21 changes: 21 additions & 0 deletions scripts/generate_precompile.sh
Original file line number Diff line number Diff line change
@@ -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 $@
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down