Improve UX whilst VC is waiting for genesis (#1915)

## Issue Addressed

- Resolves #1424

## Proposed Changes

Add a `GET lighthouse/staking` that returns 200 if the node is ready to stake (i.e., `--eth1` flag is present) or a 404 otherwise.

Whilst the VC is waiting for the genesis time to start (i.e., when the genesis state is known), check the `lighthouse/staking` endpoint and log an error if the node isn't configured for staking.

## Additional Info

NA
This commit is contained in:
Paul Hauner
2020-11-23 01:00:22 +00:00
parent 65b1cf2af1
commit 59b2247ab8
4 changed files with 106 additions and 3 deletions

View File

@@ -2147,7 +2147,7 @@ pub fn serve<T: BeaconChainTypes>(
.and(warp::path::param::<StateId>())
.and(warp::path("ssz"))
.and(warp::path::end())
.and(chain_filter)
.and(chain_filter.clone())
.and_then(|state_id: StateId, chain: Arc<BeaconChain<T>>| {
blocking_task(move || {
let state = state_id.state(&chain)?;
@@ -2164,6 +2164,25 @@ pub fn serve<T: BeaconChainTypes>(
})
});
// GET lighthouse/staking
let get_lighthouse_staking = warp::path("lighthouse")
.and(warp::path("staking"))
.and(warp::path::end())
.and(chain_filter)
.and_then(|chain: Arc<BeaconChain<T>>| {
blocking_json_task(move || {
if chain.eth1_chain.is_some() {
Ok(())
} else {
Err(warp_utils::reject::custom_not_found(
"staking is not enabled, \
see the --staking CLI flag"
.to_string(),
))
}
})
});
// Define the ultimate set of routes that will be provided to the server.
let routes = warp::get()
.and(
@@ -2211,7 +2230,8 @@ pub fn serve<T: BeaconChainTypes>(
.or(get_lighthouse_eth1_syncing.boxed())
.or(get_lighthouse_eth1_block_cache.boxed())
.or(get_lighthouse_eth1_deposit_cache.boxed())
.or(get_lighthouse_beacon_states_ssz.boxed()),
.or(get_lighthouse_beacon_states_ssz.boxed())
.or(get_lighthouse_staking.boxed()),
)
.or(warp::post().and(
post_beacon_blocks

View File

@@ -1815,6 +1815,14 @@ impl ApiTester {
self
}
pub async fn test_get_lighthouse_staking(self) -> Self {
let result = self.client.get_lighthouse_staking().await.unwrap();
assert_eq!(result, self.chain.eth1_chain.is_some());
self
}
}
#[tokio::test(core_threads = 2)]
@@ -2087,5 +2095,7 @@ async fn lighthouse_endpoints() {
.test_get_lighthouse_eth1_deposit_cache()
.await
.test_get_lighthouse_beacon_states_ssz()
.await
.test_get_lighthouse_staking()
.await;
}