Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error
for i, tx := range txs {
// If the transaction is known, pre-set the error slot
if pool.all.Get(tx.Hash()) != nil {
log.Error("Transaction already known", "tx_hash", tx.Hash())
errs[i] = txpool.ErrAlreadyKnown
knownTxMeter.Mark(1)
continue
Expand Down
3 changes: 3 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -287,7 +288,9 @@ func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
return b.eth.BlockChain().SubscribeLogsEvent(ch)
}

// SendTx sends a signed transaction to the transaction pool.
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
log.Info("transaction entering mempool", "tx_hash", signedTx.Hash().Hex())
return b.eth.txPool.Add([]*types.Transaction{signedTx}, true, false)[0]
}

Expand Down
31 changes: 27 additions & 4 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,12 @@ func (w *worker) mainLoop() {
if !w.isRunning() && w.current != nil {
// If block is already full, abort
if gp := w.current.gasPool; gp != nil && gp.Gas() < params.TxGas {
log.Info("Gas pool is full, skipping transaction", "gas", gp.Gas())
continue
}
txs := make(map[common.Address][]*txpool.LazyTransaction, len(ev.Txs))
for _, tx := range ev.Txs {
log.Info("Adding transaction to pending block", "tx_hash", tx.Hash().Hex())
acc, _ := types.Sender(w.current.signer, tx)
txs[acc] = append(txs[acc], &txpool.LazyTransaction{
Pool: w.eth.TxPool(), // We don't know where this came from, yolo resolve from everywhere
Expand Down Expand Up @@ -750,6 +752,9 @@ func (w *worker) updateSnapshot(env *environment) {
w.snapshotState = env.state.Copy()
}

// This function commits a transaction to the EVM.
// If the transaction type is BlobTxType, it calls the commitBlobTransaction function.
// Otherwise, it applies the transaction and updates the EVM state.
func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
if tx.Type() == types.BlobTxType {
return w.commitBlobTransaction(env, tx)
Expand All @@ -762,7 +767,6 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]*
env.receipts = append(env.receipts, receipt)
return receipt.Logs, nil
}

func (w *worker) commitBlobTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) {
sc := tx.BlobTxSidecar()
if sc == nil {
Expand Down Expand Up @@ -793,14 +797,20 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ
snap = env.state.Snapshot()
gp = env.gasPool.Gas()
)
log.Info("executing transaction on node", "tx_hash", tx.Hash(), "gas_available", gp)
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &env.coinbase, env.gasPool, env.state, env.header, tx, &env.header.GasUsed, *w.chain.GetVMConfig())
if err != nil {
log.Error("Transaction application failed", "tx_hash", tx.Hash(), "error", err)
env.state.RevertToSnapshot(snap)
env.gasPool.SetGas(gp)
} else {
log.Info("Transaction applied successfully", "tx_hash", tx.Hash(), "gas_used", env.header.GasUsed)
}
return receipt, err
}

// This function commits transactions by processing them in order of price and nonce.
// It handles transaction execution, gas and tip calculations, and interruption handling.
func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAndNonce, interrupt *atomic.Int32, minTip *big.Int) error {
gasLimit := env.header.GasLimit
if env.gasPool == nil {
Expand All @@ -827,7 +837,7 @@ func (w *worker) commitTransactions(env *environment, txs *transactionsByPriceAn
}
// If we don't have enough space for the next transaction, skip the account.
if env.gasPool.Gas() < ltx.Gas {
log.Trace("Not enough gas left for transaction", "hash", ltx.Hash, "left", env.gasPool.Gas(), "needed", ltx.Gas)
log.Info("Not enough gas left for transaction", "hash", ltx.Hash, "left", env.gasPool.Gas(), "needed", ltx.Gas)
txs.Pop()
continue
}
Expand Down Expand Up @@ -1000,7 +1010,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
// be customized with the plugin in the future.
func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) error {
pending := w.eth.TxPool().Pending(true)

log.Info("Pending transactions retrieved in fillTransactions", "count", len(pending))
// Split the pending transactions into locals and remotes.
localTxs, remoteTxs := make(map[common.Address][]*txpool.LazyTransaction), pending
for _, account := range w.eth.TxPool().Locals() {
Expand Down Expand Up @@ -1032,8 +1042,10 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err

// generateWork generates a sealing block based on the given parameters.
func (w *worker) generateWork(params *generateParams) *newPayloadResult {
log.Info("Starting to generate work for sealing block", "params", params)
work, err := w.prepareWork(params)
if err != nil {
log.Error("Failed to prepare work for sealing", "error", err)
return &newPayloadResult{err: err}
}
defer work.discard()
Expand All @@ -1042,18 +1054,29 @@ func (w *worker) generateWork(params *generateParams) *newPayloadResult {
interrupt := new(atomic.Int32)
timer := time.AfterFunc(w.newpayloadTimeout, func() {
interrupt.Store(commitInterruptTimeout)
log.Info("Transaction processing interrupted due to timeout", "timeout", w.newpayloadTimeout)
})
defer timer.Stop()

err := w.fillTransactions(interrupt, work)
if errors.Is(err, errBlockInterruptedByTimeout) {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(w.newpayloadTimeout))
log.Warn("Block building is interrupted by timeout", "allowance", common.PrettyDuration(w.newpayloadTimeout))
} else if err != nil {
log.Error("Error while filling transactions into block", "error", err)
} else {
log.Info("Transactions successfully filled into block")
}
} else {
log.Info("No transactions to process as per parameters")
}

log.Info("Finalizing and assembling block")
block, err := w.engine.FinalizeAndAssemble(w.chain, work.header, work.state, work.txs, nil, work.receipts, params.withdrawals)
if err != nil {
log.Error("Failed to finalize and assemble block", "error", err)
return &newPayloadResult{err: err}
}
log.Info("Block successfully finalized and assembled", "blockHash", block.Hash())
return &newPayloadResult{
block: block,
fees: totalFees(block, work.receipts),
Expand Down