Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class TransactionPool implements BlockAddedObserver {
private final EthScheduler.OrderedProcessor<BlockAddedEvent> blockAddedEventOrderedProcessor;
private final Map<VersionedHash, BlobsWithCommitments.BlobQuad> mapOfBlobsInTransactionPool =
new HashMap<>();
private final ConcurrentHashMap<VersionedHash, BlobsWithCommitments.BlobQuad> blobCacheTracker =
new ConcurrentHashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for? it seems to have no real usage

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being used to maintain the count of blobs in the cache...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to add a size method to BlobCache, it is simpler and avoid keeping this extra map

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I was trying to avoid doing that... I have added it now and removed the extra map


public TransactionPool(
final Supplier<PendingTransactions> pendingTransactionsSupplier,
Expand All @@ -129,6 +131,7 @@ public TransactionPool(
this.blockAddedEventOrderedProcessor =
ethContext.getScheduler().createOrderedProcessor(this::processBlockAddedEvent);
this.cacheForBlobsOfTransactionsAddedToABlock = blobCache;
initializeBlobMetrics();
initLogForReplay();
subscribePendingTransactions(this::mapBlobsOnTransactionAdded);
subscribeDroppedTransactions(this::unmapBlobsOnTransactionDropped);
Expand Down Expand Up @@ -639,6 +642,7 @@ public CompletableFuture<Void> setDisabled() {
pendingTransactionsListenersProxy.unsubscribe();
final PendingTransactions pendingTransactionsToSave = pendingTransactions;
pendingTransactions = new DisabledPendingTransactions();
clearBlobCacheTracker();
return saveRestoreManager
.saveToDisk(pendingTransactionsToSave)
.exceptionally(
Expand Down Expand Up @@ -671,13 +675,20 @@ private void unmapBlobsOnTransactionDropped(
}
final List<BlobsWithCommitments.BlobQuad> blobQuads =
maybeBlobsWithCommitments.get().getBlobQuads();
blobQuads.forEach(bq -> mapOfBlobsInTransactionPool.remove(bq.versionedHash()));
blobQuads.forEach(
bq -> {
mapOfBlobsInTransactionPool.remove(bq.versionedHash());
removeBlobFromCache(bq.versionedHash());
});
}

public BlobsWithCommitments.BlobQuad getBlobQuad(final VersionedHash vh) {
BlobsWithCommitments.BlobQuad blobQuad = mapOfBlobsInTransactionPool.get(vh);
if (blobQuad == null) {
blobQuad = cacheForBlobsOfTransactionsAddedToABlock.get(vh);
if (blobQuad != null) {
blobCacheTracker.putIfAbsent(vh, blobQuad);
}
}
return blobQuad;
}
Expand All @@ -686,6 +697,27 @@ public boolean isEnabled() {
return isPoolEnabled.get();
}

public int getBlobCacheSize() {
return blobCacheTracker.size();
}

public int getBlobMapSize() {
return mapOfBlobsInTransactionPool.size();
}

private void removeBlobFromCache(final VersionedHash vh) {
blobCacheTracker.remove(vh);
}

private void clearBlobCacheTracker() {
blobCacheTracker.clear();
}

private void initializeBlobMetrics() {
metrics.createBlobCacheSizeMetric(this::getBlobCacheSize);
metrics.createBlobMapSizeMetric(this::getBlobMapSize);
}

class PendingTransactionsListenersProxy {
private final Subscribers<PendingTransactionAddedListener> onAddedListeners =
Subscribers.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.function.DoubleSupplier;
import java.util.function.IntSupplier;

import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
Expand Down Expand Up @@ -285,4 +286,20 @@ private String location(final boolean receivedFromLocalSource) {
private String priority(final boolean hasPriority) {
return hasPriority ? "yes" : "no";
}

public void createBlobCacheSizeMetric(final IntSupplier sizeSupplier) {
metricsSystem.createIntegerGauge(
BesuMetricCategory.TRANSACTION_POOL,
"blob_cache_size",
"Current size of the blob cache",
sizeSupplier);
}

public void createBlobMapSizeMetric(final IntSupplier sizeSupplier) {
metricsSystem.createIntegerGauge(
BesuMetricCategory.TRANSACTION_POOL,
"blob_map_size",
"Current size of the blob map",
sizeSupplier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public enum BesuMetricCategory implements MetricCategory {
/** Stratum besu metric category. */
STRATUM("stratum"),
/** Block processing besu metric category. */
BLOCK_PROCESSING("block_processing");
BLOCK_PROCESSING("block_processing"),
/** Blob storage besu metric category. */
BLOB_STORAGE("blob_storage");
Comment thread
7suyash7 marked this conversation as resolved.
Outdated

private static final Optional<String> BESU_PREFIX = Optional.of("besu_");

Expand Down