Skip to content

Commit

Permalink
Return syncing on HTTP when sync is stalled (#6129)
Browse files Browse the repository at this point in the history
* Return syncing even when sync is stalled

* Add test
  • Loading branch information
michaelsproul authored Jul 19, 2024
1 parent adfa512 commit 54e36f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2888,7 +2888,7 @@ pub fn serve<T: BeaconChainTypes>(
.map_err(warp_utils::reject::beacon_chain_error)?;

let syncing_data = api_types::SyncingData {
is_syncing: network_globals.sync_state.read().is_syncing(),
is_syncing: !network_globals.sync_state.read().is_synced(),
is_optimistic: Some(is_optimistic),
el_offline: Some(el_offline),
head_slot,
Expand Down
42 changes: 39 additions & 3 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use http_api::{
test_utils::{create_api_server, ApiServer},
BlockId, StateId,
};
use lighthouse_network::{Enr, EnrExt, PeerId};
use lighthouse_network::{types::SyncState, Enr, EnrExt, PeerId};
use network::NetworkReceivers;
use proto_array::ExecutionStatus;
use sensitive_url::SensitiveUrl;
Expand Down Expand Up @@ -62,6 +62,7 @@ const SKIPPED_SLOTS: &[u64] = &[
];

struct ApiTester {
ctx: Arc<http_api::Context<EphemeralHarnessType<E>>>,
harness: Arc<BeaconChainHarness<EphemeralHarnessType<E>>>,
chain: Arc<BeaconChain<EphemeralHarnessType<E>>>,
client: BeaconNodeHttpClient,
Expand Down Expand Up @@ -253,7 +254,7 @@ impl ApiTester {
let log = null_logger().unwrap();

let ApiServer {
ctx: _,
ctx,
server,
listening_socket,
network_rx,
Expand Down Expand Up @@ -284,6 +285,7 @@ impl ApiTester {
);

Self {
ctx,
harness: Arc::new(harness),
chain,
client,
Expand Down Expand Up @@ -350,7 +352,7 @@ impl ApiTester {
let log = null_logger().unwrap();

let ApiServer {
ctx: _,
ctx,
server,
listening_socket,
network_rx,
Expand All @@ -371,6 +373,7 @@ impl ApiTester {
);

Self {
ctx,
harness,
chain,
client,
Expand Down Expand Up @@ -2168,6 +2171,37 @@ impl ApiTester {
self
}

pub async fn test_get_node_syncing_stalled(self) -> Self {
// Set sync status to stalled.
*self
.ctx
.network_globals
.as_ref()
.unwrap()
.sync_state
.write() = SyncState::Stalled;

let is_syncing = self
.client
.get_node_syncing()
.await
.unwrap()
.data
.is_syncing;
assert_eq!(is_syncing, true);

// Reset sync state.
*self
.ctx
.network_globals
.as_ref()
.unwrap()
.sync_state
.write() = SyncState::Synced;

self
}

pub async fn test_get_node_identity(self) -> Self {
let result = self.client.get_node_identity().await.unwrap().data;

Expand Down Expand Up @@ -6123,6 +6157,8 @@ async fn node_get() {
.await
.test_get_node_syncing()
.await
.test_get_node_syncing_stalled()
.await
.test_get_node_identity()
.await
.test_get_node_health()
Expand Down

0 comments on commit 54e36f6

Please sign in to comment.