Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: temporarily disable max block behind check on tracer readiness endpoint due to infrequent sync status updates #1378

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading