mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
cmd/evm/internal/t8ntool: use ApplyTransaction instead of ApplyMessage (#32618)
ApplyTransaction calls the hooks and builds the receipt, so some duplicated code can be removed from t8ntool. Test cases have been changed to add the `blockNumber` and `blockHash` in receipts, since they were previously not filled in.
This commit is contained in:
parent
b05fe4aa64
commit
e48242bb69
11 changed files with 33 additions and 66 deletions
|
|
@ -32,7 +32,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
|
@ -152,7 +151,6 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
gasUsed = uint64(0)
|
||||
blobGasUsed = uint64(0)
|
||||
receipts = make(types.Receipts, 0)
|
||||
txIndex = 0
|
||||
)
|
||||
gaspool.AddGas(pre.Env.GasLimit)
|
||||
vmContext := vm.BlockContext{
|
||||
|
|
@ -250,24 +248,17 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
continue
|
||||
}
|
||||
}
|
||||
statedb.SetTxContext(tx.Hash(), txIndex)
|
||||
statedb.SetTxContext(tx.Hash(), len(receipts))
|
||||
var (
|
||||
snapshot = statedb.Snapshot()
|
||||
prevGas = gaspool.Gas()
|
||||
)
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnTxStart != nil {
|
||||
evm.Config.Tracer.OnTxStart(evm.GetVMContext(), tx, msg.From)
|
||||
}
|
||||
// (ret []byte, usedGas uint64, failed bool, err error)
|
||||
msgResult, err := core.ApplyMessage(evm, msg, gaspool)
|
||||
receipt, err := core.ApplyTransactionWithEVM(msg, gaspool, statedb, vmContext.BlockNumber, blockHash, pre.Env.Timestamp, tx, &gasUsed, evm)
|
||||
if err != nil {
|
||||
statedb.RevertToSnapshot(snapshot)
|
||||
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From, "error", err)
|
||||
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
|
||||
gaspool.SetGas(prevGas)
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnTxEnd != nil {
|
||||
evm.Config.Tracer.OnTxEnd(nil, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
includedTxs = append(includedTxs, tx)
|
||||
|
|
@ -275,50 +266,11 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
return nil, nil, nil, NewError(ErrorMissingBlockhash, hashError)
|
||||
}
|
||||
blobGasUsed += txBlobGas
|
||||
gasUsed += msgResult.UsedGas
|
||||
|
||||
// Receipt:
|
||||
{
|
||||
var root []byte
|
||||
if chainConfig.IsByzantium(vmContext.BlockNumber) {
|
||||
statedb.Finalise(true)
|
||||
} else {
|
||||
root = statedb.IntermediateRoot(chainConfig.IsEIP158(vmContext.BlockNumber)).Bytes()
|
||||
}
|
||||
|
||||
// Create a new receipt for the transaction, storing the intermediate root and
|
||||
// gas used by the tx.
|
||||
receipt := &types.Receipt{Type: tx.Type(), PostState: root, CumulativeGasUsed: gasUsed}
|
||||
if msgResult.Failed() {
|
||||
receipt.Status = types.ReceiptStatusFailed
|
||||
} else {
|
||||
receipt.Status = types.ReceiptStatusSuccessful
|
||||
}
|
||||
receipt.TxHash = tx.Hash()
|
||||
receipt.GasUsed = msgResult.UsedGas
|
||||
|
||||
// If the transaction created a contract, store the creation address in the receipt.
|
||||
if msg.To == nil {
|
||||
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
|
||||
}
|
||||
|
||||
// Set the receipt logs and create the bloom filter.
|
||||
receipt.Logs = statedb.GetLogs(tx.Hash(), vmContext.BlockNumber.Uint64(), blockHash, vmContext.Time)
|
||||
receipt.Bloom = types.CreateBloom(receipt)
|
||||
|
||||
// These three are non-consensus fields:
|
||||
//receipt.BlockHash
|
||||
//receipt.BlockNumber
|
||||
receipt.TransactionIndex = uint(txIndex)
|
||||
receipts = append(receipts, receipt)
|
||||
if evm.Config.Tracer != nil && evm.Config.Tracer.OnTxEnd != nil {
|
||||
evm.Config.Tracer.OnTxEnd(receipt, nil)
|
||||
}
|
||||
}
|
||||
|
||||
txIndex++
|
||||
receipts = append(receipts, receipt)
|
||||
}
|
||||
|
||||
statedb.IntermediateRoot(chainConfig.IsEIP158(vmContext.BlockNumber))
|
||||
|
||||
// Add mining reward? (-1 means rewards are disabled)
|
||||
if miningReward >= 0 {
|
||||
// Add mining reward. The mining reward may be `0`, which only makes a difference in the cases
|
||||
|
|
|
|||
3
cmd/evm/testdata/1/exp.json
vendored
3
cmd/evm/testdata/1/exp.json
vendored
|
|
@ -29,7 +29,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x5208",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
6
cmd/evm/testdata/13/exp2.json
vendored
6
cmd/evm/testdata/13/exp2.json
vendored
|
|
@ -17,7 +17,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x84d0",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
},
|
||||
{
|
||||
|
|
@ -31,7 +32,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x84d0",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x1"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
3
cmd/evm/testdata/23/exp.json
vendored
3
cmd/evm/testdata/23/exp.json
vendored
|
|
@ -16,7 +16,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x520b",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x5",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
6
cmd/evm/testdata/24/exp.json
vendored
6
cmd/evm/testdata/24/exp.json
vendored
|
|
@ -32,7 +32,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0xa861",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
},
|
||||
{
|
||||
|
|
@ -45,7 +46,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x5aa5",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x1"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
3
cmd/evm/testdata/25/exp.json
vendored
3
cmd/evm/testdata/25/exp.json
vendored
|
|
@ -28,7 +28,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x5208",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
5
cmd/evm/testdata/28/exp.json
vendored
5
cmd/evm/testdata/28/exp.json
vendored
|
|
@ -33,7 +33,10 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0xa865",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blobGasUsed": "0x20000",
|
||||
"blobGasPrice": "0x1",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
3
cmd/evm/testdata/29/exp.json
vendored
3
cmd/evm/testdata/29/exp.json
vendored
|
|
@ -31,7 +31,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x5208",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
3
cmd/evm/testdata/3/exp.json
vendored
3
cmd/evm/testdata/3/exp.json
vendored
|
|
@ -29,7 +29,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x521f",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x5",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
6
cmd/evm/testdata/30/exp.json
vendored
6
cmd/evm/testdata/30/exp.json
vendored
|
|
@ -30,7 +30,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x5208",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
},
|
||||
{
|
||||
|
|
@ -44,7 +45,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x5208",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x1"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
3
cmd/evm/testdata/33/exp.json
vendored
3
cmd/evm/testdata/33/exp.json
vendored
|
|
@ -48,7 +48,8 @@
|
|||
"contractAddress": "0x0000000000000000000000000000000000000000",
|
||||
"gasUsed": "0x15fa9",
|
||||
"effectiveGasPrice": null,
|
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockHash": "0x1337000000000000000000000000000000000000000000000000000000000000",
|
||||
"blockNumber": "0x1",
|
||||
"transactionIndex": "0x0"
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue