Skip to content

Commit

Permalink
bring in gethparams.ChainConfig (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Sep 10, 2024
1 parent 7936469 commit cc7d5e6
Show file tree
Hide file tree
Showing 32 changed files with 339 additions and 576 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240909202038-fdd63effd030")
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240910195743-bc476fea4692")
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/precompilebind/precompile_bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ func TestPrecompileBind(t *testing.T) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240909202038-fdd63effd030")
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/go-ethereum@v0.0.0", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/go-ethereum@v0.0.0-20240910195743-bc476fea4692")
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_repair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s
defer db.Close() // Might double close, should be fine

// Initialize a fresh chain
chainConfig := *params.TestChainConfig
chainConfig := params.Copy(params.TestChainConfig)
params.GetExtra(&chainConfig).FeeConfig.MinBaseFee = big.NewInt(1)
var (
require = require.New(t)
Expand Down
14 changes: 10 additions & 4 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ func testRepopulateMissingTriesParallel(t *testing.T, parallelism int) {
// Ensure that key1 has some funds in the genesis block.
genesisBalance := big.NewInt(1000000)
gspec := &Genesis{
Config: &params.ChainConfig{HomesteadBlock: new(big.Int), ChainConfigExtra: params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}},
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
Config: params.WithExtra(
&params.ChainConfig{HomesteadBlock: new(big.Int)},
&params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig},
),
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}

blockchain, err := createBlockChain(chainDB, pruningConfig, gspec, common.Hash{})
Expand Down Expand Up @@ -426,8 +429,11 @@ func TestUngracefulAsyncShutdown(t *testing.T) {
// Ensure that key1 has some funds in the genesis block.
genesisBalance := big.NewInt(1000000)
gspec := &Genesis{
Config: &params.ChainConfig{HomesteadBlock: new(big.Int), ChainConfigExtra: params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig}},
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
Config: params.WithExtra(
&params.ChainConfig{HomesteadBlock: new(big.Int)},
&params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig},
),
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}

