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 transactions mortality #1196

Merged
merged 4 commits into from
Dec 6, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ sleep 6
--millau-port 9944 \
--millau-signer //Charlie \
--millau-messages-pallet-owner=//RialtoMessagesOwner \
--millau-transactions-mortality=64 \
--rialto-host rialto-node-alice \
--rialto-port 9944 \
--rialto-signer //Charlie \
--rialto-messages-pallet-owner=//MillauMessagesOwner \
--rialto-transactions-mortality=64 \
--lane=00000000 \
--lane=73776170 \
--prometheus-host=0.0.0.0
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 @@ -251,7 +251,11 @@ async fn background_task<SourceChain, TargetChain, TargetSign, 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