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

dry-run mode for init bridge command #1690

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion primitives/messages/src/target_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub trait MessageDispatch<AccountId> {
type DispatchPayload: Decode;

/// Fine-grained result of single message dispatch (for better diagnostic purposes)
type DispatchLevelResult: Clone + Decode + sp_std::fmt::Debug + Eq;
type DispatchLevelResult: Clone + sp_std::fmt::Debug + Eq;

/// Estimate dispatch weight.
///
Expand Down
17 changes: 13 additions & 4 deletions relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

use async_trait::async_trait;
use codec::Encode;

use crate::{
chains::{
Expand Down Expand Up @@ -46,6 +47,9 @@ pub struct InitBridge {
target: TargetConnectionParams,
#[structopt(flatten)]
target_sign: TargetSigningParams,
/// Generates all required data, but does not submit extrinsic
#[structopt(long)]
dry_run: bool,
}

#[derive(Debug, EnumString, EnumVariantNames)]
Expand Down Expand Up @@ -77,6 +81,7 @@ where
let source_client = data.source.into_client::<Self::Source>().await?;
let target_client = data.target.into_client::<Self::Target>().await?;
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
let dry_run = data.dry_run;

let (spec_version, transaction_version) = target_client.simple_runtime_version().await?;
substrate_relay_helper::finality::initialize::initialize::<Self::Engine, _, _, _>(
Expand All @@ -90,11 +95,15 @@ where
signer: target_sign,
},
move |transaction_nonce, initialization_data| {
Ok(UnsignedTransaction::new(
Self::encode_init_bridge(initialization_data).into(),
transaction_nonce,
))
let call = Self::encode_init_bridge(initialization_data);
log::info!(
target: "bridge",
"Initialize bridge call encoded as hex string: {:?}",
format!("0x{}", hex::encode(&call.encode()))
);
Ok(UnsignedTransaction::new(call.into(), transaction_nonce))
},
dry_run,
)
.await;

Expand Down
16 changes: 14 additions & 2 deletions relays/lib-substrate-relay/src/finality/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub async fn initialize<
target_transactions_signer: TargetChain::AccountId,
target_signing_data: SignParam<TargetChain>,
prepare_initialize_transaction: F,
dry_run: bool,
) where
F: FnOnce(
TargetChain::Index,
Expand All @@ -54,6 +55,7 @@ pub async fn initialize<
target_transactions_signer,
target_signing_data,
prepare_initialize_transaction,
dry_run,
)
.await;

Expand Down Expand Up @@ -88,6 +90,7 @@ async fn do_initialize<
target_transactions_signer: TargetChain::AccountId,
target_signing_data: SignParam<TargetChain>,
prepare_initialize_transaction: F,
dry_run: bool,
) -> Result<
Option<TargetChain::Hash>,
Error<SourceChain::Hash, <SourceChain::Header as HeaderT>::Number>,
Expand All @@ -110,7 +113,9 @@ where
SourceChain::NAME,
TargetChain::NAME,
);
return Ok(None)
if !dry_run {
return Ok(None)
}
}

let initialization_data = E::prepare_initialization_data(source_client).await?;
Expand All @@ -127,7 +132,14 @@ where
target_transactions_signer,
target_signing_data,
move |_, transaction_nonce| {
prepare_initialize_transaction(transaction_nonce, initialization_data)
let tx = prepare_initialize_transaction(transaction_nonce, initialization_data);
if dry_run {
Err(SubstrateError::Custom(format!(
"Not submitting extrinsic in `dry-run` mode!"
)))
} else {
tx
}
},
)
.await
Expand Down