Skip to content

Commit

Permalink
Trigger primary BN readiness check when failover has issues
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Apr 12, 2024
1 parent 8ac4353 commit c5c33e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public Iterator<? extends RemoteValidatorApiChannel> getFailoversInOrderOfReadin
.iterator();
}

public SafeFuture<Void> performPrimaryReadinessCheck() {
return performReadinessCheck(primaryBeaconNodeApi, true);
}

@Override
protected SafeFuture<?> doStart() {
return performReadinessCheckAgainstAllNodes();
Expand Down Expand Up @@ -136,10 +140,6 @@ private SafeFuture<Void> performReadinessCheckAgainstAllNodes() {
return SafeFuture.allOf(primaryReadinessCheck, SafeFuture.allOf(failoverReadinessChecks));
}

private SafeFuture<Void> performPrimaryReadinessCheck() {
return performReadinessCheck(primaryBeaconNodeApi, true);
}

private SafeFuture<Void> performFailoverReadinessCheck(final RemoteValidatorApiChannel failover) {
return performReadinessCheck(failover, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,22 @@ private synchronized void switchToFailoverEventStreamIfAvailable() {
private void findReadyFailoverAndSwitch() {
failoverBeaconNodeApis.stream()
.filter(beaconNodeReadinessManager::isReady)
.filter(failover -> !currentEventStreamHasSameEndpoint(failover))
.findFirst()
.ifPresentOrElse(
this::switchToFailoverEventStream,
validatorLogger::noFailoverBeaconNodesAvailableForEventStreaming);
() -> {
validatorLogger.noFailoverBeaconNodesAvailableForEventStreaming();
// if no failover switching is available, and we are currently connected to a failover
// event stream which has issues, trigger the readiness check against the primary BN
// immediately in the background
if (!currentEventStreamHasSameEndpoint(primaryBeaconNodeApi)) {
beaconNodeReadinessManager.performPrimaryReadinessCheck();
}
});
}

private void switchToFailoverEventStream(final RemoteValidatorApiChannel beaconNodeApi) {
if (currentEventStreamHasSameEndpoint(beaconNodeApi)) {
return;
}
eventSource.close();
eventSource = createEventSource(beaconNodeApi);
currentBeaconNodeUsedForEventStreaming = beaconNodeApi;
Expand Down

0 comments on commit c5c33e5

Please sign in to comment.