diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 624dafc60d03..9914daafd9b2 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -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 diff --git a/eth/api_backend.go b/eth/api_backend.go index 0edcce5c8789..35da87c74653 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -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" @@ -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] } diff --git a/miner/worker.go b/miner/worker.go index 201db9ea8b68..12d7010f92bf 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -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 @@ -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) @@ -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 { @@ -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 { @@ -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 } @@ -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() { @@ -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() @@ -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),