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

[WIP] core/vm: improve EVM reusability #676

Open
wants to merge 93 commits into
base: dev-upgrade
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
67fa774
eth: fix typo balacne
gzliudan Aug 7, 2024
4fb49d4
core/types: drop type v4StoredReceiptRLP
gzliudan Jun 25, 2024
ed579d2
core/types: replace core.SetReceiptsData with receipts.DeriveFields
gzliudan Jun 26, 2024
40ef9d5
core/vm: make gas cost reporting to tracers correct (#22702)
holiman Apr 27, 2021
eca6f9e
core, params: implement EIP-3529 (#22733)
gzliudan Aug 22, 2024
1bf3813
all: implement eip-1559 (#22837)
gzliudan Apr 25, 2024
69916b3
core: fix failing tests (#22888)
gzliudan May 28, 2024
58c5020
EIP-1559: miner changes (#22896)
gzliudan Apr 26, 2024
9dc1eaf
core: make txpool free space calculation more accurate (#22933)
gzliudan May 16, 2024
47948b0
EIP-1559 tx pool support (#22898)
gzliudan May 17, 2024
b775a34
core: add new eip-1559 tx constraints (#22970)
gzliudan May 17, 2024
3341a30
core, eth, internal, les: RPC methods and fields for EIP 1559 (#22964)
gzliudan May 21, 2024
649e59d
params: print right Eip1559Block for ChainConfig
gzliudan May 22, 2024
05e91f6
core, eth, miner: enforce configured mining reward post 1559 too (#22…
gzliudan May 23, 2024
8328615
all: rename internal 1559 gas fields (#23010)
gzliudan May 24, 2024
5470ef8
internal/ethapi: support for eip-1559 txs in clef (#22966)
gzliudan May 24, 2024
4f371fb
core, internal: support various eth_call invocations post 1559 (#23027)
gzliudan May 24, 2024
48f6ad2
core/vm: evm fix panic (#23047)
gzliudan Sep 19, 2024
77a6998
core/vm/runtime: add function TestColdAccountAccessCost
gzliudan Oct 18, 2024
4382dfb
Access list state test format (#22290)
gzliudan May 24, 2024
4b5b18d
accounts/abi/bind: add NoSend transact option (#22446)
reds Mar 19, 2021
0921351
tests: update for London (#22976)
gzliudan May 24, 2024
869c66a
core: make genesis parse baseFee correctly (#23013)
gzliudan May 24, 2024
93ab759
core: change baseFee into baseFeePerGas in genesis json (#23039)
gzliudan May 24, 2024
6a03341
accounts/abi/bind: fix bounded contracts and sim backend for 1559 (#2…
gzliudan May 27, 2024
03a8746
core, internal: expose effectiveGasPrice in receipts (#23050)
gzliudan May 28, 2024
478554b
tests: fix eip1559 tx on non-eip1559 network (#23054)
gzliudan May 28, 2024
f521a6a
eth/gasprice: implement feeHistory API (#23033)
gzliudan May 29, 2024
bed91f6
accounts/abi/bind: fix gas price suggestion with pre EIP-1559 clients…
gzliudan May 28, 2024
e8e5668
ethclient/gethclient: RPC client wrapper for geth-specific API (#22977)
gzliudan May 28, 2024
dc33925
internal/ethapi: fix panic in access list creation (#23133)
gzliudan May 28, 2024
31dad63
ethstats: fix full node interface post 1559 (#23159)
gzliudan May 28, 2024
72c7ef0
eth/gasprice, internal/ethapi: minor feehistory fixes (#23178)
gzliudan May 29, 2024
c21717b
internal/ethapi: fix transaction APIs (#23179)
gzliudan Jun 13, 2024
97578c0
internal: get pending and queued transaction by address (#22992)
gzliudan May 29, 2024
fdb0c86
core: fix pre-check for account balance under EIP-1559 (#23244)
gzliudan May 28, 2024
fca0b53
Use hexutil.Uint for blockCount parameter and oldestBlock result valu…
gzliudan May 29, 2024
7cf35e6
internal/ethapi: fix panic in accesslist creation (#23225)
gzliudan May 28, 2024
25eccb8
all: remove term whitelist in comments and log messages (#23294)
gzliudan May 29, 2024
744f975
internal/ethapi: make ext signer sign legacy (#23274)
gzliudan May 29, 2024
8647b5b
core: check if sender is EOA (#23303)
gzliudan Jun 13, 2024
8cb11d9
internal/ethapi/api: return maxFeePerGas for gasPrice for EIP-1559 tx…
gzliudan May 28, 2024
7020086
internal/ethapi: add back missing check for maxfee < maxPriorityFee (…
gzliudan May 29, 2024
32705a3
core: only check sendernoeoa in non fake mode (#23424)
gzliudan Jun 13, 2024
91a0ecb
eth/gasprice: feeHistory improvements (#23422)
gzliudan May 30, 2024
a7e9cc9
core: add change counter (#23095)
gzliudan May 30, 2024
912e6b9
core/types: copy tx recipient address (#23376)
gzliudan Jun 11, 2024
771f440
eth/gasprice: avoid modifying TestChainConfig (#23204)
gzliudan May 31, 2024
4f7e4cf
core: remove unused error from TxPool.Pending (#23720)
gzliudan May 30, 2024
b5fa90e
core/types: add MarshalBinary, UnmarshalBinary for Receipt (#22806)
gzliudan Jun 12, 2024
b2c727f
accounts/abi/bind: refactor transact method (#23719)
gzliudan May 30, 2024
efb59fb
accounts/abi/bind: fix error handling in baseFee query (#23781)
kibgzr Oct 21, 2021
c87206d
accounts/abi/bin/backends: return basefee in suggestGasPrice's (#23838)
gzliudan May 31, 2024
da15303
accounts/abi/bind/backends: make suggestGasPrice compatible with non-…
MariusVanDerWijden Nov 1, 2021
ee35efd
core: more efficient nonce-update in txpool (#22231)
holiman Nov 2, 2021
71076fc
core: check effective tip in txpool pricelimit validation (#23855)
gzliudan May 31, 2024
8f7a615
core: ignore basefee when comparing with pool gasprice in txpool (#24…
gzliudan May 31, 2024
0ecc386
core/types: document JSON field name equivalents of DynamicFeeTx (#24…
gzliudan Jun 11, 2024
4a03722
internal/ethapi: use same receiver names (#24252)
gzliudan Jun 13, 2024
4b9b50e
core/statedb: always clear out access list when setting a new one (#2…
gzliudan May 31, 2024
1e8fcd3
core/types: improve error for too short transaction / receipt encodin…
gzliudan Jun 12, 2024
4faa463
graphql: fee history fields (#24452)
gzliudan Jun 20, 2024
5fbc3f6
eth/tracers/logger: remove unnecessary comparisons in accessList.equa…
Apr 21, 2022
4a047b8
core: fix the order of address in queue (#24908)
zhaochonghe May 19, 2022
63e1f7f
internal/ethapi: add comment explaining return of nil instead of erro…
gzliudan Jun 25, 2024
790ba2e
core: fix typo in txpool (#25149)
aaronbuchwald Jun 22, 2022
ea322f4
internal/ethapi: error if tx args includes ChainId not match local (#…
gzliudan Jun 13, 2024
c8c1c1b
ethclient: add FeeHistory support (#25403)
gzliudan May 31, 2024
b4605a1
eth/gasprice/feehistory: support finalized block (#25442)
gzliudan May 31, 2024
0f168b9
internal/ethapi: don't estimate gas if no limit provided in eth_creat…
gzliudan Jun 10, 2024
55293d6
internal/ethapi: rework setDefaults for tx args so fee logic is separ…
gzliudan Jun 13, 2024
886ceeb
internal/ethapi: fix comment typo (#25548)
ucwong Aug 19, 2022
83112e3
core: preallocate maps in TxPool helper methods (#25737)
dbadoy Sep 12, 2022
03becc4
core: don't cache zero nonce in txNoncer (#25603)
dbadoy Sep 16, 2022
a088512
core: fix datarace in txpool, fixes #25870 and #25869 (#25872)
holiman Sep 26, 2022
f156ec5
all: refactor txpool into it's own package in prep for 4844 (#26038)
gzliudan Jun 10, 2024
6e0199d
core/types: rename tx files to group them better together (#26044)
karalabe Oct 26, 2022
097bd66
core/vm: implement EIP-3860: Limit and meter initcode (#23847)
gzliudan Aug 22, 2024
5c06bbe
consensus/misc: move eip1559 into a package (#27828)
gzliudan Jun 11, 2024
076a177
core/types: add EffectiveGasPrice in Receipt (#26713)
gzliudan Jun 11, 2024
375ecc7
all: fix null effectiveGasPrice
gzliudan Jun 26, 2024
ec0c891
internal/ethapi: avoid int overflow in GetTransactionReceipt (#26911)
gzliudan Jun 25, 2024
93ad177
eth/gasprice: change feehistory input type from int to uint64 (#26922)
gzliudan Jun 12, 2024
cd91f1e
core/types: fix discrepancy in receipt.EffectiveGasPrice json encodin…
gzliudan Jun 12, 2024
1155266
internal/ethapi: implement eth_getBlockReceipts (#27702)
gzliudan Jun 25, 2024
bbf990f
ethclient: fix forwarding 1559 gas fields (#28462)
gzliudan Jun 12, 2024
a80ff45
internal/ethapi: ethSendTransaction check baseFee (#27834)
gzliudan Jun 14, 2024
4552f24
ethclient: apply accessList field in toCallArg (#28832)
colinlyguo Jan 19, 2024
5a11235
eth/gasprice: fix percentile validation in eth_feeHistory (#28954)
fjl Feb 8, 2024
349da7b
internal/ethapi: support unlimited rpc gas cap in eth_createAccessLis…
gzliudan Jun 14, 2024
eb228c2
eth/tracers,internal/ethapi: use correct baseFee when BlockOverrides …
gzliudan Jun 14, 2024
19112ca
all: remove noop vm config flags (#23111)
gzliudan Sep 24, 2024
3ed3fd5
core/vm: improve EVM reusability (#26341)
gzliudan Oct 16, 2024
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
22 changes: 18 additions & 4 deletions accounts/abi/bind/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ var (
// have any code associated with it (i.e. suicided).
ErrNoCode = errors.New("no contract code at given address")

// This error is raised when attempting to perform a pending state action
// ErrNoPendingState is raised when attempting to perform a pending state action
// on a backend that doesn't implement PendingContractCaller.
ErrNoPendingState = errors.New("backend does not support pending state")

// This error is returned by WaitDeployed if contract creation leaves an
// empty contract behind.
// ErrNoCodeAfterDeploy is returned by WaitDeployed if contract creation leaves
// an empty contract behind.
ErrNoCodeAfterDeploy = errors.New("no contract code after deployment")
)

Expand All @@ -47,7 +47,8 @@ type ContractCaller interface {
// CodeAt returns the code of the given account. This is needed to differentiate
// between contract internal errors and the local chain being out of sync.
CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
// ContractCall executes an Ethereum contract call with the specified data as the

// CallContract executes an Ethereum contract call with the specified data as the
// input.
CallContract(ctx context.Context, call XDPoSChain.CallMsg, blockNumber *big.Int) ([]byte, error)
}
Expand All @@ -58,6 +59,7 @@ type ContractCaller interface {
type PendingContractCaller interface {
// PendingCodeAt returns the code of the given account in the pending state.
PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error)

// PendingCallContract executes an Ethereum contract call against the pending state.
PendingCallContract(ctx context.Context, call XDPoSChain.CallMsg) ([]byte, error)
}
Expand All @@ -67,19 +69,31 @@ type PendingContractCaller interface {
// used when the user does not provide some needed values, but rather leaves it up
// to the transactor to decide.
type ContractTransactor interface {
// HeaderByNumber returns a block header from the current canonical chain. If
// number is nil, the latest known header is returned.
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

// PendingCodeAt returns the code of the given account in the pending state.
PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

// PendingNonceAt retrieves the current pending nonce associated with an account.
PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// execution of a transaction.
SuggestGasPrice(ctx context.Context) (*big.Int, error)

// SuggestGasTipCap retrieves the currently suggested 1559 priority fee to allow
// a timely execution of a transaction.
SuggestGasTipCap(ctx context.Context) (*big.Int, error)

// EstimateGas tries to estimate the gas needed to execute a specific
// transaction based on the current pending state of the backend blockchain.
// There is no guarantee that this is the true gas limit requirement as other
// transactions may be added or removed by miners, but it should provide a basis
// for setting a reasonable default.
EstimateGas(ctx context.Context, call XDPoSChain.CallMsg) (gas uint64, err error)

// SendTransaction injects the transaction into the pending pool for execution.
SendTransaction(ctx context.Context, tx *types.Transaction) error
}
Expand Down
70 changes: 63 additions & 7 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common
return receipt, nil
}

// HeaderByNumber returns a block header from the current canonical chain. If number is
// nil, the latest known header is returned.
func (b *SimulatedBackend) HeaderByNumber(ctx context.Context, block *big.Int) (*types.Header, error) {
b.mu.Lock()
defer b.mu.Unlock()

if block == nil || block.Cmp(b.pendingBlock.Number()) == 0 {
return b.blockchain.CurrentHeader(), nil
}

return b.blockchain.GetHeaderByNumber(uint64(block.Int64())), nil
}

// PendingCodeAt returns the code associated with an account in the pending state.
func (b *SimulatedBackend) PendingCodeAt(ctx context.Context, contract common.Address) ([]byte, error) {
b.mu.Lock()
Expand Down Expand Up @@ -300,8 +313,17 @@ func (b *SimulatedBackend) PendingNonceAt(ctx context.Context, account common.Ad
}

// SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated
// chain doens't have miners, we just return a gas price of 1 for any call.
// chain doesn't have miners, we just return a gas price of 1 for any call.
func (b *SimulatedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
if b.pendingBlock.Header().BaseFee != nil {
return b.pendingBlock.Header().BaseFee, nil
}
return big.NewInt(1), nil
}

// SuggestGasTipCap implements ContractTransactor.SuggestGasTipCap. Since the simulated
// chain doesn't have miners, we just return a gas tip of 1 for any call.
func (b *SimulatedBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
return big.NewInt(1), nil
}

Expand Down Expand Up @@ -358,10 +380,38 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call XDPoSChain.Call
// callContract implements common code between normal and pending contract calls.
// state is modified during execution, make sure to copy it if necessary.
func (b *SimulatedBackend) callContract(ctx context.Context, call XDPoSChain.CallMsg, block *types.Block, statedb *state.StateDB) (ret []byte, usedGas uint64, failed bool, err error) {
// Ensure message is initialized properly.
if call.GasPrice == nil {
call.GasPrice = big.NewInt(1)
// Gas prices post 1559 need to be initialized
if call.GasPrice != nil && (call.GasFeeCap != nil || call.GasTipCap != nil) {
return nil, 0, false, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
}
head := b.blockchain.CurrentHeader()
if !b.blockchain.Config().IsEIP1559(head.Number) {
// If there's no basefee, then it must be a non-1559 execution
if call.GasPrice == nil {
call.GasPrice = new(big.Int)
}
call.GasFeeCap, call.GasTipCap = call.GasPrice, call.GasPrice
} else {
// A basefee is provided, necessitating 1559-type execution
if call.GasPrice != nil {
// User specified the legacy gas field, convert to 1559 gas typing
call.GasFeeCap, call.GasTipCap = call.GasPrice, call.GasPrice
} else {
// User specified 1559 gas feilds (or none), use those
if call.GasFeeCap == nil {
call.GasFeeCap = new(big.Int)
}
if call.GasTipCap == nil {
call.GasTipCap = new(big.Int)
}
// Backfill the legacy gasPrice for EVM execution, unless we're all zeroes
call.GasPrice = new(big.Int)
if call.GasFeeCap.BitLen() > 0 || call.GasTipCap.BitLen() > 0 {
call.GasPrice = math.BigMin(new(big.Int).Add(call.GasTipCap, head.BaseFee), call.GasFeeCap)
}
}
}
// Ensure message is initialized properly.
if call.Gas == 0 {
call.Gas = 50000000
}
Expand All @@ -384,7 +434,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call XDPoSChain.Cal
evmContext := core.NewEVMBlockContext(block.Header(), b.blockchain, nil)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(evmContext, txContext, statedb, nil, b.config, vm.Config{})
vmenv := vm.NewEVM(evmContext, txContext, statedb, nil, b.config, vm.Config{NoBaseFee: true})
gaspool := new(core.GasPool).AddGas(math.MaxUint64)
owner := common.Address{}
ret, usedGas, failed, err, _ = core.NewStateTransition(vmenv, msg, gaspool).TransitionDb(owner)
Expand Down Expand Up @@ -522,9 +572,11 @@ type callMsg struct {

func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) CheckNonce() bool { return false }
func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
Expand Down Expand Up @@ -554,7 +606,11 @@ func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*t
}

func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
return core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash)), nil
number := rawdb.ReadHeaderNumber(fb.db, hash)
if number == nil {
return nil, nil
}
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
}

func (fb *filterBackend) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) {
Expand Down
Loading