Skip to content

Commit 5fc76d3

Browse files
fab-10jflo
authored andcommitted
Dedicated log marker for invalid txs removed from the txpool (besu-eth#6826)
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net> Signed-off-by: Justin Florentine <justin+github@florentine.us> Co-authored-by: Justin Florentine <justin+github@florentine.us>
1 parent 836e235 commit 5fc76d3

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
- Extend error handling of plugin RPC methods [#6759](https://github.com/hyperledger/besu/pull/6759)
2828
- Added engine_newPayloadV4 and engine_getPayloadV4 methods [#6783](https://github.com/hyperledger/besu/pull/6783)
2929
- Reduce storage size of receipts [#6602](https://github.com/hyperledger/besu/pull/6602)
30+
- Dedicated log marker for invalid txs removed from the txpool [#6826](https://github.com/hyperledger/besu/pull/6826)
3031
- Prevent startup with BONSAI and privacy enabled [#6809](https://github.com/hyperledger/besu/pull/6809)
3132

33+
3234
### Bug fixes
3335
- Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665)
3436
- Make block transaction selection max time aware of PoA transitions [#6676](https://github.com/hyperledger/besu/pull/6676)

besu/src/main/resources/log4j2.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<Logger name="io.vertx.core.dns.DnsException">
4949
<RegexFilter regex="DNS query error occurred:.*" onMatch="DENY" onMismatch="NEUTRAL" />
5050
</Logger>
51+
<Logger name="org.hyperledger.besu.ethereum.eth.transactions">
52+
<MarkerFilter marker="INVALID_TX_REMOVED" onMatch="DENY" onMismatch="NEUTRAL" />
53+
</Logger>
5154
<Root level="${sys:root.log.level}">
5255
<AppenderRef ref="Router" />
5356
</Root>

ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/LayeredPendingTransactions.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
3838
import org.hyperledger.besu.evm.account.Account;
3939
import org.hyperledger.besu.evm.account.AccountState;
40+
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
4041

4142
import java.util.ArrayDeque;
4243
import java.util.ArrayList;
@@ -53,10 +54,13 @@
5354
import kotlin.ranges.LongRange;
5455
import org.slf4j.Logger;
5556
import org.slf4j.LoggerFactory;
57+
import org.slf4j.Marker;
58+
import org.slf4j.MarkerFactory;
5659

5760
public class LayeredPendingTransactions implements PendingTransactions {
5861
private static final Logger LOG = LoggerFactory.getLogger(LayeredPendingTransactions.class);
5962
private static final Logger LOG_FOR_REPLAY = LoggerFactory.getLogger("LOG_FOR_REPLAY");
63+
private static final Marker INVALID_TX_REMOVED = MarkerFactory.getMarker("INVALID_TX_REMOVED");
6064
private final TransactionPoolConfiguration poolConfig;
6165
private final AbstractPrioritizedTransactions prioritizedTransactions;
6266

@@ -234,7 +238,8 @@ private void logTransactionForReplayAdd(
234238
.log();
235239
}
236240

237-
private void logTransactionForReplayDelete(final PendingTransaction pendingTransaction) {
241+
private void logDiscardedTransaction(
242+
final PendingTransaction pendingTransaction, final TransactionSelectionResult result) {
238243
// csv fields: sequence, addedAt, sender, nonce, type, hash, rlp
239244
LOG_FOR_REPLAY
240245
.atTrace()
@@ -252,6 +257,19 @@ private void logTransactionForReplayDelete(final PendingTransaction pendingTrans
252257
return rlp.encoded().toHexString();
253258
})
254259
.log();
260+
LOG.atInfo()
261+
.addMarker(INVALID_TX_REMOVED)
262+
.addKeyValue("txhash", pendingTransaction::getHash)
263+
.addKeyValue("txlog", pendingTransaction::toTraceLog)
264+
.addKeyValue("reason", result)
265+
.addKeyValue(
266+
"txrlp",
267+
() -> {
268+
final BytesValueRLPOutput rlp = new BytesValueRLPOutput();
269+
pendingTransaction.getTransaction().writeTo(rlp);
270+
return rlp.encoded().toHexString();
271+
})
272+
.log();
255273
}
256274

257275
private TransactionAddedResult nonceChecks(
@@ -333,7 +351,7 @@ public synchronized void selectTransactions(
333351

334352
if (res.discard()) {
335353
invalidTransactions.add(candidatePendingTx);
336-
logTransactionForReplayDelete(candidatePendingTx);
354+
logDiscardedTransaction(candidatePendingTx, res);
337355
}
338356

339357
if (res.stop()) {

ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/AbstractPendingTransactionsSorter.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
3333
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolReplacementHandler;
3434
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
35+
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
3536
import org.hyperledger.besu.evm.account.Account;
3637
import org.hyperledger.besu.evm.account.AccountState;
3738
import org.hyperledger.besu.metrics.BesuMetricCategory;
@@ -61,6 +62,8 @@
6162

6263
import org.slf4j.Logger;
6364
import org.slf4j.LoggerFactory;
65+
import org.slf4j.Marker;
66+
import org.slf4j.MarkerFactory;
6467

6568
/**
6669
* Holds the current set of pending transactions with the ability to iterate them based on priority
@@ -71,6 +74,7 @@
7174
public abstract class AbstractPendingTransactionsSorter implements PendingTransactions {
7275
private static final Logger LOG =
7376
LoggerFactory.getLogger(AbstractPendingTransactionsSorter.class);
77+
private static final Marker INVALID_TX_REMOVED = MarkerFactory.getMarker("INVALID_TX_REMOVED");
7478

7579
protected final Clock clock;
7680
protected final TransactionPoolConfiguration poolConfig;
@@ -247,6 +251,7 @@ public void selectTransactions(final TransactionSelector selector) {
247251

248252
if (result.discard()) {
249253
transactionsToRemove.add(transactionToProcess.getTransaction());
254+
logDiscardedTransaction(transactionToProcess, result);
250255
}
251256

252257
if (result.stop()) {
@@ -259,6 +264,23 @@ public void selectTransactions(final TransactionSelector selector) {
259264
}
260265
}
261266

267+
private void logDiscardedTransaction(
268+
final PendingTransaction pendingTransaction, final TransactionSelectionResult result) {
269+
LOG.atInfo()
270+
.addMarker(INVALID_TX_REMOVED)
271+
.addKeyValue("txhash", pendingTransaction::getHash)
272+
.addKeyValue("txlog", pendingTransaction::toTraceLog)
273+
.addKeyValue("reason", result)
274+
.addKeyValue(
275+
"txrlp",
276+
() -> {
277+
final BytesValueRLPOutput rlp = new BytesValueRLPOutput();
278+
pendingTransaction.getTransaction().writeTo(rlp);
279+
return rlp.encoded().toHexString();
280+
})
281+
.log();
282+
}
283+
262284
private AccountTransactionOrder createSenderTransactionOrder(final Address address) {
263285
return new AccountTransactionOrder(
264286
transactionsBySender.get(address).streamPendingTransactions());

0 commit comments

Comments
 (0)