From 0641b882acbea1fd236445312306969ad6567639 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Thu, 12 Jan 2023 20:23:24 +0000 Subject: [PATCH] small refactor --- .../sync/forward/singlepeer/PeerSync.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/singlepeer/PeerSync.java b/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/singlepeer/PeerSync.java index 3a8c0675a08..b7c92587937 100644 --- a/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/singlepeer/PeerSync.java +++ b/beacon/sync/src/main/java/tech/pegasys/teku/beacon/sync/forward/singlepeer/PeerSync.java @@ -19,7 +19,6 @@ import com.google.common.base.Throwables; import java.time.Duration; import java.util.List; -import java.util.Optional; import java.util.concurrent.CancellationException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -159,8 +158,6 @@ private SafeFuture executeSync( final UInt64 count = requestContext.getCount(); final boolean blobsSidecarsRequired = requestContext.areBlobsSidecarsRequired(); - readyForRequest.complete(null); - return readyForRequest .thenCompose( __ -> { @@ -185,18 +182,17 @@ private SafeFuture executeSync( final SafeFuture readyForNextRequest = asyncRunner.getDelayedFuture(NEXT_REQUEST_TIMEOUT); + final BlockAndBlobsSidecarMatcher blockAndBlobsSidecarMatcher = + new BlockAndBlobsSidecarMatcher( + blobsSidecarManager, + this::storeBlobsSidecarAndImportBlock, + this::importBlock); + final RpcResponseListener blockListener; - final Optional maybeBlockAndBlobsSidecarMatcher; final SafeFuture blobsSidecarsRequest; if (blobsSidecarsRequired) { - final BlockAndBlobsSidecarMatcher blockAndBlobsSidecarMatcher = - new BlockAndBlobsSidecarMatcher( - blobsSidecarManager, - this::storeBlobsSidecarAndImportBlock, - this::importBlock); blockListener = blockAndBlobsSidecarMatcher::recordBlock; - maybeBlockAndBlobsSidecarMatcher = Optional.of(blockAndBlobsSidecarMatcher); LOG.debug( "Request {} blobs sidecars starting at {} from peer {}", count, @@ -206,7 +202,6 @@ private SafeFuture executeSync( peer.requestBlobsSidecarsByRange( ancestorStartSlot, count, blockAndBlobsSidecarMatcher::recordBlobsSidecar); } else { - maybeBlockAndBlobsSidecarMatcher = Optional.empty(); blockListener = this::importBlock; blobsSidecarsRequest = SafeFuture.COMPLETE; } @@ -220,8 +215,7 @@ private SafeFuture executeSync( blobsSidecarsRequest) .thenApply( __ -> { - maybeBlockAndBlobsSidecarMatcher.ifPresent( - BlockAndBlobsSidecarMatcher::clearCache); + blockAndBlobsSidecarMatcher.clearCache(); return request; }); })