Skip to content

Commit

Permalink
Fix transactions mortality (paritytech#1196)
Browse files Browse the repository at this point in the history
* added lost stall timeout fix

* use best_block.parent() to start mortal tx era

* fmt

* Revert "revert messages transactions mortality"

This reverts commit 7777635.
  • Loading branch information
svyatonik authored Dec 6, 2021
1 parent bf4fbdf commit 1b6685f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 12 additions & 2 deletions relays/client-substrate/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use jsonrpsee_ws_client::{
},
WsClient as RpcClient, WsClientBuilder as RpcClientBuilder,
};
use num_traits::{Bounded, Zero};
use num_traits::{Bounded, CheckedSub, One, Zero};
use pallet_balances::AccountData;
use pallet_transaction_payment::InclusionFee;
use relay_utils::{relay_loop::RECONNECT_DELAY, HeaderId};
Expand Down Expand Up @@ -349,7 +349,17 @@ impl<C: Chain> Client<C> {
let _guard = self.submit_signed_extrinsic_lock.lock().await;
let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
let best_header = self.best_header().await?;
let best_header_id = HeaderId(*best_header.number(), best_header.hash());

// By using parent of best block here, we are protecing again best-block reorganizations.
// E.g. transaction my have been submitted when the best block was `A[num=100]`. Then it has
// been changed to `B[num=100]`. Hash of `A` has been included into transaction signature
// payload. So when signature will be checked, the check will fail and transaction will be
// dropped from the pool.
let best_header_id = match best_header.number().checked_sub(&One::one()) {
Some(parent_block_number) => HeaderId(parent_block_number, *best_header.parent_hash()),
None => HeaderId(*best_header.number(), best_header.hash()),
};

self.jsonrpsee_execute(move |client| async move {
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce);
let tx_hash = Substrate::<C>::author_submit_extrinsic(&*client, extrinsic).await?;
Expand Down
6 changes: 5 additions & 1 deletion relays/lib-substrate-relay/src/on_demand_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ async fn background_task<P: SubstrateFinalitySyncPipeline>(
P::TargetChain::AVERAGE_BLOCK_INTERVAL,
),
recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT,
stall_timeout: STALL_TIMEOUT,
stall_timeout: relay_substrate_client::transaction_stall_timeout(
target_transactions_mortality,
TargetChain::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
),
only_mandatory_headers,
},
MetricsParams::disabled(),
Expand Down

0 comments on commit 1b6685f

Please sign in to comment.