Emit mortal transactions from relay (#1073)

* mortal relay transactions

* sign block hash for mortal transactions

* TransactionEraOf

* add explanation

* enable mortal transactions for Westend -> Millau headers relay

* clippy

* spellcheck
This commit is contained in:
Svyatoslav Nikolsky
2021-09-02 10:55:57 +03:00
committed by Bastian Köcher
parent 8b52cd2593
commit 864c830618
33 changed files with 249 additions and 73 deletions
@@ -25,8 +25,14 @@ use relay_utils::{metrics::MetricsParams, BlockNumberBase};
use sp_core::Bytes;
use std::{fmt::Debug, marker::PhantomData, time::Duration};
/// Default synchronization loop timeout.
pub(crate) const STALL_TIMEOUT: Duration = Duration::from_secs(120);
/// 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 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
@@ -62,6 +68,7 @@ pub trait SubstrateFinalitySyncPipeline: 'static + Clone + Debug + Send + Sync {
/// Make submit header transaction.
fn make_submit_finality_proof_transaction(
&self,
era: bp_runtime::TransactionEraOf<Self::TargetChain>,
transaction_nonce: <Self::TargetChain as Chain>::Index,
header: <Self::FinalitySyncPipeline as FinalitySyncPipeline>::Header,
proof: <Self::FinalitySyncPipeline as FinalitySyncPipeline>::FinalityProof,
@@ -123,6 +130,7 @@ pub async fn run<SourceChain, TargetChain, P>(
source_client: Client<SourceChain>,
target_client: Client<TargetChain>,
only_mandatory_headers: bool,
transactions_mortality: Option<u32>,
metrics_params: MetricsParams,
) -> anyhow::Result<()>
where
@@ -146,11 +154,15 @@ where
finality_relay::run(
FinalitySource::new(source_client, None),
SubstrateFinalityTarget::new(target_client, pipeline),
SubstrateFinalityTarget::new(target_client, pipeline, transactions_mortality),
FinalitySyncParams {
tick: std::cmp::max(SourceChain::AVERAGE_BLOCK_INTERVAL, TargetChain::AVERAGE_BLOCK_INTERVAL),
recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT,
stall_timeout: STALL_TIMEOUT,
stall_timeout: relay_substrate_client::transaction_stall_timeout(
transactions_mortality,
TargetChain::AVERAGE_BLOCK_INTERVAL,
)
.unwrap_or(STALL_TIMEOUT),
only_mandatory_headers,
},
metrics_params,