mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Return syncing on HTTP when sync is stalled (#6129)
* Return syncing even when sync is stalled * Add test
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
@@ -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,
|
||||
@@ -253,7 +254,7 @@ impl ApiTester {
|
||||
let log = null_logger().unwrap();
|
||||
|
||||
let ApiServer {
|
||||
ctx: _,
|
||||
ctx,
|
||||
server,
|
||||
listening_socket,
|
||||
network_rx,
|
||||
@@ -284,6 +285,7 @@ impl ApiTester {
|
||||
);
|
||||
|
||||
Self {
|
||||
ctx,
|
||||
harness: Arc::new(harness),
|
||||
chain,
|
||||
client,
|
||||
@@ -350,7 +352,7 @@ impl ApiTester {
|
||||
let log = null_logger().unwrap();
|
||||
|
||||
let ApiServer {
|
||||
ctx: _,
|
||||
ctx,
|
||||
server,
|
||||
listening_socket,
|
||||
network_rx,
|
||||
@@ -371,6 +373,7 @@ impl ApiTester {
|
||||
);
|
||||
|
||||
Self {
|
||||
ctx,
|
||||
harness,
|
||||
chain,
|
||||
client,
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user