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

libevm renaming nits #683

Merged
merged 2 commits into from
Nov 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
go mod edit -replace github.com/ava-labs/avalanchego=./avalanchego
go mod tidy
go clean -modcache # avoid conflicts with the golangci-lint-action cache
- run: ./scripts/lint_allowed_geth_imports.sh
- run: ./scripts/lint_allowed_eth_imports.sh
shell: bash
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/predicate"
"github.com/ava-labs/libevm/common"
gethtypes "github.com/ava-labs/libevm/core/types"
ethtypes "github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/core/vm"
"github.com/ava-labs/libevm/log"
"github.com/holiman/uint256"
Expand Down Expand Up @@ -165,7 +165,7 @@ func newEVMBlockContext(header *types.Header, chain ChainContext, author *common
BaseFee: baseFee,
BlobBaseFee: blobBaseFee,
GasLimit: header.GasLimit,
Header: &gethtypes.Header{
Header: &ethtypes.Header{
Number: new(big.Int).Set(header.Number),
Time: header.Time,
Extra: extra,
Expand Down
2 changes: 1 addition & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
}

//go:generate go run github.com/fjl/gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
//go:generate go run github.com/ethereum/go-ethereum/rlp/rlpgen -type Header -out gen_header_rlp.go
//go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type Header -out gen_header_rlp.go

// Header represents a block header in the Ethereum blockchain.
type Header struct {
Expand Down
94 changes: 47 additions & 47 deletions core/types/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,73 @@
package types

import (
gethtypes "github.com/ava-labs/libevm/core/types"
ethtypes "github.com/ava-labs/libevm/core/types"
)

// The following types are used directly as their upstream definitions.
// So we list them all here to avoid having many individual files.
type (
AccessList = gethtypes.AccessList
AccessTuple = gethtypes.AccessTuple
AccessListTx = gethtypes.AccessListTx
Bloom = gethtypes.Bloom
Receipt = gethtypes.Receipt
Receipts = gethtypes.Receipts
ReceiptForStorage = gethtypes.ReceiptForStorage
LegacyTx = gethtypes.LegacyTx
DynamicFeeTx = gethtypes.DynamicFeeTx
BlobTx = gethtypes.BlobTx
BlobTxSidecar = gethtypes.BlobTxSidecar
Signer = gethtypes.Signer
HomesteadSigner = gethtypes.HomesteadSigner
AccessList = ethtypes.AccessList
AccessTuple = ethtypes.AccessTuple
AccessListTx = ethtypes.AccessListTx
Bloom = ethtypes.Bloom
Receipt = ethtypes.Receipt
Receipts = ethtypes.Receipts
ReceiptForStorage = ethtypes.ReceiptForStorage
LegacyTx = ethtypes.LegacyTx
DynamicFeeTx = ethtypes.DynamicFeeTx
BlobTx = ethtypes.BlobTx
BlobTxSidecar = ethtypes.BlobTxSidecar
Signer = ethtypes.Signer
HomesteadSigner = ethtypes.HomesteadSigner

Transaction = gethtypes.Transaction
Transactions = gethtypes.Transactions
TxByNonce = gethtypes.TxByNonce
TxData = gethtypes.TxData
Transaction = ethtypes.Transaction
Transactions = ethtypes.Transactions
TxByNonce = ethtypes.TxByNonce
TxData = ethtypes.TxData
)

// The following constants are used directly as their upstream definitions.
const (
BloomBitLength = gethtypes.BloomBitLength
BloomByteLength = gethtypes.BloomByteLength
ReceiptStatusFailed = gethtypes.ReceiptStatusFailed
ReceiptStatusSuccessful = gethtypes.ReceiptStatusSuccessful
BloomBitLength = ethtypes.BloomBitLength
BloomByteLength = ethtypes.BloomByteLength
ReceiptStatusFailed = ethtypes.ReceiptStatusFailed
ReceiptStatusSuccessful = ethtypes.ReceiptStatusSuccessful

// Transaction types.
LegacyTxType = gethtypes.LegacyTxType
AccessListTxType = gethtypes.AccessListTxType
DynamicFeeTxType = gethtypes.DynamicFeeTxType
BlobTxType = gethtypes.BlobTxType
LegacyTxType = ethtypes.LegacyTxType
AccessListTxType = ethtypes.AccessListTxType
DynamicFeeTxType = ethtypes.DynamicFeeTxType
BlobTxType = ethtypes.BlobTxType
)

// The following functions are used directly as their upstream definitions.
var (
BloomLookup = gethtypes.BloomLookup
BytesToBloom = gethtypes.BytesToBloom
CreateBloom = gethtypes.CreateBloom
NewReceipt = gethtypes.NewReceipt
NewContractCreation = gethtypes.NewContractCreation
NewTransaction = gethtypes.NewTransaction
BloomLookup = ethtypes.BloomLookup
BytesToBloom = ethtypes.BytesToBloom
CreateBloom = ethtypes.CreateBloom
NewReceipt = ethtypes.NewReceipt
NewContractCreation = ethtypes.NewContractCreation
NewTransaction = ethtypes.NewTransaction

// Signers
NewEIP155Signer = gethtypes.NewEIP155Signer
NewEIP2930Signer = gethtypes.NewEIP2930Signer
NewLondonSigner = gethtypes.NewLondonSigner
NewCancunSigner = gethtypes.NewCancunSigner
MakeSigner = gethtypes.MakeSigner
LatestSigner = gethtypes.LatestSigner
LatestSignerForChainID = gethtypes.LatestSignerForChainID
SignTx = gethtypes.SignTx
SignNewTx = gethtypes.SignNewTx
MustSignNewTx = gethtypes.MustSignNewTx
Sender = gethtypes.Sender
NewEIP155Signer = ethtypes.NewEIP155Signer
NewEIP2930Signer = ethtypes.NewEIP2930Signer
NewLondonSigner = ethtypes.NewLondonSigner
NewCancunSigner = ethtypes.NewCancunSigner
MakeSigner = ethtypes.MakeSigner
LatestSigner = ethtypes.LatestSigner
LatestSignerForChainID = ethtypes.LatestSignerForChainID
SignTx = ethtypes.SignTx
SignNewTx = ethtypes.SignNewTx
MustSignNewTx = ethtypes.MustSignNewTx
Sender = ethtypes.Sender

// Transactions
NewTx = gethtypes.NewTx
TxDifference = gethtypes.TxDifference
NewTx = ethtypes.NewTx
TxDifference = ethtypes.TxDifference

// Errors
ErrTxTypeNotSupported = gethtypes.ErrTxTypeNotSupported
ErrGasFeeCapTooLow = gethtypes.ErrGasFeeCapTooLow
ErrTxTypeNotSupported = ethtypes.ErrTxTypeNotSupported
ErrGasFeeCapTooLow = ethtypes.ErrGasFeeCapTooLow
)
4 changes: 2 additions & 2 deletions core/types/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

package types

import gethtypes "github.com/ava-labs/libevm/core/types"
import ethtypes "github.com/ava-labs/libevm/core/types"

// Log represents a contract log event. These events are generated by the LOG opcode and
// stored/indexed by the node.
type Log = gethtypes.Log
type Log = ethtypes.Log

// FlattenLogs converts a nested array of logs to a single array of logs.
func FlattenLogs(list [][]*Log) []*Log {
Expand Down
2 changes: 1 addition & 1 deletion core/types/state_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/holiman/uint256"
)

//go:generate go run github.com/ethereum/go-ethereum/rlp/rlpgen -type StateAccount -out gen_account_rlp.go
//go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type StateAccount -out gen_account_rlp.go

// StateAccount is the Ethereum consensus representation of accounts.
// These objects are stored in the main account trie.
Expand Down
8 changes: 4 additions & 4 deletions eth/tracers/tracers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ import (
"fmt"

"github.com/ava-labs/libevm/core/vm"
gethtracers "github.com/ava-labs/libevm/eth/tracers"
ethtracers "github.com/ava-labs/libevm/eth/tracers"
)

// Context contains some contextual infos for a transaction execution that is not
// available from within the EVM object.
type Context = gethtracers.Context
type Context = ethtracers.Context

// Tracer interface extends vm.EVMLogger and additionally
// allows collecting the tracing result.
type Tracer = gethtracers.Tracer
type Tracer = ethtracers.Tracer

// DefaultDirectory is the collection of tracers bundled by default.
var DefaultDirectory = gethtracers.DefaultDirectory
var DefaultDirectory = ethtracers.DefaultDirectory

const (
memoryPadLimit = 1024 * 1024
Expand Down
4 changes: 2 additions & 2 deletions nativeasset/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/vmerrs"
"github.com/ava-labs/libevm/common"
gethtypes "github.com/ava-labs/libevm/core/types"
ethtypes "github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/core/vm"
"github.com/holiman/uint256"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestStatefulPrecompile(t *testing.T) {
Time: 0,
CanTransfer: CanTransfer,
Transfer: Transfer,
Header: &gethtypes.Header{
Header: &ethtypes.Header{
Number: big.NewInt(0),
},
}
Expand Down
6 changes: 3 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/coreth/utils"
gethparams "github.com/ava-labs/libevm/params"
ethparams "github.com/ava-labs/libevm/params"
)

// Avalanche ChainIDs
Expand Down Expand Up @@ -547,11 +547,11 @@ var (
// ChainConfig is stored in the database on a per block basis. This means
// that any network, identified by its genesis block, can have its own
// set of configuration options.
type ChainConfig = gethparams.ChainConfig
type ChainConfig = ethparams.ChainConfig

// Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions
// that do not have or require information about the block.
//
// Rules is a one time interface meaning that it shouldn't be used in between transition
// phases.
type Rules = gethparams.Rules
type Rules = ethparams.Rules
4 changes: 2 additions & 2 deletions params/config_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/ava-labs/avalanchego/upgrade"
"github.com/ava-labs/coreth/utils"
"github.com/ava-labs/libevm/common"
gethparams "github.com/ava-labs/libevm/params"
ethparams "github.com/ava-labs/libevm/params"
)

const (
Expand Down Expand Up @@ -236,7 +236,7 @@ func configTimestampEqual(x, y *uint64) bool {

// ConfigCompatError is raised if the locally-stored blockchain is initialised with a
// ChainConfig that would alter the past.
type ConfigCompatError = gethparams.ConfigCompatError
type ConfigCompatError = ethparams.ConfigCompatError

func newTimestampCompatError(what string, storedtime, newtime *uint64) *ConfigCompatError {
var rew *uint64
Expand Down
8 changes: 4 additions & 4 deletions params/config_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import (
"github.com/ava-labs/coreth/precompile/modules"
"github.com/ava-labs/coreth/precompile/precompileconfig"
"github.com/ava-labs/libevm/common"
gethparams "github.com/ava-labs/libevm/params"
ethparams "github.com/ava-labs/libevm/params"
)

// libevmInit would ideally be a regular init() function, but it MUST be run
// before any calls to [ChainConfig.Rules]. See `config.go` for its call site.
func libevmInit() any {
extras = gethparams.RegisterExtras(gethparams.Extras[*ChainConfigExtra, RulesExtra]{
extras = ethparams.RegisterExtras(ethparams.Extras[*ChainConfigExtra, RulesExtra]{
ReuseJSONRoot: true, // Reuse the root JSON input when unmarshalling the extra payload.
NewRules: constructRulesExtra,
})
return nil
}

var extras gethparams.ExtraPayloads[*ChainConfigExtra, RulesExtra]
var extras ethparams.ExtraPayloads[*ChainConfigExtra, RulesExtra]

// constructRulesExtra acts as an adjunct to the [params.ChainConfig.Rules]
// method. Its primary purpose is to construct the extra payload for the
// [params.Rules] but it MAY also modify the [params.Rules].
func constructRulesExtra(c *gethparams.ChainConfig, r *gethparams.Rules, cEx *ChainConfigExtra, blockNum *big.Int, isMerge bool, timestamp uint64) RulesExtra {
func constructRulesExtra(c *ethparams.ChainConfig, r *ethparams.Rules, cEx *ChainConfigExtra, blockNum *big.Int, isMerge bool, timestamp uint64) RulesExtra {
var rules RulesExtra
if cEx == nil {
return rules
Expand Down
8 changes: 4 additions & 4 deletions plugin/evm/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"strings"

"github.com/ava-labs/coreth/log"
gethlog "github.com/ava-labs/libevm/log"
ethlog "github.com/ava-labs/libevm/log"
"golang.org/x/exp/slog"
)

type CorethLogger struct {
gethlog.Logger
ethlog.Logger

logLevel *slog.LevelVar
}
Expand Down Expand Up @@ -47,14 +47,14 @@ func InitLogger(alias string, level string, jsonFormat bool, writer io.Writer) (

// Create handler
c := CorethLogger{
Logger: gethlog.NewLogger(handler),
Logger: ethlog.NewLogger(handler),
logLevel: logLevel,
}

if err := c.SetLogLevel(level); err != nil {
return CorethLogger{}, err
}
gethlog.SetDefault(c.Logger)
ethlog.SetDefault(c.Logger)
return c, nil
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/prestate_tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/ava-labs/coreth/tests"
"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/common/math"
gethtypes "github.com/ava-labs/libevm/core/types"
ethtypes "github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/core/vm"
)

Expand Down Expand Up @@ -67,7 +67,7 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
Difficulty: (*big.Int)(test.Context.Difficulty),
GasLimit: uint64(test.Context.GasLimit),
BaseFee: test.Genesis.BaseFee,
Header: &gethtypes.Header{
Header: &ethtypes.Header{
Number: new(big.Int).SetUint64(uint64(test.Context.Number)),
Time: uint64(test.Context.Time),
},
Expand Down
4 changes: 2 additions & 2 deletions precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/coreth/precompile/precompileconfig"
"github.com/ava-labs/libevm/common"
gethtypes "github.com/ava-labs/libevm/core/types"
ethtypes "github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/core/vm"
"github.com/holiman/uint256"
)

type Log = gethtypes.Log
type Log = ethtypes.Log

// StatefulPrecompiledContract is the interface for executing a precompiled contract
type StatefulPrecompiledContract interface {
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions scripts/lint_allowed_eth_imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

# Ensure that there are no eth imports that are not marked as explicitly allowed via ./scripts/eth-allowed-packages.txt
# 1. Recursively search through all go files for any lines that include a direct import from go-ethereum
# 2. Ignore lines that import libevm with a named import starting with "eth"
# 3. Sort the unique results
# 4. Print out the difference between the search results and the list of specified allowed package imports from libevm.
libevm_regexp='"github.com/ava-labs/libevm/.*"'
allow_named_imports='eth\w\+ "'
extra_imports=$(grep -r --include='*.go' --exclude=mocks.go "${libevm_regexp}" -h | grep -v "${allow_named_imports}" | grep -o "${libevm_regexp}" | sort -u | comm -23 - ./scripts/eth-allowed-packages.txt)
if [ -n "${extra_imports}" ]; then
echo "new ethereum imports should be added to ./scripts/eth-allowed-packages.txt to prevent accidental imports:"
echo "${extra_imports}"
exit 1
fi
19 changes: 0 additions & 19 deletions scripts/lint_allowed_geth_imports.sh

This file was deleted.

Loading