Skip to content

Commit

Permalink
fix: temporarily disable max block behind check on tracer readiness e…
Browse files Browse the repository at this point in the history
…ndpoint due to infrequent sync status updates
  • Loading branch information
powerslider committed Oct 4, 2024
1 parent 5244e9d commit 222d77c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public <T extends PluginRpcRequest, R> R execute(T request, Function<T, R> proce
}
}

public int availableConcurrentRequestSlots() {
return semaphore.availablePermits();
}

public boolean isNodeAtMaxCapacity() {
return semaphore.availablePermits() == 0;
return availableConcurrentRequestSlots() == 0;
}
}

0 comments on commit 222d77c

Please sign in to comment.