-
Notifications
You must be signed in to change notification settings - Fork 840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose transaction count by type metrics for the layered txpool #6903
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
|
||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.datatypes.TransactionType; | ||
import org.hyperledger.besu.ethereum.core.BlockHeader; | ||
import org.hyperledger.besu.ethereum.core.Transaction; | ||
import org.hyperledger.besu.ethereum.eth.transactions.BlobCache; | ||
|
@@ -39,6 +40,7 @@ | |
import org.hyperledger.besu.util.Subscribers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -74,7 +76,7 @@ public abstract class AbstractTransactionsLayer implements TransactionsLayer { | |
private OptionalLong nextLayerOnAddedListenerId = OptionalLong.empty(); | ||
private OptionalLong nextLayerOnDroppedListenerId = OptionalLong.empty(); | ||
protected long spaceUsed = 0; | ||
|
||
protected final int[] txCountByType = new int[TransactionType.values().length]; | ||
private final BlobCache blobCache; | ||
|
||
protected AbstractTransactionsLayer( | ||
|
@@ -91,6 +93,11 @@ protected AbstractTransactionsLayer( | |
metrics.initSpaceUsed(this::getLayerSpaceUsed, name()); | ||
metrics.initTransactionCount(pendingTransactions::size, name()); | ||
metrics.initUniqueSenderCount(txsBySender::size, name()); | ||
Arrays.stream(TransactionType.values()) | ||
.forEach( | ||
type -> | ||
metrics.initTransactionCountByType( | ||
() -> txCountByType[type.ordinal()], name(), type)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using ordinal to track the external feels fragile, but if experimental tx types start showing up they may leave large gaps. However... it's what we express externally, so this looks like it will work. See my other comment on the metric. |
||
this.blobCache = blobCache; | ||
} | ||
|
||
|
@@ -101,6 +108,7 @@ public void reset() { | |
pendingTransactions.clear(); | ||
txsBySender.clear(); | ||
spaceUsed = 0; | ||
Arrays.fill(txCountByType, 0); | ||
nextLayer.reset(); | ||
} | ||
|
||
|
@@ -286,7 +294,7 @@ private void processAdded(final PendingTransaction addedTx) { | |
pendingTransactions.put(addedTx.getHash(), addedTx); | ||
final var senderTxs = txsBySender.computeIfAbsent(addedTx.getSender(), s -> new TreeMap<>()); | ||
senderTxs.put(addedTx.getNonce(), addedTx); | ||
increaseSpaceUsed(addedTx); | ||
increaseCounters(addedTx); | ||
metrics.incrementAdded(addedTx, name()); | ||
internalAdd(senderTxs, addedTx); | ||
} | ||
|
@@ -332,7 +340,7 @@ private void evict(final long spaceToFree, final int txsToEvict) { | |
|
||
protected void replaced(final PendingTransaction replacedTx) { | ||
pendingTransactions.remove(replacedTx.getHash()); | ||
decreaseSpaceUsed(replacedTx); | ||
decreaseCounters(replacedTx); | ||
metrics.incrementRemoved(replacedTx, REPLACED.label(), name()); | ||
internalReplaced(replacedTx); | ||
notifyTransactionDropped(replacedTx); | ||
|
@@ -368,7 +376,7 @@ protected PendingTransaction processRemove( | |
final PendingTransaction removedTx = pendingTransactions.remove(transaction.getHash()); | ||
|
||
if (removedTx != null) { | ||
decreaseSpaceUsed(removedTx); | ||
decreaseCounters(removedTx); | ||
metrics.incrementRemoved(removedTx, removalReason.label(), name()); | ||
internalRemove(senderTxs, removedTx, removalReason); | ||
} | ||
|
@@ -381,7 +389,7 @@ protected PendingTransaction processEvict( | |
final RemovalReason reason) { | ||
final PendingTransaction removedTx = pendingTransactions.remove(evictedTx.getHash()); | ||
if (removedTx != null) { | ||
decreaseSpaceUsed(evictedTx); | ||
decreaseCounters(evictedTx); | ||
metrics.incrementRemoved(evictedTx, reason.label(), name()); | ||
internalEvict(senderTxs, removedTx); | ||
} | ||
|
@@ -467,12 +475,14 @@ protected abstract void internalRemove( | |
|
||
protected abstract PendingTransaction getEvictable(); | ||
|
||
protected void increaseSpaceUsed(final PendingTransaction pendingTransaction) { | ||
protected void increaseCounters(final PendingTransaction pendingTransaction) { | ||
spaceUsed += pendingTransaction.memorySize(); | ||
++txCountByType[pendingTransaction.getTransaction().getType().ordinal()]; | ||
} | ||
|
||
protected void decreaseSpaceUsed(final PendingTransaction pendingTransaction) { | ||
protected void decreaseCounters(final PendingTransaction pendingTransaction) { | ||
spaceUsed -= pendingTransaction.memorySize(); | ||
--txCountByType[pendingTransaction.getTransaction().getType().ordinal()]; | ||
} | ||
|
||
protected abstract long cacheFreeSpace(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the type name, should we expose the EIP-2718 type number? We shouldn't use ordinal and should encode it in TransactionType but that has some weirdness for frontier types. May be best for a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think it makes sense to explicitly add the EIP-2718 type number to the tx type, and expose it in the metric label.
About the use of
type.ordinal()
, it is only used internally to index the array of int for the counters, and not exposed outside.