Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jan 12, 2023
1 parent 57f1ac9 commit 0641b88
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,8 +158,6 @@ private SafeFuture<PeerSyncResult> executeSync(
final UInt64 count = requestContext.getCount();
final boolean blobsSidecarsRequired = requestContext.areBlobsSidecarsRequired();

readyForRequest.complete(null);

return readyForRequest
.thenCompose(
__ -> {
Expand All @@ -185,18 +182,17 @@ private SafeFuture<PeerSyncResult> executeSync(
final SafeFuture<Void> readyForNextRequest =
asyncRunner.getDelayedFuture(NEXT_REQUEST_TIMEOUT);

final BlockAndBlobsSidecarMatcher blockAndBlobsSidecarMatcher =
new BlockAndBlobsSidecarMatcher(
blobsSidecarManager,
this::storeBlobsSidecarAndImportBlock,
this::importBlock);

final RpcResponseListener<SignedBeaconBlock> blockListener;
final Optional<BlockAndBlobsSidecarMatcher> maybeBlockAndBlobsSidecarMatcher;
final SafeFuture<Void> 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,
Expand All @@ -206,7 +202,6 @@ private SafeFuture<PeerSyncResult> executeSync(
peer.requestBlobsSidecarsByRange(
ancestorStartSlot, count, blockAndBlobsSidecarMatcher::recordBlobsSidecar);
} else {
maybeBlockAndBlobsSidecarMatcher = Optional.empty();
blockListener = this::importBlock;
blobsSidecarsRequest = SafeFuture.COMPLETE;
}
Expand All @@ -220,8 +215,7 @@ private SafeFuture<PeerSyncResult> executeSync(
blobsSidecarsRequest)
.thenApply(
__ -> {
maybeBlockAndBlobsSidecarMatcher.ifPresent(
BlockAndBlobsSidecarMatcher::clearCache);
blockAndBlobsSidecarMatcher.clearCache();
return request;
});
})
Expand Down

0 comments on commit 0641b88

Please sign in to comment.