Compare commits
5 Commits
ffd2983028
...
5848954691
Author | SHA1 | Date |
---|---|---|
rjl493456442 | 5848954691 | |
Hyunsoo Shin (Lake) | 19fa71b917 | |
Martin HS | 02159d553f | |
Martin HS | ab4a1cc01f | |
Gary Rong | 7c19e2a9fb |
|
@ -151,7 +151,6 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
statedb = MakePreState(rawdb.NewMemoryDatabase(), pre.Pre)
|
||||
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
|
||||
gaspool = new(core.GasPool)
|
||||
blockHash = common.Hash{0x13, 0x37}
|
||||
rejectedTxs []*rejectedTx
|
||||
includedTxs types.Transactions
|
||||
gasUsed = uint64(0)
|
||||
|
@ -312,7 +311,9 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
}
|
||||
|
||||
// Set the receipt logs and create the bloom filter.
|
||||
receipt.Logs = statedb.GetLogs(tx.Hash(), vmContext.BlockNumber.Uint64(), blockHash)
|
||||
receipt.Logs = statedb.GetLogs(tx.Hash())
|
||||
// TODO (rjl493456442) should we derive fields for logs? receipts?
|
||||
|
||||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||
// These three are non-consensus fields:
|
||||
//receipt.BlockHash
|
||||
|
@ -367,9 +368,9 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
|
|||
var requests [][]byte
|
||||
if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) {
|
||||
// EIP-6110 deposits
|
||||
var allLogs []*types.Log
|
||||
var allLogs [][]*types.Log
|
||||
for _, receipt := range receipts {
|
||||
allLogs = append(allLogs, receipt.Logs...)
|
||||
allLogs = append(allLogs, receipt.Logs)
|
||||
}
|
||||
depositRequests, err := core.ParseDepositLogs(allLogs, chainConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -34,7 +34,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"github.com/ethereum/go-ethereum/common/prque"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
||||
|
@ -1534,7 +1533,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
|||
|
||||
// writeBlockAndSetHead is the internal implementation of WriteBlockAndSetHead.
|
||||
// This function expects the chain mutex to be held.
|
||||
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
||||
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs [][]*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
||||
if err := bc.writeBlockWithState(block, receipts, state); err != nil {
|
||||
return NonStatTy, err
|
||||
}
|
||||
|
@ -1552,7 +1551,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
|
|||
|
||||
bc.chainFeed.Send(ChainEvent{Header: block.Header()})
|
||||
if len(logs) > 0 {
|
||||
bc.logsFeed.Send(logs)
|
||||
bc.logsFeed.Send(types.DeriveLogFields(block.Hash(), block.NumberU64(), logs, block.Transactions(), false))
|
||||
}
|
||||
// In theory, we should fire a ChainHeadEvent when we inject
|
||||
// a canonical block, but sometimes we can insert a batch of
|
||||
|
@ -2157,25 +2156,11 @@ func (bc *BlockChain) recoverAncestors(block *types.Block, makeWitness bool) (co
|
|||
// collectLogs collects the logs that were generated or removed during the
|
||||
// processing of a block. These logs are later announced as deleted or reborn.
|
||||
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
|
||||
var blobGasPrice *big.Int
|
||||
excessBlobGas := b.ExcessBlobGas()
|
||||
if excessBlobGas != nil {
|
||||
blobGasPrice = eip4844.CalcBlobFee(*excessBlobGas)
|
||||
var logs [][]*types.Log
|
||||
for _, receipt := range rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64()) {
|
||||
logs = append(logs, receipt.Logs)
|
||||
}
|
||||
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
|
||||
if err := receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), blobGasPrice, b.Transactions()); err != nil {
|
||||
log.Error("Failed to derive block receipts fields", "hash", b.Hash(), "number", b.NumberU64(), "err", err)
|
||||
}
|
||||
var logs []*types.Log
|
||||
for _, receipt := range receipts {
|
||||
for _, log := range receipt.Logs {
|
||||
if removed {
|
||||
log.Removed = true
|
||||
}
|
||||
logs = append(logs, log)
|
||||
}
|
||||
}
|
||||
return logs
|
||||
return types.DeriveLogFields(b.Hash(), b.NumberU64(), logs, b.Transactions(), removed)
|
||||
}
|
||||
|
||||
// reorg takes two blocks, an old chain and a new chain and will reconstruct the
|
||||
|
|
|
@ -124,6 +124,7 @@ func (b *BlockGen) addTx(bc *BlockChain, vmConfig vm.Config, tx *types.Transacti
|
|||
}
|
||||
b.txs = append(b.txs, tx)
|
||||
b.receipts = append(b.receipts, receipt)
|
||||
|
||||
if b.header.BlobGasUsed != nil {
|
||||
*b.header.BlobGasUsed += receipt.BlobGasUsed
|
||||
}
|
||||
|
@ -350,9 +351,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
|||
var requests [][]byte
|
||||
if config.IsPrague(b.header.Number, b.header.Time) {
|
||||
// EIP-6110 deposits
|
||||
var blockLogs []*types.Log
|
||||
var blockLogs [][]*types.Log
|
||||
for _, r := range b.receipts {
|
||||
blockLogs = append(blockLogs, r.Logs...)
|
||||
blockLogs = append(blockLogs, r.Logs)
|
||||
}
|
||||
depositRequests, err := ParseDepositLogs(blockLogs, config)
|
||||
if err != nil {
|
||||
|
@ -421,7 +422,6 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
|||
if err := receipts.DeriveFields(config, block.Hash(), block.NumberU64(), block.Time(), block.BaseFee(), blobGasPrice, txs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Re-expand to ensure all receipts are returned.
|
||||
receipts = receipts[:receiptsCount]
|
||||
|
||||
|
|
|
@ -244,15 +244,12 @@ func (s *StateDB) AddLog(log *types.Log) {
|
|||
s.logSize++
|
||||
}
|
||||
|
||||
// GetLogs returns the logs matching the specified transaction hash, and annotates
|
||||
// them with the given blockNumber and blockHash.
|
||||
func (s *StateDB) GetLogs(hash common.Hash, blockNumber uint64, blockHash common.Hash) []*types.Log {
|
||||
logs := s.logs[hash]
|
||||
for _, l := range logs {
|
||||
l.BlockNumber = blockNumber
|
||||
l.BlockHash = blockHash
|
||||
}
|
||||
return logs
|
||||
// GetLogs returns the logs matching the specified transaction hash.
|
||||
//
|
||||
// TODO (rjl493456442) these logs are partially annotated (with transaction
|
||||
// information), please get rid of these annotations as well.
|
||||
func (s *StateDB) GetLogs(hash common.Hash) []*types.Log {
|
||||
return s.logs[hash]
|
||||
}
|
||||
|
||||
func (s *StateDB) Logs() []*types.Log {
|
||||
|
|
|
@ -673,9 +673,9 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
|
|||
return fmt.Errorf("got GetRefund() == %d, want GetRefund() == %d",
|
||||
state.GetRefund(), checkstate.GetRefund())
|
||||
}
|
||||
if !reflect.DeepEqual(state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{})) {
|
||||
if !reflect.DeepEqual(state.GetLogs(common.Hash{}), checkstate.GetLogs(common.Hash{})) {
|
||||
return fmt.Errorf("got GetLogs(common.Hash{}) == %v, want GetLogs(common.Hash{}) == %v",
|
||||
state.GetLogs(common.Hash{}, 0, common.Hash{}), checkstate.GetLogs(common.Hash{}, 0, common.Hash{}))
|
||||
state.GetLogs(common.Hash{}), checkstate.GetLogs(common.Hash{}))
|
||||
}
|
||||
if !maps.Equal(state.journal.dirties, checkstate.journal.dirties) {
|
||||
getKeys := func(dirty map[common.Address]int) string {
|
||||
|
|
|
@ -18,14 +18,12 @@ package core
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/consensus/misc"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"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/params"
|
||||
)
|
||||
|
||||
|
@ -55,15 +53,12 @@ func NewStateProcessor(config *params.ChainConfig, chain *HeaderChain) *StatePro
|
|||
// transactions failed to execute due to insufficient gas it will return an error.
|
||||
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (*ProcessResult, error) {
|
||||
var (
|
||||
receipts types.Receipts
|
||||
usedGas = new(uint64)
|
||||
header = block.Header()
|
||||
blockHash = block.Hash()
|
||||
blockNumber = block.Number()
|
||||
allLogs []*types.Log
|
||||
gp = new(GasPool).AddGas(block.GasLimit())
|
||||
receipts types.Receipts
|
||||
usedGas = new(uint64)
|
||||
header = block.Header()
|
||||
allLogs [][]*types.Log
|
||||
gp = new(GasPool).AddGas(block.GasLimit())
|
||||
)
|
||||
|
||||
// Mutate the block and state according to any hard-fork specs
|
||||
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
|
||||
misc.ApplyDAOHardFork(statedb)
|
||||
|
@ -96,12 +91,12 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
}
|
||||
statedb.SetTxContext(tx.Hash(), i)
|
||||
|
||||
receipt, err := ApplyTransactionWithEVM(msg, gp, statedb, blockNumber, blockHash, tx, usedGas, evm)
|
||||
receipt, err := ApplyTransactionWithEVM(msg, gp, statedb, tx, usedGas, evm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
|
||||
}
|
||||
receipts = append(receipts, receipt)
|
||||
allLogs = append(allLogs, receipt.Logs...)
|
||||
allLogs = append(allLogs, receipt.Logs)
|
||||
}
|
||||
// Read requests if Prague is enabled.
|
||||
var requests [][]byte
|
||||
|
@ -134,16 +129,17 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
|||
// ApplyTransactionWithEVM attempts to apply a transaction to the given state database
|
||||
// and uses the input parameters for its environment similar to ApplyTransaction. However,
|
||||
// this method takes an already created EVM instance as input.
|
||||
func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (receipt *types.Receipt, err error) {
|
||||
func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (receipt *types.Receipt, err error) {
|
||||
if hooks := evm.Config.Tracer; hooks != nil {
|
||||
if hooks.OnTxStart != nil {
|
||||
hooks.OnTxStart(evm.GetVMContext(), tx, msg.From)
|
||||
}
|
||||
if hooks.OnTxEnd != nil {
|
||||
// TODO (rjl493456442) the receipt only contain consensus fields,
|
||||
// should we derive the others here?
|
||||
defer func() { hooks.OnTxEnd(receipt, err) }()
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new context to be used in the EVM environment.
|
||||
txContext := NewEVMTxContext(msg)
|
||||
evm.SetTxContext(txContext)
|
||||
|
@ -153,9 +149,9 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Update the state with pending changes.
|
||||
var root []byte
|
||||
blockNumber := evm.Context.BlockNumber
|
||||
if evm.ChainConfig().IsByzantium(blockNumber) {
|
||||
evm.StateDB.Finalise(true)
|
||||
} else {
|
||||
|
@ -163,11 +159,13 @@ func ApplyTransactionWithEVM(msg *Message, gp *GasPool, statedb *state.StateDB,
|
|||
}
|
||||
*usedGas += result.UsedGas
|
||||
|
||||
return MakeReceipt(evm, result, statedb, blockNumber, blockHash, tx, *usedGas, root), nil
|
||||
return MakeReceipt(evm, result, statedb, tx, *usedGas, root), nil
|
||||
}
|
||||
|
||||
// MakeReceipt generates the receipt object for a transaction given its execution result.
|
||||
func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas uint64, root []byte) *types.Receipt {
|
||||
// MakeReceipt generates the receipt object for a transaction based on its execution
|
||||
// result. Note that the generated receipt only includes the consensus fields. Any
|
||||
// additional fields must be derived separately by the caller if needed.
|
||||
func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, tx *types.Transaction, usedGas uint64, root []byte) *types.Receipt {
|
||||
// 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: usedGas}
|
||||
|
@ -176,31 +174,17 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
|
|||
} else {
|
||||
receipt.Status = types.ReceiptStatusSuccessful
|
||||
}
|
||||
receipt.TxHash = tx.Hash()
|
||||
receipt.GasUsed = result.UsedGas
|
||||
|
||||
if tx.Type() == types.BlobTxType {
|
||||
receipt.BlobGasUsed = uint64(len(tx.BlobHashes()) * params.BlobTxBlobGasPerBlob)
|
||||
receipt.BlobGasPrice = evm.Context.BlobBaseFee
|
||||
}
|
||||
|
||||
// If the transaction created a contract, store the creation address in the receipt.
|
||||
if tx.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())
|
||||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||
|
||||
// Merge the tx-local access event into the "block-local" one, in order to collect
|
||||
// all values, so that the witness can be built.
|
||||
//
|
||||
// TODO (rjl493456442) relocate it to a better place.
|
||||
if statedb.GetTrie().IsVerkle() {
|
||||
statedb.AccessEvents().Merge(evm.AccessEvents)
|
||||
}
|
||||
|
||||
// Set the receipt logs and create the bloom filter.
|
||||
receipt.Logs = statedb.GetLogs(tx.Hash(), blockNumber.Uint64(), blockHash)
|
||||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||
receipt.BlockHash = blockHash
|
||||
receipt.BlockNumber = blockNumber
|
||||
receipt.TransactionIndex = uint(statedb.TxIndex())
|
||||
return receipt
|
||||
}
|
||||
|
||||
|
@ -208,13 +192,16 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b
|
|||
// 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.
|
||||
//
|
||||
// Note that the generated receipt only includes the consensus fields. Any
|
||||
// additional fields must be derived separately by the caller if needed.
|
||||
func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64) (*types.Receipt, error) {
|
||||
msg, err := TransactionToMessage(tx, types.MakeSigner(evm.ChainConfig(), header.Number, header.Time), header.BaseFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Create a new context to be used in the EVM environment
|
||||
return ApplyTransactionWithEVM(msg, gp, statedb, header.Number, header.Hash(), tx, usedGas, evm)
|
||||
return ApplyTransactionWithEVM(msg, gp, statedb, tx, usedGas, evm)
|
||||
}
|
||||
|
||||
// ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root
|
||||
|
@ -312,15 +299,17 @@ func processRequestsSystemCall(evm *vm.EVM, requestType byte, addr common.Addres
|
|||
|
||||
// ParseDepositLogs extracts the EIP-6110 deposit values from logs emitted by
|
||||
// BeaconDepositContract.
|
||||
func ParseDepositLogs(logs []*types.Log, config *params.ChainConfig) ([]byte, error) {
|
||||
func ParseDepositLogs(logs [][]*types.Log, config *params.ChainConfig) ([]byte, error) {
|
||||
deposits := make([]byte, 1) // note: first byte is 0x00 (== deposit request type)
|
||||
for _, log := range logs {
|
||||
if log.Address == config.DepositContractAddress {
|
||||
request, err := types.DepositLogToRequest(log.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse deposit data: %v", err)
|
||||
for _, subLogs := range logs {
|
||||
for _, log := range subLogs {
|
||||
if log.Address == config.DepositContractAddress {
|
||||
request, err := types.DepositLogToRequest(log.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse deposit data: %v", err)
|
||||
}
|
||||
deposits = append(deposits, request...)
|
||||
}
|
||||
deposits = append(deposits, request...)
|
||||
}
|
||||
}
|
||||
return deposits, nil
|
||||
|
|
|
@ -55,6 +55,6 @@ type Processor interface {
|
|||
type ProcessResult struct {
|
||||
Receipts types.Receipts
|
||||
Requests [][]byte
|
||||
Logs []*types.Log
|
||||
Logs [][]*types.Log
|
||||
GasUsed uint64
|
||||
}
|
||||
|
|
|
@ -59,3 +59,28 @@ type logMarshaling struct {
|
|||
TxIndex hexutil.Uint
|
||||
Index hexutil.Uint
|
||||
}
|
||||
|
||||
// DeriveLogFields fills the logs with contextual infos like corresponding block
|
||||
// and transaction info.
|
||||
func DeriveLogFields(hash common.Hash, number uint64, logs [][]*Log, txs []*Transaction, removed bool) []*Log {
|
||||
var (
|
||||
combined []*Log
|
||||
logIndex = uint(0)
|
||||
)
|
||||
for i := 0; i < len(txs); i++ {
|
||||
for j := 0; j < len(logs[i]); j++ {
|
||||
l := logs[i][j]
|
||||
l.BlockNumber = number
|
||||
l.BlockHash = hash
|
||||
l.TxHash = txs[i].Hash()
|
||||
l.TxIndex = uint(i)
|
||||
l.Index = logIndex
|
||||
if removed {
|
||||
l.Removed = true
|
||||
}
|
||||
combined = append(combined, l)
|
||||
logIndex++
|
||||
}
|
||||
}
|
||||
return combined
|
||||
}
|
||||
|
|
|
@ -321,8 +321,8 @@ func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) {
|
|||
}
|
||||
}
|
||||
|
||||
// DeriveFields fills the receipts with their computed fields based on consensus
|
||||
// data and contextual infos like containing block and transactions.
|
||||
// DeriveFields fills the receipts and logs with their computed fields based
|
||||
// on consensus data and contextual infos like containing block and transactions.
|
||||
func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, number uint64, time uint64, baseFee *big.Int, blobGasPrice *big.Int, txs []*Transaction) error {
|
||||
signer := MakeSigner(config, new(big.Int).SetUint64(number), time)
|
||||
|
||||
|
|
|
@ -1037,7 +1037,7 @@ func (api *API) traceTx(ctx context.Context, tx *types.Transaction, message *cor
|
|||
|
||||
// Call Prepare to clear out the statedb access list
|
||||
statedb.SetTxContext(txctx.TxHash, txctx.TxIndex)
|
||||
_, err = core.ApplyTransactionWithEVM(message, new(core.GasPool).AddGas(message.GasLimit), statedb, vmctx.BlockNumber, txctx.BlockHash, tx, &usedGas, evm)
|
||||
_, err = core.ApplyTransactionWithEVM(message, new(core.GasPool).AddGas(message.GasLimit), statedb, tx, &usedGas, evm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("tracing failed: %w", err)
|
||||
}
|
||||
|
|
|
@ -363,26 +363,35 @@ func (t *mdLogger) OnEnter(depth int, typ byte, from common.Address, to common.A
|
|||
if depth != 0 {
|
||||
return
|
||||
}
|
||||
create := vm.OpCode(typ) == vm.CREATE
|
||||
if !create {
|
||||
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
|
||||
from.String(), to.String(),
|
||||
input, gas, value)
|
||||
if create := vm.OpCode(typ) == vm.CREATE; !create {
|
||||
fmt.Fprintf(t.out, "Pre-execution info:\n"+
|
||||
" - from: `%v`\n"+
|
||||
" - to: `%v`\n"+
|
||||
" - data: `%#x`\n"+
|
||||
" - gas: `%d`\n"+
|
||||
" - value: `%v` wei\n",
|
||||
from.String(), to.String(), input, gas, value)
|
||||
} else {
|
||||
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
|
||||
from.String(), to.String(),
|
||||
input, gas, value)
|
||||
fmt.Fprintf(t.out, "Pre-execution info:\n"+
|
||||
" - from: `%v`\n"+
|
||||
" - create: `%v`\n"+
|
||||
" - data: `%#x`\n"+
|
||||
" - gas: `%d`\n"+
|
||||
" - value: `%v` wei\n",
|
||||
from.String(), to.String(), input, gas, value)
|
||||
}
|
||||
|
||||
fmt.Fprintf(t.out, `
|
||||
| Pc | Op | Cost | Stack | RStack | Refund |
|
||||
|-------|-------------|------|-----------|-----------|---------|
|
||||
| Pc | Op | Cost | Refund | Stack |
|
||||
|-------|-------------|------|-----------|-----------|
|
||||
`)
|
||||
}
|
||||
|
||||
func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
if depth == 0 {
|
||||
fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
|
||||
fmt.Fprintf(t.out, "\nPost-execution info:\n"+
|
||||
" - output: `%#x`\n"+
|
||||
" - consumed gas: `%d`\n"+
|
||||
" - error: `%v`\n",
|
||||
output, gasUsed, err)
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +399,8 @@ func (t *mdLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, r
|
|||
// OnOpcode also tracks SLOAD/SSTORE ops to track storage change.
|
||||
func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||
stack := scope.StackData()
|
||||
fmt.Fprintf(t.out, "| %4d | %10v | %3d |", pc, vm.OpCode(op).String(), cost)
|
||||
fmt.Fprintf(t.out, "| %4d | %10v | %3d |%10v |", pc, vm.OpCode(op).String(),
|
||||
cost, t.env.StateDB.GetRefund())
|
||||
|
||||
if !t.cfg.DisableStack {
|
||||
// format stack
|
||||
|
@ -401,7 +411,6 @@ func (t *mdLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.
|
|||
b := fmt.Sprintf("[%v]", strings.Join(a, ","))
|
||||
fmt.Fprintf(t.out, "%10v |", b)
|
||||
}
|
||||
fmt.Fprintf(t.out, "%10v |", t.env.StateDB.GetRefund())
|
||||
fmt.Fprintln(t.out, "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(t.out, "Error: %v\n", err)
|
||||
|
|
|
@ -71,7 +71,7 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *tracing.Hooks {
|
|||
l.hooks = &tracing.Hooks{
|
||||
OnTxStart: l.OnTxStart,
|
||||
OnSystemCallStart: l.onSystemCallStart,
|
||||
OnExit: l.OnEnd,
|
||||
OnExit: l.OnExit,
|
||||
OnOpcode: l.OnOpcode,
|
||||
OnFault: l.OnFault,
|
||||
}
|
||||
|
@ -152,13 +152,6 @@ func (l *jsonLogger) OnEnter(depth int, typ byte, from common.Address, to common
|
|||
l.encoder.Encode(frame)
|
||||
}
|
||||
|
||||
func (l *jsonLogger) OnEnd(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
if depth > 0 {
|
||||
return
|
||||
}
|
||||
l.OnExit(depth, output, gasUsed, err, false)
|
||||
}
|
||||
|
||||
func (l *jsonLogger) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
type endLog struct {
|
||||
Output string `json:"output"`
|
||||
|
|
|
@ -21,7 +21,6 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
|
@ -179,6 +178,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
txes = make([]*types.Transaction, len(block.Calls))
|
||||
callResults = make([]simCallResult, len(block.Calls))
|
||||
receipts = make([]*types.Receipt, len(block.Calls))
|
||||
|
||||
// Block hash will be repaired after execution.
|
||||
tracer = newTracer(sim.traceTransfers, blockContext.BlockNumber.Uint64(), common.Hash{}, common.Hash{}, 0)
|
||||
vmConfig = &vm.Config{
|
||||
|
@ -186,7 +186,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
Tracer: tracer.Hooks(),
|
||||
}
|
||||
)
|
||||
var tracingStateDB = vm.StateDB(sim.state)
|
||||
tracingStateDB := vm.StateDB(sim.state)
|
||||
if hooks := tracer.Hooks(); hooks != nil {
|
||||
tracingStateDB = state.NewHookedState(sim.state, hooks)
|
||||
}
|
||||
|
@ -206,7 +206,8 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
tx := call.ToTransaction(types.DynamicFeeTxType)
|
||||
txes[i] = tx
|
||||
tracer.reset(tx.Hash(), uint(i))
|
||||
// EoA check is always skipped, even in validation mode.
|
||||
|
||||
// EOA check is always skipped, even in validation mode.
|
||||
msg := call.ToMessage(header.BaseFee, !sim.validate, true)
|
||||
evm.SetTxContext(core.NewEVMTxContext(msg))
|
||||
result, err := applyMessageWithEVM(ctx, evm, msg, timeout, sim.gp)
|
||||
|
@ -222,10 +223,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
root = sim.state.IntermediateRoot(sim.chainConfig.IsEIP158(blockContext.BlockNumber)).Bytes()
|
||||
}
|
||||
gasUsed += result.UsedGas
|
||||
receipts[i] = core.MakeReceipt(evm, result, sim.state, blockContext.BlockNumber, common.Hash{}, tx, gasUsed, root)
|
||||
blobGasUsed += receipts[i].BlobGasUsed
|
||||
logs := tracer.Logs()
|
||||
callRes := simCallResult{ReturnValue: result.Return(), Logs: logs, GasUsed: hexutil.Uint64(result.UsedGas)}
|
||||
receipts[i] = core.MakeReceipt(evm, result, sim.state, tx, gasUsed, root)
|
||||
blobGasUsed += tx.BlobGas()
|
||||
|
||||
callRes := simCallResult{ReturnValue: result.Return(), Logs: tracer.Logs(), GasUsed: hexutil.Uint64(result.UsedGas)}
|
||||
if result.Failed() {
|
||||
callRes.Status = hexutil.Uint64(types.ReceiptStatusFailed)
|
||||
if errors.Is(result.Err, vm.ErrExecutionReverted) {
|
||||
|
@ -242,6 +243,7 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
|
|||
}
|
||||
header.Root = sim.state.IntermediateRoot(true)
|
||||
header.GasUsed = gasUsed
|
||||
|
||||
if sim.chainConfig.IsCancun(header.Number, header.Time) {
|
||||
header.BlobGasUsed = &blobGasUsed
|
||||
}
|
||||
|
@ -289,7 +291,7 @@ func (sim *simulator) activePrecompiles(base *types.Header) vm.PrecompiledContra
|
|||
isMerge = (base.Difficulty.Sign() == 0)
|
||||
rules = sim.chainConfig.Rules(base.Number, isMerge, base.Time)
|
||||
)
|
||||
return maps.Clone(vm.ActivePrecompiledContracts(rules))
|
||||
return vm.ActivePrecompiledContracts(rules)
|
||||
}
|
||||
|
||||
// sanitizeChain checks the chain integrity. Specifically it checks that
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/txpool"
|
||||
|
@ -133,13 +134,13 @@ func (miner *Miner) BuildPayload(args *BuildPayloadArgs, witness bool) (*Payload
|
|||
// getPending retrieves the pending block based on the current head block.
|
||||
// The result might be nil if pending generation is failed.
|
||||
func (miner *Miner) getPending() *newPayloadResult {
|
||||
header := miner.chain.CurrentHeader()
|
||||
miner.pendingMu.Lock()
|
||||
defer miner.pendingMu.Unlock()
|
||||
|
||||
header := miner.chain.CurrentHeader()
|
||||
if cached := miner.pending.resolve(header.Hash()); cached != nil {
|
||||
return cached
|
||||
}
|
||||
|
||||
var (
|
||||
timestamp = uint64(time.Now().Unix())
|
||||
withdrawal types.Withdrawals
|
||||
|
@ -160,6 +161,15 @@ func (miner *Miner) getPending() *newPayloadResult {
|
|||
if ret.err != nil {
|
||||
return nil
|
||||
}
|
||||
// Derive the receipt fields for RPC querying.
|
||||
var blobGasPrice *big.Int
|
||||
if ret.block.ExcessBlobGas() != nil {
|
||||
blobGasPrice = eip4844.CalcBlobFee(*ret.block.ExcessBlobGas())
|
||||
}
|
||||
err := types.Receipts(ret.receipts).DeriveFields(miner.chain.Config(), ret.block.Hash(), ret.block.NumberU64(), ret.block.Time(), ret.block.BaseFee(), blobGasPrice, ret.block.Transactions())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
miner.pending.update(header.Hash(), ret)
|
||||
return ret
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ type newPayloadResult struct {
|
|||
fees *big.Int // total block fees
|
||||
sidecars []*types.BlobTxSidecar // collected blobs of blob transactions
|
||||
stateDB *state.StateDB // StateDB after executing the transactions
|
||||
receipts []*types.Receipt // Receipts collected during construction
|
||||
receipts []*types.Receipt // Receipts collected during construction, only contain consensus fields
|
||||
requests [][]byte // Consensus layer requests collected during block construction
|
||||
witness *stateless.Witness // Witness is an optional stateless proof
|
||||
}
|
||||
|
@ -113,11 +113,10 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo
|
|||
}
|
||||
|
||||
body := types.Body{Transactions: work.txs, Withdrawals: params.withdrawals}
|
||||
allLogs := make([]*types.Log, 0)
|
||||
var allLogs [][]*types.Log
|
||||
for _, r := range work.receipts {
|
||||
allLogs = append(allLogs, r.Logs...)
|
||||
allLogs = append(allLogs, r.Logs)
|
||||
}
|
||||
|
||||
// Collect consensus-layer requests if Prague is enabled.
|
||||
var requests [][]byte
|
||||
if miner.chainConfig.IsPrague(work.header.Number, work.header.Time) {
|
||||
|
@ -138,7 +137,6 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo
|
|||
reqHash := types.CalcRequestsHash(requests)
|
||||
work.header.RequestsHash = &reqHash
|
||||
}
|
||||
|
||||
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts)
|
||||
if err != nil {
|
||||
return &newPayloadResult{err: err}
|
||||
|
|
Loading…
Reference in New Issue