Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storagext): losing transactions on reorg #651

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions storage-provider/client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<Self, jsonrpsee::core::ClientError> {
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: {}",
Expand Down
13 changes: 11 additions & 2 deletions storagext/lib/src/runtime/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,22 @@ impl Client {
Call: subxt::tx::Payload,
Keypair: subxt::tx::Signer<PolkaStorageConfig>,
{
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(&current_header, 8)
.mortal(&finalized_block.block.header, TX_VALID_FOR)
.nonce(current_nonce)
.build();

Expand Down
Loading