From ee7f0f78d7a13b737541cac4d6d4544a26bee59d Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Tue, 26 Mar 2024 11:01:29 +0100 Subject: [PATCH] Dedicated log marker for invalid txs removed from the txpool Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 1 + besu/src/main/resources/log4j2.xml | 3 +++ .../layered/LayeredPendingTransactions.java | 22 +++++++++++++++++-- .../AbstractPendingTransactionsSorter.java | 22 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b24a6f89a..436748a4eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Extend error handling of plugin RPC methods [#6759](https://github.com/hyperledger/besu/pull/6759) - Added engine_newPayloadV4 and engine_getPayloadV4 methods [#6783](https://github.com/hyperledger/besu/pull/6783) - Reduce storage size of receipts [#6602](https://github.com/hyperledger/besu/pull/6602) +- Dedicated log marker for invalid txs removed from the txpool [#6826](https://github.com/hyperledger/besu/pull/6826) ### Bug fixes - Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665) diff --git a/besu/src/main/resources/log4j2.xml b/besu/src/main/resources/log4j2.xml index 80ba817fe7c..d47cc9a40fc 100644 --- a/besu/src/main/resources/log4j2.xml +++ b/besu/src/main/resources/log4j2.xml @@ -48,6 +48,9 @@ + + + diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java index d9b6b60814d..5b2eadf87f0 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java @@ -37,6 +37,7 @@ import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; +import org.hyperledger.besu.plugin.data.TransactionSelectionResult; import java.util.ArrayDeque; import java.util.ArrayList; @@ -53,10 +54,13 @@ import kotlin.ranges.LongRange; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; public class LayeredPendingTransactions implements PendingTransactions { private static final Logger LOG = LoggerFactory.getLogger(LayeredPendingTransactions.class); private static final Logger LOG_FOR_REPLAY = LoggerFactory.getLogger("LOG_FOR_REPLAY"); + private static final Marker INVALID_TX_REMOVED = MarkerFactory.getMarker("INVALID_TX_REMOVED"); private final TransactionPoolConfiguration poolConfig; private final AbstractPrioritizedTransactions prioritizedTransactions; @@ -234,7 +238,8 @@ private void logTransactionForReplayAdd( .log(); } - private void logTransactionForReplayDelete(final PendingTransaction pendingTransaction) { + private void logDiscardedTransaction( + final PendingTransaction pendingTransaction, final TransactionSelectionResult result) { // csv fields: sequence, addedAt, sender, nonce, type, hash, rlp LOG_FOR_REPLAY .atTrace() @@ -252,6 +257,19 @@ private void logTransactionForReplayDelete(final PendingTransaction pendingTrans return rlp.encoded().toHexString(); }) .log(); + LOG.atInfo() + .addMarker(INVALID_TX_REMOVED) + .addKeyValue("txhash", pendingTransaction::getHash) + .addKeyValue("txlog", pendingTransaction::toTraceLog) + .addKeyValue("reason", result) + .addKeyValue( + "txrlp", + () -> { + final BytesValueRLPOutput rlp = new BytesValueRLPOutput(); + pendingTransaction.getTransaction().writeTo(rlp); + return rlp.encoded().toHexString(); + }) + .log(); } private TransactionAddedResult nonceChecks( @@ -333,7 +351,7 @@ public synchronized void selectTransactions( if (res.discard()) { invalidTransactions.add(candidatePendingTx); - logTransactionForReplayDelete(candidatePendingTx); + logDiscardedTransaction(candidatePendingTx, res); } if (res.stop()) { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java index bb53a8e4fbd..fa2efa53c84 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolReplacementHandler; import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; +import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.metrics.BesuMetricCategory; @@ -61,6 +62,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; /** * Holds the current set of pending transactions with the ability to iterate them based on priority @@ -71,6 +74,7 @@ public abstract class AbstractPendingTransactionsSorter implements PendingTransactions { private static final Logger LOG = LoggerFactory.getLogger(AbstractPendingTransactionsSorter.class); + private static final Marker INVALID_TX_REMOVED = MarkerFactory.getMarker("INVALID_TX_REMOVED"); protected final Clock clock; protected final TransactionPoolConfiguration poolConfig; @@ -247,6 +251,7 @@ public void selectTransactions(final TransactionSelector selector) { if (result.discard()) { transactionsToRemove.add(transactionToProcess.getTransaction()); + logDiscardedTransaction(transactionToProcess, result); } if (result.stop()) { @@ -259,6 +264,23 @@ public void selectTransactions(final TransactionSelector selector) { } } + private void logDiscardedTransaction( + final PendingTransaction pendingTransaction, final TransactionSelectionResult result) { + LOG.atInfo() + .addMarker(INVALID_TX_REMOVED) + .addKeyValue("txhash", pendingTransaction::getHash) + .addKeyValue("txlog", pendingTransaction::toTraceLog) + .addKeyValue("reason", result) + .addKeyValue( + "txrlp", + () -> { + final BytesValueRLPOutput rlp = new BytesValueRLPOutput(); + pendingTransaction.getTransaction().writeTo(rlp); + return rlp.encoded().toHexString(); + }) + .log(); + } + private AccountTransactionOrder createSenderTransactionOrder(final Address address) { return new AccountTransactionOrder( transactionsBySender.get(address).streamPendingTransactions());