From ed0f30abdd2a7d8639f465c939140c26809c22f2 Mon Sep 17 00:00:00 2001 From: aaronbuchwald Date: Wed, 1 Mar 2023 17:44:38 -0800 Subject: [PATCH] Start coreth migration (#552) * Start coreth migration * Bump version to v0.4.11 and avalanchego dep * goimports core/blockchain.go * Update compatibility.json * Update compatibility in README * Bump avalanchego dep to v1.9.10 --- README.md | 1 + compatibility.json | 1 + core/blockchain.go | 4 ++-- core/vm/contracts.go | 18 +++++++++++++----- go.mod | 6 +++--- go.sum | 13 ++++++------- peer/network.go | 5 +++++ plugin/evm/factory.go | 4 ++-- plugin/evm/version.go | 2 +- scripts/versions.sh | 4 ++-- sync/client/leaf_syncer.go | 16 ++++++++-------- sync/statesync/trie_segments.go | 17 +++++++++++------ 12 files changed, 55 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 0bc1bfce3d..bac609568b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and [v0.4.8] AvalancheGo@v1.9.6-v1.9.8 (Protocol Version: 22) [v0.4.9] AvalancheGo@v1.9.9 (Protocol Version: 23) [v0.4.10] AvalancheGo@v1.9.9 (Protocol Version: 23) +[v0.4.11] AvalancheGo@v1.9.10 (Protocol Version: 24) ``` ## API diff --git a/compatibility.json b/compatibility.json index 456fbede01..d84a25cbbe 100644 --- a/compatibility.json +++ b/compatibility.json @@ -1,5 +1,6 @@ { "rpcChainVMProtocolVersion": { + "v0.4.11": 24, "v0.4.10": 23, "v0.4.9": 23, "v0.4.8": 22, diff --git a/core/blockchain.go b/core/blockchain.go index 50e688e473..16c0a43bfd 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1568,7 +1568,7 @@ type BadBlockReason struct { Receipts types.Receipts `json:"receipts"` Number uint64 `json:"number"` Hash common.Hash `json:"hash"` - Error error `json:"error"` + Error string `json:"error"` } func (b *BadBlockReason) String() string { @@ -1624,7 +1624,7 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e Receipts: receipts, Number: block.NumberU64(), Hash: block.Hash(), - Error: err, + Error: err.Error(), } badBlockCounter.Inc(1) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 2d8ec6b79d..859094e04e 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -44,6 +44,7 @@ import ( "github.com/ethereum/go-ethereum/crypto/bls12381" "github.com/ethereum/go-ethereum/crypto/bn256" + big2 "github.com/holiman/big" "golang.org/x/crypto/ripemd160" ) @@ -417,15 +418,22 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) { } // Retrieve the operands and execute the exponentiation var ( - base = new(big.Int).SetBytes(getData(input, 0, baseLen)) - exp = new(big.Int).SetBytes(getData(input, baseLen, expLen)) - mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen)) + base = new(big2.Int).SetBytes(getData(input, 0, baseLen)) + exp = new(big2.Int).SetBytes(getData(input, baseLen, expLen)) + mod = new(big2.Int).SetBytes(getData(input, baseLen+expLen, modLen)) + v []byte ) - if mod.BitLen() == 0 { + switch { + case mod.BitLen() == 0: // Modulo 0 is undefined, return zero return common.LeftPadBytes([]byte{}, int(modLen)), nil + case base.BitLen() == 1: // a bit length of 1 means it's 1 (or -1). + //If base == 1, then we can just return base % mod (if mod >= 1, which it is) + v = base.Mod(base, mod).Bytes() + default: + v = base.Exp(base, exp, mod).Bytes() } - return common.LeftPadBytes(base.Exp(base, exp, mod).Bytes(), int(modLen)), nil + return common.LeftPadBytes(v, int(modLen)), nil } // newCurvePoint unmarshals a binary blob into a bn256 elliptic curve point, diff --git a/go.mod b/go.mod index d1d8e4a515..e4bae89122 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/VictoriaMetrics/fastcache v1.10.0 - github.com/ava-labs/avalanchego v1.9.9 + github.com/ava-labs/avalanchego v1.9.10 github.com/cespare/cp v0.1.0 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.8.0 @@ -18,6 +18,7 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/hashicorp/go-bexpr v0.1.10 github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d + github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e github.com/holiman/bloomfilter/v2 v2.0.3 github.com/holiman/uint256 v1.2.0 github.com/mattn/go-colorable v0.1.12 @@ -53,8 +54,7 @@ require ( github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/deepmap/oapi-codegen v1.8.2 // indirect github.com/edsrzf/mmap-go v1.0.0 // indirect github.com/go-logr/logr v1.2.3 // indirect diff --git a/go.sum b/go.sum index 079a2539f6..cfcf45fdc5 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.9 h1:R7GBCjFBC/taZeJNJ4MtdniifC7j9eLwRezhCGa/wmc= -github.com/ava-labs/avalanchego v1.9.9/go.mod h1:mnM/wzJIaKXzLV323Yh0EbLtsicoaFSgaDESrED9dr0= +github.com/ava-labs/avalanchego v1.9.10 h1:IQYUruncY3yuKLwfbGXGslydTJQcjzLMtZuW8g5wQOY= +github.com/ava-labs/avalanchego v1.9.10/go.mod h1:nNc+4JCIJMaEt2xRmeMVAUyQwDIap7RvnMrfWD2Tpo8= 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= @@ -126,14 +126,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= -github.com/decred/dcrd/chaincfg/chainhash v1.0.2 h1:rt5Vlq/jM3ZawwiacWjPa+smINyLRN07EO0cNBV6DGU= -github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60= github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= -github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837 h1:g2cyFTu5FKWhCo7L4hVJ797Q506B4EywA7L9I6OebgA= -github.com/decred/dcrd/dcrec/secp256k1/v3 v3.0.0-20200627015759-01fd2de07837/go.mod h1:J70FGZSbzsjecRTiTzER+3f1KZLNaXkuv+yeFTKoxM8= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU= @@ -308,6 +305,8 @@ github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuW github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e h1:pIYdhNkDh+YENVNi3gto8n9hAmRxKxoar0iE6BLucjw= +github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e/go.mod h1:j9cQbcqHQujT0oKJ38PylVfqohClLr3CvDC+Qcg+lhU= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM= diff --git a/peer/network.go b/peer/network.go index 6d0ebe5990..b366eff027 100644 --- a/peer/network.go +++ b/peer/network.go @@ -467,6 +467,11 @@ func (n *network) Shutdown() { n.lock.Lock() defer n.lock.Unlock() + // clean up any pending requests + for requestID := range n.outstandingRequestHandlers { + delete(n.outstandingRequestHandlers, requestID) + } + // reset peers n.peers = NewPeerTracker() } diff --git a/plugin/evm/factory.go b/plugin/evm/factory.go index 555ab453b3..0b31ceca41 100644 --- a/plugin/evm/factory.go +++ b/plugin/evm/factory.go @@ -5,7 +5,7 @@ package evm import ( "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow" + "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms" ) @@ -18,6 +18,6 @@ var ( type Factory struct{} -func (f *Factory) New(*snow.Context) (interface{}, error) { +func (f *Factory) New(logging.Logger) (interface{}, error) { return &VM{}, nil } diff --git a/plugin/evm/version.go b/plugin/evm/version.go index 84c649ba2e..1c71b5c59f 100644 --- a/plugin/evm/version.go +++ b/plugin/evm/version.go @@ -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.10" + Version string = "v0.4.11" ) func init() { diff --git a/scripts/versions.sh b/scripts/versions.sh index a95c7f3c78..2cf2271d1c 100644 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash # 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.10'} +SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-'v0.4.11'} # Don't export them as they're used in the context of other calls -AVALANCHEGO_VERSION=${AVALANCHE_VERSION:-'v1.9.9'} +AVALANCHEGO_VERSION=${AVALANCHE_VERSION:-'v1.9.10'} GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'} # This won't be used, but it's here to make code syncs easier diff --git a/sync/client/leaf_syncer.go b/sync/client/leaf_syncer.go index 324320fb84..6aa1dab7f4 100644 --- a/sync/client/leaf_syncer.go +++ b/sync/client/leaf_syncer.go @@ -28,13 +28,13 @@ const defaultLeafRequestLimit = 1024 // the same value for Root, Account, Start, and NodeType throughout the sync. // The value returned by End can change between calls to OnLeafs. type LeafSyncTask interface { - Root() common.Hash // Root of the trie to sync - Account() common.Hash // Account hash of the trie to sync (only applicable to storage tries) - Start() []byte // Starting key to request new leaves - End() []byte // End key to request new leaves - OnStart() (bool, error) // Callback when tasks begins, returns true if work can be skipped - OnLeafs(keys, vals [][]byte) error // Callback when new leaves are received from the network - OnFinish() error // Callback when there are no more leaves in the trie to sync or when we reach End() + Root() common.Hash // Root of the trie to sync + Account() common.Hash // Account hash of the trie to sync (only applicable to storage tries) + Start() []byte // Starting key to request new leaves + End() []byte // End key to request new leaves + OnStart() (bool, error) // Callback when tasks begins, returns true if work can be skipped + OnLeafs(keys, vals [][]byte) error // Callback when new leaves are received from the network + OnFinish(ctx context.Context) error // Callback when there are no more leaves in the trie to sync or when we reach End() } type CallbackLeafSyncer struct { @@ -131,7 +131,7 @@ func (c *CallbackLeafSyncer) syncTask(ctx context.Context, task LeafSyncTask) er // If we have completed syncing this task, invoke [OnFinish] and mark the task // as complete. if done || !leafsResponse.More { - return task.OnFinish() + return task.OnFinish(ctx) } if len(leafsResponse.Keys) == 0 { diff --git a/sync/statesync/trie_segments.go b/sync/statesync/trie_segments.go index 3874f3cf7f..b355287dc1 100644 --- a/sync/statesync/trie_segments.go +++ b/sync/statesync/trie_segments.go @@ -5,6 +5,7 @@ package statesync import ( "bytes" + "context" "encoding/binary" "fmt" "sync" @@ -157,7 +158,7 @@ func (t *trieToSync) addSegment(start, end []byte) *trieSegment { // segmentFinished is called when one the trie segment with index [idx] finishes syncing. // creates intermediary hash nodes for the trie up to the last contiguous segment received from start. -func (t *trieToSync) segmentFinished(idx int) error { +func (t *trieToSync) segmentFinished(ctx context.Context, idx int) error { t.lock.Lock() defer t.lock.Unlock() @@ -182,6 +183,10 @@ func (t *trieToSync) segmentFinished(idx int) error { defer it.Release() for it.Next() { + if err := ctx.Err(); err != nil { + return err + } + if len(segment.end) > 0 && bytes.Compare(it.Key(), segment.end) > 0 { // don't go past the end of the segment. (data belongs to the next segment) break @@ -336,11 +341,11 @@ func (t *trieSegment) String() string { } // these functions implement the LeafSyncTask interface. -func (t *trieSegment) Root() common.Hash { return t.trie.root } -func (t *trieSegment) Account() common.Hash { return t.trie.account } -func (t *trieSegment) End() []byte { return t.end } -func (t *trieSegment) OnStart() (bool, error) { return t.trie.task.OnStart() } -func (t *trieSegment) OnFinish() error { return t.trie.segmentFinished(t.idx) } +func (t *trieSegment) Root() common.Hash { return t.trie.root } +func (t *trieSegment) Account() common.Hash { return t.trie.account } +func (t *trieSegment) End() []byte { return t.end } +func (t *trieSegment) OnStart() (bool, error) { return t.trie.task.OnStart() } +func (t *trieSegment) OnFinish(ctx context.Context) error { return t.trie.segmentFinished(ctx, t.idx) } func (t *trieSegment) Start() []byte { if t.pos != nil {