Skip to content

Commit cc6320c

Browse files
svyatonikbkchr
authored andcommitted
Fix transactions mortality (#1196)
* added lost stall timeout fix * use best_block.parent() to start mortal tx era * fmt * Revert "revert messages transactions mortality" This reverts commit 77776357dafdfa80dcb3ec307d76fcfd0d5195bb.
1 parent e675b13 commit cc6320c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

bridges/relays/client-substrate/src/client.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use jsonrpsee_ws_client::{
3434
},
3535
WsClient as RpcClient, WsClientBuilder as RpcClientBuilder,
3636
};
37-
use num_traits::{Bounded, Zero};
37+
use num_traits::{Bounded, CheckedSub, One, Zero};
3838
use pallet_balances::AccountData;
3939
use pallet_transaction_payment::InclusionFee;
4040
use relay_utils::{relay_loop::RECONNECT_DELAY, HeaderId};
@@ -349,7 +349,17 @@ impl<C: Chain> Client<C> {
349349
let _guard = self.submit_signed_extrinsic_lock.lock().await;
350350
let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
351351
let best_header = self.best_header().await?;
352-
let best_header_id = HeaderId(*best_header.number(), best_header.hash());
352+
353+
// By using parent of best block here, we are protecing again best-block reorganizations.
354+
// E.g. transaction my have been submitted when the best block was `A[num=100]`. Then it has
355+
// been changed to `B[num=100]`. Hash of `A` has been included into transaction signature
356+
// payload. So when signature will be checked, the check will fail and transaction will be
357+
// dropped from the pool.
358+
let best_header_id = match best_header.number().checked_sub(&One::one()) {
359+
Some(parent_block_number) => HeaderId(parent_block_number, *best_header.parent_hash()),
360+
None => HeaderId(*best_header.number(), best_header.hash()),
361+
};
362+
353363
self.jsonrpsee_execute(move |client| async move {
354364
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce);
355365
let tx_hash = Substrate::<C>::author_submit_extrinsic(&*client, extrinsic).await?;

bridges/relays/lib-substrate-relay/src/on_demand_headers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ async fn background_task<P: SubstrateFinalitySyncPipeline>(
220220
P::TargetChain::AVERAGE_BLOCK_INTERVAL,
221221
),
222222
recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT,
223-
stall_timeout: STALL_TIMEOUT,
223+
stall_timeout: relay_substrate_client::transaction_stall_timeout(
224+
target_transactions_mortality,
225+
TargetChain::AVERAGE_BLOCK_INTERVAL,
226+
STALL_TIMEOUT,
227+
),
224228
only_mandatory_headers,
225229
},
226230
MetricsParams::disabled(),

0 commit comments

Comments
 (0)