mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
961a0070cc
So there is an issue with tracing certain blocks/transactions on Polygon, for example: ``` > '{"method": "trace_transaction","params":["0xb198d93f640343a98f90d93aa2b74b4fc5c64f3a649f1608d2bfd1004f9dee0e"],"id":1,"jsonrpc":"2.0"}' ``` gives the error `first run for txIndex 1 error: insufficient funds for gas * price + value: address 0x10AD27A96CDBffC90ab3b83bF695911426A69f5E have 16927727762862809 want 17594166808296934` The reason is that this transaction is from the author of the block, which doesn't have enough ETH to pay for the gas fee + tx value if he's not the block author receiving transactions fees. The issue is that currently the APIs are using `ethash.NewFaker()` Engine for running traces, etc. which doesn't know how to get the author for a specific block (which is consensus dependant); as it was noting in several TODO comments. The fix is to pass the Engine to the BaseAPI, which can then be used to create the right Block Context. I chose to split the current Engine interface in 2, with Reader and Writer, so that the BaseAPI only receives the Reader one, which might be safer (even though it's only used for getting the block Author).
117 lines
4.8 KiB
Go
117 lines
4.8 KiB
Go
// Copyright 2019 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// 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,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// 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/>.
|
|
|
|
package core
|
|
|
|
import (
|
|
"github.com/ledgerwatch/erigon/common"
|
|
"github.com/ledgerwatch/erigon/consensus"
|
|
"github.com/ledgerwatch/erigon/core/state"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
"github.com/ledgerwatch/erigon/core/vm"
|
|
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
"github.com/ledgerwatch/erigon/params"
|
|
)
|
|
|
|
// applyTransaction attempts to apply a transaction to the given state database
|
|
// and uses the input parameters for its environment. It returns the receipt
|
|
// for the transaction, gas used and an error if the transaction failed,
|
|
// indicating the block was invalid.
|
|
func applyTransaction(config *params.ChainConfig, engine consensus.EngineReader, gp *GasPool, ibs *state.IntraBlockState, stateWriter state.StateWriter, header *types.Header, tx types.Transaction, usedGas *uint64, evm vm.VMInterface, cfg vm.Config) (*types.Receipt, []byte, error) {
|
|
rules := evm.ChainRules()
|
|
msg, err := tx.AsMessage(*types.MakeSigner(config, header.Number.Uint64()), header.BaseFee, rules)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
msg.SetCheckNonce(!cfg.StatelessExec)
|
|
|
|
if msg.FeeCap().IsZero() && engine != nil {
|
|
// Only zero-gas transactions may be service ones
|
|
syscall := func(contract common.Address, data []byte) ([]byte, error) {
|
|
return SysCallContract(contract, data, *config, ibs, header, engine, true /* constCall */)
|
|
}
|
|
msg.SetIsFree(engine.IsServiceTransaction(msg.From(), syscall))
|
|
}
|
|
|
|
txContext := NewEVMTxContext(msg)
|
|
if cfg.TraceJumpDest {
|
|
txContext.TxHash = tx.Hash()
|
|
}
|
|
|
|
// Update the evm with the new transaction context.
|
|
evm.Reset(txContext, ibs)
|
|
|
|
result, err := ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
// Update the state with pending changes
|
|
if err = ibs.FinalizeTx(rules, stateWriter); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
*usedGas += result.UsedGas
|
|
|
|
// Set the receipt logs and create the bloom filter.
|
|
// based on the eip phase, we're passing whether the root touch-delete accounts.
|
|
var receipt *types.Receipt
|
|
if !cfg.NoReceipts {
|
|
// by the tx.
|
|
receipt = &types.Receipt{Type: tx.Type(), CumulativeGasUsed: *usedGas}
|
|
if result.Failed() {
|
|
receipt.Status = types.ReceiptStatusFailed
|
|
} else {
|
|
receipt.Status = types.ReceiptStatusSuccessful
|
|
}
|
|
receipt.TxHash = tx.Hash()
|
|
receipt.GasUsed = result.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.GetNonce())
|
|
}
|
|
// Set the receipt logs and create a bloom for filtering
|
|
receipt.Logs = ibs.GetLogs(tx.Hash())
|
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
|
receipt.BlockNumber = header.Number
|
|
receipt.TransactionIndex = uint(ibs.TxIndex())
|
|
}
|
|
|
|
return receipt, result.ReturnData, err
|
|
}
|
|
|
|
// ApplyTransaction attempts to apply a transaction to the given state database
|
|
// and uses the input parameters for its environment. It returns the receipt
|
|
// for the transaction, gas used and an error if the transaction failed,
|
|
// indicating the block was invalid.
|
|
func ApplyTransaction(config *params.ChainConfig, blockHashFunc func(n uint64) common.Hash, engine consensus.EngineReader, author *common.Address, gp *GasPool, ibs *state.IntraBlockState, stateWriter state.StateWriter, header *types.Header, tx types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, []byte, error) {
|
|
// Create a new context to be used in the EVM environment
|
|
|
|
// Add addresses to access list if applicable
|
|
// about the transaction and calling mechanisms.
|
|
cfg.SkipAnalysis = SkipAnalysis(config, header.Number.Uint64())
|
|
|
|
var vmenv vm.VMInterface
|
|
|
|
if tx.IsStarkNet() {
|
|
vmenv = &vm.CVMAdapter{Cvm: vm.NewCVM(ibs)}
|
|
} else {
|
|
blockContext := NewEVMBlockContext(header, blockHashFunc, engine, author)
|
|
vmenv = vm.NewEVM(blockContext, evmtypes.TxContext{}, ibs, config, cfg)
|
|
}
|
|
|
|
return applyTransaction(config, engine, gp, ibs, stateWriter, header, tx, usedGas, vmenv, cfg)
|
|
}
|