erigon-pulse/core/state_transition.go

495 lines
17 KiB
Go
Raw Permalink Normal View History

2015-07-07 00:54:22 +00:00
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
2015-07-07 00:54:22 +00:00
//
// The go-ethereum library is free software: you can redistribute it and/or modify
2015-07-07 00:54:22 +00:00
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
2015-07-07 00:54:22 +00:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2015-07-07 00:54:22 +00:00
// GNU Lesser General Public License for more details.
//
// 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/>.
2015-07-07 00:54:22 +00:00
2014-12-04 09:28:02 +00:00
package core
import (
2020-05-19 10:28:20 +00:00
"fmt"
"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg"
types2 "github.com/ledgerwatch/erigon-lib/types"
cmath "github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/params"
)
var emptyCodeHash = crypto.Keccak256Hash(nil)
2014-06-13 11:06:27 +00:00
/*
The State Transitioning Model
A state transition is a change made when a transaction is applied to the current world state
2018-07-24 10:17:12 +00:00
The state transitioning model does all the necessary work to work out a valid new state root.
1) Nonce handling
2) Pre pay gas
3) Create a new state object if the recipient is \0*32
4) Value transfer
== If contract creation ==
2022-08-10 12:04:13 +00:00
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object
== end ==
5) Run Script section
6) Derive new state root
*/
type StateTransition struct {
gp *GasPool
msg Message
gas uint64
gasPrice *uint256.Int
2021-07-11 04:05:56 +00:00
gasFeeCap *uint256.Int
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
tip *uint256.Int
initialGas uint64
value *uint256.Int
data []byte
state evmtypes.IntraBlockState
evm *vm.EVM
//some pre-allocated intermediate variables
sharedBuyGas *uint256.Int
sharedBuyGasBalance *uint256.Int
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
isBor bool
}
// Message represents a message sent to a contract.
type Message interface {
From() libcommon.Address
To() *libcommon.Address
GasPrice() *uint256.Int
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
FeeCap() *uint256.Int
Tip() *uint256.Int
Gas() uint64
BlobGas() uint64
MaxFeePerBlobGas() *uint256.Int
Value() *uint256.Int
Nonce() uint64
CheckNonce() bool
Data() []byte
AccessList() types2.AccessList
BlobHashes() []libcommon.Hash
IsFree() bool
}
2015-03-18 12:00:01 +00:00
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
// ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not.
type ExecutionResult struct {
UsedGas uint64 // Total used gas but include the refunded gas
Err error // Any error encountered during the execution(listed in core/vm/errors.go)
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
}
// Unwrap returns the internal evm error which allows us for further
// analysis outside.
func (result *ExecutionResult) Unwrap() error {
return result.Err
}
// Failed returns the indicator whether the execution is successful or not
func (result *ExecutionResult) Failed() bool { return result.Err != nil }
// Return is a helper function to help caller distinguish between revert reason
// and function return. Return returns the data after execution if no error occurs.
func (result *ExecutionResult) Return() []byte {
if result.Err != nil {
return nil
}
return libcommon.CopyBytes(result.ReturnData)
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
}
// Revert returns the concrete revert reason if the execution is aborted by `REVERT`
// opcode. Note the reason can be nil if no data supplied with revert opcode.
func (result *ExecutionResult) Revert() []byte {
if result.Err != vm.ErrExecutionReverted {
return nil
}
return libcommon.CopyBytes(result.ReturnData)
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
}
// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func IntrinsicGas(data []byte, accessList types2.AccessList, isContractCreation bool, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) {
// Zero and non-zero bytes are priced differently
dataLen := uint64(len(data))
dataNonZeroLen := uint64(0)
for _, byt := range data {
if byt != 0 {
dataNonZeroLen++
}
}
gas, status := txpoolcfg.CalcIntrinsicGas(dataLen, dataNonZeroLen, accessList, isContractCreation, isHomestead, isEIP2028, isEIP3860)
if status != txpoolcfg.Success {
return 0, ErrGasUintOverflow
all: add support for EIP-2718, EIP-2930 transactions (#21502) This adds support for EIP-2718 typed transactions as well as EIP-2930 access list transactions (tx type 1). These EIPs are scheduled for the Berlin fork. There very few changes to existing APIs in core/types, and several new APIs to deal with access list transactions. In particular, there are two new constructor functions for transactions: types.NewTx and types.SignNewTx. Since the canonical encoding of typed transactions is not RLP-compatible, Transaction now has new methods for encoding and decoding: MarshalBinary and UnmarshalBinary. The existing EIP-155 signer does not support the new transaction types. All code dealing with transaction signatures should be updated to use the newer EIP-2930 signer. To make this easier for future updates, we have added new constructor functions for types.Signer: types.LatestSigner and types.LatestSignerForChainID. This change also adds support for the YoloV3 testnet. Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Felix Lange <fjl@twurst.com> Co-authored-by: Ryan Schneider <ryanleeschneider@gmail.com> # Conflicts: # accounts/abi/bind/backends/simulated.go # cmd/evm/internal/t8ntool/execution.go # cmd/evm/internal/t8ntool/transition.go # cmd/geth/main.go # cmd/geth/usage.go # core/bench_test.go # core/state/statedb.go # core/state_prefetcher.go # core/state_processor.go # core/state_transition.go # core/tx_pool.go # core/types/block.go # core/types/derive_sha.go # core/types/gen_tx_json.go # core/types/receipt.go # core/types/receipt_test.go # core/types/transaction.go # core/types/transaction_signing.go # core/types/transaction_test.go # ethclient/ethclient.go # ethclient/signer.go # graphql/graphql.go # internal/ethapi/api.go # internal/guide/guide_test.go # les/benchmark.go # les/odr_test.go # light/odr_test.go # light/txpool.go # miner/worker.go # miner/worker_test.go # signer/core/api.go # tests/state_test_util.go # trie/stacktrie_test.go # turbo/stages/blockchain_test.go
2021-02-25 14:26:57 +00:00
}
return gas, nil
}
// NewStateTransition initialises and returns a new state transition object.
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition {
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
isBor := evm.ChainConfig().Bor != nil
return &StateTransition{
2021-07-11 04:05:56 +00:00
gp: gp,
evm: evm,
msg: msg,
gasPrice: msg.GasPrice(),
gasFeeCap: msg.FeeCap(),
tip: msg.Tip(),
value: msg.Value(),
data: msg.Data(),
state: evm.IntraBlockState(),
sharedBuyGas: uint256.NewInt(0),
sharedBuyGasBalance: uint256.NewInt(0),
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
isBor: isBor,
}
}
// ApplyMessage computes the new state by applying the given message
// against the old state within the environment.
//
// ApplyMessage returns the bytes returned by any EVM execution (if it took place),
// the gas used (which includes gas refunds) and an error if it failed. An error always
// indicates a core error meaning that the message would always fail for that particular
// state and would never be accepted within a block.
// `refunds` is false when it is not required to apply gas refunds
// `gasBailout` is true when it is not required to fail transaction if the balance is not enough to pay gas.
// for trace_call to replicate OE/Parity behaviour
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, refunds bool, gasBailout bool) (*ExecutionResult, error) {
return NewStateTransition(evm, msg, gp).TransitionDb(refunds, gasBailout)
}
// to returns the recipient of the message.
func (st *StateTransition) to() libcommon.Address {
if st.msg == nil || st.msg.To() == nil /* contract creation */ {
return libcommon.Address{}
}
return *st.msg.To()
}
func (st *StateTransition) buyGas(gasBailout bool) error {
gasVal := st.sharedBuyGas
gasVal.SetUint64(st.msg.Gas())
gasVal, overflow := gasVal.MulOverflow(gasVal, st.gasPrice)
if overflow {
return fmt.Errorf("%w: address %v", ErrInsufficientFunds, st.msg.From().Hex())
}
// compute blob fee for eip-4844 data blobs if any
blobGasVal := new(uint256.Int)
if st.evm.ChainRules().IsCancun {
if st.evm.Context.ExcessBlobGas == nil {
return fmt.Errorf("%w: Cancun is active but ExcessBlobGas is nil", ErrInternalFailure)
}
blobGasPrice, err := misc.GetBlobGasPrice(st.evm.ChainConfig(), *st.evm.Context.ExcessBlobGas)
if err != nil {
return err
}
blobGasVal, overflow = blobGasVal.MulOverflow(blobGasPrice, new(uint256.Int).SetUint64(st.msg.BlobGas()))
if overflow {
return fmt.Errorf("%w: overflow converting blob gas: %v", ErrInsufficientFunds, blobGasVal)
}
if err := st.gp.SubBlobGas(st.msg.BlobGas()); err != nil {
return err
}
}
balanceCheck := gasVal
2021-07-11 04:05:56 +00:00
if st.gasFeeCap != nil {
balanceCheck = st.sharedBuyGasBalance.SetUint64(st.msg.Gas())
balanceCheck, overflow = balanceCheck.MulOverflow(balanceCheck, st.gasFeeCap)
if overflow {
return fmt.Errorf("%w: address %v", ErrInsufficientFunds, st.msg.From().Hex())
}
balanceCheck, overflow = balanceCheck.AddOverflow(balanceCheck, st.value)
if overflow {
return fmt.Errorf("%w: address %v", ErrInsufficientFunds, st.msg.From().Hex())
}
balanceCheck, overflow = balanceCheck.AddOverflow(balanceCheck, blobGasVal)
if overflow {
return fmt.Errorf("%w: address %v", ErrInsufficientFunds, st.msg.From().Hex())
}
}
2022-08-10 12:04:13 +00:00
var subBalance = false
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
if !gasBailout {
2021-03-12 17:26:06 +00:00
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)
}
} else {
subBalance = true
}
if err := st.gp.SubGas(st.msg.Gas()); err != nil {
if !gasBailout {
return err
}
}
st.gas += st.msg.Gas()
st.initialGas = st.msg.Gas()
if subBalance {
st.state.SubBalance(st.msg.From(), gasVal)
st.state.SubBalance(st.msg.From(), blobGasVal)
}
return nil
}
func CheckEip1559TxGasFeeCap(from libcommon.Address, gasFeeCap, tip, baseFee *uint256.Int, isFree bool) error {
if gasFeeCap.Lt(tip) {
return fmt.Errorf("%w: address %v, tip: %s, gasFeeCap: %s", ErrTipAboveFeeCap,
from.Hex(), tip, gasFeeCap)
}
if baseFee != nil && gasFeeCap.Lt(baseFee) && !isFree {
return fmt.Errorf("%w: address %v, gasFeeCap: %s baseFee: %s", ErrFeeCapTooLow,
from.Hex(), gasFeeCap, baseFee)
}
return nil
}
// DESCRIBED: docs/programmers_guide/guide.md#nonce
func (st *StateTransition) preCheck(gasBailout bool) error {
// Make sure this transaction's nonce is correct.
if st.msg.CheckNonce() {
stNonce := st.state.GetNonce(st.msg.From())
if msgNonce := st.msg.Nonce(); stNonce < msgNonce {
return fmt.Errorf("%w: address %v, tx: %d state: %d", ErrNonceTooHigh,
st.msg.From().Hex(), msgNonce, stNonce)
} else if stNonce > msgNonce {
return fmt.Errorf("%w: address %v, tx: %d state: %d", ErrNonceTooLow,
st.msg.From().Hex(), msgNonce, stNonce)
} else if stNonce+1 < stNonce {
return fmt.Errorf("%w: address %v, nonce: %d", ErrNonceMax,
st.msg.From().Hex(), stNonce)
}
// Make sure the sender is an EOA (EIP-3607)
if codeHash := st.state.GetCodeHash(st.msg.From()); codeHash != emptyCodeHash && codeHash != (libcommon.Hash{}) {
// libcommon.Hash{} means that the sender is not in the state.
// Historically there were transactions with 0 gas price and non-existing sender,
// so we have to allow that.
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA,
st.msg.From().Hex(), codeHash)
}
}
2021-07-11 04:05:56 +00:00
// Make sure the transaction gasFeeCap is greater than the block's baseFee.
if st.evm.ChainRules().IsLondon {
2021-07-11 04:05:56 +00:00
// Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call)
if !st.evm.Config().NoBaseFee || !st.gasFeeCap.IsZero() || !st.tip.IsZero() {
if err := CheckEip1559TxGasFeeCap(st.msg.From(), st.gasFeeCap, st.tip, st.evm.Context.BaseFee, st.msg.IsFree()); err != nil {
return err
2021-07-11 04:05:56 +00:00
}
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
}
}
if st.msg.BlobGas() > 0 && st.evm.ChainRules().IsCancun {
if st.evm.Context.ExcessBlobGas == nil {
return fmt.Errorf("%w: Cancun is active but ExcessBlobGas is nil", ErrInternalFailure)
}
blobGasPrice, err := misc.GetBlobGasPrice(st.evm.ChainConfig(), *st.evm.Context.ExcessBlobGas)
if err != nil {
return err
}
maxFeePerBlobGas := st.msg.MaxFeePerBlobGas()
if blobGasPrice.Cmp(maxFeePerBlobGas) > 0 {
return fmt.Errorf("%w: address %v, maxFeePerBlobGas: %v blobGasPrice: %v, excessBlobGas: %v",
ErrMaxFeePerBlobGas,
st.msg.From().Hex(), st.msg.MaxFeePerBlobGas(), blobGasPrice, st.evm.Context.ExcessBlobGas)
}
}
return st.buyGas(gasBailout)
2014-06-19 11:41:17 +00:00
}
// TransitionDb will transition the state by applying the current message and
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
// returning the evm execution result with following fields.
//
2022-08-10 12:04:13 +00:00
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
//
// However if any consensus issue encountered, return the error directly with
// nil evm execution result.
func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*ExecutionResult, error) {
coinbase := st.evm.Context.Coinbase
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
var input1 *uint256.Int
var input2 *uint256.Int
if st.isBor {
input1 = st.state.GetBalance(st.msg.From()).Clone()
input2 = st.state.GetBalance(coinbase).Clone()
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
}
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
// First check this message satisfies all consensus rules before
// applying the message. The rules include these clauses
//
// 1. the nonce of the message caller is correct
// 2. caller has enough balance to cover transaction fee(gaslimit * gasprice)
// 3. the amount of gas required is available in the block
// 4. the purchased gas is enough to cover intrinsic usage
// 5. there is no overflow when calculating intrinsic gas
// 6. caller has enough balance to cover asset transfer for **topmost** call
// Check clauses 1-3 and 6, buy gas if everything is correct
if err := st.preCheck(gasBailout); err != nil {
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
return nil, err
2014-06-19 11:41:17 +00:00
}
if st.evm.Config().Debug {
st.evm.Config().Tracer.CaptureTxStart(st.initialGas)
defer func() {
st.evm.Config().Tracer.CaptureTxEnd(st.gas)
}()
}
msg := st.msg
sender := vm.AccountRef(msg.From())
contractCreation := msg.To() == nil
rules := st.evm.ChainRules()
vmConfig := st.evm.Config()
isEIP3860 := vmConfig.HasEip3860(rules)
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
// Check clauses 4-5, subtract intrinsic gas if everything is correct
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860)
if err != nil {
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
return nil, err
}
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
if st.gas < gas {
return nil, fmt.Errorf("%w: have %d, want %d", ErrIntrinsicGas, st.gas, gas)
}
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
st.gas -= gas
var bailout bool
// Gas bailout (for trace_call) should only be applied if there is not sufficient balance to perform value transfer
if gasBailout {
if !msg.Value().IsZero() && !st.evm.Context.CanTransfer(st.state, msg.From(), msg.Value()) {
bailout = true
}
}
// Check whether the init code size has been exceeded.
if isEIP3860 && contractCreation && len(st.data) > params.MaxInitCodeSize {
return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(st.data), params.MaxInitCodeSize)
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
// - reset transient storage(eip 1153)
st.state.Prepare(rules, msg.From(), coinbase, msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
all: add support for EIP-2718, EIP-2930 transactions (#21502) This adds support for EIP-2718 typed transactions as well as EIP-2930 access list transactions (tx type 1). These EIPs are scheduled for the Berlin fork. There very few changes to existing APIs in core/types, and several new APIs to deal with access list transactions. In particular, there are two new constructor functions for transactions: types.NewTx and types.SignNewTx. Since the canonical encoding of typed transactions is not RLP-compatible, Transaction now has new methods for encoding and decoding: MarshalBinary and UnmarshalBinary. The existing EIP-155 signer does not support the new transaction types. All code dealing with transaction signatures should be updated to use the newer EIP-2930 signer. To make this easier for future updates, we have added new constructor functions for types.Signer: types.LatestSigner and types.LatestSignerForChainID. This change also adds support for the YoloV3 testnet. Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Felix Lange <fjl@twurst.com> Co-authored-by: Ryan Schneider <ryanleeschneider@gmail.com> # Conflicts: # accounts/abi/bind/backends/simulated.go # cmd/evm/internal/t8ntool/execution.go # cmd/evm/internal/t8ntool/transition.go # cmd/geth/main.go # cmd/geth/usage.go # core/bench_test.go # core/state/statedb.go # core/state_prefetcher.go # core/state_processor.go # core/state_transition.go # core/tx_pool.go # core/types/block.go # core/types/derive_sha.go # core/types/gen_tx_json.go # core/types/receipt.go # core/types/receipt_test.go # core/types/transaction.go # core/types/transaction_signing.go # core/types/transaction_test.go # ethclient/ethclient.go # ethclient/signer.go # graphql/graphql.go # internal/ethapi/api.go # internal/guide/guide_test.go # les/benchmark.go # les/odr_test.go # light/odr_test.go # light/txpool.go # miner/worker.go # miner/worker_test.go # signer/core/api.go # tests/state_test_util.go # trie/stacktrie_test.go # turbo/stages/blockchain_test.go
2021-02-25 14:26:57 +00:00
var (
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
ret []byte
vmerr error // vm errors do not effect consensus and are therefore not assigned to err
)
if contractCreation {
// The reason why we don't increment nonce here is that we need the original
// nonce to calculate the address of the contract that is being created
// It does get incremented inside the `Create` call, after the computation
// of the contract's address, but before the execution of the code.
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
ret, _, st.gas, vmerr = st.evm.Create(sender, st.data, st.gas, st.value)
2014-07-07 11:59:09 +00:00
} else {
2015-03-24 14:23:16 +00:00
// Increment the nonce for the next transaction
st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value, bailout)
}
if refunds {
if rules.IsLondon {
// After EIP-3529: refunds are capped to gasUsed / 5
st.refundGas(params.RefundQuotientEIP3529)
} else {
// Before EIP-3529: refunds were capped to gasUsed / 2
st.refundGas(params.RefundQuotient)
}
}
effectiveTip := st.gasPrice
if rules.IsLondon {
if st.gasFeeCap.Gt(st.evm.Context.BaseFee) {
effectiveTip = cmath.Min256(st.tip, new(uint256.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
} else {
effectiveTip = u256.Num0
}
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
}
amount := new(uint256.Int).SetUint64(st.gasUsed())
amount.Mul(amount, effectiveTip) // gasUsed * effectiveTip = how much goes to the block producer (miner, validator)
st.state.AddBalance(coinbase, amount)
if !msg.IsFree() && rules.IsLondon {
burntContractAddress := st.evm.ChainConfig().GetBurntContract(st.evm.Context.BlockNumber)
if burntContractAddress != nil {
burnAmount := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasUsed()), st.evm.Context.BaseFee)
st.state.AddBalance(*burntContractAddress, burnAmount)
}
}
if st.isBor {
// Deprecating transfer log and will be removed in future fork. PLEASE DO NOT USE this transfer log going forward. Parameters won't get updated as expected going forward with EIP1559
// add transfer log
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
output1 := input1.Clone()
output2 := input2.Clone()
AddFeeTransferLog(
st.state,
msg.From(),
coinbase,
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
amount,
input1,
input2,
output1.Sub(output1, amount),
output2.Add(output2, amount),
)
}
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
return &ExecutionResult{
UsedGas: st.gasUsed(),
Err: vmerr,
ReturnData: ret,
all: seperate consensus error and evm internal error (#20830) * all: seperate consensus error and evm internal error There are actually two types of error will be returned when a tranaction/message call is executed: (a) consensus error (b) evm internal error. The former should be converted to a consensus issue, e.g. The sender doesn't enough asset to purchase the gas it specifies. The latter is allowed since evm itself is a blackbox and internal error is allowed to happen. This PR emphasizes the difference by introducing a executionResult structure. The evm error is embedded inside. So if any error returned, it indicates consensus issue happens. And also this PR improve the `EstimateGas` API to return the concrete revert reason if the transaction always fails * all: polish * accounts/abi/bind/backends: add tests * accounts/abi/bind/backends, internal: cleanup error message * all: address comments * core: fix lint * accounts, core, eth, internal: address comments * accounts, internal: resolve revert reason if possible * accounts, internal: address comments # Conflicts: # accounts/abi/abi.go # accounts/abi/bind/backends/simulated.go # cmd/geth/retesteth.go # core/state/snapshot/difflayer_test.go # core/state/snapshot/disklayer_test.go # core/state/snapshot/iterator_test.go # core/state_processor.go # core/state_transition.go # core/vm/evm.go # core/vm/instructions.go # core/vm/jump_table.go # eth/api_tracer.go # internal/ethapi/api.go # les/odr_test.go # light/odr_test.go # tests/state_test_util.go
2020-04-22 08:25:36 +00:00
}, nil
2014-07-24 10:04:15 +00:00
}
2014-12-18 20:58:26 +00:00
func (st *StateTransition) refundGas(refundQuotient uint64) {
// Apply refund counter, capped to half of the used gas.
refund := st.gasUsed() / refundQuotient
if refund > st.state.GetRefund() {
refund = st.state.GetRefund()
}
st.gas += refund
// Return ETH for remaining gas, exchanged at the original rate.
remaining := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gas), st.gasPrice)
st.state.AddBalance(st.msg.From(), remaining)
2014-12-18 20:58:26 +00:00
// Also return remaining gas to the block gas counter so it is
// available for the next transaction.
st.gp.AddGas(st.gas)
2014-12-18 20:58:26 +00:00
}
// gasUsed returns the amount of gas used up by the state transition.
func (st *StateTransition) gasUsed() uint64 {
return st.initialGas - st.gas
2014-12-18 20:58:26 +00:00
}