From 222d77c525df8117626ee60d3b9d351ab0253795 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Fri, 4 Oct 2024 17:20:30 +0300 Subject: [PATCH] fix: temporarily disable max block behind check on tracer readiness endpoint due to infrequent sync status updates --- .../readiness/TracerReadinessPlugin.java | 55 +++++++++++++------ .../linea/plugins/rpc/RequestLimiter.java | 6 +- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/plugins/readiness/TracerReadinessPlugin.java b/arithmetization/src/main/java/net/consensys/linea/plugins/readiness/TracerReadinessPlugin.java index 71062dcef2..d490321606 100644 --- a/arithmetization/src/main/java/net/consensys/linea/plugins/readiness/TracerReadinessPlugin.java +++ b/arithmetization/src/main/java/net/consensys/linea/plugins/readiness/TracerReadinessPlugin.java @@ -15,8 +15,6 @@ package net.consensys.linea.plugins.readiness; -import static java.util.Collections.singletonMap; - import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; @@ -80,19 +78,26 @@ public void beforeExternalServices() { public void start() { super.start(); - BesuServiceProvider.getBesuEventsService(this.besuContext) - .addSyncStatusListener( - syncStatus -> - syncStatus.ifPresent( - status -> { - boolean isInMaxBlockBehindRange = - status.getHighestBlock() - status.getCurrentBlock() - <= configuration.maxBlocksBehind(); - - // log.info("SYNC STATUS: {}", isInMaxBlockBehindRange); - - isInSync.set(isInMaxBlockBehindRange); - })); + // TODO: Checking for isInMaxBlockBehindRange is temporarily disabled until we find a way for + // more frequent sync status updates, because currently they happen only if the node loses a + // peer. + // BesuServiceProvider.getBesuEventsService(this.besuContext) + // .addSyncStatusListener( + // syncStatus -> + // syncStatus.ifPresent( + // status -> { + // boolean isInMaxBlockBehindRange = + // status.getHighestBlock() - status.getCurrentBlock() + // <= configuration.maxBlocksBehind(); + // + // log.info( + // "Sync Status (isInMaxBlocksBehind) Range: {}", + // isInMaxBlockBehindRange); + // log.info("Highest Block: {}", status.getHighestBlock()); + // log.info("Current Block: {}", status.getCurrentBlock()); + // + // isInSync.set(isInMaxBlockBehindRange); + // })); // Initialize Vertx final Vertx vertx = Vertx.vertx(); @@ -135,7 +140,22 @@ public void start() { } private String statusResponse(final String status) { - return new JsonObject(singletonMap("status", status)).encodePrettily(); + final RequestLimiter requestLimiter = + RequestLimiterDispatcher.getLimiter( + RequestLimiterDispatcher.SINGLE_INSTANCE_REQUEST_LIMITER_KEY); + + return new JsonObject( + Map.of( + "isInitialSyncPhaseDone", + synchronizationService.isInitialSyncPhaseDone(), + "status", + status, + // TODO: Temporarily disabled. + // "isInMaxBlockBehindRange", + // isInSync, + "availableConcurrentRequestSlots", + requestLimiter.availableConcurrentRequestSlots())) + .encodePrettily(); } private HttpServerOptions httpServerOptions(final TracerReadinessConfiguration config) { @@ -153,7 +173,8 @@ private boolean isTracerReady() { RequestLimiterDispatcher.SINGLE_INSTANCE_REQUEST_LIMITER_KEY); return synchronizationService.isInitialSyncPhaseDone() - && isInSync.get() + // TODO: Temporarily disabled. + // && isInSync.get() && !requestLimiter.isNodeAtMaxCapacity(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/RequestLimiter.java b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/RequestLimiter.java index 7c695009fe..e8dfa7be06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/RequestLimiter.java +++ b/arithmetization/src/main/java/net/consensys/linea/plugins/rpc/RequestLimiter.java @@ -55,7 +55,11 @@ public R execute(T request, Function proce } } + public int availableConcurrentRequestSlots() { + return semaphore.availablePermits(); + } + public boolean isNodeAtMaxCapacity() { - return semaphore.availablePermits() == 0; + return availableConcurrentRequestSlots() == 0; } }