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
@@ -32,7 +32,6 @@ pallet-bridge-messages = { path = "../../modules/messages" }
bp-runtime = { path = "../../primitives/runtime" }
bp-messages = { path = "../../primitives/messages" }
# Substrate Dependencies
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -16,7 +16,7 @@
//! 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_runtime::AccountIdOf;
@@ -26,16 +26,8 @@ use relay_substrate_client::{
};
use relay_utils::{metrics::MetricsParams, BlockNumberBase};
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.
///
/// 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(
transactions_mortality,
TargetChain::AVERAGE_BLOCK_INTERVAL,
)
.unwrap_or(STALL_TIMEOUT),
STALL_TIMEOUT,
),
only_mandatory_headers,
},
metrics_params,
@@ -98,8 +98,7 @@ where
move |best_block_id, transaction_nonce| {
pipeline.make_submit_finality_proof_transaction(
relay_substrate_client::TransactionEra::new(
best_block_id.0,
best_block_id.1,
best_block_id,
transactions_mortality,
),
transaction_nonce,
@@ -18,6 +18,8 @@
#![warn(missing_docs)]
use std::time::Duration;
pub mod conversion_rate_update;
pub mod error;
pub mod finality_pipeline;
@@ -28,3 +30,12 @@ pub mod messages_lane;
pub mod messages_source;
pub mod messages_target;
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>,
/// Sign parameters for messages source chain.
pub source_sign: SS,
/// Mortality of source transactions.
pub source_transactions_mortality: Option<u32>,
/// Messages target client.
pub target_client: Client<TC>,
/// Sign parameters for messages target chain.
pub target_sign: TS,
/// Mortality of target transactions.
pub target_transactions_mortality: Option<u32>,
/// Optional on-demand source to target headers relay.
pub source_to_target_headers_relay: Option<OnDemandHeadersRelay<SC>>,
/// Optional on-demand target to source headers relay.
@@ -113,6 +117,7 @@ pub trait SubstrateMessageLane: 'static + Clone + Send + Sync {
/// Make messages delivery transaction.
fn make_messages_delivery_transaction(
&self,
best_block_id: TargetHeaderIdOf<Self::MessageLane>,
transaction_nonce: IndexOf<Self::TargetChain>,
generated_at_header: SourceHeaderIdOf<Self::MessageLane>,
nonces: RangeInclusive<MessageNonce>,
@@ -126,6 +131,7 @@ pub trait SubstrateMessageLane: 'static + Clone + Send + Sync {
/// Make messages receiving proof transaction.
fn make_messages_receiving_proof_transaction(
&self,
best_block_id: SourceHeaderIdOf<Self::MessageLane>,
transaction_nonce: IndexOf<Self::SourceChain>,
generated_at_header: TargetHeaderIdOf<Self::MessageLane>,
proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -144,10 +150,14 @@ pub struct SubstrateMessageLaneToSubstrate<
pub source_client: Client<Source>,
/// Parameters required to sign transactions for source chain.
pub source_sign: SourceSignParams,
/// Source transactions mortality.
pub source_transactions_mortality: Option<u32>,
/// Client for the target Substrate chain.
pub target_client: Client<Target>,
/// Parameters required to sign transactions for target chain.
pub target_sign: TargetSignParams,
/// Target transactions mortality.
pub target_transactions_mortality: Option<u32>,
/// Account id of relayer at the source chain.
pub relayer_id_at_source: Source::AccountId,
}
@@ -159,8 +169,10 @@ impl<Source: Chain, SourceSignParams: Clone, Target: Chain, TargetSignParams: Cl
Self {
source_client: self.source_client.clone(),
source_sign: self.source_sign.clone(),
source_transactions_mortality: self.source_transactions_mortality,
target_client: self.target_client.clone(),
target_sign: self.target_sign.clone(),
target_transactions_mortality: self.target_transactions_mortality,
relayer_id_at_source: self.relayer_id_at_source.clone(),
}
}
@@ -245,8 +245,9 @@ where
self.client
.submit_signed_extrinsic(
self.lane.source_transactions_author(),
move |_, transaction_nonce| {
move |best_block_id, transaction_nonce| {
lane.make_messages_receiving_proof_transaction(
best_block_id,
transaction_nonce,
generated_at_block,
proof,
@@ -268,6 +269,7 @@ where
) -> <P::MessageLane as MessageLane>::SourceChainBalance {
self.client
.estimate_extrinsic_fee(self.lane.make_messages_receiving_proof_transaction(
HeaderId(Default::default(), Default::default()),
Zero::zero(),
HeaderId(Default::default(), Default::default()),
prepare_dummy_messages_delivery_proof::<P::SourceChain, P::TargetChain>(),
@@ -227,8 +227,9 @@ where
self.client
.submit_signed_extrinsic(
self.lane.target_transactions_author(),
move |_, transaction_nonce| {
move |best_block_id, transaction_nonce| {
lane.make_messages_delivery_transaction(
best_block_id,
transaction_nonce,
generated_at_header,
nonces_clone,
@@ -264,6 +265,7 @@ where
// Prepare 'dummy' delivery transaction - we only care about its length and dispatch weight.
let delivery_tx = self.lane.make_messages_delivery_transaction(
HeaderId(Default::default(), Default::default()),
Zero::zero(),
HeaderId(Default::default(), Default::default()),
nonces.clone(),
@@ -299,6 +301,7 @@ where
let larger_delivery_tx_fee = self
.client
.estimate_extrinsic_fee(self.lane.make_messages_delivery_transaction(
HeaderId(Default::default(), Default::default()),
Zero::zero(),
HeaderId(Default::default(), Default::default()),
nonces.clone(),
@@ -473,6 +476,7 @@ mod tests {
fn make_messages_receiving_proof_transaction(
&self,
_best_block_id: SourceHeaderIdOf<Self::MessageLane>,
_transaction_nonce: IndexOf<Rococo>,
_generated_at_block: TargetHeaderIdOf<Self::MessageLane>,
_proof: <Self::MessageLane as MessageLane>::MessagesReceivingProof,
@@ -486,6 +490,7 @@ mod tests {
fn make_messages_delivery_transaction(
&self,
_best_block_id: TargetHeaderIdOf<Self::MessageLane>,
_transaction_nonce: IndexOf<Wococo>,
_generated_at_header: SourceHeaderIdOf<Self::MessageLane>,
_nonces: RangeInclusive<MessageNonce>,
@@ -38,9 +38,9 @@ use relay_utils::{
use crate::{
finality_pipeline::{
SubstrateFinalitySyncPipeline, SubstrateFinalityToSubstrate, RECENT_FINALITY_PROOFS_LIMIT,
STALL_TIMEOUT,
},
finality_target::SubstrateFinalityTarget,
STALL_TIMEOUT,
};
/// On-demand Substrate <-> Substrate headers relay.