Skip to content

Commit

Permalink
Dedicated log marker for invalid txs removed from the txpool (hyperle…
Browse files Browse the repository at this point in the history
…dger#6826)

Signed-off-by: Fabio Di Fabio <[email protected]>
Signed-off-by: Justin Florentine <[email protected]>
Co-authored-by: Justin Florentine <[email protected]>
  • Loading branch information
2 people authored and matthew1001 committed Jun 7, 2024
1 parent 836e235 commit 5fc76d3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
- 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)
- Prevent startup with BONSAI and privacy enabled [#6809](https://github.com/hyperledger/besu/pull/6809)


### Bug fixes
- Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665)
- Make block transaction selection max time aware of PoA transitions [#6676](https://github.com/hyperledger/besu/pull/6676)
Expand Down
3 changes: 3 additions & 0 deletions besu/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<Logger name="io.vertx.core.dns.DnsException">
<RegexFilter regex="DNS query error occurred:.*" onMatch="DENY" onMismatch="NEUTRAL" />
</Logger>
<Logger name="org.hyperledger.besu.ethereum.eth.transactions">
<MarkerFilter marker="INVALID_TX_REMOVED" onMatch="DENY" onMismatch="NEUTRAL" />
</Logger>
<Root level="${sys:root.log.level}">
<AppenderRef ref="Router" />
</Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand Down Expand Up @@ -333,7 +351,7 @@ public synchronized void selectTransactions(

if (res.discard()) {
invalidTransactions.add(candidatePendingTx);
logTransactionForReplayDelete(candidatePendingTx);
logDiscardedTransaction(candidatePendingTx, res);
}

if (res.stop()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -247,6 +251,7 @@ public void selectTransactions(final TransactionSelector selector) {

if (result.discard()) {
transactionsToRemove.add(transactionToProcess.getTransaction());
logDiscardedTransaction(transactionToProcess, result);
}

if (result.stop()) {
Expand All @@ -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());
Expand Down

0 comments on commit 5fc76d3

Please sign in to comment.