diff --git a/CHANGELOG.md b/CHANGELOG.md index d868630e8f9..6e045d3d29c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncing.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncing.java index 749346dd4de..ba1851c670d 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncing.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncing.java @@ -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( @@ -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()); } diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncingTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncingTest.java index d3d99f657b5..40d8ffe7432 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncingTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/node/GetSyncingTest.java @@ -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)); diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java index d305fb55fa8..b63d8894097 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/BlockBlobSidecarsTrackersPoolImpl.java @@ -407,7 +407,8 @@ public synchronized boolean containsBlobSidecar(final BlobIdentifier blobIdentif } @Override - public Optional getBlobSidecar(final Bytes32 blockRoot, final UInt64 index) { + public synchronized Optional getBlobSidecar( + final Bytes32 blockRoot, final UInt64 index) { return Optional.ofNullable(blockBlobSidecarsTrackers.get(blockRoot)) .flatMap(tracker -> tracker.getBlobSidecar(index)); }