Skip to content

Commit

Permalink
Add tool for auto generating runtime code from metadata (paritytech#1812
Browse files Browse the repository at this point in the history
)

* Create CLI tool for generating indirect runtimes code

* Use the generated runtime for rialto parachain

* Avoid autogenerated files when executing cargo spellcheck

* Fix clippy warning
  • Loading branch information
serban300 committed Apr 10, 2024
1 parent 1568eab commit 1ad4c4a
Show file tree
Hide file tree
Showing 11 changed files with 9,866 additions and 79 deletions.
2 changes: 1 addition & 1 deletion bridges/primitives/chain-millau/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fixed-hash = { version = "0.8.0", default-features = false }
hash256-std-hasher = { version = "0.15.2", default-features = false }
impl-codec = { version = "0.6", default-features = false }
impl-serde = { version = "0.4.0", optional = true }
parity-util-mem = { version = "0.12", default-features = false, features = ["primitive-types"] }
parity-util-mem = { version = "0.11.0", default-features = false, features = ["primitive-types"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/polkadot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
parity-util-mem = { version = "0.12.0", optional = true }
parity-util-mem = { version = "0.11.0", optional = true }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["derive"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use substrate_relay_helper::finality::{
substrate_relay_helper::generate_submit_finality_proof_call_builder!(
MillauFinalityToRialtoParachain,
MillauFinalityToRialtoParachainCallBuilder,
relay_rialto_parachain_client::runtime::Call::BridgeMillauGrandpa,
relay_rialto_parachain_client::runtime::BridgeMillauGrandpaCall::submit_finality_proof
relay_rialto_parachain_client::RuntimeCall::BridgeMillauGrandpa,
relay_rialto_parachain_client::BridgeGrandpaCall::submit_finality_proof
);

/// Description of Millau -> Rialto finalized headers bridge.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use substrate_relay_helper::messages_lane::{
substrate_relay_helper::generate_receive_message_proof_call_builder!(
MillauMessagesToRialtoParachain,
MillauMessagesToRialtoParachainReceiveMessagesProofCallBuilder,
relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_proof
relay_rialto_parachain_client::RuntimeCall::BridgeMillauMessages,
relay_rialto_parachain_client::BridgeMessagesCall::receive_messages_proof
);

/// Description of Millau -> RialtoParachain messages bridge.
Expand Down
12 changes: 9 additions & 3 deletions bridges/relays/bin-substrate/src/chains/rialto_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use bridge_runtime_common::CustomNetworkId;
use relay_rialto_parachain_client::RialtoParachain;
use relay_substrate_client::{calls::XcmCall, SimpleRuntimeVersion};
use relay_substrate_client::SimpleRuntimeVersion;
use xcm::latest::prelude::*;

impl CliEncodeMessage for RialtoParachain {
fn encode_send_xcm(
message: xcm::VersionedXcm<()>,
bridge_instance_index: u8,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
type RuntimeCall = relay_rialto_parachain_client::RuntimeCall;
type XcmCall = relay_rialto_parachain_client::runtime_types::pallet_xcm::pallet::Call;

let dest = match bridge_instance_index {
bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX =>
(Parent, X1(GlobalConsensus(CustomNetworkId::Millau.as_network_id()))),
Expand All @@ -37,9 +40,12 @@ impl CliEncodeMessage for RialtoParachain {
),
};

let xcm_call = XcmCall::send(Box::new(dest.into()), Box::new(message));
let xcm_call = XcmCall::send {
dest: Box::new(unsafe { std::mem::transmute(xcm::VersionedMultiLocation::from(dest)) }),
message: Box::new(unsafe { std::mem::transmute(message) }),
};

Ok(relay_rialto_parachain_client::runtime::Call::PolkadotXcm(xcm_call).into())
Ok(RuntimeCall::PolkadotXcm(xcm_call).into())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use substrate_relay_helper::{
substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
RialtoParachainMessagesToMillau,
RialtoParachainMessagesToMillauReceiveMessagesDeliveryProofCallBuilder,
relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_delivery_proof
relay_rialto_parachain_client::RuntimeCall::BridgeMillauMessages,
relay_rialto_parachain_client::BridgeMessagesCall::receive_messages_delivery_proof
);

/// Description of RialtoParachain -> Millau messages bridge.
Expand Down
14 changes: 7 additions & 7 deletions bridges/relays/bin-substrate/src/cli/init_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
cli::{bridge::CliBridgeBase, chain_schema::*},
};
use bp_runtime::Chain as ChainBase;
use relay_substrate_client::{calls::SudoCall, AccountKeyPairOf, Chain, UnsignedTransaction};
use relay_substrate_client::{AccountKeyPairOf, Chain, UnsignedTransaction};
use sp_core::Pair;
use structopt::StructOpt;
use strum::{EnumString, EnumVariantNames, VariantNames};
Expand Down Expand Up @@ -123,14 +123,14 @@ impl BridgeInitializer for MillauToRialtoParachainCliBridge {
fn encode_init_bridge(
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
) -> <Self::Target as Chain>::Call {
use relay_rialto_parachain_client::runtime;
type RuntimeCall = relay_rialto_parachain_client::RuntimeCall;
type BridgeGrandpaCall = relay_rialto_parachain_client::BridgeGrandpaCall;
type SudoCall = relay_rialto_parachain_client::SudoCall;

let initialize_call =
runtime::Call::BridgeMillauGrandpa(runtime::BridgeMillauGrandpaCall::initialize {
init_data,
});
let sudo_call = SudoCall::sudo(Box::new(initialize_call));
runtime::Call::Sudo(sudo_call)
RuntimeCall::BridgeMillauGrandpa(BridgeGrandpaCall::initialize { init_data });

RuntimeCall::Sudo(SudoCall::sudo { call: Box::new(initialize_call) })
}
}

Expand Down
2 changes: 2 additions & 0 deletions bridges/relays/client-rialto-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5" }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
subxt = { git = "https://github.com/paritytech/subxt", branch = "master" }

# Bridge dependencies

Expand All @@ -24,3 +25,4 @@ relay-substrate-client = { path = "../client-substrate" }

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-weights = { git = "https://github.com/paritytech/substrate", branch = "master" }
Loading

0 comments on commit 1ad4c4a

Please sign in to comment.