Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridges - add version guarding for standalone relaying of parachains and messages #5952

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions bridges/relays/lib-substrate-relay/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use rbtag::BuildInfo;
use sp_runtime::traits::TryConvert;
use std::str::FromStr;
use structopt::StructOpt;
use strum::{EnumString, VariantNames};

pub mod bridge;
pub mod chain_schema;
Expand Down Expand Up @@ -139,17 +138,6 @@ where
}
}

#[doc = "Runtime version params."]
#[derive(StructOpt, Debug, PartialEq, Eq, Clone, Copy, EnumString, VariantNames)]
pub enum RuntimeVersionType {
/// Auto query version from chain
Auto,
/// Custom `spec_version` and `transaction_version`
Custom,
/// Read version from bundle dependencies directly.
Bundle,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub trait HeadersRelayer: RelayToRelayHeadersCliBridge {
signer: target_sign,
mortality: target_transactions_mortality,
};

Self::Finality::start_relay_guards(&target_client, target_client.can_start_version_guard())
.await?;

Expand Down
16 changes: 16 additions & 0 deletions bridges/relays/lib-substrate-relay/src/cli/relay_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ where
anyhow::format_err!("Invalid laneId: {:?}!", invalid_lane_id)
})?;

Self::start_relay_guards(&target_client, target_client.can_start_version_guard()).await?;

crate::messages::run::<Self::MessagesLane, _, _>(MessagesRelayParams {
source_client,
source_transaction_params: TransactionParams {
Expand Down Expand Up @@ -216,4 +218,18 @@ where
)
.await
}

/// Add relay guards if required.
async fn start_relay_guards(
target_client: &impl Client<Self::Target>,
enable_version_guard: bool,
) -> relay_substrate_client::Result<()> {
if enable_version_guard {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the enable_version_guard: bool and move the if outside of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it could be all simplified, I have TODO for that here: #5923,
we have three copies of this exact function

relay_substrate_client::guard::abort_on_spec_version_change(
target_client.clone(),
target_client.simple_runtime_version().await?.spec_version,
);
}
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::{
chain_schema::*,
DefaultClient, PrometheusParams,
},
finality::SubstrateFinalitySyncPipeline,
parachains::{source::ParachainsSource, target::ParachainsTarget, ParachainsPipelineAdapter},
TransactionParams,
};
Expand Down Expand Up @@ -104,6 +105,9 @@ where
data.prometheus_params.into_metrics_params()?;
GlobalMetrics::new()?.register_and_spawn(&metrics_params.registry)?;

Self::RelayFinality::start_relay_guards(target_client.target_client(), target_client.target_client().can_start_version_guard())
.await?;

parachains_relay::parachains_loop::run(
source_client,
target_client,
Expand Down
8 changes: 8 additions & 0 deletions bridges/relays/parachains/src/parachains_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ pub async fn run<P: ParachainsPipeline>(
where
P::SourceRelayChain: Chain<BlockNumber = RelayBlockNumber>,
{
log::info!(
target: "bridge",
"Starting {} -> {} finality proof relay: relaying (only_free_headers: {:?}) headers",
P::SourceParachain::NAME,
P::TargetChain::NAME,
only_free_headers,
);

let exit_signal = exit_signal.shared();
relay_utils::relay_loop(source_client, target_client)
.with_metrics(metrics_params)
Expand Down
Loading