@@ -32,7 +32,6 @@ import (
3232 "github.com/ethereum/go-ethereum/core/tracing"
3333 "github.com/ethereum/go-ethereum/core/types"
3434 "github.com/ethereum/go-ethereum/core/vm"
35- "github.com/ethereum/go-ethereum/crypto"
3635 "github.com/ethereum/go-ethereum/ethdb"
3736 "github.com/ethereum/go-ethereum/log"
3837 "github.com/ethereum/go-ethereum/params"
@@ -152,7 +151,6 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
152151 gasUsed = uint64 (0 )
153152 blobGasUsed = uint64 (0 )
154153 receipts = make (types.Receipts , 0 )
155- txIndex = 0
156154 )
157155 gaspool .AddGas (pre .Env .GasLimit )
158156 vmContext := vm.BlockContext {
@@ -250,75 +248,29 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
250248 continue
251249 }
252250 }
253- statedb .SetTxContext (tx .Hash (), txIndex )
251+ statedb .SetTxContext (tx .Hash (), len ( receipts ) )
254252 var (
255253 snapshot = statedb .Snapshot ()
256254 prevGas = gaspool .Gas ()
257255 )
258- if evm .Config .Tracer != nil && evm .Config .Tracer .OnTxStart != nil {
259- evm .Config .Tracer .OnTxStart (evm .GetVMContext (), tx , msg .From )
260- }
261- // (ret []byte, usedGas uint64, failed bool, err error)
262- msgResult , err := core .ApplyMessage (evm , msg , gaspool )
256+ receipt , err := core .ApplyTransactionWithEVM (msg , gaspool , statedb , vmContext .BlockNumber , blockHash , pre .Env .Timestamp , tx , & gasUsed , evm )
263257 if err != nil {
264258 statedb .RevertToSnapshot (snapshot )
265259 log .Info ("rejected tx" , "index" , i , "hash" , tx .Hash (), "from" , msg .From , "error" , err )
266260 rejectedTxs = append (rejectedTxs , & rejectedTx {i , err .Error ()})
267261 gaspool .SetGas (prevGas )
268- if evm .Config .Tracer != nil && evm .Config .Tracer .OnTxEnd != nil {
269- evm .Config .Tracer .OnTxEnd (nil , err )
270- }
271262 continue
272263 }
273264 includedTxs = append (includedTxs , tx )
274265 if hashError != nil {
275266 return nil , nil , nil , NewError (ErrorMissingBlockhash , hashError )
276267 }
277268 blobGasUsed += txBlobGas
278- gasUsed += msgResult .UsedGas
279-
280- // Receipt:
281- {
282- var root []byte
283- if chainConfig .IsByzantium (vmContext .BlockNumber ) {
284- statedb .Finalise (true )
285- } else {
286- root = statedb .IntermediateRoot (chainConfig .IsEIP158 (vmContext .BlockNumber )).Bytes ()
287- }
288-
289- // Create a new receipt for the transaction, storing the intermediate root and
290- // gas used by the tx.
291- receipt := & types.Receipt {Type : tx .Type (), PostState : root , CumulativeGasUsed : gasUsed }
292- if msgResult .Failed () {
293- receipt .Status = types .ReceiptStatusFailed
294- } else {
295- receipt .Status = types .ReceiptStatusSuccessful
296- }
297- receipt .TxHash = tx .Hash ()
298- receipt .GasUsed = msgResult .UsedGas
299-
300- // If the transaction created a contract, store the creation address in the receipt.
301- if msg .To == nil {
302- receipt .ContractAddress = crypto .CreateAddress (evm .TxContext .Origin , tx .Nonce ())
303- }
304-
305- // Set the receipt logs and create the bloom filter.
306- receipt .Logs = statedb .GetLogs (tx .Hash (), vmContext .BlockNumber .Uint64 (), blockHash , vmContext .Time )
307- receipt .Bloom = types .CreateBloom (receipt )
308-
309- // These three are non-consensus fields:
310- //receipt.BlockHash
311- //receipt.BlockNumber
312- receipt .TransactionIndex = uint (txIndex )
313- receipts = append (receipts , receipt )
314- if evm .Config .Tracer != nil && evm .Config .Tracer .OnTxEnd != nil {
315- evm .Config .Tracer .OnTxEnd (receipt , nil )
316- }
317- }
318-
319- txIndex ++
269+ receipts = append (receipts , receipt )
320270 }
271+
321272 statedb .IntermediateRoot (chainConfig .IsEIP158 (vmContext .BlockNumber ))
273+
322274 // Add mining reward? (-1 means rewards are disabled)
323275 if miningReward >= 0 {
324276 // Add mining reward. The mining reward may be `0`, which only makes a difference in the cases
0 commit comments