mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 17:31:03 +00:00
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:
committed by
Bastian Köcher
parent
8b52cd2593
commit
864c830618
@@ -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,
|
||||
|
||||
@@ -30,12 +30,17 @@ use relay_utils::relay_loop::Client as RelayClient;
|
||||
pub struct SubstrateFinalityTarget<C: Chain, P> {
|
||||
client: Client<C>,
|
||||
pipeline: P,
|
||||
transactions_mortality: Option<u32>,
|
||||
}
|
||||
|
||||
impl<C: Chain, P> SubstrateFinalityTarget<C, P> {
|
||||
/// Create new Substrate headers target.
|
||||
pub fn new(client: Client<C>, pipeline: P) -> Self {
|
||||
SubstrateFinalityTarget { client, pipeline }
|
||||
pub fn new(client: Client<C>, pipeline: P, transactions_mortality: Option<u32>) -> Self {
|
||||
SubstrateFinalityTarget {
|
||||
client,
|
||||
pipeline,
|
||||
transactions_mortality,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +49,7 @@ impl<C: Chain, P: SubstrateFinalitySyncPipeline> Clone for SubstrateFinalityTarg
|
||||
SubstrateFinalityTarget {
|
||||
client: self.client.clone(),
|
||||
pipeline: self.pipeline.clone(),
|
||||
transactions_mortality: self.transactions_mortality,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,9 +95,19 @@ where
|
||||
) -> Result<(), SubstrateError> {
|
||||
let transactions_author = self.pipeline.transactions_author();
|
||||
let pipeline = self.pipeline.clone();
|
||||
let transactions_mortality = self.transactions_mortality;
|
||||
self.client
|
||||
.submit_signed_extrinsic(transactions_author, move |transaction_nonce| {
|
||||
pipeline.make_submit_finality_proof_transaction(transaction_nonce, header, proof)
|
||||
.submit_signed_extrinsic(transactions_author, 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,
|
||||
transactions_mortality,
|
||||
),
|
||||
transaction_nonce,
|
||||
header,
|
||||
proof,
|
||||
)
|
||||
})
|
||||
.await
|
||||
.map(drop)
|
||||
|
||||
@@ -88,7 +88,7 @@ async fn do_initialize<SourceChain: Chain, TargetChain: Chain>(
|
||||
);
|
||||
|
||||
let initialization_tx_hash = target_client
|
||||
.submit_signed_extrinsic(target_transactions_signer, move |transaction_nonce| {
|
||||
.submit_signed_extrinsic(target_transactions_signer, move |_, transaction_nonce| {
|
||||
prepare_initialize_transaction(transaction_nonce, initialization_data)
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -246,7 +246,7 @@ where
|
||||
) -> Result<(), SubstrateError> {
|
||||
let lane = self.lane.clone();
|
||||
self.client
|
||||
.submit_signed_extrinsic(self.lane.source_transactions_author(), move |transaction_nonce| {
|
||||
.submit_signed_extrinsic(self.lane.source_transactions_author(), move |_, transaction_nonce| {
|
||||
lane.make_messages_receiving_proof_transaction(transaction_nonce, generated_at_block, proof)
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -229,7 +229,7 @@ where
|
||||
let lane = self.lane.clone();
|
||||
let nonces_clone = nonces.clone();
|
||||
self.client
|
||||
.submit_signed_extrinsic(self.lane.target_transactions_author(), move |transaction_nonce| {
|
||||
.submit_signed_extrinsic(self.lane.target_transactions_author(), move |_, transaction_nonce| {
|
||||
lane.make_messages_delivery_transaction(transaction_nonce, generated_at_header, nonces_clone, proof)
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -56,6 +56,7 @@ impl<SourceChain: Chain> OnDemandHeadersRelay<SourceChain> {
|
||||
pub fn new<TargetChain: Chain, TargetSign, P>(
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
target_transactions_mortality: Option<u32>,
|
||||
pipeline: P,
|
||||
maximal_headers_difference: SourceChain::BlockNumber,
|
||||
) -> Self
|
||||
@@ -79,6 +80,7 @@ impl<SourceChain: Chain> OnDemandHeadersRelay<SourceChain> {
|
||||
background_task(
|
||||
source_client,
|
||||
target_client,
|
||||
target_transactions_mortality,
|
||||
pipeline,
|
||||
maximal_headers_difference,
|
||||
required_header_number,
|
||||
@@ -110,7 +112,7 @@ impl<SourceChain: Chain> OnDemandHeadersRelay<SourceChain> {
|
||||
async fn background_task<SourceChain, TargetChain, TargetSign, P>(
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
// pipeline: SubstrateFinalityToSubstrate<SourceChain, TargetChain, TargetSign>,
|
||||
target_transactions_mortality: Option<u32>,
|
||||
pipeline: P,
|
||||
maximal_headers_difference: SourceChain::BlockNumber,
|
||||
required_header_number: RequiredHeaderNumberRef<SourceChain>,
|
||||
@@ -130,7 +132,8 @@ async fn background_task<SourceChain, TargetChain, TargetSign, P>(
|
||||
_,
|
||||
SubstrateFinalityToSubstrate<SourceChain, TargetChain, TargetSign>,
|
||||
>::new(source_client.clone(), Some(required_header_number.clone()));
|
||||
let mut finality_target = SubstrateFinalityTarget::new(target_client.clone(), pipeline.clone());
|
||||
let mut finality_target =
|
||||
SubstrateFinalityTarget::new(target_client.clone(), pipeline.clone(), target_transactions_mortality);
|
||||
let mut latest_non_mandatory_at_source = Zero::zero();
|
||||
|
||||
let mut restart_relay = true;
|
||||
|
||||
Reference in New Issue
Block a user