diff --git a/storage-provider/client/src/rpc_client.rs b/storage-provider/client/src/rpc_client.rs index d74e0202..4af29b9f 100644 --- a/storage-provider/client/src/rpc_client.rs +++ b/storage-provider/client/src/rpc_client.rs @@ -4,6 +4,8 @@ //! this module covers that, furthermore, the client it provides //! supports both WebSockets and HTTP. +use std::time::Duration; + use jsonrpsee::{ core::{ client::{BatchResponse, ClientT, Subscription, SubscriptionClientT}, @@ -21,14 +23,23 @@ pub enum PolkaStorageRpcClient { Https(jsonrpsee::http_client::HttpClient), } +/// RPC commands which submit an extrinsic wait for finalization. +/// Finalization takes ~60secs (the default request timeout), however when reorg happens, it's two times that. +const REQUEST_TIMEOUT: Duration = Duration::from_secs(120); + impl PolkaStorageRpcClient { pub async fn new(url: &Url) -> Result { match url.scheme() { "ws" | "wss" => Ok(PolkaStorageRpcClient::Ws( - WsClientBuilder::new().build(url).await?, + WsClientBuilder::new() + .request_timeout(REQUEST_TIMEOUT) + .build(url) + .await?, )), "http" | "https" => Ok(PolkaStorageRpcClient::Https( - HttpClientBuilder::new().build(url)?, + HttpClientBuilder::new() + .request_timeout(REQUEST_TIMEOUT) + .build(url)?, )), scheme => Err(jsonrpsee::core::ClientError::Custom(format!( "unsupported url scheme: {}", diff --git a/storagext/lib/src/runtime/client.rs b/storagext/lib/src/runtime/client.rs index 434754bd..8f513fd8 100644 --- a/storagext/lib/src/runtime/client.rs +++ b/storagext/lib/src/runtime/client.rs @@ -198,13 +198,22 @@ impl Client { Call: subxt::tx::Payload, Keypair: subxt::tx::Signer, { + let finalized_block_hash = self.legacy_rpc.chain_get_finalized_head().await?; + let finalized_block = self + .legacy_rpc + .chain_get_block(Some(finalized_block_hash)) + .await? + .expect("chain to have info about the finalized head"); + let current_nonce = self .legacy_rpc .system_account_next_index(&account_keypair.account_id()) .await?; - let current_header = self.legacy_rpc.chain_get_header(None).await?.unwrap(); + // Default used by subxt + // https://github.com/paritytech/subxt/blob/f363f77a60271b840e8dfb4f6e2f0f728f5ced06/core/src/config/signed_extensions.rs#L231 + const TX_VALID_FOR: u64 = 32; let ext_params = DefaultExtrinsicParamsBuilder::new() - .mortal(¤t_header, 8) + .mortal(&finalized_block.block.header, TX_VALID_FOR) .nonce(current_nonce) .build();