From b2397fc5ac92bb324ac09594c87463ec37ea96e0 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Wed, 16 Sep 2020 11:55:36 -0400 Subject: Add nil to newBlockChan if block verification errors --- plugin/evm/vm.go | 1 + 1 file changed, 1 insertion(+) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 9ab4781..d9ddd70 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -295,6 +295,7 @@ func (vm *VM) Initialize( vm: vm, } if blk.Verify() != nil { + vm.newBlockChan <- nil return errInvalidBlock } vm.newBlockChan <- blk -- cgit v1.2.3-70-g09d2 From 8478802ddacc027a8d8c866da9365f6739d9d9d4 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 16 Sep 2020 18:26:55 -0400 Subject: ... --- accounts/accounts.go | 8 ++++---- accounts/external/backend.go | 14 +++++++------- accounts/keystore/account_cache.go | 4 ++-- accounts/keystore/file_cache.go | 2 +- accounts/keystore/key.go | 4 ++-- accounts/keystore/keystore.go | 6 +++--- accounts/keystore/passphrase.go | 8 ++++---- accounts/keystore/plain.go | 2 +- accounts/keystore/presale.go | 2 +- accounts/keystore/wallet.go | 4 ++-- accounts/keystore/watch.go | 2 +- accounts/manager.go | 4 ++-- accounts/scwallet/hub.go | 6 +++--- accounts/scwallet/securechannel.go | 2 +- accounts/scwallet/wallet.go | 8 ++++---- consensus/dummy/consensus.go | 4 ++-- core/blockchain.go | 2 +- core/gen_genesis.go | 6 +++--- core/gen_genesis_account.go | 6 +++--- core/state/journal.go | 2 +- core/types/receipt.go | 2 +- core/types/transaction_signing.go | 2 +- coreth.go | 10 +++++----- examples/block/main.go | 8 ++++---- examples/chain/main.go | 8 ++++---- examples/counter/main.go | 8 ++++---- examples/multicoin/main.go | 10 +++++----- examples/payments/main.go | 6 +++--- node/api.go | 8 ++++---- plugin/evm/block.go | 2 +- plugin/evm/database.go | 2 +- plugin/evm/export_tx.go | 2 +- plugin/evm/import_tx.go | 2 +- plugin/evm/service.go | 6 +++--- plugin/evm/tx.go | 2 +- plugin/evm/user.go | 2 +- plugin/evm/vm.go | 8 ++++---- 37 files changed, 92 insertions(+), 92 deletions(-) (limited to 'plugin/evm') diff --git a/accounts/accounts.go b/accounts/accounts.go index 2f39684..17978d3 100644 --- a/accounts/accounts.go +++ b/accounts/accounts.go @@ -22,10 +22,10 @@ import ( "math/big" "github.com/ava-labs/coreth/core/types" - ethereum "github.com/ava-labs/go-ethereum" - gethaccounts "github.com/ava-labs/go-ethereum/accounts" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/event" + ethereum "github.com/ethereum/go-ethereum" + gethaccounts "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/event" "golang.org/x/crypto/sha3" ) diff --git a/accounts/external/backend.go b/accounts/external/backend.go index 41329d3..f3744cf 100644 --- a/accounts/external/backend.go +++ b/accounts/external/backend.go @@ -23,13 +23,13 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/go-ethereum" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/event" - "github.com/ava-labs/go-ethereum/log" - "github.com/ava-labs/go-ethereum/rpc" - "github.com/ava-labs/go-ethereum/signer/core" + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/signer/core" ) type ExternalBackend struct { diff --git a/accounts/keystore/account_cache.go b/accounts/keystore/account_cache.go index 2067ccb..76bd552 100644 --- a/accounts/keystore/account_cache.go +++ b/accounts/keystore/account_cache.go @@ -28,8 +28,8 @@ import ( "time" "github.com/ava-labs/coreth/accounts" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/log" mapset "github.com/deckarep/golang-set" ) diff --git a/accounts/keystore/file_cache.go b/accounts/keystore/file_cache.go index ac87f0c..73ff6ae 100644 --- a/accounts/keystore/file_cache.go +++ b/accounts/keystore/file_cache.go @@ -25,7 +25,7 @@ import ( "time" mapset "github.com/deckarep/golang-set" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/log" ) // fileCache is a cache of files seen during scan of keystore. diff --git a/accounts/keystore/key.go b/accounts/keystore/key.go index 3654daa..dc54adb 100644 --- a/accounts/keystore/key.go +++ b/accounts/keystore/key.go @@ -30,8 +30,8 @@ import ( "time" "github.com/ava-labs/coreth/accounts" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/pborman/uuid" ) diff --git a/accounts/keystore/keystore.go b/accounts/keystore/keystore.go index 1bcaf13..cb4df04 100644 --- a/accounts/keystore/keystore.go +++ b/accounts/keystore/keystore.go @@ -34,9 +34,9 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/event" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/event" ) var ( diff --git a/accounts/keystore/passphrase.go b/accounts/keystore/passphrase.go index 04f31ff..f8a62c6 100644 --- a/accounts/keystore/passphrase.go +++ b/accounts/keystore/passphrase.go @@ -39,9 +39,9 @@ import ( "path/filepath" "github.com/ava-labs/coreth/accounts" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/math" - "github.com/ava-labs/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/crypto" "github.com/pborman/uuid" "golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/scrypt" @@ -121,7 +121,7 @@ func (ks keyStorePassphrase) StoreKey(filename string, key *Key, auth string) er "This indicates that the keystore is corrupted. \n" + "The corrupted file is stored at \n%v\n" + "Please file a ticket at:\n\n" + - "https://github.com/ava-labs/go-ethereum/issues." + + "https://github.com/ethereum/go-ethereum/issues." + "The error was : %s" //lint:ignore ST1005 This is a message for the user return fmt.Errorf(msg, tmpName, err) diff --git a/accounts/keystore/plain.go b/accounts/keystore/plain.go index bc5b377..f62a133 100644 --- a/accounts/keystore/plain.go +++ b/accounts/keystore/plain.go @@ -22,7 +22,7 @@ import ( "os" "path/filepath" - "github.com/ava-labs/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ) type keyStorePlain struct { diff --git a/accounts/keystore/presale.go b/accounts/keystore/presale.go index 5122b0d..4833c6c 100644 --- a/accounts/keystore/presale.go +++ b/accounts/keystore/presale.go @@ -26,7 +26,7 @@ import ( "fmt" "github.com/ava-labs/coreth/accounts" - "github.com/ava-labs/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" "github.com/pborman/uuid" "golang.org/x/crypto/pbkdf2" ) diff --git a/accounts/keystore/wallet.go b/accounts/keystore/wallet.go index 3be901b..7092385 100644 --- a/accounts/keystore/wallet.go +++ b/accounts/keystore/wallet.go @@ -21,8 +21,8 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/core/types" - ethereum "github.com/ava-labs/go-ethereum" - "github.com/ava-labs/go-ethereum/crypto" + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/crypto" ) // keystoreWallet implements the accounts.Wallet interface for the original diff --git a/accounts/keystore/watch.go b/accounts/keystore/watch.go index 7fa5b3c..d6ef533 100644 --- a/accounts/keystore/watch.go +++ b/accounts/keystore/watch.go @@ -21,7 +21,7 @@ package keystore import ( "time" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/log" "github.com/rjeczalik/notify" ) diff --git a/accounts/manager.go b/accounts/manager.go index 87d3df8..acf41ed 100644 --- a/accounts/manager.go +++ b/accounts/manager.go @@ -21,8 +21,8 @@ import ( "sort" "sync" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/event" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/event" ) // Config contains the settings of the global account manager. diff --git a/accounts/scwallet/hub.go b/accounts/scwallet/hub.go index 67483b8..1d0c124 100644 --- a/accounts/scwallet/hub.go +++ b/accounts/scwallet/hub.go @@ -42,9 +42,9 @@ import ( "time" "github.com/ava-labs/coreth/accounts" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/event" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" pcsc "github.com/gballet/go-libpcsclite" ) diff --git a/accounts/scwallet/securechannel.go b/accounts/scwallet/securechannel.go index a5666c9..9b70c69 100644 --- a/accounts/scwallet/securechannel.go +++ b/accounts/scwallet/securechannel.go @@ -25,7 +25,7 @@ import ( "crypto/sha512" "fmt" - "github.com/ava-labs/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto" pcsc "github.com/gballet/go-libpcsclite" "github.com/wsddn/go-ecdh" "golang.org/x/crypto/pbkdf2" diff --git a/accounts/scwallet/wallet.go b/accounts/scwallet/wallet.go index 5d2aff8..2f08c17 100644 --- a/accounts/scwallet/wallet.go +++ b/accounts/scwallet/wallet.go @@ -35,10 +35,10 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/core/types" - ethereum "github.com/ava-labs/go-ethereum" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/log" + ethereum "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" pcsc "github.com/gballet/go-libpcsclite" "github.com/status-im/keycard-go/derivationpath" ) diff --git a/consensus/dummy/consensus.go b/consensus/dummy/consensus.go index 494e4be..2108684 100644 --- a/consensus/dummy/consensus.go +++ b/consensus/dummy/consensus.go @@ -13,8 +13,8 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/rpc" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/rlp" mapset "github.com/deckarep/golang-set" ) diff --git a/core/blockchain.go b/core/blockchain.go index 342790e..b861220 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -31,10 +31,10 @@ import ( "github.com/ava-labs/coreth/consensus" "github.com/ava-labs/coreth/core/rawdb" "github.com/ava-labs/coreth/core/state" + "github.com/ava-labs/coreth/core/state/snapshot" "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/core/vm" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/state/snapshot" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/common/prque" diff --git a/core/gen_genesis.go b/core/gen_genesis.go index 97175f7..b683ace 100644 --- a/core/gen_genesis.go +++ b/core/gen_genesis.go @@ -8,9 +8,9 @@ import ( "math/big" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/common/math" ) var _ = (*genesisSpecMarshaling)(nil) diff --git a/core/gen_genesis_account.go b/core/gen_genesis_account.go index b90b658..a2f503f 100644 --- a/core/gen_genesis_account.go +++ b/core/gen_genesis_account.go @@ -7,9 +7,9 @@ import ( "errors" "math/big" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/common/math" ) var _ = (*genesisAccountMarshaling)(nil) diff --git a/core/state/journal.go b/core/state/journal.go index cfa1a4a..0cc556b 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -19,7 +19,7 @@ package state import ( "math/big" - "github.com/ava-labs/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ) // journalEntry is a modification entry in the state change journal that can be diff --git a/core/types/receipt.go b/core/types/receipt.go index 4d57f59..21ac8a1 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -24,7 +24,7 @@ import ( "math/big" "unsafe" - "github.com/ethereum/coreth/params" + "github.com/ava-labs/coreth/params" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index ecc65d5..819c680 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -22,7 +22,7 @@ import ( "fmt" "math/big" - "github.com/ethereum/coreth/params" + "github.com/ava-labs/coreth/params" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" ) diff --git a/coreth.go b/coreth.go index c8a0e41..1fe2613 100644 --- a/coreth.go +++ b/coreth.go @@ -14,11 +14,11 @@ import ( "github.com/ava-labs/coreth/miner" "github.com/ava-labs/coreth/node" "github.com/ava-labs/coreth/rpc" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/ethdb" - "github.com/ava-labs/go-ethereum/event" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" "github.com/mattn/go-isatty" ) diff --git a/examples/block/main.go b/examples/block/main.go index 45d7586..89540c6 100644 --- a/examples/block/main.go +++ b/examples/block/main.go @@ -8,10 +8,10 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/eth" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" "math/big" ) diff --git a/examples/chain/main.go b/examples/chain/main.go index 26fc5ce..17003b5 100644 --- a/examples/chain/main.go +++ b/examples/chain/main.go @@ -8,10 +8,10 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/eth" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/log" - "github.com/ava-labs/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rlp" "math/big" "sync" ) diff --git a/examples/counter/main.go b/examples/counter/main.go index 85aa9d1..9e18cd8 100644 --- a/examples/counter/main.go +++ b/examples/counter/main.go @@ -10,10 +10,10 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/eth" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/compiler" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/compiler" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" "go/build" "math/big" "os" diff --git a/examples/multicoin/main.go b/examples/multicoin/main.go index 792a5b5..1f96647 100644 --- a/examples/multicoin/main.go +++ b/examples/multicoin/main.go @@ -10,11 +10,11 @@ import ( "github.com/ava-labs/coreth/core/vm" "github.com/ava-labs/coreth/eth" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/accounts/abi" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/compiler" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/accounts/abi" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/compiler" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" "go/build" "math/big" "os" diff --git a/examples/payments/main.go b/examples/payments/main.go index 40a90c2..fee2060 100644 --- a/examples/payments/main.go +++ b/examples/payments/main.go @@ -8,9 +8,9 @@ import ( "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/eth" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/log" "math/big" ) diff --git a/node/api.go b/node/api.go index 4196a6b..e74d10b 100644 --- a/node/api.go +++ b/node/api.go @@ -22,10 +22,10 @@ import ( //"strings" "github.com/ava-labs/coreth/rpc" - "github.com/ava-labs/go-ethereum/common/hexutil" - "github.com/ava-labs/go-ethereum/crypto" - "github.com/ava-labs/go-ethereum/p2p" - "github.com/ava-labs/go-ethereum/p2p/enode" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/p2p/enode" ) // apis returns the collection of built-in RPC APIs. diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 134fa29..98280f0 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/ava-labs/coreth/core/types" - "github.com/ava-labs/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/rlp" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/choices" diff --git a/plugin/evm/database.go b/plugin/evm/database.go index aedbc9b..38b21d0 100644 --- a/plugin/evm/database.go +++ b/plugin/evm/database.go @@ -6,7 +6,7 @@ package evm import ( "errors" - "github.com/ava-labs/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/ethdb" "github.com/ava-labs/avalanchego/database" ) diff --git a/plugin/evm/export_tx.go b/plugin/evm/export_tx.go index 43f858c..0487c44 100644 --- a/plugin/evm/export_tx.go +++ b/plugin/evm/export_tx.go @@ -8,7 +8,7 @@ import ( "math/big" "github.com/ava-labs/coreth/core/state" - "github.com/ava-labs/go-ethereum/log" + "github.com/ethereum/go-ethereum/log" "github.com/ava-labs/avalanchego/chains/atomic" "github.com/ava-labs/avalanchego/database" diff --git a/plugin/evm/import_tx.go b/plugin/evm/import_tx.go index c6ad2d9..7d17c4e 100644 --- a/plugin/evm/import_tx.go +++ b/plugin/evm/import_tx.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/utils/math" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - "github.com/ava-labs/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ) // UnsignedImportTx is an unsigned ImportTx diff --git a/plugin/evm/service.go b/plugin/evm/service.go index 33429b5..65d389d 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -20,9 +20,9 @@ import ( "github.com/ava-labs/avalanchego/utils/crypto" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/json" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/common/hexutil" - ethcrypto "github.com/ava-labs/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + ethcrypto "github.com/ethereum/go-ethereum/crypto" ) const ( diff --git a/plugin/evm/tx.go b/plugin/evm/tx.go index e573580..e39a053 100644 --- a/plugin/evm/tx.go +++ b/plugin/evm/tx.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - "github.com/ava-labs/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ) // Max size of memo field diff --git a/plugin/evm/user.go b/plugin/evm/user.go index cfa302b..b751634 100644 --- a/plugin/evm/user.go +++ b/plugin/evm/user.go @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto" - "github.com/ava-labs/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" ) // Key in the database whose corresponding value is the list of diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 9ab4781..5c5a5b5 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -22,11 +22,11 @@ import ( "github.com/ava-labs/coreth/node" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/go-ethereum/common" - "github.com/ava-labs/go-ethereum/rlp" - "github.com/ava-labs/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/rpc" - ethcrypto "github.com/ava-labs/go-ethereum/crypto" + ethcrypto "github.com/ethereum/go-ethereum/crypto" avalancheRPC "github.com/gorilla/rpc/v2" -- cgit v1.2.3-70-g09d2 From ed839907e592ad25e6119e145e7e05ca78b00fcd Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 16 Sep 2020 22:54:37 -0400 Subject: ... --- accounts/external/backend.go | 2 +- consensus/dummy/consensus.go | 4 ++-- core/blockchain.go | 17 ++++++++-------- core/state/database.go | 2 +- core/state/dump.go | 43 ++++++++++++++++++++++------------------- core/state/snapshot/account.go | 20 ++++++++++--------- core/state/snapshot/generate.go | 11 ++++++----- core/state/statedb.go | 5 +++-- core/types/block.go | 32 +++++++++++++++++++----------- core/vm/evm.go | 12 +++++++----- eth/api_backend.go | 2 +- eth/backend.go | 2 +- eth/filters/filter.go | 2 +- examples/chain/main.go | 4 +++- examples/counter/counter.sol | 2 +- examples/multicoin/main.go | 4 ++-- internal/ethapi/backend.go | 2 +- plugin/evm/vm.go | 2 +- 18 files changed, 95 insertions(+), 73 deletions(-) (limited to 'plugin/evm') diff --git a/accounts/external/backend.go b/accounts/external/backend.go index f3744cf..e0fc91d 100644 --- a/accounts/external/backend.go +++ b/accounts/external/backend.go @@ -23,12 +23,12 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/core/types" + "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/signer/core" ) diff --git a/consensus/dummy/consensus.go b/consensus/dummy/consensus.go index da63673..42e224d 100644 --- a/consensus/dummy/consensus.go +++ b/consensus/dummy/consensus.go @@ -262,10 +262,10 @@ func (self *DummyEngine) Finalize( func (self *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { - var extdata []byte + var extdata *[]byte if self.cb.OnFinalizeAndAssemble != nil { ret, err := self.cb.OnFinalizeAndAssemble(state, txs) - extdata = ret + extdata = &ret if err != nil { return nil, err } diff --git a/core/blockchain.go b/core/blockchain.go index 82e3b6c..b3a7ffa 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2492,12 +2492,13 @@ func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscr } func (bc *BlockChain) ManualHead(hash common.Hash) error { - block := bc.GetBlockByHash(hash) - if block == nil { - return errors.New("block not found") - } - bc.chainmu.Lock() - defer bc.chainmu.Unlock() - bc.writeHeadBlock(block) - return nil + return bc.FastSyncCommitHead(hash) + //block := bc.GetBlockByHash(hash) + //if block == nil { + // return errors.New("block not found") + //} + //bc.chainmu.Lock() + //defer bc.chainmu.Unlock() + //bc.writeHeadBlock(block) + //return nil } diff --git a/core/state/database.go b/core/state/database.go index a9342f5..385c25d 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -21,8 +21,8 @@ import ( "fmt" "github.com/VictoriaMetrics/fastcache" + "github.com/ava-labs/coreth/core/rawdb" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/trie" lru "github.com/hashicorp/golang-lru" diff --git a/core/state/dump.go b/core/state/dump.go index 9bb946d..6f09398 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -37,14 +37,15 @@ type DumpCollector interface { // DumpAccount represents an account in the state. type DumpAccount struct { - Balance string `json:"balance"` - Nonce uint64 `json:"nonce"` - Root string `json:"root"` - CodeHash string `json:"codeHash"` - Code string `json:"code,omitempty"` - Storage map[common.Hash]string `json:"storage,omitempty"` - Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode - SecureKey hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key + Balance string `json:"balance"` + Nonce uint64 `json:"nonce"` + Root string `json:"root"` + CodeHash string `json:"codeHash"` + IsMultiCoin bool `json:"isMultiCoin"` + Code string `json:"code,omitempty"` + Storage map[common.Hash]string `json:"storage,omitempty"` + Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode + SecureKey hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key } @@ -89,14 +90,15 @@ type iterativeDump struct { // OnAccount implements DumpCollector interface func (d iterativeDump) OnAccount(addr common.Address, account DumpAccount) { dumpAccount := &DumpAccount{ - Balance: account.Balance, - Nonce: account.Nonce, - Root: account.Root, - CodeHash: account.CodeHash, - Code: account.Code, - Storage: account.Storage, - SecureKey: account.SecureKey, - Address: nil, + Balance: account.Balance, + Nonce: account.Nonce, + Root: account.Root, + CodeHash: account.CodeHash, + IsMultiCoin: account.IsMultiCoin, + Code: account.Code, + Storage: account.Storage, + SecureKey: account.SecureKey, + Address: nil, } if addr != (common.Address{}) { dumpAccount.Address = &addr @@ -123,10 +125,11 @@ func (s *StateDB) DumpToCollector(c DumpCollector, excludeCode, excludeStorage, panic(err) } account := DumpAccount{ - Balance: data.Balance.String(), - Nonce: data.Nonce, - Root: common.Bytes2Hex(data.Root[:]), - CodeHash: common.Bytes2Hex(data.CodeHash), + Balance: data.Balance.String(), + Nonce: data.Nonce, + Root: common.Bytes2Hex(data.Root[:]), + CodeHash: common.Bytes2Hex(data.CodeHash), + IsMultiCoin: data.IsMultiCoin, } addrBytes := s.trie.GetKey(it.Key) if addrBytes == nil { diff --git a/core/state/snapshot/account.go b/core/state/snapshot/account.go index b92e942..303c2fc 100644 --- a/core/state/snapshot/account.go +++ b/core/state/snapshot/account.go @@ -29,17 +29,19 @@ import ( // or slim-snapshot format which replaces the empty root and code hash as nil // byte slice. type Account struct { - Nonce uint64 - Balance *big.Int - Root []byte - CodeHash []byte + Nonce uint64 + Balance *big.Int + Root []byte + CodeHash []byte + IsMultiCoin bool } // SlimAccount converts a state.Account content into a slim snapshot account -func SlimAccount(nonce uint64, balance *big.Int, root common.Hash, codehash []byte) Account { +func SlimAccount(nonce uint64, balance *big.Int, root common.Hash, codehash []byte, isMultiCoin bool) Account { slim := Account{ - Nonce: nonce, - Balance: balance, + Nonce: nonce, + Balance: balance, + IsMultiCoin: isMultiCoin, } if root != emptyRoot { slim.Root = root[:] @@ -52,8 +54,8 @@ func SlimAccount(nonce uint64, balance *big.Int, root common.Hash, codehash []by // SlimAccountRLP converts a state.Account content into a slim snapshot // version RLP encoded. -func SlimAccountRLP(nonce uint64, balance *big.Int, root common.Hash, codehash []byte) []byte { - data, err := rlp.EncodeToBytes(SlimAccount(nonce, balance, root, codehash)) +func SlimAccountRLP(nonce uint64, balance *big.Int, root common.Hash, codehash []byte, isMultiCoin bool) []byte { + data, err := rlp.EncodeToBytes(SlimAccount(nonce, balance, root, codehash, isMultiCoin)) if err != nil { panic(err) } diff --git a/core/state/snapshot/generate.go b/core/state/snapshot/generate.go index dac782f..27f8dfc 100644 --- a/core/state/snapshot/generate.go +++ b/core/state/snapshot/generate.go @@ -161,15 +161,16 @@ func (dl *diskLayer) generate(stats *generatorStats) { accountHash := common.BytesToHash(accIt.Key) var acc struct { - Nonce uint64 - Balance *big.Int - Root common.Hash - CodeHash []byte + Nonce uint64 + Balance *big.Int + Root common.Hash + CodeHash []byte + IsMultiCoin bool } if err := rlp.DecodeBytes(accIt.Value, &acc); err != nil { log.Crit("Invalid account encountered during snapshot creation", "err", err) } - data := SlimAccountRLP(acc.Nonce, acc.Balance, acc.Root, acc.CodeHash) + data := SlimAccountRLP(acc.Nonce, acc.Balance, acc.Root, acc.CodeHash, acc.IsMultiCoin) // If the account is not yet in-progress, write it out if accMarker == nil || !bytes.Equal(accountHash[:], accMarker) { diff --git a/core/state/statedb.go b/core/state/statedb.go index 805c607..b472bd7 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -270,11 +270,12 @@ func (self *StateDB) GetBalanceMultiCoin(addr common.Address, coinID common.Hash func (self *StateDB) EnableMultiCoin(addr common.Address) error { stateObject := self.GetOrNewStateObject(addr) if stateObject.data.Root != emptyRoot && stateObject.data.Root != zeroRoot { - return errors.New("not a fresh account") + return errors.New(fmt.Sprintf("not a fresh account: %s", stateObject.data.Root.Hex())) } if !stateObject.EnableMultiCoin() { return errors.New("multi-coin mode already enabled") } + log.Debug(fmt.Sprintf("enabled MC for %s", addr.Hex())) return nil } @@ -527,7 +528,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) { // enough to track account updates at commit time, deletions need tracking // at transaction boundary level to ensure we capture state clearing. if s.snap != nil { - s.snapAccounts[obj.addrHash] = snapshot.SlimAccountRLP(obj.data.Nonce, obj.data.Balance, obj.data.Root, obj.data.CodeHash) + s.snapAccounts[obj.addrHash] = snapshot.SlimAccountRLP(obj.data.Nonce, obj.data.Balance, obj.data.Root, obj.data.CodeHash, obj.data.IsMultiCoin) } } diff --git a/core/types/block.go b/core/types/block.go index 37f3464..99d6cc8 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -166,7 +166,7 @@ type Body struct { Transactions []*Transaction Uncles []*Header Version uint32 - ExtData []byte `rlp:"nil"` + ExtData *[]byte `rlp:"nil"` } // Block represents an entire block in the Ethereum blockchain. @@ -175,7 +175,7 @@ type Block struct { uncles []*Header transactions Transactions version uint32 - extdata []byte + extdata *[]byte // caches hash atomic.Value @@ -216,7 +216,7 @@ type myextblock struct { Txs []*Transaction Uncles []*Header Version uint32 - ExtData []byte `rlp:"nil"` + ExtData *[]byte `rlp:"nil"` } // [deprecated by eth/63] @@ -235,7 +235,7 @@ type storageblock struct { // The values of TxHash, UncleHash, ReceiptHash and Bloom in header // are ignored and set to values derived from the given txs, uncles // and receipts. -func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata []byte) *Block { +func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata *[]byte) *Block { b := &Block{header: CopyHeader(header), td: new(big.Int)} // TODO: panic if len(txs) != len(receipts) @@ -264,8 +264,11 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []* } } - b.extdata = make([]byte, len(extdata)) - copy(b.extdata, extdata) + if extdata != nil { + data := make([]byte, len(*extdata)) + b.extdata = &data + copy(*b.extdata, *extdata) + } return b } @@ -321,13 +324,13 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error { } func (b *Block) SetExtraData(data []byte) { - b.extdata = data + b.extdata = &data b.header.ExtDataHash = rlpHash(data) b.hash = atomic.Value{} } func (b *Block) ExtraData() []byte { - return b.extdata + return *b.extdata } func (b *Block) SetVersion(ver uint32) { @@ -460,16 +463,23 @@ func (b *Block) WithSeal(header *Header) *Block { } // WithBody returns a new block with the given transaction and uncle contents. -func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, version uint32, extdata []byte) *Block { +func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, version uint32, extdata *[]byte) *Block { + var data *[]byte + if extdata != nil { + _data := make([]byte, len(*extdata)) + data = &_data + } block := &Block{ header: CopyHeader(b.header), transactions: make([]*Transaction, len(transactions)), uncles: make([]*Header, len(uncles)), - extdata: make([]byte, len(extdata)), + extdata: data, version: version, } copy(block.transactions, transactions) - copy(block.extdata, extdata) + if data != nil { + copy(*block.extdata, *extdata) + } for i := range uncles { block.uncles[i] = CopyHeader(uncles[i]) } diff --git a/core/vm/evm.go b/core/vm/evm.go index 85b7ba7..e895211 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -275,17 +275,19 @@ func (evm *EVM) CallExpert(caller ContractRef, addr common.Address, input []byte return nil, gas, ErrDepth } - mcerr := evm.Context.CanTransferMC(evm.StateDB, caller.Address(), addr, coinID, value2) + // Fail if we're trying to transfer more than the available balance + if value.Sign() != 0 && !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) { + return nil, gas, ErrInsufficientBalance + } + + var to = AccountRef(addr) + mcerr := evm.Context.CanTransferMC(evm.StateDB, caller.Address(), to.Address(), coinID, value2) if mcerr == 1 { return nil, gas, ErrInsufficientBalance } else if mcerr != 0 { return nil, gas, ErrIncompatibleAccount } - // Fail if we're trying to transfer more than the available balance - if value.Sign() != 0 && !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) { - return nil, gas, ErrInsufficientBalance - } snapshot := evm.StateDB.Snapshot() p, isPrecompile := evm.precompile(addr) diff --git a/eth/api_backend.go b/eth/api_backend.go index 65c3be4..bbc8691 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -24,6 +24,7 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/consensus" "github.com/ava-labs/coreth/core" + "github.com/ava-labs/coreth/core/bloombits" "github.com/ava-labs/coreth/core/rawdb" "github.com/ava-labs/coreth/core/state" "github.com/ava-labs/coreth/core/types" @@ -33,7 +34,6 @@ import ( "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" diff --git a/eth/backend.go b/eth/backend.go index b1c29a5..728ec4d 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -31,6 +31,7 @@ import ( "github.com/ava-labs/coreth/consensus/dummy" "github.com/ava-labs/coreth/consensus/ethash" "github.com/ava-labs/coreth/core" + "github.com/ava-labs/coreth/core/bloombits" "github.com/ava-labs/coreth/core/rawdb" "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/core/vm" @@ -43,7 +44,6 @@ import ( "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" diff --git a/eth/filters/filter.go b/eth/filters/filter.go index e189391..48a76c7 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -22,10 +22,10 @@ import ( "math/big" "github.com/ava-labs/coreth/core" + "github.com/ava-labs/coreth/core/bloombits" "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" ) diff --git a/examples/chain/main.go b/examples/chain/main.go index 17003b5..94c5d6b 100644 --- a/examples/chain/main.go +++ b/examples/chain/main.go @@ -138,6 +138,8 @@ func run(config *eth.Config, a1, a2, b1, b2 int) { bob := NewTestChain("bob", config, aliceBlk, bobBlk, aliceAck, bobAck) alice.Start() bob.Start() + log.Info("alice genesis", "block", alice.chain.GetGenesisBlock().Hash().Hex()) + log.Info("bob genesis", "block", bob.chain.GetGenesisBlock().Hash().Hex()) alice.GenRandomTree(a1, a2) log.Info("alice finished generating the tree") //time.Sleep(1 * time.Second) @@ -205,7 +207,7 @@ func main() { ByzantiumBlock: big.NewInt(0), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), - IstanbulBlock: nil, + IstanbulBlock: big.NewInt(0), Ethash: nil, } diff --git a/examples/counter/counter.sol b/examples/counter/counter.sol index b21c3bf..952b925 100644 --- a/examples/counter/counter.sol +++ b/examples/counter/counter.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.6.0; +pragma solidity >=0.6.0; contract Counter { uint256 x; diff --git a/examples/multicoin/main.go b/examples/multicoin/main.go index 1f96647..fc379d4 100644 --- a/examples/multicoin/main.go +++ b/examples/multicoin/main.go @@ -47,12 +47,12 @@ func main() { ByzantiumBlock: big.NewInt(0), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), - IstanbulBlock: nil, + IstanbulBlock: big.NewInt(0), Ethash: nil, } // configure the genesis block - genesisJSON := `{"config":{"chainId":1,"homesteadBlock":0,"daoForkBlock":0,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0},"nonce":"0x0","timestamp":"0x0","extraData":"0x00","gasLimit":"0x5f5e100","difficulty":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","coinbase":"0x0000000000000000000000000000000000000000","alloc":{"751a0b96e1042bee789452ecb20253fba40dbe85":{"balance":"0x1000000000000000", "mcbalance": {"0x0000000000000000000000000000000000000000000000000000000000000000": 1000000000000000000}}, "0100000000000000000000000000000000000000": {"code": "0x730000000000000000000000000000000000000000301460806040526004361061004b5760003560e01c80631e01043914610050578063abb24ba014610092578063b6510bb3146100a9575b600080fd5b61007c6004803603602081101561006657600080fd5b8101908080359060200190929190505050610118565b6040518082815260200191505060405180910390f35b81801561009e57600080fd5b506100a761013b565b005b8180156100b557600080fd5b50610116600480360360808110156100cc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001909291908035906020019092919050505061013e565b005b60003073ffffffffffffffffffffffffffffffffffffffff1682905d9050919050565b5c565b8373ffffffffffffffffffffffffffffffffffffffff1681836108fc8690811502906040516000604051808303818888878c8af69550505050505015801561018a573d6000803e3d6000fd5b505050505056fea2646970667358221220ed2100d6623a884d196eceefabe5e03da4309a2562bb25262f3874f1acb31cd764736f6c634300060a0033", "balance": "0x0", "mcbalance": {}}},"number":"0x0","gasUsed":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}` + genesisJSON := `{"config":{"chainId":1,"homesteadBlock":0,"daoForkBlock":0,"daoForkSupport":true,"eip150Block":0,"eip150Hash":"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0","eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"constantinopleBlock":0,"petersburgBlock":0},"nonce":"0x0","timestamp":"0x0","extraData":"0x00","gasLimit":"0x5f5e100","difficulty":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","coinbase":"0x0000000000000000000000000000000000000000","alloc":{"751a0b96e1042bee789452ecb20253fba40dbe85":{"balance":"0x1000000000000000", "mcbalance": {"0x0000000000000000000000000000000000000000000000000000000000000000": 1000000000000000000}}, "0100000000000000000000000000000000000000": {"code": "0x730000000000000000000000000000000000000000301460806040526004361061004b5760003560e01c80631e01043914610050578063abb24ba014610092578063b6510bb3146100a9575b600080fd5b61007c6004803603602081101561006657600080fd5b8101908080359060200190929190505050610118565b6040518082815260200191505060405180910390f35b81801561009e57600080fd5b506100a761013b565b005b8180156100b557600080fd5b50610116600480360360808110156100cc57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190803590602001909291908035906020019092919050505061013e565b005b60003073ffffffffffffffffffffffffffffffffffffffff168290cd9050919050565bce565b8373ffffffffffffffffffffffffffffffffffffffff1681836108fc8690811502906040516000604051808303818888878c8acf9550505050505015801561018a573d6000803e3d6000fd5b505050505056fea26469706673582212205c4d96aa2a6488c426daa9567616a383dd6156eb3fe84f4905239179e553fc0f64736f6c634300060a0033", "balance": "0x0", "mcbalance": {}}},"number":"0x0","gasUsed":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}` mcAbiJSON := `[{"inputs":[],"name":"enableMultiCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"coinid","type":"uint256"}],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"coinid","type":"uint256"},{"internalType":"uint256","name":"amount2","type":"uint256"}],"name":"transfer","outputs":[],"stateMutability":"nonpayable","type":"function"}]` genesisKey := "0xabd71b35d559563fea757f0f5edbde286fb8c043105b15abb7cd57189306d7d1" diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index cee6b57..f89a3aa 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -24,13 +24,13 @@ import ( "github.com/ava-labs/coreth/accounts" "github.com/ava-labs/coreth/consensus" "github.com/ava-labs/coreth/core" + "github.com/ava-labs/coreth/core/bloombits" "github.com/ava-labs/coreth/core/state" "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/coreth/core/vm" "github.com/ava-labs/coreth/params" "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 5c5a5b5..993727e 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -22,9 +22,9 @@ import ( "github.com/ava-labs/coreth/node" "github.com/ava-labs/coreth/params" + "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/rpc" ethcrypto "github.com/ethereum/go-ethereum/crypto" -- cgit v1.2.3-70-g09d2 From c5615034cf0991b55ca626ff052d2bb02049f9e3 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 16 Sep 2020 23:17:02 -0400 Subject: adjust DB API --- plugin/evm/database.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/database.go b/plugin/evm/database.go index 38b21d0..81d1c1d 100644 --- a/plugin/evm/database.go +++ b/plugin/evm/database.go @@ -46,12 +46,19 @@ func (db Database) Sync() error { return errOpNotSupported } // NewBatch implements ethdb.Database func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} } -// NewIterator implements ethdb.Database -func (db Database) NewIterator() ethdb.Iterator { return db.Database.NewIterator() } +//// NewIterator implements ethdb.Database +//func (db Database) NewIterator() ethdb.Iterator { +// return db.Database.NewIterator() +//} + +//// NewIteratorWithPrefix implements ethdb.Database +//func (db Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator { +// return db.NewIteratorWithPrefix(prefix) +//} -// NewIteratorWithPrefix implements ethdb.Database -func (db Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator { - return db.NewIteratorWithPrefix(prefix) +// NewIterator implements ethdb.Database +func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { + return db.NewIteratorWithStartAndPrefix(start, prefix) } // NewIteratorWithStart implements ethdb.Database -- cgit v1.2.3-70-g09d2 From 92fdc0a4b6208387424029182a131b25a2f92dac Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Wed, 16 Sep 2020 23:39:26 -0400 Subject: Switch from ctx.Log to eth logger --- plugin/evm/block.go | 7 +++---- plugin/evm/service.go | 17 +++++++++-------- plugin/evm/vm.go | 27 ++++++++++++++------------- 3 files changed, 26 insertions(+), 25 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/block.go b/plugin/evm/block.go index 98280f0..ff1f6ae 100644 --- a/plugin/evm/block.go +++ b/plugin/evm/block.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/ava-labs/coreth/core/types" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/ava-labs/avalanchego/ids" @@ -30,7 +31,7 @@ func (b *Block) ID() ids.ID { return b.id } func (b *Block) Accept() error { vm := b.vm - vm.ctx.Log.Verbo("Block %s is accepted", b.id) + log.Trace(fmt.Sprintf("Block %s is accepted", b.ID())) vm.updateStatus(b.id, choices.Accepted) if err := vm.acceptedDB.Put(b.ethBlock.Number().Bytes(), b.id.Bytes()); err != nil { return err @@ -50,7 +51,7 @@ func (b *Block) Accept() error { // Reject implements the snowman.Block interface func (b *Block) Reject() error { - b.vm.ctx.Log.Verbo("Block %s is rejected", b.ID()) + log.Trace(fmt.Sprintf("Block %s is rejected", b.ID())) b.vm.updateStatus(b.ID(), choices.Rejected) return nil } @@ -68,10 +69,8 @@ func (b *Block) Status() choices.Status { func (b *Block) Parent() snowman.Block { parentID := ids.NewID(b.ethBlock.ParentHash()) if block := b.vm.getBlock(parentID); block != nil { - b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", parentID, block.Status()) return block } - b.vm.ctx.Log.Verbo("Parent(%s) has status: %s", parentID, choices.Unknown) return &missing.Block{BlkID: parentID} } diff --git a/plugin/evm/service.go b/plugin/evm/service.go index 65d389d..a3325b7 100644 --- a/plugin/evm/service.go +++ b/plugin/evm/service.go @@ -14,15 +14,16 @@ import ( "github.com/ava-labs/coreth" - "github.com/ava-labs/coreth/core/types" "github.com/ava-labs/avalanchego/api" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/json" + "github.com/ava-labs/coreth/core/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethcrypto "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/log" ) const ( @@ -87,7 +88,7 @@ func (api *SnowmanAPI) GetAcceptedFront(ctx context.Context) (*GetAcceptedFrontR // GetGenesisBalance returns the current funds in the genesis func (api *DebugAPI) GetGenesisBalance(ctx context.Context) (*hexutil.Big, error) { lastAccepted := api.vm.getLastAccepted() - api.vm.ctx.Log.Verbo("Currently accepted block front: %s", lastAccepted.ethBlock.Hash().Hex()) + log.Trace(fmt.Sprintf("Currently accepted block front: %s", lastAccepted.ethBlock.Hash().Hex())) state, err := api.vm.chain.BlockState(lastAccepted.ethBlock) if err != nil { return nil, err @@ -97,7 +98,7 @@ func (api *DebugAPI) GetGenesisBalance(ctx context.Context) (*hexutil.Big, error // SpendGenesis funds func (api *DebugAPI) SpendGenesis(ctx context.Context, nonce uint64) error { - api.vm.ctx.Log.Info("Spending the genesis") + log.Info("Spending the genesis") value := big.NewInt(1000000000000) gasLimit := 21000 @@ -127,7 +128,7 @@ func (api *DebugAPI) SpendGenesis(ctx context.Context, nonce uint64) error { // IssueBlock to the chain func (api *DebugAPI) IssueBlock(ctx context.Context) error { - api.vm.ctx.Log.Info("Issuing a new block") + log.Info("Issuing a new block") return api.vm.tryBlockGen() } @@ -146,7 +147,7 @@ type ExportKeyReply struct { // ExportKey returns a private key from the provided user func (service *AvaxAPI) ExportKey(r *http.Request, args *ExportKeyArgs, reply *ExportKeyReply) error { - service.vm.ctx.Log.Info("Platform: ExportKey called") + log.Info("EVM: ExportKey called") address, err := service.vm.ParseEthAddress(args.Address) if err != nil { @@ -176,7 +177,7 @@ type ImportKeyArgs struct { // ImportKey adds a private key to the provided user func (service *AvaxAPI) ImportKey(r *http.Request, args *ImportKeyArgs, reply *api.JsonAddress) error { - service.vm.ctx.Log.Info("Platform: ImportKey called for user '%s'", args.Username) + log.Info(fmt.Sprintf("EVM: ImportKey called for user '%s'", args.Username)) if !strings.HasPrefix(args.PrivateKey, constants.SecretKeyPrefix) { return fmt.Errorf("private key missing %s prefix", constants.SecretKeyPrefix) @@ -228,7 +229,7 @@ type ImportAVAXArgs struct { // ImportAVAX issues a transaction to import AVAX from the X-chain. The AVAX // must have already been exported from the X-Chain. func (service *AvaxAPI) ImportAVAX(_ *http.Request, args *ImportAVAXArgs, response *api.JsonTxID) error { - service.vm.ctx.Log.Info("Platform: ImportAVAX called") + log.Info("EVM: ImportAVAX called") chainID, err := service.vm.ctx.BCLookup.Lookup(args.SourceChain) if err != nil { @@ -277,7 +278,7 @@ type ExportAVAXArgs struct { // ExportAVAX exports AVAX from the P-Chain to the X-Chain // It must be imported on the X-Chain to complete the transfer func (service *AvaxAPI) ExportAVAX(_ *http.Request, args *ExportAVAXArgs, response *api.JsonTxID) error { - service.vm.ctx.Log.Info("Platform: ExportAVAX called") + log.Info("EVM: ExportAVAX called") if args.Amount == 0 { return errors.New("argument 'amount' must be > 0") diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 67ae5ce..2b78d43 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -22,9 +22,10 @@ import ( "github.com/ava-labs/coreth/node" "github.com/ava-labs/coreth/params" - "github.com/ava-labs/coreth/rpc" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/rpc" ethcrypto "github.com/ethereum/go-ethereum/crypto" @@ -287,7 +288,7 @@ func (vm *VM) Initialize( return nil, nil }) chain.SetOnSealFinish(func(block *types.Block) error { - vm.ctx.Log.Verbo("EVM sealed a block") + log.Trace("EVM sealed a block") blk := &Block{ id: ids.NewID(block.Hash()), @@ -366,14 +367,14 @@ func (vm *VM) Initialize( var hash common.Hash if err = rlp.DecodeBytes(b, &hash); err == nil { if block := chain.GetBlockByHash(hash); block == nil { - vm.ctx.Log.Debug("lastAccepted block not found in chaindb") + log.Debug("lastAccepted block not found in chaindb") } else { lastAccepted = block } } } if lastAccepted == nil { - vm.ctx.Log.Debug("lastAccepted is unavailable, setting to the genesis block") + log.Debug("lastAccepted is unavailable, setting to the genesis block") lastAccepted = chain.GetGenesisBlock() } vm.lastAccepted = &Block{ @@ -382,7 +383,7 @@ func (vm *VM) Initialize( vm: vm, } vm.genesisHash = chain.GetGenesisBlock().Hash() - vm.ctx.Log.Info(fmt.Sprintf("lastAccepted = %s", vm.lastAccepted.ethBlock.Hash().Hex())) + log.Info(fmt.Sprintf("lastAccepted = %s", vm.lastAccepted.ethBlock.Hash().Hex())) // TODO: shutdown this go routine go vm.ctx.Log.RecoverAndPanic(func() { @@ -390,10 +391,10 @@ func (vm *VM) Initialize( for { select { case <-vm.txSubmitChan: - vm.ctx.Log.Verbo("New tx detected, trying to generate a block") + log.Trace("New tx detected, trying to generate a block") vm.tryBlockGen() case <-vm.atomicTxSubmitChan: - vm.ctx.Log.Verbo("New atomic Tx detected, trying to generate a block") + log.Trace("New atomic Tx detected, trying to generate a block") vm.tryBlockGen() case <-time.After(5 * time.Second): vm.tryBlockGen() @@ -439,7 +440,7 @@ func (vm *VM) BuildBlock() (snowman.Block, error) { vm.blockDelayTimer.SetTimeoutIn(minBlockTime) vm.bdlock.Unlock() - vm.ctx.Log.Debug("built block 0x%x", block.ID().Bytes()) + log.Debug(fmt.Sprintf("built block 0x%x", block.ID().Bytes())) // make sure Tx Pool is updated <-vm.txPoolStabilizedOk return block, nil @@ -623,7 +624,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { acceptedIDBytes, err := vm.acceptedDB.Get(heightKey) if err == nil { if acceptedID, err := ids.ToID(acceptedIDBytes); err != nil { - vm.ctx.Log.Error("snowman-eth: acceptedID bytes didn't match expected value: %s", err) + log.Error(fmt.Sprintf("snowman-eth: acceptedID bytes didn't match expected value: %s", err)) } else { if acceptedID.Equals(blockID) { vm.blockStatusCache.Put(blockID, choices.Accepted) @@ -638,7 +639,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { if status == choices.Accepted { err := vm.acceptedDB.Put(heightKey, blockID.Bytes()) if err != nil { - vm.ctx.Log.Error("snowman-eth: failed to write back acceptedID bytes: %s", err) + log.Error(fmt.Sprintf("snowman-eth: failed to write back acceptedID bytes: %s", err)) } tempBlock := wrappedBlk @@ -656,7 +657,7 @@ func (vm *VM) getCachedStatus(blockID ids.ID) choices.Status { } if err := vm.acceptedDB.Put(heightKey, parentID.Bytes()); err != nil { - vm.ctx.Log.Error("snowman-eth: failed to write back acceptedID bytes: %s", err) + log.Error(fmt.Sprintf("snowman-eth: failed to write back acceptedID bytes: %s", err)) } } } @@ -726,10 +727,10 @@ func (vm *VM) writeBackMetadata() { b, err := rlp.EncodeToBytes(vm.lastAccepted.ethBlock.Hash()) if err != nil { - vm.ctx.Log.Error("snowman-eth: error while writing back metadata") + log.Error("snowman-eth: error while writing back metadata") return } - vm.ctx.Log.Debug("writing back metadata") + log.Debug("writing back metadata") vm.chaindb.Put([]byte(lastAcceptedKey), b) atomic.StoreUint32(&vm.writingMetadata, 0) } -- cgit v1.2.3-70-g09d2 From 7063564c571bcdc94b981db7ed3707902f0466d0 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 00:25:32 -0400 Subject: disable snapshot --- examples/multicoin/main.go | 3 +++ plugin/evm/vm.go | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'plugin/evm') diff --git a/examples/multicoin/main.go b/examples/multicoin/main.go index fc379d4..bfad5ca 100644 --- a/examples/multicoin/main.go +++ b/examples/multicoin/main.go @@ -64,6 +64,9 @@ func main() { genKey := coreth.NewKeyFromECDSA(hk) config.Genesis = genesisBlock + config.TrieCleanCache += config.SnapshotCache + config.SnapshotCache = 0 + // grab the control of block generation and disable auto uncle config.Miner.ManualMining = true config.Miner.ManualUncle = true diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 993727e..55411cf 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -243,6 +243,10 @@ func (vm *VM) Initialize( config := eth.DefaultConfig config.ManualCanonical = true config.Genesis = g + // disable the experimental snapshot feature from geth + config.TrieCleanCache += config.SnapshotCache + config.SnapshotCache = 0 + config.Miner.ManualMining = true config.Miner.DisableUncle = true -- cgit v1.2.3-70-g09d2 From aedd4b46cdc0a48c1b06a3e920bf57f8c28d401d Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 03:08:39 -0400 Subject: fix the block completion race --- coreth.go | 5 +++++ miner/miner.go | 4 ++++ plugin/evm/vm.go | 21 ++++++++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) (limited to 'plugin/evm') diff --git a/coreth.go b/coreth.go index 4d0c2ee..1d6b92e 100644 --- a/coreth.go +++ b/coreth.go @@ -17,6 +17,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/trie" //"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" @@ -85,6 +86,10 @@ func (self *ETHChain) GenBlock() { self.backend.Miner().GenBlock() } +func (self *ETHChain) SubscribeNewMinedBlockEvent() *event.TypeMuxSubscription { + return self.backend.Miner().GetWorkerMux().Subscribe(core.NewMinedBlockEvent{}) +} + func (self *ETHChain) VerifyBlock(block *types.Block) bool { txnHash := types.DeriveSha(block.Transactions(), new(trie.Trie)) uncleHash := types.CalcUncleHash(block.Uncles()) diff --git a/miner/miner.go b/miner/miner.go index e8e59a4..bbe704f 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -135,3 +135,7 @@ func (miner *Miner) SubscribePendingLogs(ch chan<- []*types.Log) event.Subscript func (miner *Miner) GenBlock() { miner.worker.genBlock() } + +func (miner *Miner) GetWorkerMux() *event.TypeMux { + return miner.worker.mux +} diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c6bc728..c9836c6 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -160,7 +160,7 @@ type VM struct { chaindb Database newBlockChan chan *Block networkChan chan<- commonEng.Message - newTxPoolHeadChan chan core.NewTxPoolHeadEvent + newTxPoolHeadChan *event.TypeMuxSubscription acceptedDB database.Database @@ -344,23 +344,26 @@ func (vm *VM) Initialize( vm.bdTimerState = bdTimerStateLong vm.bdGenWaitFlag = true - vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) + //vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) vm.txPoolStabilizedOk = make(chan struct{}, 1) // TODO: read size from options vm.pendingAtomicTxs = make(chan *Tx, 1024) vm.atomicTxSubmitChan = make(chan struct{}, 1) - chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) + //chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) + vm.newTxPoolHeadChan = vm.chain.SubscribeNewMinedBlockEvent() // TODO: shutdown this go routine go ctx.Log.RecoverAndPanic(func() { for { select { - case h := <-vm.newTxPoolHeadChan: - vm.txPoolStabilizedLock.Lock() - if vm.txPoolStabilizedHead == h.Block.Hash() { - vm.txPoolStabilizedOk <- struct{}{} - vm.txPoolStabilizedHead = common.Hash{} + case e := <-vm.newTxPoolHeadChan.Chan(): + switch h := e.Data.(core.NewTxPoolHeadEvent) { + vm.txPoolStabilizedLock.Lock() + if vm.txPoolStabilizedHead == h.Block.Hash() { + vm.txPoolStabilizedOk <- struct{}{} + vm.txPoolStabilizedHead = common.Hash{} + } + vm.txPoolStabilizedLock.Unlock() } - vm.txPoolStabilizedLock.Unlock() } } }) -- cgit v1.2.3-70-g09d2 From 8123ec9caeb1917519c1f8f67f386df142578728 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 17 Sep 2020 03:23:13 -0400 Subject: ... --- plugin/evm/vm.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c9836c6..73a97e8 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" @@ -356,13 +357,15 @@ func (vm *VM) Initialize( for { select { case e := <-vm.newTxPoolHeadChan.Chan(): - switch h := e.Data.(core.NewTxPoolHeadEvent) { + switch h := e.Data.(type) { + case core.NewMinedBlockEvent: vm.txPoolStabilizedLock.Lock() if vm.txPoolStabilizedHead == h.Block.Hash() { vm.txPoolStabilizedOk <- struct{}{} vm.txPoolStabilizedHead = common.Hash{} } vm.txPoolStabilizedLock.Unlock() + default: } } } -- cgit v1.2.3-70-g09d2 From b9cb07277a70f126e5ce098faff6fb88cab6c29a Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Thu, 17 Sep 2020 14:11:53 -0400 Subject: Fix panic on shutdown form orphaned goroutine --- plugin/evm/vm.go | 98 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 37 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 73a97e8..583a0c5 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -23,8 +23,8 @@ import ( "github.com/ava-labs/coreth/params" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" @@ -165,9 +165,10 @@ type VM struct { acceptedDB database.Database - txPoolStabilizedHead common.Hash - txPoolStabilizedOk chan struct{} - txPoolStabilizedLock sync.Mutex + txPoolStabilizedHead common.Hash + txPoolStabilizedOk chan struct{} + txPoolStabilizedLock sync.Mutex + txPoolStabilizedShutdownChan chan struct{} metalock sync.Mutex blockCache, blockStatusCache cache.LRU @@ -183,12 +184,15 @@ type VM struct { genlock sync.Mutex txSubmitChan <-chan struct{} atomicTxSubmitChan chan struct{} + shutdownSubmitChan chan struct{} codec codec.Codec clock timer.Clock txFee uint64 pendingAtomicTxs chan *Tx blockAtomicInputCache cache.LRU + shutdownWg sync.WaitGroup + fx secp256k1fx.Fx } @@ -347,29 +351,14 @@ func (vm *VM) Initialize( vm.bdGenWaitFlag = true //vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) vm.txPoolStabilizedOk = make(chan struct{}, 1) + vm.txPoolStabilizedShutdownChan = make(chan struct{}, 1) // Signal goroutine to shutdown // TODO: read size from options vm.pendingAtomicTxs = make(chan *Tx, 1024) vm.atomicTxSubmitChan = make(chan struct{}, 1) + vm.shutdownSubmitChan = make(chan struct{}, 1) //chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) vm.newTxPoolHeadChan = vm.chain.SubscribeNewMinedBlockEvent() - // TODO: shutdown this go routine - go ctx.Log.RecoverAndPanic(func() { - for { - select { - case e := <-vm.newTxPoolHeadChan.Chan(): - switch h := e.Data.(type) { - case core.NewMinedBlockEvent: - vm.txPoolStabilizedLock.Lock() - if vm.txPoolStabilizedHead == h.Block.Hash() { - vm.txPoolStabilizedOk <- struct{}{} - vm.txPoolStabilizedHead = common.Hash{} - } - vm.txPoolStabilizedLock.Unlock() - default: - } - } - } - }) + go ctx.Log.RecoverAndPanic(vm.awaitTxPoolStabilized) chain.Start() var lastAccepted *types.Block @@ -396,21 +385,7 @@ func (vm *VM) Initialize( log.Info(fmt.Sprintf("lastAccepted = %s", vm.lastAccepted.ethBlock.Hash().Hex())) // TODO: shutdown this go routine - go vm.ctx.Log.RecoverAndPanic(func() { - vm.txSubmitChan = vm.chain.GetTxSubmitCh() - for { - select { - case <-vm.txSubmitChan: - log.Trace("New tx detected, trying to generate a block") - vm.tryBlockGen() - case <-vm.atomicTxSubmitChan: - log.Trace("New atomic Tx detected, trying to generate a block") - vm.tryBlockGen() - case <-time.After(5 * time.Second): - vm.tryBlockGen() - } - } - }) + go vm.ctx.Log.RecoverAndPanic(vm.awaitSubmittedTxs) vm.codec = Codec return vm.fx.Initialize(vm) @@ -431,7 +406,10 @@ func (vm *VM) Shutdown() error { } vm.writeBackMetadata() + close(vm.txPoolStabilizedShutdownChan) + close(vm.shutdownSubmitChan) vm.chain.Stop() + vm.shutdownWg.Wait() return nil } @@ -745,6 +723,52 @@ func (vm *VM) writeBackMetadata() { atomic.StoreUint32(&vm.writingMetadata, 0) } +// awaitTxPoolStabilized waits for a txPoolHead channel event +// and notifies the VM when the tx pool has stabilized to the +// expected block hash +// Waits for signal to shutdown from txPoolStabilizedShutdownChan chan +func (vm *VM) awaitTxPoolStabilized() { + vm.shutdownWg.Add(1) + for { + select { + case e := <-vm.newTxPoolHeadChan.Chan(): + switch h := e.Data.(type) { + case core.NewMinedBlockEvent: + vm.txPoolStabilizedLock.Lock() + if vm.txPoolStabilizedHead == h.Block.Hash() { + vm.txPoolStabilizedOk <- struct{}{} + vm.txPoolStabilizedHead = common.Hash{} + } + vm.txPoolStabilizedLock.Unlock() + default: + } + case <-vm.txPoolStabilizedShutdownChan: + vm.shutdownWg.Done() + return + } + } +} + +func (vm *VM) awaitSubmittedTxs() { + vm.shutdownWg.Add(1) + vm.txSubmitChan = vm.chain.GetTxSubmitCh() + for { + select { + case <-vm.txSubmitChan: + log.Trace("New tx detected, trying to generate a block") + vm.tryBlockGen() + case <-vm.atomicTxSubmitChan: + log.Trace("New atomic Tx detected, trying to generate a block") + vm.tryBlockGen() + case <-time.After(5 * time.Second): + vm.tryBlockGen() + case <-vm.shutdownSubmitChan: + vm.shutdownWg.Done() + return + } + } +} + func (vm *VM) getLastAccepted() *Block { vm.metalock.Lock() defer vm.metalock.Unlock() -- cgit v1.2.3-70-g09d2 From 1a17fcec0e23aba017e3641c708e40e79be8e153 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Thu, 17 Sep 2020 14:32:42 -0400 Subject: move wg add outside of goroutines to prevent race condition --- plugin/evm/vm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 583a0c5..92e51e6 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -358,6 +358,7 @@ func (vm *VM) Initialize( vm.shutdownSubmitChan = make(chan struct{}, 1) //chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) vm.newTxPoolHeadChan = vm.chain.SubscribeNewMinedBlockEvent() + vm.shutdownWg.Add(1) go ctx.Log.RecoverAndPanic(vm.awaitTxPoolStabilized) chain.Start() @@ -385,6 +386,7 @@ func (vm *VM) Initialize( log.Info(fmt.Sprintf("lastAccepted = %s", vm.lastAccepted.ethBlock.Hash().Hex())) // TODO: shutdown this go routine + vm.shutdownWg.Add(1) go vm.ctx.Log.RecoverAndPanic(vm.awaitSubmittedTxs) vm.codec = Codec @@ -728,7 +730,6 @@ func (vm *VM) writeBackMetadata() { // expected block hash // Waits for signal to shutdown from txPoolStabilizedShutdownChan chan func (vm *VM) awaitTxPoolStabilized() { - vm.shutdownWg.Add(1) for { select { case e := <-vm.newTxPoolHeadChan.Chan(): @@ -750,7 +751,6 @@ func (vm *VM) awaitTxPoolStabilized() { } func (vm *VM) awaitSubmittedTxs() { - vm.shutdownWg.Add(1) vm.txSubmitChan = vm.chain.GetTxSubmitCh() for { select { -- cgit v1.2.3-70-g09d2 From b0a75c03303fe22f31fe1e1f0fa29a1e1cd78253 Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Thu, 17 Sep 2020 14:37:10 -0400 Subject: Defer wg Done call instead of calling before return --- plugin/evm/vm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 92e51e6..c02b835 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -730,6 +730,7 @@ func (vm *VM) writeBackMetadata() { // expected block hash // Waits for signal to shutdown from txPoolStabilizedShutdownChan chan func (vm *VM) awaitTxPoolStabilized() { + defer vm.shutdownWg.Done() for { select { case e := <-vm.newTxPoolHeadChan.Chan(): @@ -744,13 +745,13 @@ func (vm *VM) awaitTxPoolStabilized() { default: } case <-vm.txPoolStabilizedShutdownChan: - vm.shutdownWg.Done() return } } } func (vm *VM) awaitSubmittedTxs() { + defer vm.shutdownWg.Done() vm.txSubmitChan = vm.chain.GetTxSubmitCh() for { select { @@ -763,7 +764,6 @@ func (vm *VM) awaitSubmittedTxs() { case <-time.After(5 * time.Second): vm.tryBlockGen() case <-vm.shutdownSubmitChan: - vm.shutdownWg.Done() return } } -- cgit v1.2.3-70-g09d2 From 3ea6a7940e40677b629270dfc7a1466bca295bd3 Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 18 Sep 2020 13:09:22 -0400 Subject: clean up the code --- consensus/dummy/consensus.go | 4 ++-- core/types/block.go | 26 +++++++++++++++----------- examples/block/main.go | 2 +- examples/counter/main.go | 2 +- examples/payments/main.go | 2 +- plugin/evm/database.go | 10 ---------- plugin/evm/vm.go | 22 ++++++++++------------ rpc/types.go | 2 -- 8 files changed, 30 insertions(+), 40 deletions(-) (limited to 'plugin/evm') diff --git a/consensus/dummy/consensus.go b/consensus/dummy/consensus.go index 42e224d..da63673 100644 --- a/consensus/dummy/consensus.go +++ b/consensus/dummy/consensus.go @@ -262,10 +262,10 @@ func (self *DummyEngine) Finalize( func (self *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { - var extdata *[]byte + var extdata []byte if self.cb.OnFinalizeAndAssemble != nil { ret, err := self.cb.OnFinalizeAndAssemble(state, txs) - extdata = &ret + extdata = ret if err != nil { return nil, err } diff --git a/core/types/block.go b/core/types/block.go index 0a93601..8e23488 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -235,7 +235,7 @@ type storageblock struct { // The values of TxHash, UncleHash, ReceiptHash and Bloom in header // are ignored and set to values derived from the given txs, uncles // and receipts. -func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata *[]byte) *Block { +func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher Hasher, extdata []byte) *Block { b := &Block{header: CopyHeader(header), td: new(big.Int)} // TODO: panic if len(txs) != len(receipts) @@ -265,9 +265,9 @@ func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []* } if extdata != nil { - data := make([]byte, len(*extdata)) - b.extdata = &data - copy(*b.extdata, *extdata) + _data := make([]byte, len(extdata)) + b.extdata = &_data + copy(*b.extdata, extdata) } return b @@ -324,7 +324,13 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error { } func (b *Block) SetExtraData(data []byte) { - b.extdata = &data + if data != nil { + _data := make([]byte, len(data)) + b.extdata = &_data + copy(*b.extdata, data) + } else { + b.extdata = nil + } b.header.ExtDataHash = rlpHash(data) b.hash = atomic.Value{} } @@ -467,22 +473,20 @@ func (b *Block) WithSeal(header *Header) *Block { // WithBody returns a new block with the given transaction and uncle contents. func (b *Block) WithBody(transactions []*Transaction, uncles []*Header, version uint32, extdata *[]byte) *Block { - var data *[]byte + var extdataCopied *[]byte if extdata != nil { _data := make([]byte, len(*extdata)) - data = &_data + extdataCopied = &_data + copy(*extdataCopied, *extdata) } block := &Block{ header: CopyHeader(b.header), transactions: make([]*Transaction, len(transactions)), uncles: make([]*Header, len(uncles)), - extdata: data, + extdata: extdataCopied, version: version, } copy(block.transactions, transactions) - if data != nil { - copy(*block.extdata, *extdata) - } for i := range uncles { block.uncles[i] = CopyHeader(uncles[i]) } diff --git a/examples/block/main.go b/examples/block/main.go index 89540c6..55fedfe 100644 --- a/examples/block/main.go +++ b/examples/block/main.go @@ -37,7 +37,7 @@ func main() { ByzantiumBlock: big.NewInt(0), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), - IstanbulBlock: nil, + IstanbulBlock: big.NewInt(0), Ethash: nil, } diff --git a/examples/counter/main.go b/examples/counter/main.go index 9e18cd8..f78f28f 100644 --- a/examples/counter/main.go +++ b/examples/counter/main.go @@ -45,7 +45,7 @@ func main() { ByzantiumBlock: big.NewInt(0), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), - IstanbulBlock: nil, + IstanbulBlock: big.NewInt(0), Ethash: nil, } diff --git a/examples/payments/main.go b/examples/payments/main.go index fee2060..9023b3a 100644 --- a/examples/payments/main.go +++ b/examples/payments/main.go @@ -36,7 +36,7 @@ func main() { ByzantiumBlock: big.NewInt(0), ConstantinopleBlock: big.NewInt(0), PetersburgBlock: big.NewInt(0), - IstanbulBlock: nil, + IstanbulBlock: big.NewInt(0), Ethash: nil, } diff --git a/plugin/evm/database.go b/plugin/evm/database.go index 81d1c1d..18890fa 100644 --- a/plugin/evm/database.go +++ b/plugin/evm/database.go @@ -46,16 +46,6 @@ func (db Database) Sync() error { return errOpNotSupported } // NewBatch implements ethdb.Database func (db Database) NewBatch() ethdb.Batch { return Batch{db.Database.NewBatch()} } -//// NewIterator implements ethdb.Database -//func (db Database) NewIterator() ethdb.Iterator { -// return db.Database.NewIterator() -//} - -//// NewIteratorWithPrefix implements ethdb.Database -//func (db Database) NewIteratorWithPrefix(prefix []byte) ethdb.Iterator { -// return db.NewIteratorWithPrefix(prefix) -//} - // NewIterator implements ethdb.Database func (db Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { return db.NewIteratorWithStartAndPrefix(start, prefix) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c02b835..200a08d 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -154,14 +154,14 @@ func init() { type VM struct { ctx *snow.Context - chainID *big.Int - networkID uint64 - genesisHash common.Hash - chain *coreth.ETHChain - chaindb Database - newBlockChan chan *Block - networkChan chan<- commonEng.Message - newTxPoolHeadChan *event.TypeMuxSubscription + chainID *big.Int + networkID uint64 + genesisHash common.Hash + chain *coreth.ETHChain + chaindb Database + newBlockChan chan *Block + networkChan chan<- commonEng.Message + newMinedBlockSub *event.TypeMuxSubscription acceptedDB database.Database @@ -349,15 +349,13 @@ func (vm *VM) Initialize( vm.bdTimerState = bdTimerStateLong vm.bdGenWaitFlag = true - //vm.newTxPoolHeadChan = make(chan core.NewTxPoolHeadEvent, 1) vm.txPoolStabilizedOk = make(chan struct{}, 1) vm.txPoolStabilizedShutdownChan = make(chan struct{}, 1) // Signal goroutine to shutdown // TODO: read size from options vm.pendingAtomicTxs = make(chan *Tx, 1024) vm.atomicTxSubmitChan = make(chan struct{}, 1) vm.shutdownSubmitChan = make(chan struct{}, 1) - //chain.GetTxPool().SubscribeNewHeadEvent(vm.newTxPoolHeadChan) - vm.newTxPoolHeadChan = vm.chain.SubscribeNewMinedBlockEvent() + vm.newMinedBlockSub = vm.chain.SubscribeNewMinedBlockEvent() vm.shutdownWg.Add(1) go ctx.Log.RecoverAndPanic(vm.awaitTxPoolStabilized) chain.Start() @@ -733,7 +731,7 @@ func (vm *VM) awaitTxPoolStabilized() { defer vm.shutdownWg.Done() for { select { - case e := <-vm.newTxPoolHeadChan.Chan(): + case e := <-vm.newMinedBlockSub.Chan(): switch h := e.Data.(type) { case core.NewMinedBlockEvent: vm.txPoolStabilizedLock.Lock() diff --git a/rpc/types.go b/rpc/types.go index 3ee46f3..99e29fc 100644 --- a/rpc/types.go +++ b/rpc/types.go @@ -92,7 +92,6 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error { *bn = EarliestBlockNumber return nil case "latest": - //*bn = LatestBlockNumber *bn = AcceptedBlockNumber return nil case "pending": @@ -148,7 +147,6 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error { bnh.BlockNumber = &bn return nil case "latest": - //*bn = LatestBlockNumber bn := AcceptedBlockNumber bnh.BlockNumber = &bn return nil -- cgit v1.2.3-70-g09d2