referrerpolicy=no-referrer-when-downgrade

relay_substrate_client/
lib.rs

1// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Bridges Common is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Tools to interact with Substrate node using RPC methods.
18
19#![warn(missing_docs)]
20
21mod chain;
22mod client;
23mod error;
24mod sync_header;
25mod transaction_tracker;
26
27pub mod calls;
28pub mod guard;
29pub mod metrics;
30pub mod test_chain;
31
32use std::time::Duration;
33
34pub use crate::{
35	chain::{
36		AccountKeyPairOf, BlockWithJustification, CallOf, Chain, ChainWithBalances,
37		ChainWithGrandpa, ChainWithMessages, ChainWithRewards, ChainWithRuntimeVersion,
38		ChainWithTransactions, ChainWithUtilityPallet, FullRuntimeUtilityPallet,
39		MockedRuntimeUtilityPallet, Parachain, RelayChain, SignParam, SignedBlockOf,
40		TransactionStatusOf, UnsignedTransaction, UtilityPallet,
41	},
42	client::{
43		is_ancient_block, rpc_with_caching as new, ChainRuntimeVersion, Client,
44		OpaqueGrandpaAuthoritiesSet, RpcWithCachingClient, SimpleRuntimeVersion, StreamDescription,
45		Subscription, ANCIENT_BLOCK_THRESHOLD,
46	},
47	error::{Error, Result},
48	sync_header::SyncHeader,
49	transaction_tracker::TransactionTracker,
50};
51pub use bp_runtime::{
52	AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain as ChainBase, HashOf, HeaderIdOf,
53	HeaderOf, NonceOf, Parachain as ParachainBase, SignatureOf, TransactionEra, TransactionEraOf,
54	UnderlyingChainProvider,
55};
56
57/// Substrate-over-websocket connection params.
58#[derive(Debug, Clone)]
59pub struct ConnectionParams {
60	/// Websocket endpoint URL.
61	pub uri: String,
62	/// Defined chain runtime version
63	pub chain_runtime_version: ChainRuntimeVersion,
64}
65
66impl Default for ConnectionParams {
67	fn default() -> Self {
68		ConnectionParams {
69			uri: "ws://localhost:9944".into(),
70			chain_runtime_version: ChainRuntimeVersion::Auto,
71		}
72	}
73}
74
75/// Returns stall timeout for relay loop.
76///
77/// Relay considers himself stalled if he has submitted transaction to the node, but it has not
78/// been mined for this period.
79pub fn transaction_stall_timeout(
80	mortality_period: Option<u32>,
81	average_block_interval: Duration,
82	default_stall_timeout: Duration,
83) -> Duration {
84	// 1 extra block for transaction to reach the pool && 1 for relayer to awake after it is mined
85	mortality_period
86		.map(|mortality_period| average_block_interval.saturating_mul(mortality_period + 1 + 1))
87		.unwrap_or(default_stall_timeout)
88}