diff --git a/params/config_test.go b/params/config_test.go index 707cf89f9d..b5998ebab8 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -24,7 +24,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . -package params +package params_test import ( "encoding/json" @@ -40,6 +40,8 @@ import ( "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + + . "github.com/ava-labs/subnet-evm/params" ) func TestCheckCompatible(t *testing.T) { diff --git a/params/precompile_config_test.go b/params/precompile_config_test.go index 4e2c287241..f66a40742c 100644 --- a/params/precompile_config_test.go +++ b/params/precompile_config_test.go @@ -1,7 +1,7 @@ // (c) 2022 Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package params +package params_test import ( "encoding/json" @@ -17,6 +17,8 @@ import ( "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + + . "github.com/ava-labs/subnet-evm/params" ) func TestVerifyWithChainConfig(t *testing.T) { @@ -270,17 +272,19 @@ func TestGetPrecompileConfig(t *testing.T) { deployerallowlist.ConfigKey: deployerallowlist.NewConfig(utils.NewUint64(10), nil, nil, nil), } - deployerConfig := config.getActivePrecompileConfig(deployerallowlist.ContractAddress, 0) - require.Nil(deployerConfig) + configs := config.GetActivatingPrecompileConfigs(deployerallowlist.ContractAddress, nil, 0, config.PrecompileUpgrades) + require.Len(configs, 0) - deployerConfig = config.getActivePrecompileConfig(deployerallowlist.ContractAddress, 10) - require.NotNil(deployerConfig) + configs = config.GetActivatingPrecompileConfigs(deployerallowlist.ContractAddress, nil, 10, config.PrecompileUpgrades) + require.GreaterOrEqual(len(configs), 1) + require.NotNil(configs[len(configs)-1]) - deployerConfig = config.getActivePrecompileConfig(deployerallowlist.ContractAddress, 11) - require.NotNil(deployerConfig) + configs = config.GetActivatingPrecompileConfigs(deployerallowlist.ContractAddress, nil, 11, config.PrecompileUpgrades) + require.GreaterOrEqual(len(configs), 1) + require.NotNil(configs[len(configs)-1]) - txAllowListConfig := config.getActivePrecompileConfig(txallowlist.ContractAddress, 0) - require.Nil(txAllowListConfig) + txAllowListConfig := config.GetActivatingPrecompileConfigs(txallowlist.ContractAddress, nil, 0, config.PrecompileUpgrades) + require.Len(txAllowListConfig, 0) } func TestPrecompileUpgradeUnmarshalJSON(t *testing.T) { diff --git a/params/precompile_upgrade_test.go b/params/precompile_upgrade_test.go index 8384ef4279..5c21b08534 100644 --- a/params/precompile_upgrade_test.go +++ b/params/precompile_upgrade_test.go @@ -1,7 +1,7 @@ // (c) 2022, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package params +package params_test import ( "testing" @@ -11,6 +11,8 @@ import ( "github.com/ava-labs/subnet-evm/utils" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" + + . "github.com/ava-labs/subnet-evm/params" ) func TestVerifyUpgradeConfig(t *testing.T) { @@ -279,7 +281,7 @@ func (tt *upgradeCompatibilityTest) run(t *testing.T, chainConfig ChainConfig) { newCfg := chainConfig newCfg.UpgradeConfig = *upgrade - err := chainConfig.checkCompatible(&newCfg, nil, tt.startTimestamps[i]) + err := chainConfig.CheckCompatible(&newCfg, 0, tt.startTimestamps[i]) // if this is not the final upgradeBytes, continue applying // the next upgradeBytes. (only check the result on the last apply) diff --git a/params/state_upgrade_test.go b/params/state_upgrade_test.go index 6ee4094fc0..da4361d3cb 100644 --- a/params/state_upgrade_test.go +++ b/params/state_upgrade_test.go @@ -1,7 +1,7 @@ // (c) 2022, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package params +package params_test import ( "encoding/json" @@ -12,6 +12,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/stretchr/testify/require" + + . "github.com/ava-labs/subnet-evm/params" ) func TestVerifyStateUpgrades(t *testing.T) { diff --git a/precompile/contract/contract.go b/precompile/contract/contract.go index 0be76a8955..bab3a943a0 100644 --- a/precompile/contract/contract.go +++ b/precompile/contract/contract.go @@ -6,9 +6,27 @@ package contract import ( "fmt" + "github.com/ava-labs/subnet-evm/core/types" + "github.com/ava-labs/subnet-evm/precompile/interfaces" "github.com/ethereum/go-ethereum/common" ) +// Guarantee that we don't have a circular dependency if importing types here. +var _ *types.Transaction = nil + +// Temporary type aliases for proof-of-concept only. This allows all other code +// to work as expected, requiring only the `modules` package to change to a +// direct dependency on `interfaces`. As seen above, this allows importing +// of `types`. +type ( + StatefulPrecompiledContract = interfaces.StatefulPrecompiledContract + StateDB = interfaces.StateDB + AccessibleState = interfaces.AccessibleState + ConfigurationBlockContext = interfaces.ConfigurationBlockContext + Configurator = interfaces.Configurator + BlockContext = interfaces.BlockContext +) + const ( SelectorLen = 4 ) diff --git a/precompile/contract/interfaces.go b/precompile/interfaces/interfaces.go similarity index 92% rename from precompile/contract/interfaces.go rename to precompile/interfaces/interfaces.go index 5ac6baa486..54310aa006 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/interfaces/interfaces.go @@ -1,8 +1,9 @@ -// (c) 2023, Ava Labs, Inc. All rights reserved. +// (c) 2023-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -// Defines the interface for the configuration and execution of a precompile contract -package contract +// Package interfaces defines the interfaces used in building and running +// stateful precompiles. +package interfaces import ( "math/big" diff --git a/precompile/modules/module.go b/precompile/modules/module.go index d0a047c94d..445b61707f 100644 --- a/precompile/modules/module.go +++ b/precompile/modules/module.go @@ -6,7 +6,7 @@ package modules import ( "bytes" - "github.com/ava-labs/subnet-evm/precompile/contract" + "github.com/ava-labs/subnet-evm/precompile/interfaces" "github.com/ethereum/go-ethereum/common" ) @@ -17,9 +17,9 @@ type Module struct { Address common.Address // Contract returns a thread-safe singleton that can be used as the StatefulPrecompiledContract when // this config is enabled. - Contract contract.StatefulPrecompiledContract + Contract interfaces.StatefulPrecompiledContract // Configurator is used to configure the stateful precompile when the config is enabled. - contract.Configurator + interfaces.Configurator } type moduleArray []Module