blockchain, err := create(chainDB, gspec, common.Hash{})
Expand Down
10 changes: 5 additions & 5 deletions core/gen_genesis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ type Genesis struct {

// field type overrides for gencodec
type genesisSpecMarshaling struct {
Config *ChainConfig
Nonce math.HexOrDecimal64
Timestamp math.HexOrDecimal64
ExtraData hexutil.Bytes
Expand Down
26 changes: 0 additions & 26 deletions core/genesis_libevm.go

This file was deleted.

11 changes: 6 additions & 5 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestSetupGenesis(t *testing.T) {
}

func testSetupGenesis(t *testing.T, scheme string) {
preSubnetConfig := *params.TestPreSubnetEVMChainConfig
preSubnetConfig := params.Copy(params.TestPreSubnetEVMChainConfig)
params.GetExtra(&preSubnetConfig).SubnetEVMTimestamp = utils.NewUint64(100)
var (
customghash = common.HexToHash("0x4a12fe7bf8d40d152d7e9de22337b115186a4662aa3a97217b36146202bbfc66")
Expand All @@ -84,7 +84,7 @@ func testSetupGenesis(t *testing.T, scheme string) {
oldcustomg = customg
)

rollbackpreSubnetConfig := preSubnetConfig
rollbackpreSubnetConfig := params.Copy(&preSubnetConfig)
params.GetExtra(&rollbackpreSubnetConfig).SubnetEVMTimestamp = utils.NewUint64(90)
oldcustomg.Config = &rollbackpreSubnetConfig

Expand Down Expand Up @@ -208,7 +208,7 @@ func TestStatefulPrecompilesConfigure(t *testing.T) {
for name, test := range map[string]test{
"allow list enabled in genesis": {
getConfig: func() *params.ChainConfig {
config := *params.TestChainConfig
config := params.Copy(params.TestChainConfig)
params.GetExtra(&config).GenesisPrecompiles = params.Precompiles{
deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{addr}, nil, nil),
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestPrecompileActivationAfterHeaderBlock(t *testing.T) {
// header must be bigger than last accepted
require.Greater(block.Time, bc.lastAccepted.Time())

activatedGenesisConfig := *customg.Config
activatedGenesisConfig := params.Copy(customg.Config)
contractDeployerConfig := deployerallowlist.NewConfig(utils.NewUint64(51), nil, nil, nil)
params.GetExtra(&activatedGenesisConfig).UpgradeConfig.PrecompileUpgrades = []params.PrecompileUpgrade{
{
Expand All @@ -307,7 +307,7 @@ func TestPrecompileActivationAfterHeaderBlock(t *testing.T) {

func TestGenesisWriteUpgradesRegression(t *testing.T) {
require := require.New(t)
config := *params.TestChainConfig
config := params.Copy(params.TestChainConfig)
genesis := &Genesis{
Config: &config,
Alloc: types.GenesisAlloc{
Expand Down Expand Up @@ -367,6 +367,7 @@ func TestVerkleGenesisCommit(t *testing.T) {
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
CancunTime: &verkleTime,
VerkleTime: &verkleTime,
}
Expand Down
3 changes: 2 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ func ApplyPrecompileActivations(c *params.ChainConfig, parentTimestamp *uint64,
// This ensures that the order we call Configure for each precompile is consistent.
// This ensures even if precompiles read/write state other than their own they will observe
// an identical global state in a deterministic order when they are configured.
extra := params.GetExtra(c)
for _, module := range modules.RegisteredModules() {
for _, activatingConfig := range params.GetExtra(c).GetActivatingPrecompileConfigs(module.Address, parentTimestamp, blockTimestamp, params.GetExtra(c).PrecompileUpgrades) {
for _, activatingConfig := range extra.GetActivatingPrecompileConfigs(module.Address, parentTimestamp, blockTimestamp, extra.PrecompileUpgrades) {
// If this transition activates the upgrade, configure the stateful precompile.
// (or deconfigure it if it is being disabled.)
if activatingConfig.IsDisabled() {
Expand Down
58 changes: 30 additions & 28 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func u64(val uint64) *uint64 { return &val }
// blockchain imports bad blocks, meaning blocks which have valid headers but
// contain invalid transactions
func TestStateProcessorErrors(t *testing.T) {
cpcfg := *params.TestChainConfig
cpcfg := params.Copy(params.TestChainConfig)
config := &cpcfg
config.CancunTime = u64(0)
params.GetExtra(config).FeeConfig.MinBaseFee = big.NewInt(params.TestMaxBaseFee)
Expand Down Expand Up @@ -256,21 +256,21 @@ func TestStateProcessorErrors(t *testing.T) {
var (
db = rawdb.NewMemoryDatabase()
gspec = &Genesis{
Config: &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
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),
ChainConfigExtra: params.ChainConfigExtra{
FeeConfig: params.DefaultFeeConfig,
Config: params.WithExtra(
&params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
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),
},
},
&params.ChainConfigExtra{FeeConfig: params.DefaultFeeConfig},
),
Alloc: types.GenesisAlloc{
common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7"): types.Account{
Balance: big.NewInt(1000000000000000000), // 1 ether
Expand Down Expand Up @@ -353,18 +353,20 @@ func TestBadTxAllowListBlock(t *testing.T) {
db = rawdb.NewMemoryDatabase()
testAddr = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7")

config = &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
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),
ChainConfigExtra: params.ChainConfigExtra{
config = params.WithExtra(
&params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
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),
},
&params.ChainConfigExtra{
FeeConfig: params.DefaultFeeConfig,
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: utils.NewUint64(0),
Expand All @@ -373,7 +375,7 @@ func TestBadTxAllowListBlock(t *testing.T) {
txallowlist.ConfigKey: txallowlist.NewConfig(utils.NewUint64(0), nil, nil, nil),
},
},
}
)
signer = types.LatestSigner(config)
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")

Expand Down
2 changes: 1 addition & 1 deletion core/test_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ func TestStatefulPrecompiles(t *testing.T, create func(db ethdb.Database, gspec

// Ensure that key1 has sufficient funds in the genesis block for all of the tests.
genesisBalance := new(big.Int).Mul(big.NewInt(1000000), big.NewInt(params.Ether))
config := *params.TestChainConfig
config := params.Copy(params.TestChainConfig)
// Set all of the required config parameters
params.GetExtra(&config).GenesisPrecompiles = params.Precompiles{
deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(0), []common.Address{addr1}, nil, nil),
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/blobpool/blobpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var testChainConfig *params.ChainConfig

func init() {
testChainConfig = new(params.ChainConfig)
*testChainConfig = *params.TestChainConfig
*testChainConfig = params.Copy(params.TestChainConfig)
params.GetExtra(testChainConfig).FeeConfig.MinBaseFee = new(big.Int).SetUint64(1)

testChainConfig.CancunTime = new(uint64)
Expand Down
28 changes: 15 additions & 13 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,25 @@ type Config struct {
// sets defaults on the config
func setDefaults(cfg *Config) {
if cfg.ChainConfig == nil {
cfg.ChainConfig = &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: new(big.Int),
EIP150Block: new(big.Int),
EIP155Block: new(big.Int),
EIP158Block: new(big.Int),
ByzantiumBlock: new(big.Int),
ConstantinopleBlock: new(big.Int),
PetersburgBlock: new(big.Int),
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
ChainConfigExtra: params.ChainConfigExtra{
cfg.ChainConfig = params.WithExtra(
&params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: new(big.Int),
EIP150Block: new(big.Int),
EIP155Block: new(big.Int),
EIP158Block: new(big.Int),
ByzantiumBlock: new(big.Int),
ConstantinopleBlock: new(big.Int),
PetersburgBlock: new(big.Int),
IstanbulBlock: new(big.Int),
MuirGlacierBlock: new(big.Int),
},
&params.ChainConfigExtra{
NetworkUpgrades: params.NetworkUpgrades{
SubnetEVMTimestamp: new(uint64),
},
},
}
)
}

if cfg.Difficulty == nil {
Expand Down
2 changes: 1 addition & 1 deletion eth/gasprice/gasprice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func TestSuggestGasPriceAfterFeeConfigUpdate(t *testing.T) {
}

// create a chain config with fee manager enabled at genesis with [addr] as the admin
chainConfig := *params.TestChainConfig
chainConfig := params.Copy(params.TestChainConfig)
params.GetExtra(&chainConfig).GenesisPrecompiles = params.Precompiles{
feemanager.ConfigKey: feemanager.NewConfig(utils.NewUint64(0), []common.Address{addr}, nil, nil, nil),
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func APIs(backend Backend) []rpc.API {
// along with a boolean that indicates whether the copy is canonical (equivalent to the original).
func overrideConfig(original *params.ChainConfig, override *params.ChainConfig) (*params.ChainConfig, bool) {
copy := new(params.ChainConfig)
*copy = *original
*copy = params.Copy(original)
canon := true

if timestamp := params.GetExtra(override).SubnetEVMTimestamp; timestamp != nil {
Expand Down
8 changes: 4 additions & 4 deletions eth/tracers/api_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestTraceBlockPrecompileActivation(t *testing.T) {

// Initialize test accounts
accounts := newAccounts(3)
copyConfig := *params.TestChainConfig
copyConfig := params.Copy(params.TestChainConfig)
genesis := &core.Genesis{
Config: &copyConfig,
Alloc: types.GenesisAlloc{
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestTraceTransactionPrecompileActivation(t *testing.T) {

// Initialize test accounts
accounts := newAccounts(3)
copyConfig := *params.TestChainConfig
copyConfig := params.Copy(params.TestChainConfig)
genesis := &core.Genesis{
Config: &copyConfig,
Alloc: types.GenesisAlloc{
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestTraceChainPrecompileActivation(t *testing.T) {
// Initialize test accounts
// Note: the balances in this test have been increased compared to go-ethereum.
accounts := newAccounts(3)
copyConfig := *params.TestChainConfig
copyConfig := params.Copy(params.TestChainConfig)
genesis := &core.Genesis{
Config: &copyConfig,
Alloc: types.GenesisAlloc{
Expand Down Expand Up @@ -297,7 +297,7 @@ func TestTraceCallWithOverridesStateUpgrade(t *testing.T) {

// Initialize test accounts
accounts := newAccounts(3)
copyConfig := *params.TestChainConfig
copyConfig := params.Copy(params.TestChainConfig)
genesis := &core.Genesis{
Config: &copyConfig,
Alloc: types.GenesisAlloc{
Expand Down
Loading

0 comments on commit cc7d5e6

Please sign in to comment.