Skip to content

Commit

Permalink
sync upstream v0.5.0 (157e9b9)
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Apr 12, 2023
2 parents 766c112 + 157e9b9 commit 88372ef
Show file tree
Hide file tree
Showing 52 changed files with 843 additions and 797 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Bench

on:
workflow_dispatch:
pull_request:

jobs:
bench:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.19"
- run: go mod download
shell: bash
- run: ./scripts/build_bench_precompiles.sh
shell: bash

1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Release

on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and
[v0.4.8] [email protected] (Protocol Version: 22)
[v0.4.9] [email protected] (Protocol Version: 23)
[v0.4.10] [email protected] (Protocol Version: 23)
[v0.4.11] [email protected] (Protocol Version: 24)
[v0.4.12] [email protected] (Protocol Version: 24)
[v0.4.11] [email protected] (Protocol Version: 24)
[v0.4.12] [email protected] (Protocol Version: 24)
[v0.5.0] [email protected] (Protocol Version: 25)
```

## API
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call
if transfer == nil {
transfer = new(big.Int)
}
log.Warn("Gas estimation capped by limited funds", "original", hi, "balance", balance,
log.Info("Gas estimation capped by limited funds", "original", hi, "balance", balance,
"sent", transfer, "feecap", feeCap, "fundable", allowance)
hi = allowance.Uint64()
}
Expand Down
1 change: 1 addition & 0 deletions compatibility.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rpcChainVMProtocolVersion": {
"v0.5.0": 25,
"v0.4.12": 24,
"v0.4.11": 24,
"v0.4.10": 23,
Expand Down
8 changes: 4 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,9 +1358,9 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
storageUpdateTimer.Inc(statedb.StorageUpdates.Milliseconds()) // Storage updates are complete, we can mark them
accountHashTimer.Inc(statedb.AccountHashes.Milliseconds()) // Account hashes are complete, we can mark them
storageHashTimer.Inc(statedb.StorageHashes.Milliseconds()) // Storage hashes are complete, we can mark them
additionalTrieProc := statedb.AccountHashes + statedb.StorageHashes + statedb.AccountUpdates + statedb.StorageUpdates - trieproc
blockStateValidationTimer.Inc((time.Since(substart) - additionalTrieProc).Milliseconds())
blockTrieOpsTimer.Inc((trieproc + additionalTrieProc).Milliseconds())
validationTrieProcTime := statedb.AccountHashes + statedb.StorageHashes + statedb.AccountUpdates + statedb.StorageUpdates - trieproc
blockStateValidationTimer.Inc((time.Since(substart) - validationTrieProcTime).Milliseconds())
blockTrieOpsTimer.Inc((trieproc + validationTrieProcTime).Milliseconds())

// If [writes] are disabled, skip [writeBlockWithState] so that we do not write the block
// or the state trie to disk.
Expand Down Expand Up @@ -1510,7 +1510,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(),
"drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash())
} else {
log.Warn("Unlikely preference change (rewind to ancestor) occurred", "oldnum", oldHead.Number(), "oldhash", oldHead.Hash(), "newnum", newHead.Number(), "newhash", newHead.Hash())
log.Debug("Preference change (rewind to ancestor) occurred", "oldnum", oldHead.Number(), "oldhash", oldHead.Hash(), "newnum", newHead.Number(), "newhash", newHead.Hash())
}
// Insert the new chain(except the head block(reverse order)),
// taking care of the proper incremental order.
Expand Down
2 changes: 1 addition & 1 deletion core/state/test_statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)

func NewTestStateDB(t *testing.T) contract.StateDB {
func NewTestStateDB(t testing.TB) contract.StateDB {
db := memorydb.New()
stateDB, err := New(common.Hash{}, NewDatabase(db), nil)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanchego v1.9.11
github.com/ava-labs/avalanchego v1.10.0
github.com/cespare/cp v0.1.0
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
Expand Down Expand Up @@ -47,6 +47,7 @@ require (
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand All @@ -61,8 +63,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.11 h1:5hXHJMvErfaolWD7Hw9gZaVylck2shBaV/2NTHA0BfA=
github.com/ava-labs/avalanchego v1.9.11/go.mod h1:nNc+4JCIJMaEt2xRmeMVAUyQwDIap7RvnMrfWD2Tpo8=
github.com/ava-labs/avalanchego v1.10.0 h1:Rn6Nyd62OkzQG5QpCgtCGVXtjuiaEzxV000kqG9aUIg=
github.com/ava-labs/avalanchego v1.10.0/go.mod h1:hTaSLGN4y/EmhmYd+yjUj9Lsm00q70V78jOYDdnLrgQ=
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
4 changes: 2 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,14 +1162,14 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
if transfer == nil {
transfer = new(hexutil.Big)
}
log.Warn("Gas estimation capped by limited funds", "original", hi, "balance", balance,
log.Info("Gas estimation capped by limited funds", "original", hi, "balance", balance,
"sent", transfer.ToInt(), "maxFeePerGas", feeCap, "fundable", allowance)
hi = allowance.Uint64()
}
}
// Recap the highest gas allowance with specified gascap.
if gasCap != 0 && hi > gasCap {
log.Warn("Caller gas above allowance, capping", "requested", hi, "cap", gasCap)
log.Info("Caller gas above allowance, capping", "requested", hi, "cap", gasCap)
hi = gasCap
}
cap = hi
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
gas = uint64(*args.Gas)
}
if globalGasCap != 0 && globalGasCap < gas {
log.Warn("Caller gas above allowance, capping", "requested", gas, "cap", globalGasCap)
log.Info("Caller gas above allowance, capping", "requested", gas, "cap", globalGasCap)
gas = globalGasCap
}
var (
Expand Down
11 changes: 5 additions & 6 deletions plugin/evm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ func (b *Block) ShouldVerifyWithContext(context.Context) (bool, error) {

// VerifyWithContext implements the block.WithVerifyContext interface
func (b *Block) VerifyWithContext(ctx context.Context, proposerVMBlockCtx *block.Context) error {
if proposerVMBlockCtx != nil {
log.Debug("Verifying block with context", "block", b.ID(), "height", b.Height())
} else {
log.Debug("Verifying block without context", "block", b.ID(), "height", b.Height())
}

return b.verify(&precompileconfig.ProposerPredicateContext{
PrecompilePredicateContext: precompileconfig.PrecompilePredicateContext{
SnowCtx: b.vm.ctx,
Expand All @@ -220,6 +214,11 @@ func (b *Block) VerifyWithContext(ctx context.Context, proposerVMBlockCtx *block
// Enforces that the predicates are valid within [predicateContext].
// Writes the block details to disk and the state to the trie manager iff writes=true.
func (b *Block) verify(predicateContext *precompileconfig.ProposerPredicateContext, writes bool) error {
if predicateContext.ProposerVMBlockCtx != nil {
log.Debug("Verifying block with context", "block", b.ID(), "height", b.Height())
} else {
log.Debug("Verifying block without context", "block", b.ID(), "height", b.Height())
}
if err := b.syntacticVerify(); err != nil {
return fmt.Errorf("syntactic block verification failed: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions plugin/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const (
defaultPopulateMissingTriesParallelism = 1024
defaultStateSyncServerTrieCache = 64 // MB
defaultAcceptedCacheSize = 32 // blocks
defaultWarpAPIEnabled = true

// defaultStateSyncMinBlocks is the minimum number of blocks the blockchain
// should be ahead of local last accepted to perform state sync.
Expand All @@ -56,7 +55,8 @@ const (
// time assumptions:
// - normal bootstrap processing time: ~14 blocks / second
// - state sync time: ~6 hrs.
defaultStateSyncMinBlocks = 300_000
defaultStateSyncMinBlocks = 300_000
defaultStateSyncRequestSize = 256 // the number of key/values to ask peers for per request
)

var (
Expand Down Expand Up @@ -187,6 +187,7 @@ type Config struct {
StateSyncIDs string `json:"state-sync-ids"`
StateSyncCommitInterval uint64 `json:"state-sync-commit-interval"`
StateSyncMinBlocks uint64 `json:"state-sync-min-blocks"`
StateSyncRequestSize uint16 `json:"state-sync-request-size"`

// SkipUpgradeCheck disables checking that upgrades must take place before the last
// accepted block. Skipping this check is useful when a node operator does not update
Expand Down Expand Up @@ -225,7 +226,6 @@ func (c *Config) SetDefaults() {
c.RPCGasCap = defaultRpcGasCap
c.RPCTxFeeCap = defaultRpcTxFeeCap
c.MetricsExpensiveEnabled = defaultMetricsExpensiveEnabled
c.WarpAPIEnabled = defaultWarpAPIEnabled

c.TxPoolJournal = core.DefaultTxPoolConfig.Journal
c.TxPoolRejournal = Duration{core.DefaultTxPoolConfig.Rejournal}
Expand Down Expand Up @@ -265,6 +265,7 @@ func (c *Config) SetDefaults() {
c.StateSyncServerTrieCache = defaultStateSyncServerTrieCache
c.StateSyncCommitInterval = defaultSyncableCommitInterval
c.StateSyncMinBlocks = defaultStateSyncMinBlocks
c.StateSyncRequestSize = defaultStateSyncRequestSize
c.AllowUnprotectedTxHashes = defaultAllowUnprotectedTxHashes
c.AcceptedCacheSize = defaultAcceptedCacheSize
}
Expand Down
8 changes: 4 additions & 4 deletions plugin/evm/message/cross_chain_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func (c *crossChainHandler) HandleEthCallRequest(ctx context.Context, requesting
transactionArgs := ethapi.TransactionArgs{}
err := json.Unmarshal(ethCallRequest.RequestArgs, &transactionArgs)
if err != nil {
log.Debug("error occurred with JSON unmarshalling ethCallRequest.RequestArgs", "err", err)
log.Error("error occurred with JSON unmarshalling ethCallRequest.RequestArgs", "err", err)
return nil, nil
}

result, err := ethapi.DoCall(ctx, c.backend, transactionArgs, lastAcceptedBlockNumberOrHash, nil, c.backend.RPCEVMTimeout(), c.backend.RPCGasCap())
if err != nil {
log.Debug("error occurred with EthCall", "err", err, "transactionArgs", ethCallRequest.RequestArgs, "blockNumberOrHash", lastAcceptedBlockNumberOrHash)
log.Error("error occurred with EthCall", "err", err, "transactionArgs", ethCallRequest.RequestArgs, "blockNumberOrHash", lastAcceptedBlockNumberOrHash)
return nil, nil
}

executionResult, err := json.Marshal(&result)
if err != nil {
log.Debug("error occurred with JSON marshalling result", "err", err)
log.Error("error occurred with JSON marshalling result", "err", err)
return nil, nil
}

Expand All @@ -65,7 +65,7 @@ func (c *crossChainHandler) HandleEthCallRequest(ctx context.Context, requesting

responseBytes, err := c.crossChainCodec.Marshal(Version, response)
if err != nil {
log.Warn("error occurred with marshalling EthCallResponse", "err", err, "EthCallResponse", response)
log.Error("error occurred with marshalling EthCallResponse", "err", err, "EthCallResponse", response)
return nil, nil
}

Expand Down
6 changes: 4 additions & 2 deletions plugin/evm/syncervm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type stateSyncClientConfig struct {
// Specifies the number of blocks behind the latest state summary that the chain must be
// in order to prefer performing state sync over falling back to the normal bootstrapping
// algorithm.
stateSyncMinBlocks uint64
stateSyncMinBlocks uint64
stateSyncRequestSize uint16 // number of key/value pairs to ask peers for per request

lastAcceptedHeight uint64

Expand Down Expand Up @@ -257,7 +258,7 @@ func (client *stateSyncerClient) syncBlocks(ctx context.Context, fromHash common
}
blocks, err := client.client.GetBlocks(ctx, nextHash, nextHeight, parentsPerRequest)
if err != nil {
log.Warn("could not get blocks from peer", "err", err, "nextHash", nextHash, "remaining", i+1)
log.Error("could not get blocks from peer", "err", err, "nextHash", nextHash, "remaining", i+1)
return err
}
for _, block := range blocks {
Expand All @@ -283,6 +284,7 @@ func (client *stateSyncerClient) syncStateTrie(ctx context.Context) error {
DB: client.chaindb,
MaxOutstandingCodeHashes: statesync.DefaultMaxOutstandingCodeHashes,
NumCodeFetchingWorkers: statesync.DefaultNumCodeFetchingWorkers,
RequestSize: client.stateSyncRequestSize,
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
// GitCommit is set by the build script
GitCommit string
// Version is the version of Subnet EVM
Version string = "v0.4.12"
Version string = "v0.5.0"
)

func init() {
Expand Down
23 changes: 12 additions & 11 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (vm *VM) Initialize(
vm.syntacticBlockValidator = NewBlockValidator()

if g.Config.FeeConfig == commontype.EmptyFeeConfig {
log.Warn("No fee config given in genesis, setting default fee config", "DefaultFeeConfig", params.DefaultFeeConfig)
log.Info("No fee config given in genesis, setting default fee config", "DefaultFeeConfig", params.DefaultFeeConfig)
g.Config.FeeConfig = params.DefaultFeeConfig
}

Expand Down Expand Up @@ -372,7 +372,7 @@ func (vm *VM) Initialize(
log.Info("Setting fee recipient", "address", address)
vm.ethConfig.Miner.Etherbase = address
} else {
log.Warn("Config has not specified any coinbase address. Defaulting to the blackhole address.")
log.Info("Config has not specified any coinbase address. Defaulting to the blackhole address.")
vm.ethConfig.Miner.Etherbase = constants.BlackholeAddr
}

Expand Down Expand Up @@ -508,15 +508,16 @@ func (vm *VM) initializeStateSyncClient(lastAcceptedHeight uint64) error {
BlockParser: vm,
},
),
enabled: vm.config.StateSyncEnabled,
skipResume: vm.config.StateSyncSkipResume,
stateSyncMinBlocks: vm.config.StateSyncMinBlocks,
lastAcceptedHeight: lastAcceptedHeight, // TODO clean up how this is passed around
chaindb: vm.chaindb,
metadataDB: vm.metadataDB,
acceptedBlockDB: vm.acceptedBlockDB,
db: vm.db,
toEngine: vm.toEngine,
enabled: vm.config.StateSyncEnabled,
skipResume: vm.config.StateSyncSkipResume,
stateSyncMinBlocks: vm.config.StateSyncMinBlocks,
stateSyncRequestSize: vm.config.StateSyncRequestSize,
lastAcceptedHeight: lastAcceptedHeight, // TODO clean up how this is passed around
chaindb: vm.chaindb,
metadataDB: vm.metadataDB,
acceptedBlockDB: vm.acceptedBlockDB,
db: vm.db,
toEngine: vm.toEngine,
})

// If StateSync is disabled, clear any ongoing summary so that we will not attempt to resume
Expand Down
23 changes: 3 additions & 20 deletions plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,14 @@
package main

import (
"context"
"fmt"
"os"

"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/ulimit"
"github.com/ava-labs/avalanchego/version"
"github.com/ava-labs/avalanchego/vms/rpcchainvm"

"github.com/ava-labs/subnet-evm/plugin/evm"
"github.com/ava-labs/subnet-evm/plugin/runner"
)

func main() {
printVersion, err := PrintVersion()
if err != nil {
fmt.Printf("couldn't get config: %s", err)
os.Exit(1)
}
if printVersion {
fmt.Printf("Subnet-EVM/%s [AvalancheGo=%s, rpcchainvm=%d]\n", evm.Version, version.Current, version.RPCChainVMProtocol)
os.Exit(0)
}
if err := ulimit.Set(ulimit.DefaultFDLimit, logging.NoLog{}); err != nil {
fmt.Printf("failed to set fd limit correctly due to: %s", err)
os.Exit(1)
}
rpcchainvm.Serve(context.Background(), &evm.VM{})
versionString := fmt.Sprintf("Subnet-EVM/%s [AvalancheGo=%s, rpcchainvm=%d]", evm.Version, version.Current, version.RPCChainVMProtocol)
runner.Run(versionString)
}
2 changes: 1 addition & 1 deletion plugin/keys.go → plugin/runner/keys.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package main
package runner

const (
versionKey = "version"
Expand Down
2 changes: 1 addition & 1 deletion plugin/params.go → plugin/runner/params.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package main
package runner

import (
"flag"
Expand Down
Loading

0 comments on commit 88372ef

Please sign in to comment.