Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into use-libevm
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Oct 11, 2024
2 parents 0976d50 + 7242ae2 commit 062dc35
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 6 deletions.
90 changes: 90 additions & 0 deletions core/genesis_extra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// (c) 2019-2021, Ava Labs, Inc.
//
// This file is a derived work, based on the go-ethereum library whose original
// notices appear below.
//
// It is distributed under a license compatible with the licensing terms of the
// original code from which it is derived.
//
// Much love to the original authors for their work.
// **********
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package core

import (
"math/big"
"testing"
"time"

"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/triedb"
"github.com/ava-labs/coreth/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestGenesisEthUpgrades(t *testing.T) {
db := rawdb.NewMemoryDatabase()
preEthUpgrades := &params.ChainConfig{
ChainID: big.NewInt(43114), // Specifically refers to mainnet for this UT
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: false,
EIP150Block: big.NewInt(0),
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),
NetworkUpgrades: params.NetworkUpgrades{

Check failure on line 58 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Lint

unknown field NetworkUpgrades in struct literal of type "github.com/ethereum/go-ethereum/params".ChainConfig

Check failure on line 58 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (macos-latest)

unknown field NetworkUpgrades in struct literal of type "github.com/ethereum/go-ethereum/params".ChainConfig

Check failure on line 58 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (ubuntu-20.04)

unknown field NetworkUpgrades in struct literal of type "github.com/ethereum/go-ethereum/params".ChainConfig

Check failure on line 58 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (ubuntu-latest)

unknown field NetworkUpgrades in struct literal of type "github.com/ethereum/go-ethereum/params".ChainConfig

Check failure on line 58 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (windows-latest)

unknown field NetworkUpgrades in struct literal of type "github.com/ethereum/go-ethereum/params".ChainConfig
ApricotPhase1BlockTimestamp: utils.NewUint64(0),
ApricotPhase2BlockTimestamp: utils.NewUint64(0),
},
}

tdb := triedb.NewDatabase(db, triedb.HashDefaults)
config := *preEthUpgrades
// Set this up once, just to get the genesis hash
_, genHash, err := SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, common.Hash{}, false)
require.NoError(t, err)

// Write the configuration back to the db as it would be in prior versions
rawdb.WriteChainConfig(db, genHash, preEthUpgrades)

// Make some other block
block := types.NewBlock(
&types.Header{
Number: big.NewInt(1640340), // Berlin activation on mainnet
Difficulty: big.NewInt(1),
ParentHash: genHash,
Time: uint64(time.Now().Unix()),
},
nil, nil, nil, nil,
)
rawdb.WriteBlock(db, block)

// We should still be able to re-initialize
config = *preEthUpgrades
config.SetEthUpgrades() // New versions will set additional fields eg, LondonBlock

Check failure on line 87 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Lint

config.SetEthUpgrades undefined (type "github.com/ethereum/go-ethereum/params".ChainConfig has no field or method SetEthUpgrades) (typecheck)

Check failure on line 87 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (macos-latest)

config.SetEthUpgrades undefined (type "github.com/ethereum/go-ethereum/params".ChainConfig has no field or method SetEthUpgrades)

Check failure on line 87 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (ubuntu-20.04)

config.SetEthUpgrades undefined (type "github.com/ethereum/go-ethereum/params".ChainConfig has no field or method SetEthUpgrades)

Check failure on line 87 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (ubuntu-latest)

config.SetEthUpgrades undefined (type "github.com/ethereum/go-ethereum/params".ChainConfig has no field or method SetEthUpgrades)

Check failure on line 87 in core/genesis_extra_test.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests (windows-latest)

config.SetEthUpgrades undefined (type "github.com/ethereum/go-ethereum/params".ChainConfig has no field or method SetEthUpgrades)
_, _, err = SetupGenesisBlock(db, tdb, &Genesis{Config: &config}, block.Hash(), false)
require.NoError(t, err)
}
1 change: 1 addition & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction, coin
}
env.txs = append(env.txs, tx)
env.receipts = append(env.receipts, receipt)
env.size += tx.Size()
return receipt.Logs, nil
}

Expand Down
6 changes: 0 additions & 6 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ package params

import (
"encoding/json"
"errors"
"fmt"
"math/big"

Expand All @@ -48,8 +47,6 @@ var (
AvalancheFujiChainID = big.NewInt(43113)
// AvalancheLocalChainID ...
AvalancheLocalChainID = big.NewInt(43112)

errNonGenesisForkByHeight = errors.New("coreth only supports forking by height at the genesis block")
)

var (
Expand Down Expand Up @@ -631,9 +628,6 @@ func (c *ChainConfigExtra) CheckConfigForkOrder() error {
func checkForks(forks []fork, blockFork bool) error {
lastFork := fork{}
for _, cur := range forks {
if blockFork && cur.block != nil && common.Big0.Cmp(cur.block) != 0 {
return errNonGenesisForkByHeight
}
if lastFork.name != "" {
switch {
// Non-optional forks must all be present in the chain config up to the last defined fork
Expand Down

0 comments on commit 062dc35

Please sign in to comment.