;
}
/// Building `submit_finality_proof` call when you have direct access to the target
/// chain runtime.
pub struct DirectSubmitFinalityProofCallBuilder {
_phantom: PhantomData<(P, R, I)>,
}
impl
SubmitFinalityProofCallBuilder
for DirectSubmitFinalityProofCallBuilder
where
P: SubstrateFinalitySyncPipeline,
R: BridgeGrandpaConfig,
I: 'static,
R::BridgedChain: bp_runtime::Chain>,
CallOf: From>,
{
fn build_submit_finality_proof_call(
header: SyncHeader>,
proof: GrandpaJustification>,
) -> CallOf {
BridgeGrandpaCall::::submit_finality_proof {
finality_target: Box::new(header.into_inner()),
justification: proof,
}
.into()
}
}
/// Macro that generates `SubmitFinalityProofCallBuilder` implementation for the case when
/// you only have an access to the mocked version of target chain runtime. In this case you
/// should provide "name" of the call variant for the bridge GRANDPA calls and the "name" of
/// the variant for the `submit_finality_proof` call within that first option.
#[rustfmt::skip]
#[macro_export]
macro_rules! generate_mocked_submit_finality_proof_call_builder {
($pipeline:ident, $mocked_builder:ident, $bridge_grandpa:path, $submit_finality_proof:path) => {
pub struct $mocked_builder;
impl $crate::finality_pipeline::SubmitFinalityProofCallBuilder<$pipeline>
for $mocked_builder
{
fn build_submit_finality_proof_call(
header: relay_substrate_client::SyncHeader<
relay_substrate_client::HeaderOf<
<$pipeline as $crate::finality_pipeline::SubstrateFinalitySyncPipeline>::SourceChain
>
>,
proof: bp_header_chain::justification::GrandpaJustification<
relay_substrate_client::HeaderOf<
<$pipeline as $crate::finality_pipeline::SubstrateFinalitySyncPipeline>::SourceChain
>
>,
) -> relay_substrate_client::CallOf<
<$pipeline as $crate::finality_pipeline::SubstrateFinalitySyncPipeline>::TargetChain
> {
$bridge_grandpa($submit_finality_proof(Box::new(header.into_inner()), proof))
}
}
};
}
/// Run Substrate-to-Substrate finality sync loop.
pub async fn run(
source_client: Client,
target_client: Client,
only_mandatory_headers: bool,
transaction_params: TransactionParams>,
metrics_params: MetricsParams,
) -> anyhow::Result<()>
where
AccountIdOf: From< as Pair>::Public>,
P::TransactionSignScheme: TransactionSignScheme,
{
log::info!(
target: "bridge",
"Starting {} -> {} finality proof relay",
P::SourceChain::NAME,
P::TargetChain::NAME,
);
finality_relay::run(
SubstrateFinalitySource::::new(source_client, None),
SubstrateFinalityTarget::
::new(target_client, transaction_params.clone()),
finality_relay::FinalitySyncParams {
tick: std::cmp::max(
P::SourceChain::AVERAGE_BLOCK_INTERVAL,
P::TargetChain::AVERAGE_BLOCK_INTERVAL,
),
recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT,
stall_timeout: transaction_stall_timeout(
transaction_params.mortality,
P::TargetChain::AVERAGE_BLOCK_INTERVAL,
crate::STALL_TIMEOUT,
),
only_mandatory_headers,
},
metrics_params,
futures::future::pending(),
)
.await
.map_err(|e| anyhow::format_err!("{}", e))
}