Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: allow types to be imported by precompile/contract #1271

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.

package params
package params_test

import (
"encoding/json"
Expand All @@ -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) {
Expand Down
22 changes: 13 additions & 9 deletions params/precompile_config_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions params/precompile_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion params/state_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions precompile/contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions precompile/modules/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down
Loading