diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b5f3b2b6c..66dd062e81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: shell: bash - uses: actions/setup-go@v3 with: - go-version: "1.20" + go-version: "1.19" - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.20" + go-version: "1.19" - run: go mod download shell: bash - run: ./scripts/build.sh ./build/subnetevm @@ -64,7 +64,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: "1.20" + go-version: "1.19" - name: Use Node.js uses: actions/setup-node@v3 with: diff --git a/Dockerfile b/Dockerfile index cf1f08039a..3ce2199289 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ARG AVALANCHE_VERSION # ============= Compilation Stage ================ -FROM golang:1.20.1-buster AS builder +FROM golang:1.19.6-buster AS builder RUN apt-get update && apt-get install -y --no-install-recommends bash=5.0-4 make=4.2.1-1.2 gcc=4:8.3.0-1 musl-dev=1.1.21-2 ca-certificates=20200601~deb10u2 linux-headers-amd64 WORKDIR /build diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index c337cd55bf..2ab5b86e2b 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -107,12 +107,11 @@ type SimulatedBackend struct { // and uses a simulated blockchain for testing purposes. // A simulated backend always uses chainID 1337. func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend { - cpcfg := params.SimulatedTestChainConfig - if cpcfg.FeeConfig.GasLimit.Uint64() != gasLimit { - cpcfg.FeeConfig.GasLimit = big.NewInt(int64(gasLimit)) - } + copyConfig := *params.TestChainConfig + copyConfig.ChainID = big.NewInt(1337) + copyConfig.FeeConfig.GasLimit = big.NewInt(int64(gasLimit)) genesis := core.Genesis{ - Config: params.SimulatedTestChainConfig, + Config: ©Config, GasLimit: gasLimit, Alloc: alloc, } diff --git a/accounts/abi/bind/backends/simulated_test.go b/accounts/abi/bind/backends/simulated_test.go index 4406889f25..603e7ae884 100644 --- a/accounts/abi/bind/backends/simulated_test.go +++ b/accounts/abi/bind/backends/simulated_test.go @@ -137,14 +137,6 @@ func TestNewSimulatedBackend(t *testing.T) { sim := simTestBackend(testAddr) defer sim.Close() - if sim.config != params.SimulatedTestChainConfig { - t.Errorf("expected sim config to equal params.AllEthashProtocolChanges, got %v", sim.config) - } - - if sim.blockchain.Config() != params.SimulatedTestChainConfig { - t.Errorf("expected sim blockchain config to equal params.AllEthashProtocolChanges, got %v", sim.config) - } - stateDB, _ := sim.blockchain.State() bal := stateDB.GetBalance(testAddr) if bal.Cmp(expectedBal) != 0 { diff --git a/accounts/keystore/account_cache_test.go b/accounts/keystore/account_cache_test.go index 4dacf852aa..be030f0c0f 100644 --- a/accounts/keystore/account_cache_test.go +++ b/accounts/keystore/account_cache_test.go @@ -60,6 +60,7 @@ var ( } ) +// waitWatcherStart waits up to 1s for the keystore watcher to start. func waitWatcherStart(ks *KeyStore) bool { // On systems where file watch is not supported, just return "ok". if !ks.cache.watcher.enabled() { diff --git a/core/bench_test.go b/core/bench_test.go index 1e7b0c11b3..f4d73ed29c 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -41,7 +41,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" - "github.com/stretchr/testify/require" ) func BenchmarkInsertChain_empty_memdb(b *testing.B) { @@ -175,8 +174,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) { // Time the insertion of the new chain. // State and blocks are stored in the same DB. - chainman, err := NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false) - require.NoError(b, err) + chainman, _ := NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false) defer chainman.Stop() b.ReportAllocs() b.ResetTimer() diff --git a/core/blockchain.go b/core/blockchain.go index 42f9971855..ac907f6149 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -310,7 +310,6 @@ func NewBlockChain( if cacheConfig == nil { return nil, errCacheConfigNotSpecified } - // Open trie database with provided config triedb := trie.NewDatabaseWithConfig(db, &trie.Config{ Cache: cacheConfig.TrieCleanLimit, diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 5632c97d7d..2f2d1391c8 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -143,9 +143,8 @@ func TestTrieCleanJournal(t *testing.T) { // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int)}, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -639,9 +638,8 @@ func TestTransactionIndices(t *testing.T) { addr2 = crypto.PubkeyToAddress(key2.PublicKey) funds = big.NewInt(10000000000000) gspec = &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: funds}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int)}, + Alloc: GenesisAlloc{addr1: {Balance: funds}}, } signer = types.LatestSigner(gspec.Config) ) @@ -1077,8 +1075,7 @@ func TestEIP3651(t *testing.T) { addr2 = crypto.PubkeyToAddress(key2.PublicKey) funds = new(big.Int).Mul(common.Big1, big.NewInt(params.Ether)) gspec = &Genesis{ - Config: params.TestChainConfig, - GasLimit: params.TestChainConfig.FeeConfig.GasLimit.Uint64(), + Config: params.TestChainConfig, Alloc: GenesisAlloc{ addr1: {Balance: funds}, addr2: {Balance: funds}, @@ -1110,6 +1107,7 @@ func TestEIP3651(t *testing.T) { Balance: big.NewInt(0), }, }, + GasLimit: params.TestChainConfig.FeeConfig.GasLimit.Uint64(), } ) diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index c9b4e7ae07..d322550790 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -81,11 +81,7 @@ func ExampleGenerateChain() { } // Import the chain. This runs all block validation rules. - blockchain, err := NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false) - if err != nil { - fmt.Printf("could not create blockchain: %v\n", err) - return - } + blockchain, _ := NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false) defer blockchain.Stop() if i, err := blockchain.InsertChain(chain); err != nil { diff --git a/core/genesis.go b/core/genesis.go index 534acb5fed..65b9aa8aad 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -187,7 +187,11 @@ func SetupGenesisBlock( if genesis.Config.IsSubnetEVM(genesis.Timestamp) { gasLimitConfig := genesis.Config.FeeConfig.GasLimit.Uint64() if gasLimitConfig != genesis.GasLimit { - return nil, common.Hash{}, fmt.Errorf("gas limit in fee config (%d) does not match gas limit in header (%d)", gasLimitConfig, genesis.GasLimit) + return nil, common.Hash{}, fmt.Errorf( + "gas limit in fee config (%d) does not match gas limit in header (%d)", + gasLimitConfig, + genesis.GasLimit, + ) } // Verify config if err := genesis.Config.Verify(); err != nil { @@ -227,7 +231,9 @@ func SetupGenesisBlock( return newcfg, common.Hash{}, err } storedcfg := rawdb.ReadChainConfig(db, stored) + // If there is no previously stored chain config, write the chain config to disk. if storedcfg == nil { + // Note: this can happen since we did not previously write the genesis block and chain config in the same batch. log.Warn("Found genesis block without chain config") rawdb.WriteChainConfig(db, stored, newcfg) return newcfg, stored, nil diff --git a/core/genesis_test.go b/core/genesis_test.go index f0b0a21f47..22c96d34a2 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -126,8 +126,7 @@ func TestSetupGenesis(t *testing.T) { // Advance to block #4, past the SubnetEVM transition block of customg. genesis := oldcustomg.MustCommit(db) - bc, err := NewBlockChain(db, DefaultCacheConfig, &oldcustomg, dummy.NewFullFaker(), vm.Config{}, genesis.Hash(), false) - require.NoError(t, err) + bc, _ := NewBlockChain(db, DefaultCacheConfig, &oldcustomg, dummy.NewFullFaker(), vm.Config{}, genesis.Hash(), false) defer bc.Stop() blocks, _, _ := GenerateChain(oldcustomg.Config, genesis, dummy.NewFullFaker(), db, 4, 25, nil) @@ -238,23 +237,21 @@ func TestStatefulPrecompilesConfigure(t *testing.T) { // regression test for precompile activation after header block func TestPrecompileActivationAfterHeaderBlock(t *testing.T) { db := rawdb.NewMemoryDatabase() - copyCfg := *params.TestChainConfig customg := Genesis{ - Config: ©Cfg, + Config: params.TestChainConfig, Alloc: GenesisAlloc{ {1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}}, }, GasLimit: params.TestChainConfig.FeeConfig.GasLimit.Uint64(), } - bc, err := NewBlockChain(db, DefaultCacheConfig, &customg, dummy.NewFullFaker(), vm.Config{}, common.Hash{}, false) - require.NoError(t, err) + bc, _ := NewBlockChain(db, DefaultCacheConfig, &customg, dummy.NewFullFaker(), vm.Config{}, common.Hash{}, false) defer bc.Stop() // Advance header to block #4, past the ContractDeployerAllowListConfig. _, blocks, _, _ := GenerateChainWithGenesis(&customg, dummy.NewFullFaker(), 4, 25, nil) require := require.New(t) - _, err = bc.InsertChain(blocks) + _, err := bc.InsertChain(blocks) require.NoError(err) // accept up to block #2 @@ -267,24 +264,24 @@ func TestPrecompileActivationAfterHeaderBlock(t *testing.T) { // header must be bigger than last accepted require.Greater(block.Time, bc.lastAccepted.Time()) - activatedGenesis := customg - contractDeployerTimestamp := utils.NewUint64(51) - contractDeployerConfig := deployerallowlist.NewConfig(contractDeployerTimestamp, nil, nil) - activatedGenesis.Config.UpgradeConfig.PrecompileUpgrades = []params.PrecompileUpgrade{ + activatedGenesisConfig := *customg.Config + contractDeployerConfig := deployerallowlist.NewConfig(utils.NewUint64(51), nil, nil) + activatedGenesisConfig.UpgradeConfig.PrecompileUpgrades = []params.PrecompileUpgrade{ { Config: contractDeployerConfig, }, } + customg.Config = &activatedGenesisConfig // assert block is after the activation block - require.Greater(block.Time, *contractDeployerTimestamp) + require.Greater(block.Time, *contractDeployerConfig.Timestamp()) // assert last accepted block is before the activation block - require.Less(bc.lastAccepted.Time(), *contractDeployerTimestamp) + require.Less(bc.lastAccepted.Time(), *contractDeployerConfig.Timestamp()) // This should not return any error since the last accepted block is before the activation block. - config, _, err := setupGenesisBlock(db, trie.NewDatabase(db), &activatedGenesis, bc.lastAccepted.Hash()) + config, _, err := setupGenesisBlock(db, trie.NewDatabase(db), &customg, bc.lastAccepted.Hash()) require.NoError(err) - if !reflect.DeepEqual(config, activatedGenesis.Config) { - t.Errorf("returned %v\nwant %v", config, activatedGenesis.Config) + if !reflect.DeepEqual(config, customg.Config) { + t.Errorf("returned %v\nwant %v", config, customg.Config) } } diff --git a/core/headerchain_test.go b/core/headerchain_test.go index 63194f5a92..72721c3f79 100644 --- a/core/headerchain_test.go +++ b/core/headerchain_test.go @@ -85,6 +85,7 @@ func TestHeaderInsertion(t *testing.T) { if err != nil { t.Fatal(err) } + defer chain.Stop() // chain A: G->A1->A2...A128 chainA, _, _ := GenerateChain(params.TestChainConfig, types.NewBlockWithHeader(genesis.Header()), dummy.NewCoinbaseFaker(), db, 128, 10, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{0: byte(10), 19: byte(i)}) diff --git a/core/rlp_test.go b/core/rlp_test.go index 0f1e53e546..f2b30c5908 100644 --- a/core/rlp_test.go +++ b/core/rlp_test.go @@ -50,9 +50,8 @@ func getBlock(transactions int, uncles int, dataSize int) *types.Block { address = crypto.PubkeyToAddress(key.PublicKey) funds = big.NewInt(50000 * 225000000000 * 200) gspec = &Genesis{ - Config: params.TestChainConfig, - Alloc: GenesisAlloc{address: {Balance: funds}}, - GasLimit: params.TestChainConfig.FeeConfig.GasLimit.Uint64(), + Config: params.TestChainConfig, + Alloc: GenesisAlloc{address: {Balance: funds}}, } ) // We need to generate as many blocks +1 as uncles diff --git a/core/state/statedb.go b/core/state/statedb.go index 7ee3548706..45870a38ad 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -107,14 +107,13 @@ type StateDB struct { // Per-transaction access list accessList *accessList - - // Transient storage - transientStorage transientStorage - // Ordered storage slots to be used in predicate verification as set in the tx access list. // Only set in PrepareAccessList, and un-modified through execution. predicateStorageSlots map[common.Address][]byte + // Transient storage + transientStorage transientStorage + // Journal of state modifications. This is the backbone of // Snapshot and RevertToSnapshot. journal *journal diff --git a/core/state_processor_test.go b/core/state_processor_test.go index e6f9aed086..a206be7315 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -218,7 +218,6 @@ func TestStateProcessorErrors(t *testing.T) { gspec = &Genesis{ Config: ¶ms.ChainConfig{ ChainID: big.NewInt(1), - FeeConfig: params.DefaultFeeConfig, HomesteadBlock: big.NewInt(0), EIP150Block: big.NewInt(0), EIP150Hash: common.Hash{}, @@ -236,7 +235,6 @@ func TestStateProcessorErrors(t *testing.T) { Nonce: 0, }, }, - GasLimit: params.TestChainConfig.FeeConfig.GasLimit.Uint64(), } blockchain, _ = NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false) ) @@ -407,7 +405,7 @@ func TestBadTxAllowListBlock(t *testing.T) { Nonce: 0, }, }, - GasLimit: params.TestChainConfig.FeeConfig.GasLimit.Uint64(), + GasLimit: config.FeeConfig.GasLimit.Uint64(), } blockchain, _ = NewBlockChain(db, DefaultCacheConfig, gspec, dummy.NewCoinbaseFaker(), vm.Config{}, common.Hash{}, false) ) diff --git a/core/state_transition.go b/core/state_transition.go index a7cd65f748..e532f73822 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -38,7 +38,6 @@ import ( predicateutils "github.com/ava-labs/subnet-evm/utils/predicate" "github.com/ava-labs/subnet-evm/vmerrs" "github.com/ethereum/go-ethereum/common" - cmath "github.com/ethereum/go-ethereum/common/math" ) @@ -353,6 +352,7 @@ func (st *StateTransition) preCheck() error { } } } + // Make sure that transaction gasFeeCap is greater than the baseFee (post london) if st.evm.ChainConfig().IsSubnetEVM(st.evm.Context.Time) { // Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call) @@ -406,7 +406,6 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { if err := st.preCheck(); err != nil { return nil, err } - if st.evm.Config.Debug { st.evm.Config.Tracer.CaptureTxStart(st.initialGas) defer func() { diff --git a/core/test_blockchain.go b/core/test_blockchain.go index e624965971..69ac86b579 100644 --- a/core/test_blockchain.go +++ b/core/test_blockchain.go @@ -7,7 +7,6 @@ import ( "fmt" "math/big" "strings" - "sync" "testing" "github.com/ava-labs/subnet-evm/commontype" @@ -198,9 +197,10 @@ func TestInsertChainAcceptSingleBlock(t *testing.T, create func(db ethdb.Databas // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) if err != nil { @@ -268,9 +268,10 @@ func TestInsertLongForkedChain(t *testing.T, create func(db ethdb.Database, gspe // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -432,9 +433,10 @@ func TestAcceptNonCanonicalBlock(t *testing.T, create func(db ethdb.Database, gs // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -540,9 +542,10 @@ func TestSetPreferenceRewind(t *testing.T, create func(db ethdb.Database, gspec // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -673,12 +676,13 @@ func TestBuildOnVariousStages(t *testing.T, create func(db ethdb.Database, gspec // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, Alloc: GenesisAlloc{ addr1: {Balance: genesisBalance}, addr3: {Balance: genesisBalance}, }, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -830,9 +834,10 @@ func TestEmptyBlocks(t *testing.T, create func(db ethdb.Database, gspec *Genesis chainDB := rawdb.NewMemoryDatabase() gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{}, } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -880,9 +885,8 @@ func TestReorgReInsert(t *testing.T, create func(db ethdb.Database, gspec *Genes // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int)}, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } genesis := gspec.ToBlock() @@ -987,9 +991,10 @@ func TestAcceptBlockIdenticalStateRoot(t *testing.T, create func(db ethdb.Databa // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) @@ -1131,17 +1136,16 @@ func TestReprocessAcceptBlockIdenticalStateRoot(t *testing.T, create func(db eth // Ensure that key1 has some funds in the genesis block. genesisBalance := big.NewInt(1000000000) gspec := &Genesis{ - Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), FeeConfig: params.DefaultFeeConfig}, - Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, - GasLimit: params.DefaultFeeConfig.GasLimit.Uint64(), + Config: ¶ms.ChainConfig{ + HomesteadBlock: new(big.Int), + }, + Alloc: GenesisAlloc{addr1: {Balance: genesisBalance}}, } blockchain, err := create(chainDB, gspec, common.Hash{}) if err != nil { t.Fatal(err) } - var stopOnce sync.Once - defer stopOnce.Do(blockchain.Stop) signer := types.HomesteadSigner{} _, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(i int, gen *BlockGen) { @@ -1191,7 +1195,7 @@ func TestReprocessAcceptBlockIdenticalStateRoot(t *testing.T, create func(db eth t.Fatalf("Expected current block to be %s:%d, but found %s%d", expectedCurrentBlock.Hash().Hex(), expectedCurrentBlock.NumberU64(), currentBlock.Hash().Hex(), currentBlock.Number.Uint64()) } - stopOnce.Do(blockchain.Stop) + blockchain.Stop() chainDB = rawdb.NewMemoryDatabase() blockchain, err = create(chainDB, gspec, common.Hash{}) diff --git a/core/vm/gas_table_test.go b/core/vm/gas_table_test.go index ffd38aa29e..78af5c359e 100644 --- a/core/vm/gas_table_test.go +++ b/core/vm/gas_table_test.go @@ -160,9 +160,9 @@ func TestCreateGas(t *testing.T) { config.ExtraEips = []int{3860} } - // Note: we use SubnetEVM instead of AllEthashProtocolChanges (upstream) + // Note: we use TestSubnetEVMConfig instead of AllEthashProtocolChanges (upstream) // because it is the last fork before the activation of EIP-3860 - vmenv := NewEVM(vmctx, TxContext{}, statedb, params.SubnetEVMDefaultChainConfig, config) + vmenv := NewEVM(vmctx, TxContext{}, statedb, params.TestSubnetEVMConfig, config) var startGas = uint64(testGas) ret, gas, err := vmenv.Call(AccountRef(common.Address{}), address, nil, startGas, new(big.Int)) if err != nil { diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 60a5393f07..24e5542466 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -78,6 +78,13 @@ func newSubnetEVMInstructionSet() JumpTable { return validate(instructionSet) } +func newDUpgradeInstructionSet() JumpTable { + instructionSet := newSubnetEVMInstructionSet() + enable3855(&instructionSet) // PUSH0 instruction + enable3860(&instructionSet) // Limit and meter initcode + return validate(instructionSet) +} + func validate(jt JumpTable) JumpTable { for i, op := range jt { if op == nil { @@ -96,13 +103,6 @@ func validate(jt JumpTable) JumpTable { return jt } -func newDUpgradeInstructionSet() JumpTable { - instructionSet := newSubnetEVMInstructionSet() - enable3855(&instructionSet) // PUSH0 instruction - enable3860(&instructionSet) // Limit and meter initcode - return validate(instructionSet) -} - // newIstanbulInstructionSet returns the frontier, // homestead, byzantium, contantinople and petersburg instructions. func newIstanbulInstructionSet() JumpTable { diff --git a/eth/api.go b/eth/api.go index d7fbfc35a3..b9961449fc 100644 --- a/eth/api.go +++ b/eth/api.go @@ -96,7 +96,7 @@ func (api *AdminAPI) ExportChain(file string, first *uint64, last *uint64) (bool return false, errors.New("location would overwrite an existing file") } // Make sure we can create the file to export into - out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm) + out, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { return false, err } diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index 86acf18d5c..e66de42906 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -38,7 +38,6 @@ import ( "github.com/ava-labs/subnet-evm/core/rawdb" "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/core/vm" - "github.com/ava-labs/subnet-evm/ethdb" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/precompile/contracts/feemanager" "github.com/ava-labs/subnet-evm/rpc" @@ -56,7 +55,6 @@ var ( ) type testBackend struct { - db ethdb.Database chain *core.BlockChain acceptedEvent chan<- core.ChainEvent } @@ -92,14 +90,14 @@ func (b *testBackend) SubscribeChainAcceptedEvent(ch chan<- core.ChainEvent) eve return nil } -func (b *testBackend) teardown() { - b.chain.Stop() -} - func (b *testBackend) GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig, *big.Int, error) { return b.chain.GetFeeConfigAt(parent) } +func (b *testBackend) teardown() { + b.chain.Stop() +} + func newTestBackendFakerEngine(t *testing.T, config *params.ChainConfig, numBlocks int, genBlocks func(i int, b *core.BlockGen)) *testBackend { var gspec = &core.Genesis{ Config: config, @@ -143,15 +141,14 @@ func newTestBackend(t *testing.T, config *params.ChainConfig, numBlocks int, gen t.Fatal(err) } // Construct testing chain - db := rawdb.NewMemoryDatabase() - chain, err := core.NewBlockChain(db, core.DefaultCacheConfig, gspec, engine, vm.Config{}, common.Hash{}, false) + chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), core.DefaultCacheConfig, gspec, engine, vm.Config{}, common.Hash{}, false) if err != nil { t.Fatalf("Failed to create local chain, %v", err) } if _, err := chain.InsertChain(blocks); err != nil { t.Fatalf("Failed to insert chain, %v", err) } - return &testBackend{chain: chain, db: db} + return &testBackend{chain: chain} } func (b *testBackend) MinRequiredTip(ctx context.Context, header *types.Header) (*big.Int, error) { @@ -314,11 +311,12 @@ func TestSuggestTipCapSmallTips(t *testing.T) { Data: []byte{}, }) tx, err = types.SignTx(tx, signer, key) - require.NoError(t, err, "failed to create tx") + if err != nil { + t.Fatalf("failed to create tx: %s", err) + } b.AddTx(tx) } }, - // NOTE: small tips do not bias estimate expectedTip: big.NewInt(643_500_643), }, defaultOracleConfig()) } @@ -421,7 +419,8 @@ func TestSuggestGasPriceAfterFeeConfigUpdate(t *testing.T) { // issue the block with tx that changes the fee genesis := backend.chain.Genesis() engine := backend.chain.Engine() - blocks, _, err := core.GenerateChain(&chainConfig, genesis, engine, backend.db, 1, 0, func(i int, b *core.BlockGen) { + db := backend.chain.StateCache().DiskDB() + blocks, _, err := core.GenerateChain(&chainConfig, genesis, engine, db, 1, 0, func(i int, b *core.BlockGen) { b.SetCoinbase(common.Address{1}) // admin issues tx to change fee config to higher MinBaseFee diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 422ec13858..2b99cacfc0 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -211,13 +211,13 @@ func TestTraceCall(t *testing.T) { // Initialize test accounts accounts := newAccounts(3) genesis := &core.Genesis{ - Config: params.SubnetEVMDefaultChainConfig, // TODO: go-ethereum has not enabled Shanghai yet, so we use SubnetEVM here so tests pass. + Config: params.TestSubnetEVMConfig, // TODO: go-ethereum has not enabled Shanghai yet, so we use SubnetEVM here so tests pass. Alloc: core.GenesisAlloc{ accounts[0].addr: {Balance: big.NewInt(params.Ether)}, accounts[1].addr: {Balance: big.NewInt(params.Ether)}, accounts[2].addr: {Balance: big.NewInt(params.Ether)}, }, - GasLimit: params.SubnetEVMDefaultChainConfig.FeeConfig.GasLimit.Uint64(), + GasLimit: params.TestSubnetEVMConfig.FeeConfig.GasLimit.Uint64(), } genBlocks := 10 signer := types.HomesteadSigner{} @@ -479,7 +479,7 @@ func TestTracingWithOverrides(t *testing.T) { accounts := newAccounts(3) storageAccount := common.Address{0x13, 37} genesis := &core.Genesis{ - Config: params.SubnetEVMDefaultChainConfig, // TODO: go-ethereum has not enabled Shanghai yet, so we use SubnetEVM here so tests pass. + Config: params.TestSubnetEVMConfig, // TODO: go-ethereum has not enabled Shanghai yet, so we use SubnetEVM here so tests pass. Alloc: core.GenesisAlloc{ accounts[0].addr: {Balance: big.NewInt(params.Ether)}, accounts[1].addr: {Balance: big.NewInt(params.Ether)}, @@ -493,7 +493,7 @@ func TestTracingWithOverrides(t *testing.T) { }, }, }, - GasLimit: params.SubnetEVMDefaultChainConfig.FeeConfig.GasLimit.Uint64(), + GasLimit: params.TestSubnetEVMConfig.FeeConfig.GasLimit.Uint64(), } genBlocks := 10 signer := types.HomesteadSigner{} diff --git a/eth/tracers/internal/tracetest/calltrace_test.go b/eth/tracers/internal/tracetest/calltrace_test.go index c3d944361a..7b24f235a3 100644 --- a/eth/tracers/internal/tracetest/calltrace_test.go +++ b/eth/tracers/internal/tracetest/calltrace_test.go @@ -46,6 +46,9 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" + + // Force-load native, to trigger registration + _ "github.com/ava-labs/subnet-evm/eth/tracers/native" ) type callContext struct { diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index 6aa8aa328c..3e2a9763a1 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -40,6 +40,8 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" ) +//go:generate go run github.com/fjl/gencodec -type callFrame -field-override callFrameMarshaling -out gen_callframe_json.go + func init() { tracers.DefaultDirectory.Register("callTracer", newCallTracer, false) } diff --git a/miner/worker.go b/miner/worker.go index e1a96667fc..da75b344ba 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -45,7 +45,6 @@ import ( "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/params" "github.com/ava-labs/subnet-evm/precompile/precompileconfig" - "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" @@ -187,7 +186,7 @@ func (w *worker) commitNewWork(predicateContext *precompileconfig.ProposerPredic return nil, fmt.Errorf("failed to create new current environment: %w", err) } // Configure any upgrades that should go into effect during this block. - err = core.ApplyUpgrades(w.chainConfig, utils.NewUint64(parent.Time), types.NewBlockWithHeader(header), env.state) + err = core.ApplyUpgrades(w.chainConfig, &parent.Time, types.NewBlockWithHeader(header), env.state) if err != nil { log.Error("failed to configure precompiles mining new block", "parent", parent.Hash(), "number", header.Number, "timestamp", header.Time, "err", err) return nil, err @@ -371,13 +370,14 @@ func (w *worker) handleResult(env *environment, block *types.Block, createdAt ti logs = append(logs, receipt.Logs...) } - totalFees, err := core.TotalFeesFloat(block, receipts) + feesInEther, err := core.TotalFeesFloat(block, receipts) if err != nil { log.Error("TotalFeesFloat error: %s", err) } - - log.Info("Commit new mining work", "number", block.Number(), "hash", hash, "timestamp", block.Time(), "uncles", 0, "txs", env.tcount, - "gas", block.GasUsed(), "fees", totalFees, "elapsed", common.PrettyDuration(time.Since(env.start))) + log.Info("Commit new mining work", "number", block.Number(), "hash", hash, + "uncles", 0, "txs", env.tcount, + "gas", block.GasUsed(), "fees", feesInEther, + "elapsed", common.PrettyDuration(time.Since(env.start))) // Note: the miner no longer emits a NewMinedBlock event. Instead the caller // is responsible for running any additional verification and then inserting diff --git a/params/config.go b/params/config.go index 5842cb7ecb..9191797182 100644 --- a/params/config.go +++ b/params/config.go @@ -114,29 +114,9 @@ var ( UpgradeConfig: UpgradeConfig{}, } - TestPreSubnetEVMConfig = &ChainConfig{ - AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, - ChainID: big.NewInt(1), - FeeConfig: DefaultFeeConfig, - AllowFeeRecipients: false, - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP150Hash: common.Hash{}, - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{}, - GenesisPrecompiles: Precompiles{}, - UpgradeConfig: UpgradeConfig{}, - } - - SimulatedTestChainConfig = &ChainConfig{ + TestSubnetEVMConfig = &ChainConfig{ AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, - ChainID: big.NewInt(1337), + ChainID: big.NewInt(1), FeeConfig: DefaultFeeConfig, AllowFeeRecipients: false, HomesteadBlock: big.NewInt(0), @@ -151,12 +131,31 @@ var ( MuirGlacierBlock: big.NewInt(0), MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{ SubnetEVMTimestamp: utils.NewUint64(0), - DUpgradeTimestamp: utils.NewUint64(0), }, GenesisPrecompiles: Precompiles{}, UpgradeConfig: UpgradeConfig{}, } + TestPreSubnetEVMConfig = &ChainConfig{ + AvalancheContext: AvalancheContext{snow.DefaultContextTest()}, + ChainID: big.NewInt(1), + FeeConfig: DefaultFeeConfig, + AllowFeeRecipients: false, + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP150Hash: common.Hash{}, + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{}, + GenesisPrecompiles: Precompiles{}, + UpgradeConfig: UpgradeConfig{}, + } + TestRules = TestChainConfig.AvalancheRules(new(big.Int), 0) ) @@ -264,48 +263,63 @@ func (c ChainConfig) MarshalJSON() ([]byte, error) { // Description returns a human-readable description of ChainConfig. func (c *ChainConfig) Description() string { - // convert nested data structures to json - feeBytes, err := json.Marshal(c.FeeConfig) - if err != nil { - feeBytes = []byte("cannot marshal FeeConfig") - } - networkUpgradesBytes, err := json.Marshal(c.MandatoryNetworkUpgrades) - if err != nil { - networkUpgradesBytes = []byte("cannot marshal MandatoryNetworkUpgrades") - } + var banner string + + banner += fmt.Sprintf("Chain ID: %v\n", c.ChainID) + banner += "Consensus: Dummy Consensus Engine\n\n" + + // Create a list of forks with a short description of them. Forks that only + // makes sense for mainnet should be optional at printing to avoid bloating + // the output for testnets and private networks. + banner += "Hard Forks:\n" + banner += fmt.Sprintf(" - Homestead: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)\n", c.HomesteadBlock) + banner += fmt.Sprintf(" - Tangerine Whistle (EIP 150): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)\n", c.EIP150Block) + banner += fmt.Sprintf(" - Spurious Dragon/1 (EIP 155): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block) + banner += fmt.Sprintf(" - Spurious Dragon/2 (EIP 158): #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)\n", c.EIP155Block) + banner += fmt.Sprintf(" - Byzantium: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)\n", c.ByzantiumBlock) + banner += fmt.Sprintf(" - Constantinople: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)\n", c.ConstantinopleBlock) + banner += fmt.Sprintf(" - Petersburg: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)\n", c.PetersburgBlock) + banner += fmt.Sprintf(" - Istanbul: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)\n", c.IstanbulBlock) + if c.MuirGlacierBlock != nil { + banner += fmt.Sprintf(" - Muir Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/muir-glacier.md)\n", c.MuirGlacierBlock) + } + banner += "Mandatory Upgrades:\n" + banner += fmt.Sprintf(" - SubnetEVM Timestamp: #%-8d (https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0)\n", c.SubnetEVMTimestamp) + banner += fmt.Sprintf(" - DUpgrade Timestamp: #%-8d (https://github.com/ava-labs/avalanchego/releases/tag/v1.11.0)\n", c.DUpgradeTimestamp) + banner += "\n" + + // Add Subnet-EVM custom fields optionalNetworkUpgradeBytes, err := json.Marshal(c.OptionalNetworkUpgrades) if err != nil { optionalNetworkUpgradeBytes = []byte("cannot marshal OptionalNetworkUpgrades") } + banner += fmt.Sprintf("Optional Network Upgrades: %s", string(optionalNetworkUpgradeBytes)) + banner += "\n" + precompileUpgradeBytes, err := json.Marshal(c.GenesisPrecompiles) if err != nil { precompileUpgradeBytes = []byte("cannot marshal PrecompileUpgrade") } + banner += fmt.Sprintf("Precompile Upgrades: %s", string(precompileUpgradeBytes)) + banner += "\n" + upgradeConfigBytes, err := json.Marshal(c.UpgradeConfig) if err != nil { upgradeConfigBytes = []byte("cannot marshal UpgradeConfig") } + banner += fmt.Sprintf("Upgrade Config: %s", string(upgradeConfigBytes)) + banner += "\n" - return fmt.Sprintf("{ChainID: %v Homestead: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Subnet EVM: %v, DUpgrade: %v, FeeConfig: %v, AllowFeeRecipients: %v, MandatoryNetworkUpgrades: %v, OptionalNetworkUprades: %v, PrecompileUpgrade: %v, UpgradeConfig: %v, Engine: Dummy Consensus Engine}", - c.ChainID, - c.HomesteadBlock, - c.EIP150Block, - c.EIP155Block, - c.EIP158Block, - c.ByzantiumBlock, - c.ConstantinopleBlock, - c.PetersburgBlock, - c.IstanbulBlock, - c.MuirGlacierBlock, - c.SubnetEVMTimestamp, - c.DUpgradeTimestamp, - string(feeBytes), - c.AllowFeeRecipients, - string(networkUpgradesBytes), - string(optionalNetworkUpgradeBytes), - string(precompileUpgradeBytes), - string(upgradeConfigBytes), - ) + feeBytes, err := json.Marshal(c.FeeConfig) + if err != nil { + feeBytes = []byte("cannot marshal FeeConfig") + } + banner += fmt.Sprintf("Fee Config: %s", string(feeBytes)) + banner += "\n" + + banner += fmt.Sprintf("Allow Fee Recipients: %v", c.AllowFeeRecipients) + banner += "\n" + return banner } // IsHomestead returns whether num is either equal to the homestead block or greater. @@ -355,12 +369,14 @@ func (c *ChainConfig) IsIstanbul(num *big.Int) bool { return utils.IsBlockForked(c.IstanbulBlock, num) } -// IsSubnetEVM returns whether [time] is either equal to the SubnetEVM fork block timestamp or greater. +// IsSubnetEVM returns whether [time] represents a block +// with a timestamp after the SubnetEVM upgrade time. func (c *ChainConfig) IsSubnetEVM(time uint64) bool { return utils.IsTimestampForked(c.SubnetEVMTimestamp, time) } -// IsDUpgrade returns whether [time] is either equal to the DUpgrade fork block timestamp or greater. +// IsDUpgrade returns whether [time] represents a block +// with a timestamp after the DUpgrade upgrade time. func (c *ChainConfig) IsDUpgrade(time uint64) bool { return utils.IsTimestampForked(c.DUpgradeTimestamp, time) } @@ -378,7 +394,7 @@ func (r *Rules) PredicateExists(addr common.Address) bool { return proposerPredicateExists } -// IsPrecompileEnabled returns whether precompile with [address] is enabled at [blockTimestamp]. +// IsPrecompileEnabled returns whether precompile with [address] is enabled at [timestamp]. func (c *ChainConfig) IsPrecompileEnabled(address common.Address, timestamp uint64) bool { config := c.getActivePrecompileConfig(address, timestamp) return config != nil && !config.IsDisabled() @@ -520,7 +536,7 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, height *big.Int, time if isForkBlockIncompatible(c.EIP158Block, newcfg.EIP158Block, height) { return newBlockCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block) } - if c.IsEIP158(height) && !configBlockEqual(c.ChainID, newcfg.ChainID) { + if c.IsEIP158(height) && !utils.BigNumEqual(c.ChainID, newcfg.ChainID) { return newBlockCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block) } if isForkBlockIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, height) { diff --git a/params/config_test.go b/params/config_test.go index d2eee6d6ef..9bbe8b2252 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -258,21 +258,24 @@ func TestActivePrecompiles(t *testing.T) { func TestChainConfigMarshalWithUpgrades(t *testing.T) { config := ChainConfigWithUpgradesJSON{ ChainConfig: ChainConfig{ - ChainID: big.NewInt(1), - FeeConfig: DefaultFeeConfig, - AllowFeeRecipients: false, - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP150Hash: common.Hash{}, - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ByzantiumBlock: big.NewInt(0), - ConstantinopleBlock: big.NewInt(0), - PetersburgBlock: big.NewInt(0), - IstanbulBlock: big.NewInt(0), - MuirGlacierBlock: big.NewInt(0), - MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{utils.NewUint64(0), utils.NewUint64(0)}, - GenesisPrecompiles: Precompiles{}, + ChainID: big.NewInt(1), + FeeConfig: DefaultFeeConfig, + AllowFeeRecipients: false, + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP150Hash: common.Hash{}, + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + ByzantiumBlock: big.NewInt(0), + ConstantinopleBlock: big.NewInt(0), + PetersburgBlock: big.NewInt(0), + IstanbulBlock: big.NewInt(0), + MuirGlacierBlock: big.NewInt(0), + MandatoryNetworkUpgrades: MandatoryNetworkUpgrades{ + SubnetEVMTimestamp: utils.NewUint64(0), + DUpgradeTimestamp: utils.NewUint64(0), + }, + GenesisPrecompiles: Precompiles{}, }, UpgradeConfig: UpgradeConfig{ PrecompileUpgrades: []PrecompileUpgrade{ diff --git a/params/precompile_upgrade.go b/params/precompile_upgrade.go index e8213bb0ed..9e0dffded6 100644 --- a/params/precompile_upgrade.go +++ b/params/precompile_upgrade.go @@ -120,7 +120,7 @@ func (c *ChainConfig) verifyPrecompileUpgrades() error { // Verify specified timestamps are monotonically increasing across all precompile keys. // Note: It is OK for multiple configs of DIFFERENT keys to specify the same timestamp. if previousUpgradeTimestamp != nil && *upgradeTimestamp < *previousUpgradeTimestamp { - return fmt.Errorf("PrecompileUpgrade* (%s) at [%d]: config block timestamp (%v) < previous timestamp (%v)", key, i, *upgradeTimestamp, *previousUpgradeTimestamp) + return fmt.Errorf("PrecompileUpgrade (%s) at [%d]: config block timestamp (%v) < previous timestamp (%v)", key, i, *upgradeTimestamp, *previousUpgradeTimestamp) } if disabled == upgrade.IsDisabled() { diff --git a/plugin/evm/block_builder.go b/plugin/evm/block_builder.go index 83f800d118..ac78237670 100644 --- a/plugin/evm/block_builder.go +++ b/plugin/evm/block_builder.go @@ -157,8 +157,6 @@ func (b *blockBuilder) awaitSubmittedTxs() { b.signalTxsReady() if b.gossiper != nil && len(ethTxsEvent.Txs) > 0 { - // Give time for this node to build a block before attempting to - // gossip // [GossipTxs] will block unless [gossiper.txsToGossipChan] (an // unbuffered channel) is listened on if err := b.gossiper.GossipTxs(ethTxsEvent.Txs); err != nil { diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go index 78f3491b33..b3efd72c7e 100644 --- a/plugin/evm/vm_test.go +++ b/plugin/evm/vm_test.go @@ -80,8 +80,9 @@ var ( // Use chainId: 43111, so that it does not overlap with any Avalanche ChainIDs, which may have their // config overridden in vm.Initialize. genesisJSONSubnetEVM = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"subnetEVMTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}" + genesisJSONDUpgrade = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"subnetEVMTimestamp\":0,\"dUpgradeTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}" genesisJSONPreSubnetEVM = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x7A1200\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0x71562b71999873DB5b286dF957af199Ec94617F7\": {\"balance\":\"0x4192927743b88000\"}, \"0x703c4b2bD70c169f5717101CaeE543299Fc946C7\": {\"balance\":\"0x4192927743b88000\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}" - genesisJSONLatest = genesisJSONSubnetEVM + genesisJSONLatest = genesisJSONDUpgrade firstTxAmount *big.Int genesisBalance *big.Int @@ -2762,7 +2763,7 @@ func TestRewardManagerPrecompileSetRewardAddress(t *testing.T) { // reward manager was disabled at previous block // so this block should revert back to enabling fee recipients require.Equal(t, etherBase, ethBlock.Coinbase()) - require.Greater(t, int64(ethBlock.Timestamp()), disableTime.Unix()) + require.GreaterOrEqual(t, int64(ethBlock.Timestamp()), disableTime.Unix()) // Verify that Blackhole has received fees blkState, err = vm.blockChain.StateAt(ethBlock.Root()) diff --git a/plugin/evm/vm_upgrade_bytes_test.go b/plugin/evm/vm_upgrade_bytes_test.go index d6d5746922..2e5eb4e03e 100644 --- a/plugin/evm/vm_upgrade_bytes_test.go +++ b/plugin/evm/vm_upgrade_bytes_test.go @@ -237,8 +237,8 @@ func TestVMUpgradeBytesNetworkUpgradesWithGenesis(t *testing.T) { if err := json.Unmarshal([]byte(genesisJSONPreSubnetEVM), &genesis); err != nil { t.Fatalf("could not unmarshal genesis bytes: %s", err) } - genesisSubnetEVMTimestamp := uint64(5) - genesis.Config.SubnetEVMTimestamp = utils.NewUint64(genesisSubnetEVMTimestamp) + genesisSubnetEVMTimestamp := utils.NewUint64(5) + genesis.Config.SubnetEVMTimestamp = genesisSubnetEVMTimestamp genesisBytes, err := json.Marshal(&genesis) if err != nil { t.Fatalf("could not unmarshal genesis bytes: %s", err) @@ -248,7 +248,7 @@ func TestVMUpgradeBytesNetworkUpgradesWithGenesis(t *testing.T) { _, vm, _, _ := GenesisVM(t, true, string(genesisBytes), "", "") // verify upgrade is rescheduled - require.True(t, vm.chainConfig.IsSubnetEVM(*utils.NewUint64(0))) + require.True(t, vm.chainConfig.IsSubnetEVM(0)) if err := vm.Shutdown(context.Background()); err != nil { t.Fatal(err) diff --git a/scripts/build_test.sh b/scripts/build_test.sh index adb148a01e..93dea5ec11 100755 --- a/scripts/build_test.sh +++ b/scripts/build_test.sh @@ -20,5 +20,5 @@ source "$SUBNET_EVM_PATH"/scripts/constants.sh # We pass in the arguments to this script directly to enable easily passing parameters such as enabling race detection, # parallelism, and test coverage. -# DO NOT RUN "tests/precompile" or "tests/load" since it's run by ginkgo -go test -coverprofile=coverage.out -covermode=atomic -timeout="30m" $@ $(go list ./... | grep -v tests/precompile | grep -v tests/load) +# DO NOT RUN tests from the top level "tests" directory since they are run by ginkgo +go test -coverprofile=coverage.out -covermode=atomic -timeout="30m" $@ $(go list ./... | grep -v github.com/ava-labs/subnet-evm/tests) diff --git a/tests/init.go b/tests/init.go index 72a9837295..8a6c2021c3 100644 --- a/tests/init.go +++ b/tests/init.go @@ -167,7 +167,8 @@ var Forks = map[string]*params.ChainConfig{ PetersburgBlock: big.NewInt(0), IstanbulBlock: big.NewInt(0), MandatoryNetworkUpgrades: params.MandatoryNetworkUpgrades{ - DUpgradeTimestamp: utils.NewUint64(0), + SubnetEVMTimestamp: utils.NewUint64(0), + DUpgradeTimestamp: utils.NewUint64(0), }, }, }