Skip to content

Commit

Permalink
Fix is_syncing API reporting when head is synced optimistically (#8889
Browse files Browse the repository at this point in the history
)
  • Loading branch information
StefanBratanov authored Dec 6, 2024
1 parent b4af97b commit 1b68e2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

### Bug Fixes
- Added a startup script for unix systems to ensure that when jemalloc is installed the script sets the LD_PRELOAD environment variable to the use the jemalloc library
- Set `is_syncing` to `false` instead of `true` for the `/eth/v1/node/syncing` API endpoint when the head is optimistic and the sync distance is 0
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ public SyncStatusData(
final ExecutionClientDataProvider executionClientDataProvider) {
final SyncingStatus status = syncProvider.getSyncingStatus();
final SyncState syncState = syncProvider.getCurrentSyncState();
this.isSyncing = !syncState.isInSync();
this.slotsBehind = calculateSlotsBehind(status, syncState);
this.isSyncing = !slotsBehind.isZero();
this.elOffline = Optional.of(!executionClientDataProvider.isExecutionClientAvailable());
this.isOptimistic = Optional.of(syncState.isOptimistic());
this.currentSlot = status.getCurrentSlot();
// do this last, after isSyncing is calculated
this.slotsBehind = calculateSlotsBehind(status);
}

SyncStatusData(
Expand Down Expand Up @@ -138,8 +137,9 @@ public UInt64 getSlotsBehind() {
return slotsBehind;
}

private UInt64 calculateSlotsBehind(final SyncingStatus syncingStatus) {
if (isSyncing && syncingStatus.getHighestSlot().isPresent()) {
private UInt64 calculateSlotsBehind(
final SyncingStatus syncingStatus, final SyncState syncState) {
if (!syncState.isInSync() && syncingStatus.getHighestSlot().isPresent()) {
final UInt64 highestSlot = syncingStatus.getHighestSlot().get();
return highestSlot.minusMinZero(syncingStatus.getCurrentSlot());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public void shouldGetSyncStatusInSync() throws Exception {
.isEqualTo(new GetSyncing.SyncStatusData(false, false, false, 10, 0));
}

@Test
public void shouldGetSyncStatusInSyncWhenHeadIsOptimistic() throws Exception {
when(syncService.getSyncStatus()).thenReturn(getSyncStatus(false, 1, 10, 10));
when(syncService.getCurrentSyncState()).thenReturn(SyncState.OPTIMISTIC_SYNCING);

handler.handleRequest(request);
assertThat(request.getResponseCode()).isEqualTo(SC_OK);
assertThat(request.getResponseBody())
.isEqualTo(new GetSyncing.SyncStatusData(false, true, false, 10, 0));
}

@Test
public void shouldGetElOffline() throws Exception {
when(syncService.getSyncStatus()).thenReturn(getSyncStatus(false, 1, 10, 11));
Expand Down

0 comments on commit 1b68e2b

Please sign in to comment.