2626
2727import org .hyperledger .besu .datatypes .Address ;
2828import org .hyperledger .besu .datatypes .Hash ;
29+ import org .hyperledger .besu .datatypes .TransactionType ;
2930import org .hyperledger .besu .ethereum .core .BlockHeader ;
3031import org .hyperledger .besu .ethereum .core .Transaction ;
3132import org .hyperledger .besu .ethereum .eth .transactions .BlobCache ;
3940import org .hyperledger .besu .util .Subscribers ;
4041
4142import java .util .ArrayList ;
43+ import java .util .Arrays ;
4244import java .util .HashMap ;
4345import java .util .List ;
4446import java .util .Map ;
@@ -74,7 +76,7 @@ public abstract class AbstractTransactionsLayer implements TransactionsLayer {
7476 private OptionalLong nextLayerOnAddedListenerId = OptionalLong .empty ();
7577 private OptionalLong nextLayerOnDroppedListenerId = OptionalLong .empty ();
7678 protected long spaceUsed = 0 ;
77-
79+ protected final int [] txCountByType = new int [ TransactionType . values (). length ];
7880 private final BlobCache blobCache ;
7981
8082 protected AbstractTransactionsLayer (
@@ -91,6 +93,11 @@ protected AbstractTransactionsLayer(
9193 metrics .initSpaceUsed (this ::getLayerSpaceUsed , name ());
9294 metrics .initTransactionCount (pendingTransactions ::size , name ());
9395 metrics .initUniqueSenderCount (txsBySender ::size , name ());
96+ Arrays .stream (TransactionType .values ())
97+ .forEach (
98+ type ->
99+ metrics .initTransactionCountByType (
100+ () -> txCountByType [type .ordinal ()], name (), type ));
94101 this .blobCache = blobCache ;
95102 }
96103
@@ -101,6 +108,7 @@ public void reset() {
101108 pendingTransactions .clear ();
102109 txsBySender .clear ();
103110 spaceUsed = 0 ;
111+ Arrays .fill (txCountByType , 0 );
104112 nextLayer .reset ();
105113 }
106114
@@ -286,7 +294,7 @@ private void processAdded(final PendingTransaction addedTx) {
286294 pendingTransactions .put (addedTx .getHash (), addedTx );
287295 final var senderTxs = txsBySender .computeIfAbsent (addedTx .getSender (), s -> new TreeMap <>());
288296 senderTxs .put (addedTx .getNonce (), addedTx );
289- increaseSpaceUsed (addedTx );
297+ increaseCounters (addedTx );
290298 metrics .incrementAdded (addedTx , name ());
291299 internalAdd (senderTxs , addedTx );
292300 }
@@ -332,7 +340,7 @@ private void evict(final long spaceToFree, final int txsToEvict) {
332340
333341 protected void replaced (final PendingTransaction replacedTx ) {
334342 pendingTransactions .remove (replacedTx .getHash ());
335- decreaseSpaceUsed (replacedTx );
343+ decreaseCounters (replacedTx );
336344 metrics .incrementRemoved (replacedTx , REPLACED .label (), name ());
337345 internalReplaced (replacedTx );
338346 notifyTransactionDropped (replacedTx );
@@ -368,7 +376,7 @@ protected PendingTransaction processRemove(
368376 final PendingTransaction removedTx = pendingTransactions .remove (transaction .getHash ());
369377
370378 if (removedTx != null ) {
371- decreaseSpaceUsed (removedTx );
379+ decreaseCounters (removedTx );
372380 metrics .incrementRemoved (removedTx , removalReason .label (), name ());
373381 internalRemove (senderTxs , removedTx , removalReason );
374382 }
@@ -381,7 +389,7 @@ protected PendingTransaction processEvict(
381389 final RemovalReason reason ) {
382390 final PendingTransaction removedTx = pendingTransactions .remove (evictedTx .getHash ());
383391 if (removedTx != null ) {
384- decreaseSpaceUsed (evictedTx );
392+ decreaseCounters (evictedTx );
385393 metrics .incrementRemoved (evictedTx , reason .label (), name ());
386394 internalEvict (senderTxs , removedTx );
387395 }
@@ -467,12 +475,14 @@ protected abstract void internalRemove(
467475
468476 protected abstract PendingTransaction getEvictable ();
469477
470- protected void increaseSpaceUsed (final PendingTransaction pendingTransaction ) {
478+ protected void increaseCounters (final PendingTransaction pendingTransaction ) {
471479 spaceUsed += pendingTransaction .memorySize ();
480+ ++txCountByType [pendingTransaction .getTransaction ().getType ().ordinal ()];
472481 }
473482
474- protected void decreaseSpaceUsed (final PendingTransaction pendingTransaction ) {
483+ protected void decreaseCounters (final PendingTransaction pendingTransaction ) {
475484 spaceUsed -= pendingTransaction .memorySize ();
485+ --txCountByType [pendingTransaction .getTransaction ().getType ().ordinal ()];
476486 }
477487
478488 protected abstract long cacheFreeSpace ();
0 commit comments