From a8a6b3375cdb4c69c3b27d1e9834adad24f417b4 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Mon, 16 Dec 2024 16:21:00 +0000 Subject: [PATCH] Remove attempt to recover blobs when we don't have block --- .../deneb/helpers/MiscHelpersDeneb.java | 24 +++ .../blobs/BlockBlobSidecarsTracker.java | 101 ++++++------ .../BlockBlobSidecarsTrackersPoolImpl.java | 146 ++++++------------ .../blobs/BlockBlobSidecarsTrackerTest.java | 105 +++---------- ...BlockBlobSidecarsTrackersPoolImplTest.java | 57 ++++--- 5 files changed, 175 insertions(+), 258 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDeneb.java index ebf9e188b45..bea7c222df7 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/deneb/helpers/MiscHelpersDeneb.java @@ -37,8 +37,12 @@ import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema; import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; +import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody; +import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.deneb.BeaconBlockBodyDeneb; import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.deneb.BeaconBlockBodySchemaDeneb; +import tech.pegasys.teku.spec.datastructures.execution.BlobAndProof; +import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers; @@ -266,6 +270,26 @@ public BlobSidecar constructBlobSidecar( index, blob, commitment, proof, signedBeaconBlock.asHeader(), kzgCommitmentInclusionProof); } + public BlobSidecar constructBlobSidecarFromBlobAndProof( + final BlobIdentifier blobIdentifier, + final BlobAndProof blobAndProof, + final BeaconBlockBodyDeneb beaconBlockBodyDeneb, + final SignedBeaconBlockHeader signedBeaconBlockHeader) { + + final SszKZGCommitment sszKZGCommitment = + beaconBlockBodyDeneb.getBlobKzgCommitments().get(blobIdentifier.getIndex().intValue()); + + return blobSidecarSchema.create( + blobIdentifier.getIndex(), + blobAndProof.blob(), + sszKZGCommitment, + new SszKZGProof(blobAndProof.proof()), + signedBeaconBlockHeader, + computeKzgCommitmentInclusionProof(blobIdentifier.getIndex(), beaconBlockBodyDeneb)); + + + } + public boolean verifyBlobKzgCommitmentInclusionProof(final BlobSidecar blobSidecar) { if (blobSidecar.isKzgCommitmentInclusionProofValidated()) { return true; diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTracker.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTracker.java index 64c89d91ba1..6d3c9f95d21 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTracker.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTracker.java @@ -40,13 +40,15 @@ public class BlockBlobSidecarsTracker { private static final Logger LOG = LogManager.getLogger(); + private static final UInt64 CREATION_TIMING_IDX = UInt64.MAX_VALUE; private static final UInt64 BLOCK_ARRIVAL_TIMING_IDX = CREATION_TIMING_IDX.decrement(); - private static final UInt64 RPC_FETCH_TIMING_IDX = BLOCK_ARRIVAL_TIMING_IDX.decrement(); - private static final UInt64 LOCAL_EL_FETCH_TIMING_IDX = RPC_FETCH_TIMING_IDX.decrement(); + private static final UInt64 RPC_BLOCK_FETCH_TIMING_IDX = BLOCK_ARRIVAL_TIMING_IDX.decrement(); + private static final UInt64 RPC_BLOBS_FETCH_TIMING_IDX = RPC_BLOCK_FETCH_TIMING_IDX.decrement(); + private static final UInt64 LOCAL_EL_BLOBS_FETCH_TIMING_IDX = + RPC_BLOBS_FETCH_TIMING_IDX.decrement(); private final SlotAndBlockRoot slotAndBlockRoot; - private final UInt64 maxBlobsPerBlock; private final AtomicReference> block = new AtomicReference<>(Optional.empty()); @@ -56,8 +58,9 @@ public class BlockBlobSidecarsTracker { private final NavigableMap blobSidecars = new ConcurrentSkipListMap<>(); private final SafeFuture blobSidecarsComplete = new SafeFuture<>(); - private volatile boolean rpcFetchTriggered = false; - private volatile boolean localElFetchTriggered = false; + private volatile boolean localElBlobsFetchTriggered = false; + private volatile boolean rpcBlockFetchTriggered = false; + private volatile boolean rpcBlobsFetchTriggered = false; private final Optional> maybeDebugTimings; @@ -69,12 +72,9 @@ public class BlockBlobSidecarsTracker { * tracker instance will be used, so no synchronization is required * * @param slotAndBlockRoot slot and block root to create tracker for - * @param maxBlobsPerBlock max number of blobs per block for the slot */ - public BlockBlobSidecarsTracker( - final SlotAndBlockRoot slotAndBlockRoot, final UInt64 maxBlobsPerBlock) { + public BlockBlobSidecarsTracker(final SlotAndBlockRoot slotAndBlockRoot) { this.slotAndBlockRoot = slotAndBlockRoot; - this.maxBlobsPerBlock = maxBlobsPerBlock; if (LOG.isDebugEnabled()) { // don't need a concurrent hashmap since we'll interact with it from synchronized BlobSidecar // pool methods @@ -110,30 +110,12 @@ public Optional getBlobSidecar(final UInt64 index) { return Optional.ofNullable(blobSidecars.get(index)); } - public Stream getMissingBlobSidecars() { - final Optional blockCommitmentsCount = getBlockKzgCommitmentsCount(); - if (blockCommitmentsCount.isPresent()) { - return UInt64.range(UInt64.ZERO, UInt64.valueOf(blockCommitmentsCount.get())) - .filter(blobIndex -> !blobSidecars.containsKey(blobIndex)) - .map(blobIndex -> new BlobIdentifier(slotAndBlockRoot.getBlockRoot(), blobIndex)); - } - - if (blobSidecars.isEmpty()) { - return Stream.of(); - } - - // We may return maxBlobsPerBlock because we don't know the block - return UInt64.range(UInt64.ZERO, maxBlobsPerBlock) - .filter(blobIndex -> !blobSidecars.containsKey(blobIndex)) - .map(blobIndex -> new BlobIdentifier(slotAndBlockRoot.getBlockRoot(), blobIndex)); - } - - public Stream getUnusedBlobSidecarsForBlock() { + public Stream getMissingBlobSidecarsForBlock() { final Optional blockCommitmentsCount = getBlockKzgCommitmentsCount(); checkState(blockCommitmentsCount.isPresent(), "Block must me known to call this method"); - final UInt64 firstUnusedIndex = UInt64.valueOf(blockCommitmentsCount.get()); - return UInt64.range(firstUnusedIndex, maxBlobsPerBlock) + return UInt64.range(UInt64.ZERO, UInt64.valueOf(blockCommitmentsCount.get())) + .filter(blobIndex -> !blobSidecars.containsKey(blobIndex)) .map(blobIndex -> new BlobIdentifier(slotAndBlockRoot.getBlockRoot(), blobIndex)); } @@ -247,24 +229,35 @@ public boolean isComplete() { return blobSidecarsComplete.isDone(); } - public boolean isRpcFetchTriggered() { - return rpcFetchTriggered; + public boolean isLocalElBlobsFetchTriggered() { + return localElBlobsFetchTriggered; } - public void setRpcFetchTriggered() { - this.rpcFetchTriggered = true; + public void setLocalElBlobsFetchTriggered() { + this.localElBlobsFetchTriggered = true; maybeDebugTimings.ifPresent( - debugTimings -> debugTimings.put(RPC_FETCH_TIMING_IDX, System.currentTimeMillis())); + debugTimings -> + debugTimings.put(LOCAL_EL_BLOBS_FETCH_TIMING_IDX, System.currentTimeMillis())); } - public boolean isLocalElFetchTriggered() { - return localElFetchTriggered; + public boolean isRpcBlockFetchTriggered() { + return rpcBlockFetchTriggered; } - public void setLocalElFetchTriggered() { - this.localElFetchTriggered = true; + public void setRpcBlockFetchTriggered() { + this.rpcBlockFetchTriggered = true; maybeDebugTimings.ifPresent( - debugTimings -> debugTimings.put(LOCAL_EL_FETCH_TIMING_IDX, System.currentTimeMillis())); + debugTimings -> debugTimings.put(RPC_BLOCK_FETCH_TIMING_IDX, System.currentTimeMillis())); + } + + public boolean isRpcBlobsFetchTriggered() { + return rpcBlobsFetchTriggered; + } + + public void setRpcBlobsFetchTriggered() { + this.rpcBlobsFetchTriggered = true; + maybeDebugTimings.ifPresent( + debugTimings -> debugTimings.put(RPC_BLOBS_FETCH_TIMING_IDX, System.currentTimeMillis())); } private boolean areBlobsComplete() { @@ -315,22 +308,31 @@ private void printDebugTimings(final Map debugTimings) { .append(debugTimings.getOrDefault(BLOCK_ARRIVAL_TIMING_IDX, 0L) - creationTime) .append("ms - "); - if (debugTimings.containsKey(LOCAL_EL_FETCH_TIMING_IDX)) { + if (debugTimings.containsKey(LOCAL_EL_BLOBS_FETCH_TIMING_IDX)) { timingsReport - .append("Local EL fetch delay ") - .append(debugTimings.get(LOCAL_EL_FETCH_TIMING_IDX) - creationTime) + .append("Local EL blobs fetch delay ") + .append(debugTimings.get(LOCAL_EL_BLOBS_FETCH_TIMING_IDX) - creationTime) .append("ms - "); } else { timingsReport.append("Local EL fetch wasn't required - "); } - if (debugTimings.containsKey(RPC_FETCH_TIMING_IDX)) { + if (debugTimings.containsKey(RPC_BLOCK_FETCH_TIMING_IDX)) { + timingsReport + .append("RPC block fetch delay ") + .append(debugTimings.get(RPC_BLOCK_FETCH_TIMING_IDX) - creationTime) + .append("ms"); + } else { + timingsReport.append("RPC block fetch wasn't required"); + } + + if (debugTimings.containsKey(RPC_BLOBS_FETCH_TIMING_IDX)) { timingsReport - .append("RPC fetch delay ") - .append(debugTimings.get(RPC_FETCH_TIMING_IDX) - creationTime) + .append("RPC blobs fetch delay ") + .append(debugTimings.get(RPC_BLOBS_FETCH_TIMING_IDX) - creationTime) .append("ms"); } else { - timingsReport.append("RPC fetch wasn't required"); + timingsReport.append("RPC blobs fetch wasn't required"); } LOG.debug(timingsReport.toString()); @@ -342,8 +344,9 @@ public String toString() { .add("slotAndBlockRoot", slotAndBlockRoot) .add("isBlockPresent", block.get().isPresent()) .add("isComplete", isComplete()) - .add("rpcFetchTriggered", rpcFetchTriggered) - .add("localElFetchTriggered", localElFetchTriggered) + .add("localElBlobsFetchTriggered", localElBlobsFetchTriggered) + .add("rpcBlockFetchTriggered", rpcBlockFetchTriggered) + .add("rpcBlobsFetchTriggered", rpcBlobsFetchTriggered) .add("blockImportOnCompletionEnabled", blockImportOnCompletionEnabled.get()) .add( "blobSidecars", diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java index 0bfb291d0e2..d4aedb221fd 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java @@ -48,9 +48,7 @@ import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.SpecVersion; -import tech.pegasys.teku.spec.config.SpecConfigDeneb; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; -import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecarSchema; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot; @@ -58,7 +56,6 @@ import tech.pegasys.teku.spec.datastructures.execution.BlobAndProof; import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BlobIdentifier; import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; -import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel; import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb; import tech.pegasys.teku.spec.logic.versions.deneb.types.VersionedHash; @@ -154,7 +151,7 @@ public class BlockBlobSidecarsTrackersPoolImpl extends AbstractIgnoringFutureHis this.maxTrackers = maxTrackers; this.sizeGauge = sizeGauge; this.poolStatsCounters = poolStatsCounters; - this.trackerFactory = (slotAndBlockRoot) -> createTracker(spec, slotAndBlockRoot); + this.trackerFactory = BlockBlobSidecarsTracker::new; initMetrics(sizeGauge, poolStatsCounters); } @@ -209,15 +206,6 @@ private static void initMetrics( }); } - private static BlockBlobSidecarsTracker createTracker( - final Spec spec, final SlotAndBlockRoot slotAndBlockRoot) { - return new BlockBlobSidecarsTracker( - slotAndBlockRoot, - UInt64.valueOf( - SpecConfigDeneb.required(spec.atSlot(slotAndBlockRoot.getSlot()).getConfig()) - .getMaxBlobsPerBlock())); - } - @Override public synchronized void onNewBlobSidecar( final BlobSidecar blobSidecar, final RemoteOrigin remoteOrigin) { @@ -344,7 +332,7 @@ public synchronized void onCompletedBlockAndBlobSidecars( LOG.error( "Tracker for block {} is supposed to be completed but it is not. Missing blob sidecars: {}", block.toLogString(), - blobSidecarsTracker.getMissingBlobSidecars().count()); + blobSidecarsTracker.getMissingBlobSidecarsForBlock().count()); } if (orderedBlobSidecarsTrackers.add(slotAndBlockRoot)) { @@ -427,7 +415,13 @@ public synchronized Optional getBlock(final Bytes32 blockRoot @Override public synchronized Set getAllRequiredBlobSidecars() { return blockBlobSidecarsTrackers.values().stream() - .flatMap(BlockBlobSidecarsTracker::getMissingBlobSidecars) + .flatMap( + tracker -> { + if (tracker.getBlock().isEmpty()) { + return Stream.empty(); + } + return tracker.getMissingBlobSidecarsForBlock(); + }) .collect(Collectors.toSet()); } @@ -495,24 +489,12 @@ private BlockBlobSidecarsTracker internalOnNewBlock( countBlock(remoteOrigin); - if (existingTracker.isRpcFetchTriggered()) { - // block has been set for the first time and we previously triggered fetching of - // missing blobSidecars. So we may have requested to fetch more sidecars - // than the block actually requires. Let's drop them. - existingTracker - .getUnusedBlobSidecarsForBlock() - .forEach( - blobIdentifier -> - requiredBlobSidecarDroppedSubscribers.deliver( - RequiredBlobSidecarDroppedSubscriber::onRequiredBlobSidecarDropped, - blobIdentifier)); - - // if we attempted to fetch via RPC, we missed the opportunity to complete the - // tracker via local EL (local El fetch requires the block to be known) - // Let's try now - if (!existingTracker.isLocalElFetchTriggered() && !existingTracker.isComplete()) { - fetchMissingContentFromLocalEL(slotAndBlockRoot) - .finish(this::logLocalElBlobsLookupFailure); + if (existingTracker.isRpcBlockFetchTriggered()) { + // if we attempted to fetch this block via RPC, we missed the opportunity to + // complete the blob sidecars via local EL and RPC (since the block is required to + // be known) Let's try now + if (!existingTracker.isCompleted()) { + fetchMissingContent(slotAndBlockRoot).finish(this::logMissingContentFetchFailure); } } }); @@ -595,21 +577,24 @@ private void onFirstSeen( final Duration fetchDelay = calculateFetchDelay(slotAndBlockRoot); asyncRunner - .runAfterDelay( - () -> - this.fetchMissingContentFromLocalEL(slotAndBlockRoot) - .handleException(this::logLocalElBlobsLookupFailure) - .thenRun(() -> this.fetchMissingContentFromRemotePeers(slotAndBlockRoot)), - fetchDelay) - .finish( - error -> - LOG.error("An error occurred while attempting to fetch missing blobs.", error)); + .runAfterDelay(() -> fetchMissingContent(slotAndBlockRoot), fetchDelay) + .finish(this::logMissingContentFetchFailure); + } + + private SafeFuture fetchMissingContent(final SlotAndBlockRoot slotAndBlockRoot) { + return fetchMissingBlobsFromLocalEL(slotAndBlockRoot) + .handleException(this::logLocalElBlobsLookupFailure) + .thenRun(() -> fetchMissingContentFromRemotePeers(slotAndBlockRoot)); } private void logLocalElBlobsLookupFailure(final Throwable error) { LOG.warn("Local EL blobs lookup failed: {}", getRootCauseMessage(error)); } + private void logMissingContentFetchFailure(final Throwable error) { + LOG.error("An error occurred while attempting to fetch missing content.", error); + } + @VisibleForTesting Duration calculateFetchDelay(final SlotAndBlockRoot slotAndBlockRoot) { final UInt64 slot = slotAndBlockRoot.getSlot(); @@ -641,28 +626,21 @@ Duration calculateFetchDelay(final SlotAndBlockRoot slotAndBlockRoot) { return Duration.ofMillis(finalTime.minus(nowMillis).intValue()); } - private synchronized SafeFuture fetchMissingContentFromLocalEL( + private synchronized SafeFuture fetchMissingBlobsFromLocalEL( final SlotAndBlockRoot slotAndBlockRoot) { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = blockBlobSidecarsTrackers.get(slotAndBlockRoot.getBlockRoot()); - if (blockBlobSidecarsTracker == null) { + if (blockBlobSidecarsTracker == null + || blockBlobSidecarsTracker.isComplete() + || blockBlobSidecarsTracker.getBlock().isEmpty()) { return SafeFuture.COMPLETE; } - if (blockBlobSidecarsTracker.isComplete()) { - return SafeFuture.COMPLETE; - } - - if (blockBlobSidecarsTracker.getBlock().isEmpty()) { - return SafeFuture.COMPLETE; - } - - blockBlobSidecarsTracker.setLocalElFetchTriggered(); + final List missingBlobsIdentifiers = + blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock().toList(); final SpecVersion specVersion = spec.atSlot(slotAndBlockRoot.getSlot()); - final BlobSidecarSchema blobSidecarSchema = - specVersion.getSchemaDefinitions().toVersionDeneb().orElseThrow().getBlobSidecarSchema(); final MiscHelpersDeneb miscHelpersDeneb = specVersion.miscHelpers().toVersionDeneb().orElseThrow(); final SignedBeaconBlockHeader signedBeaconBlockHeader = @@ -679,9 +657,6 @@ private synchronized SafeFuture fetchMissingContentFromLocalEL( final SszList sszKZGCommitments = beaconBlockBodyDeneb.getBlobKzgCommitments(); - final List missingBlobsIdentifiers = - blockBlobSidecarsTracker.getMissingBlobSidecars().toList(); - final List versionedHashes = missingBlobsIdentifiers.stream() .map( @@ -692,6 +667,8 @@ private synchronized SafeFuture fetchMissingContentFromLocalEL( .getKZGCommitment())) .toList(); + blockBlobSidecarsTracker.setLocalElBlobsFetchTriggered(); + poolStatsCounters .labels(COUNTER_SIDECAR_TYPE, COUNTER_LOCAL_EL_FETCH_SUBTYPE) .inc(versionedHashes.size()); @@ -714,9 +691,7 @@ private synchronized SafeFuture fetchMissingContentFromLocalEL( } final BlobSidecar blobSidecar = - createBlobSidecarFromBlobAndProof( - blobSidecarSchema, - miscHelpersDeneb, + miscHelpersDeneb.constructBlobSidecarFromBlobAndProof( missingBlobsIdentifiers.get(index), blobAndProof.get(), beaconBlockBodyDeneb, @@ -726,59 +701,30 @@ private synchronized SafeFuture fetchMissingContentFromLocalEL( }); } - private BlobSidecar createBlobSidecarFromBlobAndProof( - final BlobSidecarSchema blobSidecarSchema, - final MiscHelpersDeneb miscHelpersDeneb, - final BlobIdentifier blobIdentifier, - final BlobAndProof blobAndProof, - final BeaconBlockBodyDeneb beaconBlockBodyDeneb, - final SignedBeaconBlockHeader signedBeaconBlockHeader) { - - final SszKZGCommitment sszKZGCommitment = - beaconBlockBodyDeneb.getBlobKzgCommitments().get(blobIdentifier.getIndex().intValue()); - - final BlobSidecar blobSidecar = - blobSidecarSchema.create( - blobIdentifier.getIndex(), - blobAndProof.blob(), - sszKZGCommitment, - new SszKZGProof(blobAndProof.proof()), - signedBeaconBlockHeader, - miscHelpersDeneb.computeKzgCommitmentInclusionProof( - blobIdentifier.getIndex(), beaconBlockBodyDeneb)); - - blobSidecar.markSignatureAsValidated(); - blobSidecar.markKzgCommitmentInclusionProofAsValidated(); - // assume kzg validation done by local EL - blobSidecar.markKzgAsValidated(); - - return blobSidecar; - } - private synchronized void fetchMissingContentFromRemotePeers( final SlotAndBlockRoot slotAndBlockRoot) { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = blockBlobSidecarsTrackers.get(slotAndBlockRoot.getBlockRoot()); - if (blockBlobSidecarsTracker == null) { + if (blockBlobSidecarsTracker == null || blockBlobSidecarsTracker.isComplete()) { return; } - if (blockBlobSidecarsTracker.isComplete()) { - return; - } + if (blockBlobSidecarsTracker.getBlock().isEmpty()) { - blockBlobSidecarsTracker.setRpcFetchTriggered(); + blockBlobSidecarsTracker.setRpcBlockFetchTriggered(); - if (blockBlobSidecarsTracker.getBlock().isEmpty()) { poolStatsCounters.labels(COUNTER_BLOCK_TYPE, COUNTER_RPC_FETCH_SUBTYPE).inc(); requiredBlockRootSubscribers.deliver( RequiredBlockRootSubscriber::onRequiredBlockRoot, blockBlobSidecarsTracker.getSlotAndBlockRoot().getBlockRoot()); + return; } + blockBlobSidecarsTracker.setRpcBlobsFetchTriggered(); + blockBlobSidecarsTracker - .getMissingBlobSidecars() + .getMissingBlobSidecarsForBlock() .forEach( blobIdentifier -> { poolStatsCounters.labels(COUNTER_SIDECAR_TYPE, COUNTER_RPC_FETCH_SUBTYPE).inc(); @@ -789,7 +735,8 @@ private synchronized void fetchMissingContentFromRemotePeers( private void dropMissingContent(final BlockBlobSidecarsTracker blockBlobSidecarsTracker) { - if (!blockBlobSidecarsTracker.isRpcFetchTriggered()) { + if (!blockBlobSidecarsTracker.isRpcBlockFetchTriggered() + && !blockBlobSidecarsTracker.isRpcBlobsFetchTriggered()) { return; } @@ -797,10 +744,11 @@ private void dropMissingContent(final BlockBlobSidecarsTracker blockBlobSidecars requiredBlockRootDroppedSubscribers.deliver( RequiredBlockRootDroppedSubscriber::onRequiredBlockRootDropped, blockBlobSidecarsTracker.getSlotAndBlockRoot().getBlockRoot()); + return; } blockBlobSidecarsTracker - .getMissingBlobSidecars() + .getMissingBlobSidecarsForBlock() .forEach( blobIdentifier -> requiredBlobSidecarDroppedSubscribers.deliver( diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java index 275fb2fcada..4e239efc967 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/blobs/BlockBlobSidecarsTrackerTest.java @@ -65,11 +65,11 @@ public class BlockBlobSidecarsTrackerTest { @Test void isNotCompletedJustAfterCreation() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); SafeFutureAssert.assertThatSafeFuture(blockBlobSidecarsTracker.getCompletionFuture()) .isNotCompleted(); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()).isEmpty(); + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()).isEmpty(); assertThat(blockBlobSidecarsTracker.getBlock()).isEmpty(); assertThat(blockBlobSidecarsTracker.getBlobSidecars()).isEmpty(); assertThat(blockBlobSidecarsTracker.getSlotAndBlockRoot()).isEqualTo(slotAndBlockRoot); @@ -81,12 +81,12 @@ void isNotCompletedJustAfterCreation() { @Test void setBlock_shouldAcceptCorrectBlock() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); blockBlobSidecarsTracker.setBlock(block); SafeFutureAssert.assertThatSafeFuture(blockBlobSidecarsTracker.getCompletionFuture()) .isNotCompleted(); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()) + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()) .containsExactlyInAnyOrderElementsOf(blobIdentifiersForBlock); assertThat(blockBlobSidecarsTracker.getBlock()).isEqualTo(Optional.of(block)); assertThat(blockBlobSidecarsTracker.getBlobSidecars()).isEmpty(); @@ -95,7 +95,7 @@ void setBlock_shouldAcceptCorrectBlock() { @Test void setBlock_shouldThrowWithWrongBlock() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(dataStructureUtil.randomSlotAndBlockRoot(), maxBlobsPerBlock); + new BlockBlobSidecarsTracker(dataStructureUtil.randomSlotAndBlockRoot()); assertThatThrownBy(() -> blockBlobSidecarsTracker.setBlock(block)) .isInstanceOf(IllegalArgumentException.class); } @@ -103,7 +103,7 @@ void setBlock_shouldThrowWithWrongBlock() { @Test void setBlock_shouldAcceptBlockTwice() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); blockBlobSidecarsTracker.setBlock(block); blockBlobSidecarsTracker.setBlock(block); assertThat(blockBlobSidecarsTracker.getBlock()).isEqualTo(Optional.of(block)); @@ -115,7 +115,7 @@ void setBlock_immediatelyCompletesWithBlockWithoutBlobs() { final SlotAndBlockRoot slotAndBlockRoot = block.getSlotAndBlockRoot(); final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final SafeFuture completionFuture = blockBlobSidecarsTracker.getCompletionFuture(); SafeFutureAssert.assertThatSafeFuture(completionFuture).isNotCompleted(); @@ -125,7 +125,7 @@ void setBlock_immediatelyCompletesWithBlockWithoutBlobs() { SafeFutureAssert.assertThatSafeFuture(completionFuture).isCompleted(); assertThat(blockBlobSidecarsTracker.isComplete()).isTrue(); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()).isEmpty(); + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()).isEmpty(); assertThat(blockBlobSidecarsTracker.getBlobSidecars()).isEmpty(); } @@ -135,7 +135,7 @@ void getCompletionFuture_returnsIndependentFutures() { final SlotAndBlockRoot slotAndBlockRoot = block.getSlotAndBlockRoot(); final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final SafeFuture completionFuture1 = blockBlobSidecarsTracker.getCompletionFuture(); final SafeFuture completionFuture2 = blockBlobSidecarsTracker.getCompletionFuture(); final SafeFuture completionFuture3 = blockBlobSidecarsTracker.getCompletionFuture(); @@ -168,7 +168,7 @@ void getCompletionFuture_returnsIndependentFutures() { @Test void add_shouldWorkTillCompletionWhenAddingBlobsBeforeBlockIsSet() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock.plus(1)); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final BlobSidecar toAdd = blobSidecarsForBlock.get(0); final Map added = new HashMap<>(); final SafeFuture completionFuture = blockBlobSidecarsTracker.getCompletionFuture(); @@ -183,7 +183,7 @@ void add_shouldWorkTillCompletionWhenAddingBlobsBeforeBlockIsSet() { .collect(Collectors.toSet()); SafeFutureAssert.assertThatSafeFuture(completionFuture).isNotCompleted(); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()) + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()) .containsExactlyInAnyOrderElementsOf(potentialMissingBlobs); assertThat(blockBlobSidecarsTracker.getBlobSidecars()) .containsExactlyInAnyOrderEntriesOf(added); @@ -194,7 +194,7 @@ void add_shouldWorkTillCompletionWhenAddingBlobsBeforeBlockIsSet() { // now we know the block and we know about missing blobs final List stillMissing = blobIdentifiersForBlock.subList(1, blobIdentifiersForBlock.size()); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()) + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()) .containsExactlyInAnyOrderElementsOf(stillMissing); SafeFutureAssert.assertThatSafeFuture(completionFuture).isNotCompleted(); @@ -224,7 +224,7 @@ void add_shouldWorkTillCompletionWhenAddingBlobsBeforeBlockIsSet() { @Test void add_shouldWorkWhenBlockIsSetFirst() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final SafeFuture completionFuture = blockBlobSidecarsTracker.getCompletionFuture(); blockBlobSidecarsTracker.setBlock(block); @@ -238,7 +238,7 @@ void add_shouldWorkWhenBlockIsSetFirst() { added.put(toAdd.getIndex(), toAdd); blockBlobSidecarsTracker.add(toAdd); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()) + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()) .containsExactlyInAnyOrderElementsOf(stillMissing); SafeFutureAssert.assertThatSafeFuture(completionFuture).isNotCompleted(); assertThat(blockBlobSidecarsTracker.getBlobSidecars()) @@ -249,7 +249,7 @@ void add_shouldWorkWhenBlockIsSetFirst() { @Test void add_shouldThrowWhenAddingInconsistentBlobSidecar() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(dataStructureUtil.randomSlotAndBlockRoot(), maxBlobsPerBlock); + new BlockBlobSidecarsTracker(dataStructureUtil.randomSlotAndBlockRoot()); assertThatThrownBy(() -> blockBlobSidecarsTracker.add(dataStructureUtil.randomBlobSidecar())) .isInstanceOf(IllegalArgumentException.class); } @@ -257,16 +257,16 @@ void add_shouldThrowWhenAddingInconsistentBlobSidecar() { @Test void add_shouldAcceptAcceptSameBlobSidecarTwice() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); blockBlobSidecarsTracker.setBlock(block); blockBlobSidecarsTracker.setBlock(block); assertThat(blockBlobSidecarsTracker.getBlock()).isEqualTo(Optional.of(block)); } @Test - void getMissingBlobSidecars_shouldReturnPartialBlobsIdentifierWhenBlockIsUnknown() { + void getMissingBlobSidecars_ForBlock_shouldReturnPartialBlobsIdentifierWhenBlockIsUnknown() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final BlobSidecar toAdd = blobSidecarsForBlock.get(2); blockBlobSidecarsTracker.add(toAdd); @@ -276,69 +276,14 @@ void getMissingBlobSidecars_shouldReturnPartialBlobsIdentifierWhenBlockIsUnknown .filter(blobIdentifier -> !blobIdentifier.getIndex().equals(UInt64.valueOf(2))) .collect(Collectors.toList()); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()) + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()) .containsExactlyInAnyOrderElementsOf(knownMissing); } @Test - void getUnusedBlobSidecarsForBlock_shouldReturnShouldFailIfBlockIsUnknown() { + void getMissingBlobSidecars_ForBlock_shouldRespectMaxBlobsPerBlock() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); - - assertThatThrownBy(blockBlobSidecarsTracker::getUnusedBlobSidecarsForBlock) - .isInstanceOf(IllegalStateException.class); - } - - @Test - void getUnusedBlobSidecarsForBlock_shouldReturnEmptySetIfBlockIsFull() { - final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); - - blockBlobSidecarsTracker.setBlock(block); - - assertThat(blockBlobSidecarsTracker.getUnusedBlobSidecarsForBlock()).isEmpty(); - } - - @Test - void getUnusedBlobSidecarsForBlock_shouldReturnUnusedBlobSpace() { - final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock.plus(2)); - - blockBlobSidecarsTracker.setBlock(block); - - final Set expectedUnusedBlobs = - UInt64.range(maxBlobsPerBlock, maxBlobsPerBlock.plus(2)) - .map(index -> new BlobIdentifier(slotAndBlockRoot.getBlockRoot(), index)) - .collect(Collectors.toSet()); - - assertThat(blockBlobSidecarsTracker.getUnusedBlobSidecarsForBlock()) - .containsExactlyInAnyOrderElementsOf(expectedUnusedBlobs); - } - - @Test - void getUnusedBlobSidecarsForBlock_shouldReturnAllMaxBlobsPerBlockIfBlockIsEmpty() { - - final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlockWithEmptyCommitments(); - final SlotAndBlockRoot slotAndBlockRoot = block.getSlotAndBlockRoot(); - - final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock.plus(2)); - - blockBlobSidecarsTracker.setBlock(block); - - final Set expectedUnusedBlobs = - UInt64.range(UInt64.ZERO, maxBlobsPerBlock.plus(2)) - .map(index -> new BlobIdentifier(slotAndBlockRoot.getBlockRoot(), index)) - .collect(Collectors.toSet()); - - assertThat(blockBlobSidecarsTracker.getUnusedBlobSidecarsForBlock()) - .containsExactlyInAnyOrderElementsOf(expectedUnusedBlobs); - } - - @Test - void getMissingBlobSidecars_shouldRespectMaxBlobsPerBlock() { - final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final BlobSidecar toAdd = dataStructureUtil .createRandomBlobSidecarBuilder() @@ -351,14 +296,14 @@ void getMissingBlobSidecars_shouldRespectMaxBlobsPerBlock() { final List knownMissing = blobIdentifiersForBlock.subList(0, maxBlobsPerBlock.intValue()); - assertThat(blockBlobSidecarsTracker.getMissingBlobSidecars()) + assertThat(blockBlobSidecarsTracker.getMissingBlobSidecarsForBlock()) .containsExactlyInAnyOrderElementsOf(knownMissing); } @Test void shouldNotIgnoreExcessiveBlobSidecarWhenBlockIsUnknownAndWePruneItLater() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); final BlobSidecar legitBlobSidecar = createBlobSidecar(UInt64.valueOf(2)); final BlobSidecar excessiveBlobSidecar1 = createBlobSidecar(maxBlobsPerBlock); @@ -382,7 +327,7 @@ void shouldNotIgnoreExcessiveBlobSidecarWhenBlockIsUnknownAndWePruneItLater() { @Test void add_shouldIgnoreExcessiveBlobSidecarWhenBlockIsKnown() { final BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); blockBlobSidecarsTracker.setBlock(block); @@ -400,7 +345,7 @@ void add_shouldIgnoreExcessiveBlobSidecarWhenBlockIsKnown() { @Test void enableBlockImportOnCompletion_shouldImportOnlyOnceWhenCalled() { BlockBlobSidecarsTracker blockBlobSidecarsTracker = - new BlockBlobSidecarsTracker(slotAndBlockRoot, maxBlobsPerBlock); + new BlockBlobSidecarsTracker(slotAndBlockRoot); blockBlobSidecarsTracker.setBlock(block); diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java index 2dad121a9eb..40884b71d4d 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImplTest.java @@ -463,7 +463,7 @@ public void onCompletedBlockAndBlobSidecars_shouldCreateTrackerIgnoringHistorica assertThat(blockBlobSidecarsTracker.getBlobSidecars().values()) .containsExactlyInAnyOrderElementsOf(blobSidecars); assertThat(blockBlobSidecarsTracker.getBlock()).isPresent(); - assertThat(blockBlobSidecarsTracker.isRpcFetchTriggered()).isFalse(); + assertThat(blockBlobSidecarsTracker.isRpcBlockFetchTriggered()).isFalse(); assertThatSafeFuture(blockBlobSidecarsTracker.getCompletionFuture()).isCompleted(); assertBlobSidecarsCount(blobSidecars.size()); @@ -493,7 +493,7 @@ public void onCompletedBlockAndBlobSidecars_shouldNotTriggerFetch() { assertThat(blockBlobSidecarsTracker.getBlobSidecars().values()) .containsExactlyInAnyOrderElementsOf(blobSidecars); assertThat(blockBlobSidecarsTracker.getBlock()).isPresent(); - assertThat(blockBlobSidecarsTracker.isRpcFetchTriggered()).isFalse(); + assertThat(blockBlobSidecarsTracker.isRpcBlockFetchTriggered()).isFalse(); assertThatSafeFuture(blockBlobSidecarsTracker.getCompletionFuture()).isNotCompleted(); assertBlobSidecarsCount(0); @@ -511,7 +511,7 @@ public void onCompletedBlockAndBlobSidecars_shouldNotTriggerFetch() { blockBlobSidecarsTrackersPool.getOrCreateBlockBlobSidecarsTracker(block); assertThat(blockBlobSidecarsTracker.getBlock()).isPresent(); - assertThat(blockBlobSidecarsTracker.isRpcFetchTriggered()).isFalse(); + assertThat(blockBlobSidecarsTracker.isRpcBlockFetchTriggered()).isFalse(); assertThatSafeFuture(blockBlobSidecarsTracker.getCompletionFuture()).isNotCompleted(); assertBlobSidecarsCount(0); @@ -670,7 +670,7 @@ void shouldFetchMissingBlobSidecarsFromLocalELFirst() { Optional.of( (slotAndRoot) -> { when(tracker.add(any())).thenReturn(true); - when(tracker.getMissingBlobSidecars()) + when(tracker.getMissingBlobSidecarsForBlock()) .thenAnswer(__ -> missingBlobIdentifiers.stream()); when(tracker.getBlock()).thenReturn(Optional.of(block)); return tracker; @@ -694,7 +694,7 @@ void shouldFetchMissingBlobSidecarsFromLocalELFirst() { assertThat(requiredBlobSidecarDroppedEvents).isEmpty(); // local el fetch triggered - verify(tracker).setLocalElFetchTriggered(); + verify(tracker).setLocalElBlobsFetchTriggered(); // prepare partial response of 3 blobAndProofs final List> blobAndProofsFromEL = @@ -734,7 +734,8 @@ void shouldFetchMissingBlobSidecarsViaRPCAfterLocalEL() { Optional.of( (slotAndRoot) -> { BlockBlobSidecarsTracker tracker = mock(BlockBlobSidecarsTracker.class); - when(tracker.getMissingBlobSidecars()).thenAnswer(__ -> missingBlobs.stream()); + when(tracker.getMissingBlobSidecarsForBlock()) + .thenAnswer(__ -> missingBlobs.stream()); when(tracker.getBlock()).thenReturn(Optional.of(block)); return tracker; }); @@ -770,7 +771,8 @@ void shouldFetchMissingBlobSidecarsViaRPCWhenELLookupFails() { Optional.of( (slotAndRoot) -> { BlockBlobSidecarsTracker tracker = mock(BlockBlobSidecarsTracker.class); - when(tracker.getMissingBlobSidecars()).thenAnswer(__ -> missingBlobs.stream()); + when(tracker.getMissingBlobSidecarsForBlock()) + .thenAnswer(__ -> missingBlobs.stream()); when(tracker.getBlock()).thenReturn(Optional.of(block)); return tracker; }); @@ -810,7 +812,7 @@ void shouldFetchMissingBlockAndBlobSidecars() { final BlockBlobSidecarsTracker mockedTracker = mock(BlockBlobSidecarsTracker.class); when(mockedTracker.getBlock()).thenReturn(Optional.empty()); - when(mockedTracker.getMissingBlobSidecars()).thenReturn(missingBlobs.stream()); + when(mockedTracker.getMissingBlobSidecarsForBlock()).thenReturn(missingBlobs.stream()); when(mockedTracker.getSlotAndBlockRoot()).thenReturn(block.getSlotAndBlockRoot()); mockedTrackersFactory = Optional.of((__) -> mockedTracker); @@ -821,8 +823,8 @@ void shouldFetchMissingBlockAndBlobSidecars() { asyncRunner.executeQueuedActions(); - verify(mockedTracker).setRpcFetchTriggered(); - verify(mockedTracker, never()).setLocalElFetchTriggered(); + verify(mockedTracker).setRpcBlockFetchTriggered(); + verify(mockedTracker, never()).setLocalElBlobsFetchTriggered(); assertThat(requiredBlockRootEvents).containsExactly(block.getRoot()); assertThat(requiredBlobSidecarEvents).containsExactlyElementsOf(missingBlobs); @@ -858,9 +860,7 @@ void shouldDropBlobSidecarsThatHasBeenFetchedButNotPresentInBlock() { when(tracker.getBlock()).thenReturn(Optional.empty()); when(tracker.getSlotAndBlockRoot()).thenReturn(slotAndBlockRoot); when(tracker.setBlock(block)).thenReturn(true); - when(tracker.isRpcFetchTriggered()).thenReturn(true); - when(tracker.getUnusedBlobSidecarsForBlock()) - .thenReturn(blobsNotPresentInBlock.stream()); + when(tracker.isRpcBlockFetchTriggered()).thenReturn(true); return tracker; }); @@ -895,9 +895,7 @@ void shouldNotDropUnusedBlobSidecarsIfFetchingHasNotOccurred() { when(tracker.getBlock()).thenReturn(Optional.empty()); when(tracker.getSlotAndBlockRoot()).thenReturn(slotAndBlockRoot); when(tracker.setBlock(block)).thenReturn(true); - when(tracker.isRpcFetchTriggered()).thenReturn(false); - when(tracker.getUnusedBlobSidecarsForBlock()) - .thenReturn(blobsNotUserInBlock.stream()); + when(tracker.isRpcBlockFetchTriggered()).thenReturn(false); return tracker; }); @@ -945,10 +943,10 @@ void shouldDropPossiblyFetchedBlobSidecars() { Optional.of( (slotAndRoot) -> { BlockBlobSidecarsTracker tracker = mock(BlockBlobSidecarsTracker.class); - when(tracker.getMissingBlobSidecars()).thenReturn(missingBlobs.stream()); + when(tracker.getMissingBlobSidecarsForBlock()).thenReturn(missingBlobs.stream()); when(tracker.getBlock()).thenReturn(Optional.of(block)); when(tracker.getSlotAndBlockRoot()).thenReturn(block.getSlotAndBlockRoot()); - when(tracker.isRpcFetchTriggered()).thenReturn(true); + when(tracker.isRpcBlockFetchTriggered()).thenReturn(true); return tracker; }); @@ -987,12 +985,13 @@ void shouldTryToFetchFromLocalELWhenBlockArrivesAfterRPCFetch() { mockedTrackersFactory = Optional.of( (slotAndRoot) -> { - when(tracker.getMissingBlobSidecars()).thenAnswer(__ -> missingBlobs.stream()); + when(tracker.getMissingBlobSidecarsForBlock()) + .thenAnswer(__ -> missingBlobs.stream()); when(tracker.getBlock()).thenReturn(Optional.empty()); when(tracker.setBlock(any())).thenReturn(true); when(tracker.getSlotAndBlockRoot()).thenReturn(block.getSlotAndBlockRoot()); - when(tracker.isRpcFetchTriggered()).thenReturn(true); - when(tracker.isLocalElFetchTriggered()).thenReturn(false); + when(tracker.isRpcBlockFetchTriggered()).thenReturn(true); + when(tracker.isLocalElBlobsFetchTriggered()).thenReturn(false); return tracker; }); @@ -1001,7 +1000,7 @@ void shouldTryToFetchFromLocalELWhenBlockArrivesAfterRPCFetch() { assertThat(asyncRunner.hasDelayedActions()).isTrue(); asyncRunner.executeQueuedActions(); - verify(tracker, never()).setLocalElFetchTriggered(); + verify(tracker, never()).setLocalElBlobsFetchTriggered(); when(tracker.getBlock()).thenReturn(Optional.of(block)); @@ -1011,7 +1010,7 @@ void shouldTryToFetchFromLocalELWhenBlockArrivesAfterRPCFetch() { blockBlobSidecarsTrackersPool.onNewBlock(block, Optional.empty()); - verify(tracker).setLocalElFetchTriggered(); + verify(tracker).setLocalElBlobsFetchTriggered(); verify(executionLayer).engineGetBlobs(any(), any()); } @@ -1032,7 +1031,7 @@ void shouldDropPossiblyFetchedBlock() { when(tracker.getBlock()).thenReturn(Optional.empty()); when(tracker.getSlotAndBlockRoot()) .thenReturn(signedBeaconBlock.getSlotAndBlockRoot()); - when(tracker.isRpcFetchTriggered()).thenReturn(true); + when(tracker.isRpcBlockFetchTriggered()).thenReturn(true); return tracker; }); @@ -1067,7 +1066,7 @@ void shouldNotDropPossiblyFetchedBlockIfFetchHasNotOccurred() { when(tracker.getBlock()).thenReturn(Optional.empty()); when(tracker.getSlotAndBlockRoot()) .thenReturn(signedBeaconBlock.getSlotAndBlockRoot()); - when(tracker.isRpcFetchTriggered()).thenReturn(false); + when(tracker.isRpcBlockFetchTriggered()).thenReturn(false); return tracker; }); @@ -1188,7 +1187,7 @@ void getAllRequiredBlobSidecars_shouldReturnAllRequiredBlobSidecars() { Optional.of( (slotAndRoot) -> { BlockBlobSidecarsTracker tracker = mock(BlockBlobSidecarsTracker.class); - when(tracker.getMissingBlobSidecars()).thenReturn(missingBlobs1.stream()); + when(tracker.getMissingBlobSidecarsForBlock()).thenReturn(missingBlobs1.stream()); when(tracker.getBlock()).thenReturn(Optional.of(block1)); return tracker; }); @@ -1206,7 +1205,7 @@ void getAllRequiredBlobSidecars_shouldReturnAllRequiredBlobSidecars() { Optional.of( (slotAndRoot) -> { BlockBlobSidecarsTracker tracker = mock(BlockBlobSidecarsTracker.class); - when(tracker.getMissingBlobSidecars()).thenReturn(missingBlobs2.stream()); + when(tracker.getMissingBlobSidecarsForBlock()).thenReturn(missingBlobs2.stream()); when(tracker.getBlock()).thenReturn(Optional.of(block2)); return tracker; }); @@ -1400,8 +1399,6 @@ private BlockBlobSidecarsTracker trackerFactory(final SlotAndBlockRoot slotAndBl if (mockedTrackersFactory.isPresent()) { return mockedTrackersFactory.get().apply(slotAndBlockRoot); } - return new BlockBlobSidecarsTracker( - slotAndBlockRoot, - UInt64.valueOf(spec.getMaxBlobsPerBlockForHighestMilestone().orElseThrow())); + return new BlockBlobSidecarsTracker(slotAndBlockRoot); } }