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

use libevm: params, core/vm, eth/tracers/* + some of core/types #662

Open
wants to merge 27 commits into
base: libevm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (

"github.com/ava-labs/coreth/accounts/abi"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/interfaces"
"github.com/ava-labs/coreth/nativeasset"
"github.com/ava-labs/coreth/rpc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -308,14 +308,14 @@ func wrapNativeAssetCall(opts *TransactOpts, contract *common.Address, input []b
return nil, nil, errNativeAssetDeployContract
}
// wrap input with native asset call params
input = vm.PackNativeAssetCallInput(
input = nativeasset.PackNativeAssetCallInput(
*contract,
opts.NativeAssetCall.AssetID,
opts.NativeAssetCall.AssetAmount,
input,
)
// target addr is now precompile
contract = &vm.NativeAssetCallAddr
contract = &nativeasset.NativeAssetCallAddr
}
return contract, input, nil
}
Expand Down
6 changes: 3 additions & 3 deletions accounts/abi/bind/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
"github.com/ava-labs/coreth/accounts/abi"
"github.com/ava-labs/coreth/accounts/abi/bind"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/interfaces"
"github.com/ava-labs/coreth/nativeasset"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -404,8 +404,8 @@ func TestTransactNativeAssetCall(t *testing.T) {
nativeCallTx, err := bc.Transact(opts, methodName, arg1, arg2)
assert.Nil(err)
// verify transformations
assert.Equal(vm.NativeAssetCallAddr, *nativeCallTx.To())
unpackedAddr, unpackedAssetID, unpackedAssetAmount, unpackedData, err := vm.UnpackNativeAssetCallInput(nativeCallTx.Data())
assert.Equal(nativeasset.NativeAssetCallAddr, *nativeCallTx.To())
unpackedAddr, unpackedAssetID, unpackedAssetAmount, unpackedData, err := nativeasset.UnpackNativeAssetCallInput(nativeCallTx.Data())
assert.Nil(err)
assert.NotEmpty(unpackedData)
assert.Equal(unpackedData, normalCallTx.Data())
Expand Down
5 changes: 5 additions & 0 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,11 @@ 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/[email protected]", "-replace", "github.com/ethereum/go-ethereum=github.com/ava-labs/[email protected]")
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)
}
tidier := exec.Command(gocmd, "mod", "tidy", "-compat=1.22")
tidier.Dir = pkg
if out, err := tidier.CombinedOutput(); err != nil {
Expand Down
30 changes: 17 additions & 13 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func NewFullFaker() *DummyEngine {
}

func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header *types.Header, parent *types.Header) error {
configExtra := params.GetExtra(config)
// Verify that the gas limit is <= 2^63-1
if header.GasLimit > params.MaxGasLimit {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
Expand All @@ -119,11 +120,11 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
if header.GasUsed > header.GasLimit {
return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit)
}
if config.IsCortina(header.Time) {
if configExtra.IsCortina(header.Time) {
if header.GasLimit != params.CortinaGasLimit {
return fmt.Errorf("expected gas limit to be %d in Cortina, but found %d", params.CortinaGasLimit, header.GasLimit)
}
} else if config.IsApricotPhase1(header.Time) {
} else if configExtra.IsApricotPhase1(header.Time) {
if header.GasLimit != params.ApricotPhase1GasLimit {
return fmt.Errorf("expected gas limit to be %d in ApricotPhase1, but found %d", params.ApricotPhase1GasLimit, header.GasLimit)
}
Expand All @@ -140,7 +141,7 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
}
}

if !config.IsApricotPhase3(header.Time) {
if !configExtra.IsApricotPhase3(header.Time) {
// Verify BaseFee is not present before AP3
if header.BaseFee != nil {
return fmt.Errorf("invalid baseFee before fork: have %d, want <nil>", header.BaseFee)
Expand All @@ -167,7 +168,7 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
}

// Verify BlockGasCost, ExtDataGasUsed not present before AP4
if !config.IsApricotPhase4(header.Time) {
if !configExtra.IsApricotPhase4(header.Time) {
if header.BlockGasCost != nil {
return fmt.Errorf("invalid blockGasCost before fork: have %d, want <nil>", header.BlockGasCost)
}
Expand All @@ -179,7 +180,7 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header

// Enforce BlockGasCost constraints
blockGasCostStep := ApricotPhase4BlockGasCostStep
if config.IsApricotPhase5(header.Time) {
if configExtra.IsApricotPhase5(header.Time) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
expectedBlockGasCost := calcBlockGasCost(
Expand Down Expand Up @@ -213,16 +214,17 @@ func (eng *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, header
// modified from consensus.go
func (eng *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *types.Header, parent *types.Header, uncle bool) error {
config := chain.Config()
configExtra := params.GetExtra(config)
// Ensure that we do not verify an uncle
if uncle {
return errUnclesUnsupported
}
switch {
case config.IsDurango(header.Time):
case configExtra.IsDurango(header.Time):
if len(header.Extra) < params.DynamicFeeExtraDataSize {
return fmt.Errorf("expected extra-data field length >= %d, found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
}
case config.IsApricotPhase3(header.Time):
case configExtra.IsApricotPhase3(header.Time):
if len(header.Extra) != params.DynamicFeeExtraDataSize {
return fmt.Errorf("expected extra-data field to be: %d, but found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
}
Expand Down Expand Up @@ -392,7 +394,8 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
return err
}
}
if chain.Config().IsApricotPhase4(block.Time()) {
configExtra := params.GetExtra(chain.Config())
if configExtra.IsApricotPhase4(block.Time()) {
// Validate extDataGasUsed and BlockGasCost match expectations
//
// NOTE: This is a duplicate check of what is already performed in
Expand All @@ -404,11 +407,11 @@ func (eng *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *types
return fmt.Errorf("invalid extDataGasUsed: have %d, want %d", blockExtDataGasUsed, extDataGasUsed)
}
blockGasCostStep := ApricotPhase4BlockGasCostStep
if chain.Config().IsApricotPhase5(block.Time()) {
if configExtra.IsApricotPhase5(block.Time()) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
// Calculate the expected blockGasCost for this block.
// Note: this is a deterministic transtion that defines an exact block fee for this block.
// Note: this is a deterministic transition that defines an exact block fee for this block.
blockGasCost := calcBlockGasCost(
ApricotPhase4TargetBlockRate,
ApricotPhase4MinBlockGasCost,
Expand Down Expand Up @@ -450,13 +453,14 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
return nil, err
}
}
if chain.Config().IsApricotPhase4(header.Time) {
chainConfigExtra := params.GetExtra(chain.Config())
if chainConfigExtra.IsApricotPhase4(header.Time) {
header.ExtDataGasUsed = extDataGasUsed
if header.ExtDataGasUsed == nil {
header.ExtDataGasUsed = new(big.Int).Set(common.Big0)
}
blockGasCostStep := ApricotPhase4BlockGasCostStep
if chain.Config().IsApricotPhase5(header.Time) {
if chainConfigExtra.IsApricotPhase5(header.Time) {
blockGasCostStep = ApricotPhase5BlockGasCostStep
}
// Calculate the required block gas cost for this block.
Expand Down Expand Up @@ -485,7 +489,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
// Header seems complete, assemble into a block and return
return types.NewBlockWithExtData(
header, txs, uncles, receipts, trie.NewStackTrie(nil),
extraData, chain.Config().IsApricotPhase1(header.Time),
extraData, chainConfigExtra.IsApricotPhase1(header.Time),
), nil
}

Expand Down
11 changes: 6 additions & 5 deletions consensus/dummy/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, timestamp uin
// If the current block is the first EIP-1559 block, or it is the genesis block
// return the initial slice and initial base fee.
var (
isApricotPhase3 = config.IsApricotPhase3(parent.Time)
isApricotPhase4 = config.IsApricotPhase4(parent.Time)
isApricotPhase5 = config.IsApricotPhase5(parent.Time)
isEtna = config.IsEtna(parent.Time)
configExtra = params.GetExtra(config)
isApricotPhase3 = configExtra.IsApricotPhase3(parent.Time)
isApricotPhase4 = configExtra.IsApricotPhase4(parent.Time)
isApricotPhase5 = configExtra.IsApricotPhase5(parent.Time)
isEtna = configExtra.IsEtna(parent.Time)
)
if !isApricotPhase3 || parent.Number.Cmp(common.Big0) == 0 {
initialSlice := make([]byte, params.DynamicFeeExtraDataSize)
Expand Down Expand Up @@ -332,7 +333,7 @@ func calcBlockGasCost(
//
// This function will return nil for all return values prior to Apricot Phase 4.
func MinRequiredTip(config *params.ChainConfig, header *types.Header) (*big.Int, error) {
if !config.IsApricotPhase4(header.Time) {
if !params.GetExtra(config).IsApricotPhase4(header.Time) {
return nil, nil
}
if header.BaseFee == nil {
Expand Down
2 changes: 1 addition & 1 deletion core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
)
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/state/snapshot"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/internal/version"
"github.com/ava-labs/coreth/metrics"
"github.com/ava-labs/coreth/params"
Expand All @@ -55,6 +54,7 @@ import (
"github.com/ava-labs/coreth/triedb/pathdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/state/snapshot"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/triedb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/event"
)

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 @@ -37,10 +37,10 @@ import (
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/triedb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import (
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
)

Expand Down
18 changes: 12 additions & 6 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/state/pruner"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/eth/tracers/logger"
"github.com/ava-labs/coreth/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/holiman/uint256"
)
Expand Down Expand Up @@ -310,8 +310,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)},
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
Config: params.WithExtra(
&params.ChainConfig{HomesteadBlock: new(big.Int)},
&params.ChainConfigExtra{},
),
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}

blockchain, err := createBlockChain(chainDB, pruningConfig, gspec, common.Hash{})
Expand Down Expand Up @@ -423,8 +426,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)},
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
Config: params.WithExtra(
&params.ChainConfig{HomesteadBlock: new(big.Int)},
&params.ChainConfigExtra{},
),
Alloc: types.GenesisAlloc{addr1: {Balance: genesisBalance}},
}

blockchain, err := create(chainDB, gspec, common.Hash{})
Expand Down
9 changes: 5 additions & 4 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/state"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/triedb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/holiman/uint256"
)
Expand Down Expand Up @@ -374,9 +374,10 @@ func (cm *chainMaker) makeHeader(parent *types.Block, gap uint64, state *state.S
time := parent.Time() + gap // block time is fixed at [gap] seconds

var gasLimit uint64
if cm.config.IsCortina(time) {
configExtra := params.GetExtra(cm.config)
if configExtra.IsCortina(time) {
gasLimit = params.CortinaGasLimit
} else if cm.config.IsApricotPhase1(time) {
} else if configExtra.IsApricotPhase1(time) {
gasLimit = params.ApricotPhase1GasLimit
} else {
gasLimit = CalcGasLimit(parent.GasUsed(), parent.GasLimit(), parent.GasLimit(), parent.GasLimit())
Expand All @@ -391,7 +392,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, gap uint64, state *state.S
Number: new(big.Int).Add(parent.Number(), common.Big1),
Time: time,
}
if cm.config.IsApricotPhase3(time) {
if configExtra.IsApricotPhase3(time) {
var err error
header.Extra, header.BaseFee, err = dummy.CalcBaseFee(cm.config, parent.Header(), time)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import (
"github.com/ava-labs/coreth/consensus/dummy"
"github.com/ava-labs/coreth/core/rawdb"
"github.com/ava-labs/coreth/core/types"
"github.com/ava-labs/coreth/core/vm"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/triedb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
)

Expand Down
Loading
Loading