Message transactions mortality (#1191)

* transactions mortality in message and complex relays

* logging + enable in test deployments

* spellcheck

* fmt
This commit is contained in:
Svyatoslav Nikolsky
2021-10-25 13:24:48 +03:00
committed by Bastian Köcher
parent e23266c7e6
commit 1ef41a59be
20 changed files with 253 additions and 64 deletions
+10 -9
View File
@@ -69,6 +69,10 @@ pub const ACCOUNT_DERIVATION_PREFIX: &[u8] = b"pallet-bridge/account-derivation/
/// A unique prefix for entropy when generating a cross-chain account ID for the Root account. /// A unique prefix for entropy when generating a cross-chain account ID for the Root account.
pub const ROOT_ACCOUNT_DERIVATION_PREFIX: &[u8] = b"pallet-bridge/account-derivation/root"; pub const ROOT_ACCOUNT_DERIVATION_PREFIX: &[u8] = b"pallet-bridge/account-derivation/root";
/// Generic header Id.
#[derive(RuntimeDebug, Default, Clone, Copy, Eq, Hash, PartialEq)]
pub struct HeaderId<Hash, Number>(pub Number, pub Hash);
/// Unique identifier of the chain. /// Unique identifier of the chain.
/// ///
/// In addition to its main function (identifying the chain), this type may also be used to /// In addition to its main function (identifying the chain), this type may also be used to
@@ -159,20 +163,17 @@ pub enum TransactionEra<BlockNumber, BlockHash> {
/// Transaction is immortal. /// Transaction is immortal.
Immortal, Immortal,
/// Transaction is valid for a given number of blocks, starting from given block. /// Transaction is valid for a given number of blocks, starting from given block.
Mortal(BlockNumber, BlockHash, u32), Mortal(HeaderId<BlockHash, BlockNumber>, u32),
} }
impl<BlockNumber: Copy + Into<u64>, BlockHash: Copy> TransactionEra<BlockNumber, BlockHash> { impl<BlockNumber: Copy + Into<u64>, BlockHash: Copy> TransactionEra<BlockNumber, BlockHash> {
/// Prepare transaction era, based on mortality period and current best block number. /// Prepare transaction era, based on mortality period and current best block number.
pub fn new( pub fn new(
best_block_number: BlockNumber, best_block_id: HeaderId<BlockHash, BlockNumber>,
best_block_hash: BlockHash,
mortality_period: Option<u32>, mortality_period: Option<u32>,
) -> Self { ) -> Self {
mortality_period mortality_period
.map(|mortality_period| { .map(|mortality_period| TransactionEra::Mortal(best_block_id, mortality_period))
TransactionEra::Mortal(best_block_number, best_block_hash, mortality_period)
})
.unwrap_or(TransactionEra::Immortal) .unwrap_or(TransactionEra::Immortal)
} }
@@ -185,8 +186,8 @@ impl<BlockNumber: Copy + Into<u64>, BlockHash: Copy> TransactionEra<BlockNumber,
pub fn frame_era(&self) -> sp_runtime::generic::Era { pub fn frame_era(&self) -> sp_runtime::generic::Era {
match *self { match *self {
TransactionEra::Immortal => sp_runtime::generic::Era::immortal(), TransactionEra::Immortal => sp_runtime::generic::Era::immortal(),
TransactionEra::Mortal(header_number, _, period) => TransactionEra::Mortal(header_id, period) =>
sp_runtime::generic::Era::mortal(period as _, header_number.into()), sp_runtime::generic::Era::mortal(period as _, header_id.0.into()),
} }
} }
@@ -194,7 +195,7 @@ impl<BlockNumber: Copy + Into<u64>, BlockHash: Copy> TransactionEra<BlockNumber,
pub fn signed_payload(&self, genesis_hash: BlockHash) -> BlockHash { pub fn signed_payload(&self, genesis_hash: BlockHash) -> BlockHash {
match *self { match *self {
TransactionEra::Immortal => genesis_hash, TransactionEra::Immortal => genesis_hash,
TransactionEra::Mortal(_, header_hash, _) => header_hash, TransactionEra::Mortal(header_id, _) => header_id.1,
} }
} }
} }
@@ -16,7 +16,7 @@
//! Kusama-to-Polkadot messages sync entrypoint. //! Kusama-to-Polkadot messages sync entrypoint.
use std::{ops::RangeInclusive, time::Duration}; use std::ops::RangeInclusive;
use codec::Encode; use codec::Encode;
use sp_core::{Bytes, Pair}; use sp_core::{Bytes, Pair};
@@ -41,6 +41,7 @@ use substrate_relay_helper::{
}, },
messages_source::SubstrateMessagesSource, messages_source::SubstrateMessagesSource,
messages_target::SubstrateMessagesTarget, messages_target::SubstrateMessagesTarget,
STALL_TIMEOUT,
}; };
/// Kusama-to-Polkadot message lane. /// Kusama-to-Polkadot message lane.
@@ -91,6 +92,7 @@ impl SubstrateMessageLane for KusamaMessagesToPolkadot {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: KusamaHeaderId,
transaction_nonce: bp_runtime::IndexOf<Kusama>, transaction_nonce: bp_runtime::IndexOf<Kusama>,
_generated_at_block: PolkadotHeaderId, _generated_at_block: PolkadotHeaderId,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -106,7 +108,10 @@ impl SubstrateMessageLane for KusamaMessagesToPolkadot {
let transaction = Kusama::sign_transaction( let transaction = Kusama::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.source_sign, &self.message_lane.source_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.source_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -125,6 +130,7 @@ impl SubstrateMessageLane for KusamaMessagesToPolkadot {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: PolkadotHeaderId,
transaction_nonce: bp_runtime::IndexOf<Polkadot>, transaction_nonce: bp_runtime::IndexOf<Polkadot>,
_generated_at_header: KusamaHeaderId, _generated_at_header: KusamaHeaderId,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -146,7 +152,10 @@ impl SubstrateMessageLane for KusamaMessagesToPolkadot {
let transaction = Polkadot::sign_transaction( let transaction = Polkadot::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.target_sign, &self.message_lane.target_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.target_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -170,7 +179,13 @@ type PolkadotTargetClient = SubstrateMessagesTarget<KusamaMessagesToPolkadot>;
pub async fn run( pub async fn run(
params: MessagesRelayParams<Kusama, KusamaSigningParams, Polkadot, PolkadotSigningParams>, params: MessagesRelayParams<Kusama, KusamaSigningParams, Polkadot, PolkadotSigningParams>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let stall_timeout = Duration::from_secs(5 * 60); let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout(
params.source_transactions_mortality,
params.target_transactions_mortality,
Kusama::AVERAGE_BLOCK_INTERVAL,
Polkadot::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
);
let relayer_id_at_kusama = (*params.source_sign.public().as_array_ref()).into(); let relayer_id_at_kusama = (*params.source_sign.public().as_array_ref()).into();
let lane_id = params.lane_id; let lane_id = params.lane_id;
@@ -179,8 +194,10 @@ pub async fn run(
message_lane: SubstrateMessageLaneToSubstrate { message_lane: SubstrateMessageLaneToSubstrate {
source_client: source_client.clone(), source_client: source_client.clone(),
source_sign: params.source_sign, source_sign: params.source_sign,
source_transactions_mortality: params.source_transactions_mortality,
target_client: params.target_client.clone(), target_client: params.target_client.clone(),
target_sign: params.target_sign, target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_kusama, relayer_id_at_source: relayer_id_at_kusama,
}, },
}; };
@@ -206,12 +223,17 @@ pub async fn run(
Max messages in single transaction: {}\n\t\ Max messages in single transaction: {}\n\t\
Max messages size in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\
Max messages weight in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\
Relayer mode: {:?}", Relayer mode: {:?}\n\t\
Tx mortality: {:?}/{:?}\n\t\
Stall timeout: {:?}",
lane.message_lane.relayer_id_at_source, lane.message_lane.relayer_id_at_source,
max_messages_in_single_batch, max_messages_in_single_batch,
max_messages_size_in_single_batch, max_messages_size_in_single_batch,
max_messages_weight_in_single_batch, max_messages_weight_in_single_batch,
params.relayer_mode, params.relayer_mode,
params.source_transactions_mortality,
params.target_transactions_mortality,
stall_timeout,
); );
let (metrics_params, metrics_values) = add_standalone_metrics( let (metrics_params, metrics_values) = add_standalone_metrics(
@@ -16,7 +16,7 @@
//! Millau-to-Rialto messages sync entrypoint. //! Millau-to-Rialto messages sync entrypoint.
use std::{ops::RangeInclusive, time::Duration}; use std::ops::RangeInclusive;
use codec::Encode; use codec::Encode;
use frame_support::dispatch::GetDispatchInfo; use frame_support::dispatch::GetDispatchInfo;
@@ -41,6 +41,7 @@ use substrate_relay_helper::{
}, },
messages_source::SubstrateMessagesSource, messages_source::SubstrateMessagesSource,
messages_target::SubstrateMessagesTarget, messages_target::SubstrateMessagesTarget,
STALL_TIMEOUT,
}; };
/// Millau-to-Rialto message lane. /// Millau-to-Rialto message lane.
@@ -89,6 +90,7 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: MillauHeaderId,
transaction_nonce: IndexOf<Millau>, transaction_nonce: IndexOf<Millau>,
_generated_at_block: RialtoHeaderId, _generated_at_block: RialtoHeaderId,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -102,7 +104,10 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
let transaction = Millau::sign_transaction( let transaction = Millau::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.source_sign, &self.message_lane.source_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.source_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -122,6 +127,7 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: RialtoHeaderId,
transaction_nonce: IndexOf<Rialto>, transaction_nonce: IndexOf<Rialto>,
_generated_at_header: MillauHeaderId, _generated_at_header: MillauHeaderId,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -142,7 +148,10 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
let transaction = Rialto::sign_transaction( let transaction = Rialto::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.target_sign, &self.message_lane.target_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.target_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -167,7 +176,13 @@ type RialtoTargetClient = SubstrateMessagesTarget<MillauMessagesToRialto>;
pub async fn run( pub async fn run(
params: MessagesRelayParams<Millau, MillauSigningParams, Rialto, RialtoSigningParams>, params: MessagesRelayParams<Millau, MillauSigningParams, Rialto, RialtoSigningParams>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let stall_timeout = Duration::from_secs(5 * 60); let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout(
params.source_transactions_mortality,
params.target_transactions_mortality,
Millau::AVERAGE_BLOCK_INTERVAL,
Rialto::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
);
let relayer_id_at_millau = (*params.source_sign.public().as_array_ref()).into(); let relayer_id_at_millau = (*params.source_sign.public().as_array_ref()).into();
let lane_id = params.lane_id; let lane_id = params.lane_id;
@@ -176,8 +191,10 @@ pub async fn run(
message_lane: SubstrateMessageLaneToSubstrate { message_lane: SubstrateMessageLaneToSubstrate {
source_client: source_client.clone(), source_client: source_client.clone(),
source_sign: params.source_sign, source_sign: params.source_sign,
source_transactions_mortality: params.source_transactions_mortality,
target_client: params.target_client.clone(), target_client: params.target_client.clone(),
target_sign: params.target_sign, target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_millau, relayer_id_at_source: relayer_id_at_millau,
}, },
}; };
@@ -200,12 +217,17 @@ pub async fn run(
Max messages in single transaction: {}\n\t\ Max messages in single transaction: {}\n\t\
Max messages size in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\
Max messages weight in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\
Relayer mode: {:?}", Relayer mode: {:?}\n\t\
Tx mortality: {:?}/{:?}\n\t\
Stall timeout: {:?}",
lane.message_lane.relayer_id_at_source, lane.message_lane.relayer_id_at_source,
max_messages_in_single_batch, max_messages_in_single_batch,
max_messages_size_in_single_batch, max_messages_size_in_single_batch,
max_messages_weight_in_single_batch, max_messages_weight_in_single_batch,
params.relayer_mode, params.relayer_mode,
params.source_transactions_mortality,
params.target_transactions_mortality,
stall_timeout,
); );
let (metrics_params, metrics_values) = add_standalone_metrics( let (metrics_params, metrics_values) = add_standalone_metrics(
@@ -16,7 +16,7 @@
//! Polkadot-to-Kusama messages sync entrypoint. //! Polkadot-to-Kusama messages sync entrypoint.
use std::{ops::RangeInclusive, time::Duration}; use std::ops::RangeInclusive;
use codec::Encode; use codec::Encode;
use sp_core::{Bytes, Pair}; use sp_core::{Bytes, Pair};
@@ -41,6 +41,7 @@ use substrate_relay_helper::{
}, },
messages_source::SubstrateMessagesSource, messages_source::SubstrateMessagesSource,
messages_target::SubstrateMessagesTarget, messages_target::SubstrateMessagesTarget,
STALL_TIMEOUT,
}; };
/// Polkadot-to-Kusama message lane. /// Polkadot-to-Kusama message lane.
@@ -90,6 +91,7 @@ impl SubstrateMessageLane for PolkadotMessagesToKusama {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: PolkadotHeaderId,
transaction_nonce: bp_runtime::IndexOf<Polkadot>, transaction_nonce: bp_runtime::IndexOf<Polkadot>,
_generated_at_block: KusamaHeaderId, _generated_at_block: KusamaHeaderId,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -105,7 +107,10 @@ impl SubstrateMessageLane for PolkadotMessagesToKusama {
let transaction = Polkadot::sign_transaction( let transaction = Polkadot::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.source_sign, &self.message_lane.source_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.source_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -124,6 +129,7 @@ impl SubstrateMessageLane for PolkadotMessagesToKusama {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: KusamaHeaderId,
transaction_nonce: bp_runtime::IndexOf<Kusama>, transaction_nonce: bp_runtime::IndexOf<Kusama>,
_generated_at_header: PolkadotHeaderId, _generated_at_header: PolkadotHeaderId,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -145,7 +151,10 @@ impl SubstrateMessageLane for PolkadotMessagesToKusama {
let transaction = Kusama::sign_transaction( let transaction = Kusama::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.target_sign, &self.message_lane.target_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.target_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -169,7 +178,13 @@ type KusamaTargetClient = SubstrateMessagesTarget<PolkadotMessagesToKusama>;
pub async fn run( pub async fn run(
params: MessagesRelayParams<Polkadot, PolkadotSigningParams, Kusama, KusamaSigningParams>, params: MessagesRelayParams<Polkadot, PolkadotSigningParams, Kusama, KusamaSigningParams>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let stall_timeout = Duration::from_secs(5 * 60); let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout(
params.source_transactions_mortality,
params.target_transactions_mortality,
Polkadot::AVERAGE_BLOCK_INTERVAL,
Kusama::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
);
let relayer_id_at_polkadot = (*params.source_sign.public().as_array_ref()).into(); let relayer_id_at_polkadot = (*params.source_sign.public().as_array_ref()).into();
let lane_id = params.lane_id; let lane_id = params.lane_id;
@@ -178,8 +193,10 @@ pub async fn run(
message_lane: SubstrateMessageLaneToSubstrate { message_lane: SubstrateMessageLaneToSubstrate {
source_client: source_client.clone(), source_client: source_client.clone(),
source_sign: params.source_sign, source_sign: params.source_sign,
source_transactions_mortality: params.source_transactions_mortality,
target_client: params.target_client.clone(), target_client: params.target_client.clone(),
target_sign: params.target_sign, target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_polkadot, relayer_id_at_source: relayer_id_at_polkadot,
}, },
}; };
@@ -205,12 +222,17 @@ pub async fn run(
Max messages in single transaction: {}\n\t\ Max messages in single transaction: {}\n\t\
Max messages size in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\
Max messages weight in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\
Relayer mode: {:?}", Relayer mode: {:?}\n\t\
Tx mortality: {:?}/{:?}\n\t\
Stall timeout: {:?}",
lane.message_lane.relayer_id_at_source, lane.message_lane.relayer_id_at_source,
max_messages_in_single_batch, max_messages_in_single_batch,
max_messages_size_in_single_batch, max_messages_size_in_single_batch,
max_messages_weight_in_single_batch, max_messages_weight_in_single_batch,
params.relayer_mode, params.relayer_mode,
params.source_transactions_mortality,
params.target_transactions_mortality,
stall_timeout,
); );
let (metrics_params, metrics_values) = add_standalone_metrics( let (metrics_params, metrics_values) = add_standalone_metrics(
@@ -16,7 +16,7 @@
//! Rialto-to-Millau messages sync entrypoint. //! Rialto-to-Millau messages sync entrypoint.
use std::{ops::RangeInclusive, time::Duration}; use std::ops::RangeInclusive;
use codec::Encode; use codec::Encode;
use frame_support::dispatch::GetDispatchInfo; use frame_support::dispatch::GetDispatchInfo;
@@ -41,6 +41,7 @@ use substrate_relay_helper::{
}, },
messages_source::SubstrateMessagesSource, messages_source::SubstrateMessagesSource,
messages_target::SubstrateMessagesTarget, messages_target::SubstrateMessagesTarget,
STALL_TIMEOUT,
}; };
/// Rialto-to-Millau message lane. /// Rialto-to-Millau message lane.
@@ -89,6 +90,7 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: RialtoHeaderId,
transaction_nonce: IndexOf<Rialto>, transaction_nonce: IndexOf<Rialto>,
_generated_at_block: MillauHeaderId, _generated_at_block: MillauHeaderId,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -102,7 +104,10 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
let transaction = Rialto::sign_transaction( let transaction = Rialto::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.source_sign, &self.message_lane.source_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.source_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -122,6 +127,7 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: MillauHeaderId,
transaction_nonce: IndexOf<Millau>, transaction_nonce: IndexOf<Millau>,
_generated_at_header: RialtoHeaderId, _generated_at_header: RialtoHeaderId,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -142,7 +148,10 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
let transaction = Millau::sign_transaction( let transaction = Millau::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.target_sign, &self.message_lane.target_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.target_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -167,7 +176,13 @@ type MillauTargetClient = SubstrateMessagesTarget<RialtoMessagesToMillau>;
pub async fn run( pub async fn run(
params: MessagesRelayParams<Rialto, RialtoSigningParams, Millau, MillauSigningParams>, params: MessagesRelayParams<Rialto, RialtoSigningParams, Millau, MillauSigningParams>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let stall_timeout = Duration::from_secs(5 * 60); let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout(
params.source_transactions_mortality,
params.target_transactions_mortality,
Rialto::AVERAGE_BLOCK_INTERVAL,
Millau::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
);
let relayer_id_at_rialto = (*params.source_sign.public().as_array_ref()).into(); let relayer_id_at_rialto = (*params.source_sign.public().as_array_ref()).into();
let lane_id = params.lane_id; let lane_id = params.lane_id;
@@ -176,8 +191,10 @@ pub async fn run(
message_lane: SubstrateMessageLaneToSubstrate { message_lane: SubstrateMessageLaneToSubstrate {
source_client: source_client.clone(), source_client: source_client.clone(),
source_sign: params.source_sign, source_sign: params.source_sign,
source_transactions_mortality: params.source_transactions_mortality,
target_client: params.target_client.clone(), target_client: params.target_client.clone(),
target_sign: params.target_sign, target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_rialto, relayer_id_at_source: relayer_id_at_rialto,
}, },
}; };
@@ -199,12 +216,17 @@ pub async fn run(
Max messages in single transaction: {}\n\t\ Max messages in single transaction: {}\n\t\
Max messages size in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\
Max messages weight in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\
Relayer mode: {:?}", Relayer mode: {:?}\n\t\
Tx mortality: {:?}/{:?}\n\t\
Stall timeout: {:?}",
lane.message_lane.relayer_id_at_source, lane.message_lane.relayer_id_at_source,
max_messages_in_single_batch, max_messages_in_single_batch,
max_messages_size_in_single_batch, max_messages_size_in_single_batch,
max_messages_weight_in_single_batch, max_messages_weight_in_single_batch,
params.relayer_mode, params.relayer_mode,
params.source_transactions_mortality,
params.target_transactions_mortality,
stall_timeout,
); );
let (metrics_params, metrics_values) = add_standalone_metrics( let (metrics_params, metrics_values) = add_standalone_metrics(
@@ -16,7 +16,7 @@
//! Rococo-to-Wococo messages sync entrypoint. //! Rococo-to-Wococo messages sync entrypoint.
use std::{ops::RangeInclusive, time::Duration}; use std::ops::RangeInclusive;
use codec::Encode; use codec::Encode;
use sp_core::{Bytes, Pair}; use sp_core::{Bytes, Pair};
@@ -40,6 +40,7 @@ use substrate_relay_helper::{
}, },
messages_source::SubstrateMessagesSource, messages_source::SubstrateMessagesSource,
messages_target::SubstrateMessagesTarget, messages_target::SubstrateMessagesTarget,
STALL_TIMEOUT,
}; };
/// Rococo-to-Wococo message lane. /// Rococo-to-Wococo message lane.
@@ -88,6 +89,7 @@ impl SubstrateMessageLane for RococoMessagesToWococo {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: RococoHeaderId,
transaction_nonce: IndexOf<Rococo>, transaction_nonce: IndexOf<Rococo>,
_generated_at_block: WococoHeaderId, _generated_at_block: WococoHeaderId,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -103,7 +105,10 @@ impl SubstrateMessageLane for RococoMessagesToWococo {
let transaction = Rococo::sign_transaction( let transaction = Rococo::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.source_sign, &self.message_lane.source_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.source_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -122,6 +127,7 @@ impl SubstrateMessageLane for RococoMessagesToWococo {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: WococoHeaderId,
transaction_nonce: IndexOf<Wococo>, transaction_nonce: IndexOf<Wococo>,
_generated_at_header: RococoHeaderId, _generated_at_header: RococoHeaderId,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -143,7 +149,10 @@ impl SubstrateMessageLane for RococoMessagesToWococo {
let transaction = Wococo::sign_transaction( let transaction = Wococo::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.target_sign, &self.message_lane.target_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.target_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -167,7 +176,13 @@ type WococoTargetClient = SubstrateMessagesTarget<RococoMessagesToWococo>;
pub async fn run( pub async fn run(
params: MessagesRelayParams<Rococo, RococoSigningParams, Wococo, WococoSigningParams>, params: MessagesRelayParams<Rococo, RococoSigningParams, Wococo, WococoSigningParams>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let stall_timeout = Duration::from_secs(5 * 60); let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout(
params.source_transactions_mortality,
params.target_transactions_mortality,
Rococo::AVERAGE_BLOCK_INTERVAL,
Wococo::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
);
let relayer_id_at_rococo = (*params.source_sign.public().as_array_ref()).into(); let relayer_id_at_rococo = (*params.source_sign.public().as_array_ref()).into();
let lane_id = params.lane_id; let lane_id = params.lane_id;
@@ -176,8 +191,10 @@ pub async fn run(
message_lane: SubstrateMessageLaneToSubstrate { message_lane: SubstrateMessageLaneToSubstrate {
source_client: source_client.clone(), source_client: source_client.clone(),
source_sign: params.source_sign, source_sign: params.source_sign,
source_transactions_mortality: params.source_transactions_mortality,
target_client: params.target_client.clone(), target_client: params.target_client.clone(),
target_sign: params.target_sign, target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_rococo, relayer_id_at_source: relayer_id_at_rococo,
}, },
}; };
@@ -203,12 +220,17 @@ pub async fn run(
Max messages in single transaction: {}\n\t\ Max messages in single transaction: {}\n\t\
Max messages size in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\
Max messages weight in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\
Relayer mode: {:?}", Relayer mode: {:?}\n\t\
Tx mortality: {:?}/{:?}\n\t\
Stall timeout: {:?}",
lane.message_lane.relayer_id_at_source, lane.message_lane.relayer_id_at_source,
max_messages_in_single_batch, max_messages_in_single_batch,
max_messages_size_in_single_batch, max_messages_size_in_single_batch,
max_messages_weight_in_single_batch, max_messages_weight_in_single_batch,
params.relayer_mode, params.relayer_mode,
params.source_transactions_mortality,
params.target_transactions_mortality,
stall_timeout,
); );
let (metrics_params, metrics_values) = add_standalone_metrics( let (metrics_params, metrics_values) = add_standalone_metrics(
@@ -16,7 +16,7 @@
//! Wococo-to-Rococo messages sync entrypoint. //! Wococo-to-Rococo messages sync entrypoint.
use std::{ops::RangeInclusive, time::Duration}; use std::ops::RangeInclusive;
use codec::Encode; use codec::Encode;
use sp_core::{Bytes, Pair}; use sp_core::{Bytes, Pair};
@@ -40,6 +40,7 @@ use substrate_relay_helper::{
}, },
messages_source::SubstrateMessagesSource, messages_source::SubstrateMessagesSource,
messages_target::SubstrateMessagesTarget, messages_target::SubstrateMessagesTarget,
STALL_TIMEOUT,
}; };
/// Wococo-to-Rococo message lane. /// Wococo-to-Rococo message lane.
@@ -87,6 +88,7 @@ impl SubstrateMessageLane for WococoMessagesToRococo {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: WococoHeaderId,
transaction_nonce: IndexOf<Wococo>, transaction_nonce: IndexOf<Wococo>,
_generated_at_block: RococoHeaderId, _generated_at_block: RococoHeaderId,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -102,7 +104,10 @@ impl SubstrateMessageLane for WococoMessagesToRococo {
let transaction = Wococo::sign_transaction( let transaction = Wococo::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.source_sign, &self.message_lane.source_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.source_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -121,6 +126,7 @@ impl SubstrateMessageLane for WococoMessagesToRococo {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: WococoHeaderId,
transaction_nonce: IndexOf<Rococo>, transaction_nonce: IndexOf<Rococo>,
_generated_at_header: WococoHeaderId, _generated_at_header: WococoHeaderId,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -142,7 +148,10 @@ impl SubstrateMessageLane for WococoMessagesToRococo {
let transaction = Rococo::sign_transaction( let transaction = Rococo::sign_transaction(
genesis_hash, genesis_hash,
&self.message_lane.target_sign, &self.message_lane.target_sign,
relay_substrate_client::TransactionEra::immortal(), relay_substrate_client::TransactionEra::new(
best_block_id,
self.message_lane.target_transactions_mortality,
),
UnsignedTransaction::new(call, transaction_nonce), UnsignedTransaction::new(call, transaction_nonce),
); );
log::trace!( log::trace!(
@@ -166,7 +175,13 @@ type RococoTargetClient = SubstrateMessagesTarget<WococoMessagesToRococo>;
pub async fn run( pub async fn run(
params: MessagesRelayParams<Wococo, WococoSigningParams, Rococo, RococoSigningParams>, params: MessagesRelayParams<Wococo, WococoSigningParams, Rococo, RococoSigningParams>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let stall_timeout = Duration::from_secs(5 * 60); let stall_timeout = relay_substrate_client::bidirectional_transaction_stall_timeout(
params.source_transactions_mortality,
params.target_transactions_mortality,
Wococo::AVERAGE_BLOCK_INTERVAL,
Rococo::AVERAGE_BLOCK_INTERVAL,
STALL_TIMEOUT,
);
let relayer_id_at_wococo = (*params.source_sign.public().as_array_ref()).into(); let relayer_id_at_wococo = (*params.source_sign.public().as_array_ref()).into();
let lane_id = params.lane_id; let lane_id = params.lane_id;
@@ -175,8 +190,10 @@ pub async fn run(
message_lane: SubstrateMessageLaneToSubstrate { message_lane: SubstrateMessageLaneToSubstrate {
source_client: source_client.clone(), source_client: source_client.clone(),
source_sign: params.source_sign, source_sign: params.source_sign,
source_transactions_mortality: params.source_transactions_mortality,
target_client: params.target_client.clone(), target_client: params.target_client.clone(),
target_sign: params.target_sign, target_sign: params.target_sign,
target_transactions_mortality: params.target_transactions_mortality,
relayer_id_at_source: relayer_id_at_wococo, relayer_id_at_source: relayer_id_at_wococo,
}, },
}; };
@@ -202,12 +219,17 @@ pub async fn run(
Max messages in single transaction: {}\n\t\ Max messages in single transaction: {}\n\t\
Max messages size in single transaction: {}\n\t\ Max messages size in single transaction: {}\n\t\
Max messages weight in single transaction: {}\n\t\ Max messages weight in single transaction: {}\n\t\
Relayer mode: {:?}", Relayer mode: {:?}\n\t\
Tx mortality: {:?}/{:?}\n\t\
Stall timeout: {:?}",
lane.message_lane.relayer_id_at_source, lane.message_lane.relayer_id_at_source,
max_messages_in_single_batch, max_messages_in_single_batch,
max_messages_size_in_single_batch, max_messages_size_in_single_batch,
max_messages_weight_in_single_batch, max_messages_weight_in_single_batch,
params.relayer_mode, params.relayer_mode,
params.source_transactions_mortality,
params.target_transactions_mortality,
stall_timeout,
); );
let (metrics_params, metrics_values) = add_standalone_metrics( let (metrics_params, metrics_values) = add_standalone_metrics(
@@ -512,8 +512,10 @@ impl RelayHeadersAndMessages {
let left_to_right_messages = left_to_right_messages(MessagesRelayParams { let left_to_right_messages = left_to_right_messages(MessagesRelayParams {
source_client: left_client.clone(), source_client: left_client.clone(),
source_sign: left_sign.clone(), source_sign: left_sign.clone(),
source_transactions_mortality: left_transactions_mortality.clone(),
target_client: right_client.clone(), target_client: right_client.clone(),
target_sign: right_sign.clone(), target_sign: right_sign.clone(),
target_transactions_mortality: right_transactions_mortality.clone(),
source_to_target_headers_relay: Some(left_to_right_on_demand_headers.clone()), source_to_target_headers_relay: Some(left_to_right_on_demand_headers.clone()),
target_to_source_headers_relay: Some(right_to_left_on_demand_headers.clone()), target_to_source_headers_relay: Some(right_to_left_on_demand_headers.clone()),
lane_id: lane, lane_id: lane,
@@ -529,8 +531,10 @@ impl RelayHeadersAndMessages {
let right_to_left_messages = right_to_left_messages(MessagesRelayParams { let right_to_left_messages = right_to_left_messages(MessagesRelayParams {
source_client: right_client.clone(), source_client: right_client.clone(),
source_sign: right_sign.clone(), source_sign: right_sign.clone(),
source_transactions_mortality: right_transactions_mortality.clone(),
target_client: left_client.clone(), target_client: left_client.clone(),
target_sign: left_sign.clone(), target_sign: left_sign.clone(),
target_transactions_mortality: left_transactions_mortality.clone(),
source_to_target_headers_relay: Some(right_to_left_on_demand_headers.clone()), source_to_target_headers_relay: Some(right_to_left_on_demand_headers.clone()),
target_to_source_headers_relay: Some(left_to_right_on_demand_headers.clone()), target_to_source_headers_relay: Some(left_to_right_on_demand_headers.clone()),
lane_id: lane, lane_id: lane,
@@ -76,14 +76,18 @@ impl RelayMessages {
select_full_bridge!(self.bridge, { select_full_bridge!(self.bridge, {
let source_client = self.source.to_client::<Source>().await?; let source_client = self.source.to_client::<Source>().await?;
let source_sign = self.source_sign.to_keypair::<Source>()?; let source_sign = self.source_sign.to_keypair::<Source>()?;
let source_transactions_mortality = self.source_sign.transactions_mortality()?;
let target_client = self.target.to_client::<Target>().await?; let target_client = self.target.to_client::<Target>().await?;
let target_sign = self.target_sign.to_keypair::<Target>()?; let target_sign = self.target_sign.to_keypair::<Target>()?;
let target_transactions_mortality = self.target_sign.transactions_mortality()?;
relay_messages(MessagesRelayParams { relay_messages(MessagesRelayParams {
source_client, source_client,
source_sign, source_sign,
source_transactions_mortality,
target_client, target_client,
target_sign, target_sign,
target_transactions_mortality,
source_to_target_headers_relay: None, source_to_target_headers_relay: None,
target_to_source_headers_relay: None, target_to_source_headers_relay: None,
lane_id: self.lane.into(), lane_id: self.lane.into(),
+30 -3
View File
@@ -69,13 +69,40 @@ impl Default for ConnectionParams {
/// ///
/// Relay considers himself stalled if he has submitted transaction to the node, but it has not /// Relay considers himself stalled if he has submitted transaction to the node, but it has not
/// been mined for this period. /// been mined for this period.
///
/// Returns `None` if mortality period is `None`
pub fn transaction_stall_timeout( pub fn transaction_stall_timeout(
mortality_period: Option<u32>, mortality_period: Option<u32>,
average_block_interval: Duration, average_block_interval: Duration,
) -> Option<Duration> { default_stall_timeout: Duration,
) -> Duration {
// 1 extra block for transaction to reach the pool && 1 for relayer to awake after it is mined // 1 extra block for transaction to reach the pool && 1 for relayer to awake after it is mined
mortality_period mortality_period
.map(|mortality_period| average_block_interval.saturating_mul(mortality_period + 1 + 1)) .map(|mortality_period| average_block_interval.saturating_mul(mortality_period + 1 + 1))
.unwrap_or(default_stall_timeout)
}
/// Returns stall timeout for relay loop that submit transactions to two chains.
///
/// Bidirectional relay may have two active transactions. Even if one of them has been spoiled, we
/// can't just restart the loop - the other transaction may still be alive and we'll be submitting
/// duplicate transaction, which may result in funds loss. So we'll be selecting maximal mortality
/// for choosing loop stall timeout.
pub fn bidirectional_transaction_stall_timeout(
left_mortality_period: Option<u32>,
right_mortality_period: Option<u32>,
left_average_block_interval: Duration,
right_average_block_interval: Duration,
default_stall_timeout: Duration,
) -> Duration {
std::cmp::max(
transaction_stall_timeout(
left_mortality_period,
left_average_block_interval,
default_stall_timeout,
),
transaction_stall_timeout(
right_mortality_period,
right_average_block_interval,
default_stall_timeout,
),
)
} }
@@ -32,7 +32,6 @@ pallet-bridge-messages = { path = "../../modules/messages" }
bp-runtime = { path = "../../primitives/runtime" } bp-runtime = { path = "../../primitives/runtime" }
bp-messages = { path = "../../primitives/messages" } bp-messages = { path = "../../primitives/messages" }
# Substrate Dependencies # Substrate Dependencies
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -16,7 +16,7 @@
//! Substrate-to-Substrate headers sync entrypoint. //! Substrate-to-Substrate headers sync entrypoint.
use crate::finality_target::SubstrateFinalityTarget; use crate::{finality_target::SubstrateFinalityTarget, STALL_TIMEOUT};
use bp_header_chain::justification::GrandpaJustification; use bp_header_chain::justification::GrandpaJustification;
use bp_runtime::AccountIdOf; use bp_runtime::AccountIdOf;
@@ -26,16 +26,8 @@ use relay_substrate_client::{
}; };
use relay_utils::{metrics::MetricsParams, BlockNumberBase}; use relay_utils::{metrics::MetricsParams, BlockNumberBase};
use sp_core::Bytes; use sp_core::Bytes;
use std::{fmt::Debug, marker::PhantomData, time::Duration}; use std::{fmt::Debug, marker::PhantomData};
/// Default synchronization loop timeout. If transactions generated by relay are immortal, then
/// this timeout is used.
///
/// There are no any strict requirements on block time in Substrate. But we assume here that all
/// Substrate-based chains will be designed to produce relatively fast (compared to the slowest
/// blockchains) blocks. So 1 hour seems to be a good guess for (even congested) chains to mine
/// transaction, or remove it from the pool.
pub(crate) const STALL_TIMEOUT: Duration = Duration::from_secs(60 * 60);
/// Default limit of recent finality proofs. /// Default limit of recent finality proofs.
/// ///
/// Finality delay of 4096 blocks is unlikely to happen in practice in /// Finality delay of 4096 blocks is unlikely to happen in practice in
@@ -165,8 +157,8 @@ where
stall_timeout: relay_substrate_client::transaction_stall_timeout( stall_timeout: relay_substrate_client::transaction_stall_timeout(
transactions_mortality, transactions_mortality,
TargetChain::AVERAGE_BLOCK_INTERVAL, TargetChain::AVERAGE_BLOCK_INTERVAL,
) STALL_TIMEOUT,
.unwrap_or(STALL_TIMEOUT), ),
only_mandatory_headers, only_mandatory_headers,
}, },
metrics_params, metrics_params,
@@ -98,8 +98,7 @@ where
move |best_block_id, transaction_nonce| { move |best_block_id, transaction_nonce| {
pipeline.make_submit_finality_proof_transaction( pipeline.make_submit_finality_proof_transaction(
relay_substrate_client::TransactionEra::new( relay_substrate_client::TransactionEra::new(
best_block_id.0, best_block_id,
best_block_id.1,
transactions_mortality, transactions_mortality,
), ),
transaction_nonce, transaction_nonce,
@@ -18,6 +18,8 @@
#![warn(missing_docs)] #![warn(missing_docs)]
use std::time::Duration;
pub mod conversion_rate_update; pub mod conversion_rate_update;
pub mod error; pub mod error;
pub mod finality_pipeline; pub mod finality_pipeline;
@@ -28,3 +30,12 @@ pub mod messages_lane;
pub mod messages_source; pub mod messages_source;
pub mod messages_target; pub mod messages_target;
pub mod on_demand_headers; pub mod on_demand_headers;
/// Default relay loop stall timeout. If transactions generated by relay are immortal, then
/// this timeout is used.
///
/// There are no any strict requirements on block time in Substrate. But we assume here that all
/// Substrate-based chains will be designed to produce relatively fast (compared to the slowest
/// blockchains) blocks. So 1 hour seems to be a good guess for (even congested) chains to mine
/// transaction, or remove it from the pool.
pub const STALL_TIMEOUT: Duration = Duration::from_secs(60 * 60);
@@ -44,10 +44,14 @@ pub struct MessagesRelayParams<SC: Chain, SS, TC: Chain, TS> {
pub source_client: Client<SC>, pub source_client: Client<SC>,
/// Sign parameters for messages source chain. /// Sign parameters for messages source chain.
pub source_sign: SS, pub source_sign: SS,
/// Mortality of source transactions.
pub source_transactions_mortality: Option<u32>,
/// Messages target client. /// Messages target client.
pub target_client: Client<TC>, pub target_client: Client<TC>,
/// Sign parameters for messages target chain. /// Sign parameters for messages target chain.
pub target_sign: TS, pub target_sign: TS,
/// Mortality of target transactions.
pub target_transactions_mortality: Option<u32>,
/// Optional on-demand source to target headers relay. /// Optional on-demand source to target headers relay.
pub source_to_target_headers_relay: Option<OnDemandHeadersRelay<SC>>, pub source_to_target_headers_relay: Option<OnDemandHeadersRelay<SC>>,
/// Optional on-demand target to source headers relay. /// Optional on-demand target to source headers relay.
@@ -113,6 +117,7 @@ pub trait SubstrateMessageLane: 'static + Clone + Send + Sync {
/// Make messages delivery transaction. /// Make messages delivery transaction.
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
best_block_id: TargetHeaderIdOf<Self::MessageLane>,
transaction_nonce: IndexOf<Self::TargetChain>, transaction_nonce: IndexOf<Self::TargetChain>,
generated_at_header: SourceHeaderIdOf<Self::MessageLane>, generated_at_header: SourceHeaderIdOf<Self::MessageLane>,
nonces: RangeInclusive<MessageNonce>, nonces: RangeInclusive<MessageNonce>,
@@ -126,6 +131,7 @@ pub trait SubstrateMessageLane: 'static + Clone + Send + Sync {
/// Make messages receiving proof transaction. /// Make messages receiving proof transaction.
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
best_block_id: SourceHeaderIdOf<Self::MessageLane>,
transaction_nonce: IndexOf<Self::SourceChain>, transaction_nonce: IndexOf<Self::SourceChain>,
generated_at_header: TargetHeaderIdOf<Self::MessageLane>, generated_at_header: TargetHeaderIdOf<Self::MessageLane>,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -144,10 +150,14 @@ pub struct SubstrateMessageLaneToSubstrate<
pub source_client: Client<Source>, pub source_client: Client<Source>,
/// Parameters required to sign transactions for source chain. /// Parameters required to sign transactions for source chain.
pub source_sign: SourceSignParams, pub source_sign: SourceSignParams,
/// Source transactions mortality.
pub source_transactions_mortality: Option<u32>,
/// Client for the target Substrate chain. /// Client for the target Substrate chain.
pub target_client: Client<Target>, pub target_client: Client<Target>,
/// Parameters required to sign transactions for target chain. /// Parameters required to sign transactions for target chain.
pub target_sign: TargetSignParams, pub target_sign: TargetSignParams,
/// Target transactions mortality.
pub target_transactions_mortality: Option<u32>,
/// Account id of relayer at the source chain. /// Account id of relayer at the source chain.
pub relayer_id_at_source: Source::AccountId, pub relayer_id_at_source: Source::AccountId,
} }
@@ -159,8 +169,10 @@ impl<Source: Chain, SourceSignParams: Clone, Target: Chain, TargetSignParams: Cl
Self { Self {
source_client: self.source_client.clone(), source_client: self.source_client.clone(),
source_sign: self.source_sign.clone(), source_sign: self.source_sign.clone(),
source_transactions_mortality: self.source_transactions_mortality,
target_client: self.target_client.clone(), target_client: self.target_client.clone(),
target_sign: self.target_sign.clone(), target_sign: self.target_sign.clone(),
target_transactions_mortality: self.target_transactions_mortality,
relayer_id_at_source: self.relayer_id_at_source.clone(), relayer_id_at_source: self.relayer_id_at_source.clone(),
} }
} }
@@ -245,8 +245,9 @@ where
self.client self.client
.submit_signed_extrinsic( .submit_signed_extrinsic(
self.lane.source_transactions_author(), self.lane.source_transactions_author(),
move |_, transaction_nonce| { move |best_block_id, transaction_nonce| {
lane.make_messages_receiving_proof_transaction( lane.make_messages_receiving_proof_transaction(
best_block_id,
transaction_nonce, transaction_nonce,
generated_at_block, generated_at_block,
proof, proof,
@@ -268,6 +269,7 @@ where
) -> <P::MessageLane as MessageLane>::SourceChainBalance { ) -> <P::MessageLane as MessageLane>::SourceChainBalance {
self.client self.client
.estimate_extrinsic_fee(self.lane.make_messages_receiving_proof_transaction( .estimate_extrinsic_fee(self.lane.make_messages_receiving_proof_transaction(
HeaderId(Default::default(), Default::default()),
Zero::zero(), Zero::zero(),
HeaderId(Default::default(), Default::default()), HeaderId(Default::default(), Default::default()),
prepare_dummy_messages_delivery_proof::<P::SourceChain, P::TargetChain>(), prepare_dummy_messages_delivery_proof::<P::SourceChain, P::TargetChain>(),
@@ -227,8 +227,9 @@ where
self.client self.client
.submit_signed_extrinsic( .submit_signed_extrinsic(
self.lane.target_transactions_author(), self.lane.target_transactions_author(),
move |_, transaction_nonce| { move |best_block_id, transaction_nonce| {
lane.make_messages_delivery_transaction( lane.make_messages_delivery_transaction(
best_block_id,
transaction_nonce, transaction_nonce,
generated_at_header, generated_at_header,
nonces_clone, nonces_clone,
@@ -264,6 +265,7 @@ where
// Prepare 'dummy' delivery transaction - we only care about its length and dispatch weight. // Prepare 'dummy' delivery transaction - we only care about its length and dispatch weight.
let delivery_tx = self.lane.make_messages_delivery_transaction( let delivery_tx = self.lane.make_messages_delivery_transaction(
HeaderId(Default::default(), Default::default()),
Zero::zero(), Zero::zero(),
HeaderId(Default::default(), Default::default()), HeaderId(Default::default(), Default::default()),
nonces.clone(), nonces.clone(),
@@ -299,6 +301,7 @@ where
let larger_delivery_tx_fee = self let larger_delivery_tx_fee = self
.client .client
.estimate_extrinsic_fee(self.lane.make_messages_delivery_transaction( .estimate_extrinsic_fee(self.lane.make_messages_delivery_transaction(
HeaderId(Default::default(), Default::default()),
Zero::zero(), Zero::zero(),
HeaderId(Default::default(), Default::default()), HeaderId(Default::default(), Default::default()),
nonces.clone(), nonces.clone(),
@@ -473,6 +476,7 @@ mod tests {
fn make_messages_receiving_proof_transaction( fn make_messages_receiving_proof_transaction(
&self, &self,
_best_block_id: SourceHeaderIdOf<Self::MessageLane>,
_transaction_nonce: IndexOf<Rococo>, _transaction_nonce: IndexOf<Rococo>,
_generated_at_block: TargetHeaderIdOf<Self::MessageLane>, _generated_at_block: TargetHeaderIdOf<Self::MessageLane>,
_proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof, _proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -486,6 +490,7 @@ mod tests {
fn make_messages_delivery_transaction( fn make_messages_delivery_transaction(
&self, &self,
_best_block_id: TargetHeaderIdOf<Self::MessageLane>,
_transaction_nonce: IndexOf<Wococo>, _transaction_nonce: IndexOf<Wococo>,
_generated_at_header: SourceHeaderIdOf<Self::MessageLane>, _generated_at_header: SourceHeaderIdOf<Self::MessageLane>,
_nonces: RangeInclusive<MessageNonce>, _nonces: RangeInclusive<MessageNonce>,
@@ -38,9 +38,9 @@ use relay_utils::{
use crate::{ use crate::{
finality_pipeline::{ finality_pipeline::{
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate, RECENT_FINALITY_PROOFS_LIMIT, SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate, RECENT_FINALITY_PROOFS_LIMIT,
STALL_TIMEOUT,
}, },
finality_target::SubstrateFinalityTarget, finality_target::SubstrateFinalityTarget,
STALL_TIMEOUT,
}; };
/// On-demand Substrate <-> Substrate headers relay. /// On-demand Substrate <-> Substrate headers relay.
+4
View File
@@ -22,6 +22,10 @@ sysinfo = "0.15"
time = "0.2" time = "0.2"
thiserror = "1.0.26" thiserror = "1.0.26"
# Bridge dependencies
bp-runtime = { path = "../../primitives/runtime" }
# Substrate dependencies # Substrate dependencies
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
+1 -4
View File
@@ -16,6 +16,7 @@
//! Utilities used by different relays. //! Utilities used by different relays.
pub use bp_runtime::HeaderId;
pub use error::Error; pub use error::Error;
pub use relay_loop::{relay_loop, relay_metrics}; pub use relay_loop::{relay_loop, relay_metrics};
@@ -103,10 +104,6 @@ macro_rules! bail_on_arg_error {
}; };
} }
/// Ethereum header Id.
#[derive(Debug, Default, Clone, Copy, Eq, Hash, PartialEq)]
pub struct HeaderId<Hash, Number>(pub Number, pub Hash);
/// Error type that can signal connection errors. /// Error type that can signal connection errors.
pub trait MaybeConnectionError { pub trait MaybeConnectionError {
/// Returns true if error (maybe) represents connection error. /// Returns true if error (maybe) represents connection error.