From 133fefa0bfc7b16ce207aad3608d47de21c1f2e6 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 14 Aug 2024 15:57:44 -0400 Subject: [PATCH] Add 45 second timeout when checking for jumpstarts --- crates/client/Cargo.toml | 2 +- crates/client/src/client.rs | 12 ++++++++++++ crates/client/src/errors.rs | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 8f2755ca4..62fea585e 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -33,7 +33,7 @@ anyhow ="1.0.86" # Only for the browser js-sys={ version="0.3.70", optional=true } -tokio ="1.39" +tokio ={ version="1.39", features=["time"] } [dev-dependencies] serial_test ="3.1.1" diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 7ca7c9683..c0559d8b7 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -368,6 +368,18 @@ pub async fn jumpstart_network( api: &OnlineClient, rpc: &LegacyRpcMethods, signer: sr25519::Pair, +) -> Result<(), ClientError> { + // We split the implementation out into an inner function so that we can more easily pass a + // single future to the `timeout` + tokio::time::timeout(std::time::Duration::from_secs(45), jumpstart_inner(api, rpc, signer)) + .await + .map_err(|_| ClientError::JumpstartTimeout)? +} + +async fn jumpstart_inner( + api: &OnlineClient, + rpc: &LegacyRpcMethods, + signer: sr25519::Pair, ) -> Result<(), ClientError> { // In this case we don't care too much about the result because we're more interested in the // `FinishedNetworkJumpStart` event, which happens later on. diff --git a/crates/client/src/errors.rs b/crates/client/src/errors.rs index 86e1000e9..012bf2d87 100644 --- a/crates/client/src/errors.rs +++ b/crates/client/src/errors.rs @@ -66,6 +66,8 @@ pub enum ClientError { Subxt(#[from] subxt::Error), #[error("Timed out waiting for register confirmation")] RegistrationTimeout, + #[error("Timed out waiting for jumpstart confirmation")] + JumpstartTimeout, #[error("Cannot get subgroup: {0}")] SubgroupGet(#[from] SubgroupGetError), #[error("JSON: {0}")]