Skip to content

Commit

Permalink
Fix sized messages (Follow-up on #2064) (#2103)
Browse files Browse the repository at this point in the history
* Use wasm execution on millau and rialto

It's safer like this since here are some errors that aren't caught when
using native execution

* Revert "Revert "Fix max-size messages at test chains (#2064)" (#2077)"

This reverts commit 8c8adaf.

* Adjustments
  • Loading branch information
serban300 authored May 3, 2023
1 parent 54f587a commit 557ecbc
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 45 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,21 @@ pub enum CustomNetworkId {
RialtoParachain,
}

impl TryFrom<bp_runtime::ChainId> for CustomNetworkId {
type Error = ();

fn try_from(chain: bp_runtime::ChainId) -> Result<Self, Self::Error> {
Ok(match chain {
bp_runtime::MILLAU_CHAIN_ID => Self::Millau,
bp_runtime::RIALTO_CHAIN_ID => Self::Rialto,
bp_runtime::RIALTO_PARACHAIN_CHAIN_ID => Self::RialtoParachain,
_ => return Err(()),
})
}
}

impl CustomNetworkId {
/// Converts self to XCM' network id.
pub const fn as_network_id(&self) -> NetworkId {
match *self {
CustomNetworkId::Millau => NetworkId::Kusama,
Expand Down
5 changes: 0 additions & 5 deletions deployments/networks/millau.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ services:
image: ${MILLAU_BRIDGE_NODE_IMAGE:-paritytech/millau-bridge-node}
entrypoint:
- /home/user/millau-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/millau-node-bob/tcp/30333/p2p/12D3KooWM5LFR5ne4yTQ4sBSXJ75M4bDo2MAhAW2GhL3i8fe5aRb
- --alice
Expand All @@ -32,7 +31,6 @@ services:
<<: *millau-bridge-node
entrypoint:
- /home/user/millau-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/millau-node-alice/tcp/30333/p2p/12D3KooWFqiV73ipQ1jpfVmCfLqBCp8G9PLH3zPkY9EhmdrSGA4H
- --bob
Expand All @@ -51,7 +49,6 @@ services:
<<: *millau-bridge-node
entrypoint:
- /home/user/millau-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/millau-node-alice/tcp/30333/p2p/12D3KooWFqiV73ipQ1jpfVmCfLqBCp8G9PLH3zPkY9EhmdrSGA4H
- --charlie
Expand All @@ -69,7 +66,6 @@ services:
<<: *millau-bridge-node
entrypoint:
- /home/user/millau-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/millau-node-alice/tcp/30333/p2p/12D3KooWFqiV73ipQ1jpfVmCfLqBCp8G9PLH3zPkY9EhmdrSGA4H
- --dave
Expand All @@ -87,7 +83,6 @@ services:
<<: *millau-bridge-node
entrypoint:
- /home/user/millau-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/millau-node-alice/tcp/30333/p2p/12D3KooWFqiV73ipQ1jpfVmCfLqBCp8G9PLH3zPkY9EhmdrSGA4H
- --eve
Expand Down
6 changes: 0 additions & 6 deletions deployments/networks/rialto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ services:
image: ${RIALTO_BRIDGE_NODE_IMAGE:-paritytech/rialto-bridge-node}
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/rialto-node-bob/tcp/30333/p2p/12D3KooWSEpHJj29HEzgPFcRYVc5X3sEuP3KgiUoqJNCet51NiMX
- --alice
Expand All @@ -32,7 +31,6 @@ services:
<<: *rialto-bridge-node
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/rialto-node-alice/tcp/30333/p2p/12D3KooWMF6JvV319a7kJn5pqkKbhR3fcM2cvK5vCbYZHeQhYzFE
- --bob
Expand All @@ -51,7 +49,6 @@ services:
<<: *rialto-bridge-node
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/rialto-node-alice/tcp/30333/p2p/12D3KooWMF6JvV319a7kJn5pqkKbhR3fcM2cvK5vCbYZHeQhYzFE
- --charlie
Expand All @@ -69,7 +66,6 @@ services:
<<: *rialto-bridge-node
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/rialto-node-alice/tcp/30333/p2p/12D3KooWMF6JvV319a7kJn5pqkKbhR3fcM2cvK5vCbYZHeQhYzFE
- --dave
Expand All @@ -87,7 +83,6 @@ services:
<<: *rialto-bridge-node
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/rialto-node-alice/tcp/30333/p2p/12D3KooWMF6JvV319a7kJn5pqkKbhR3fcM2cvK5vCbYZHeQhYzFE
- --eve
Expand All @@ -105,7 +100,6 @@ services:
<<: *rialto-bridge-node
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
- --chain=local
- --bootnodes=/dns4/rialto-node-alice/tcp/30333/p2p/12D3KooWMF6JvV319a7kJn5pqkKbhR3fcM2cvK5vCbYZHeQhYzFE
- --ferdie
Expand Down
7 changes: 5 additions & 2 deletions relays/bin-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ relay-utils = { path = "../utils" }
relay-westend-client = { path = "../client-westend" }
relay-wococo-client = { path = "../client-wococo" }
rialto-runtime = { path = "../../bin/rialto/runtime" }
# we are not using this runtime to craft callsour transactions, but we still need it
# to prepare large XCM messages
rialto-parachain-runtime = { path = "../../bin/rialto-parachain/runtime" }
substrate-relay-helper = { path = "../lib-substrate-relay" }

# Substrate Dependencies
Expand All @@ -62,8 +65,8 @@ polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch =
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", branch = "master" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }

xcm = { git = "https://github.com/paritytech/polkadot", branch = "master" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "master" }

[dev-dependencies]
bp-test-utils = { path = "../../primitives/test-utils" }
Expand Down
28 changes: 28 additions & 0 deletions relays/bin-substrate/src/chains/millau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,38 @@

use crate::cli::{encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use bridge_runtime_common::CustomNetworkId;
use relay_millau_client::Millau;
use relay_substrate_client::SimpleRuntimeVersion;
use xcm_executor::traits::ExportXcm;

impl CliEncodeMessage for Millau {
fn encode_wire_message(
target: xcm::v3::NetworkId,
at_target_xcm: xcm::v3::Xcm<()>,
) -> anyhow::Result<Vec<u8>> {
anyhow::ensure!(
[
CustomNetworkId::Rialto.as_network_id(),
CustomNetworkId::RialtoParachain.as_network_id()
]
.contains(&target),
anyhow::format_err!("Unsupported target chain: {:?}", target)
);

Ok(millau_runtime::xcm_config::ToRialtoOrRialtoParachainSwitchExporter::validate(
target,
0,
&mut Some(Self::dummy_universal_source()?),
&mut Some(target.into()),
&mut Some(at_target_xcm),
)
.map_err(|e| anyhow::format_err!("Failed to prepare outbound message: {:?}", e))?
.0
.1
.0)
}

fn encode_execute_xcm(
message: xcm::VersionedXcm<Self::Call>,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
Expand Down
23 changes: 23 additions & 0 deletions relays/bin-substrate/src/chains/rialto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,33 @@

use crate::cli::{encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use bridge_runtime_common::CustomNetworkId;
use relay_rialto_client::Rialto;
use relay_substrate_client::SimpleRuntimeVersion;
use xcm_executor::traits::ExportXcm;

impl CliEncodeMessage for Rialto {
fn encode_wire_message(
target: xcm::v3::NetworkId,
at_target_xcm: xcm::v3::Xcm<()>,
) -> anyhow::Result<Vec<u8>> {
anyhow::ensure!(
target == CustomNetworkId::Millau.as_network_id(),
anyhow::format_err!("Unsupported target chain: {:?}", target)
);

Ok(rialto_runtime::millau_messages::ToMillauBlobExporter::validate(
target,
0,
&mut Some(Self::dummy_universal_source()?),
&mut Some(target.into()),
&mut Some(at_target_xcm),
)
.map_err(|e| anyhow::format_err!("Failed to prepare outbound message: {:?}", e))?
.0
.0)
}

fn encode_execute_xcm(
message: xcm::VersionedXcm<Self::Call>,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
Expand Down
23 changes: 23 additions & 0 deletions relays/bin-substrate/src/chains/rialto_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,33 @@

use crate::cli::{encode_message::CliEncodeMessage, CliChain};
use bp_runtime::EncodedOrDecodedCall;
use bridge_runtime_common::CustomNetworkId;
use relay_rialto_parachain_client::RialtoParachain;
use relay_substrate_client::SimpleRuntimeVersion;
use xcm_executor::traits::ExportXcm;

impl CliEncodeMessage for RialtoParachain {
fn encode_wire_message(
target: xcm::v3::NetworkId,
at_target_xcm: xcm::v3::Xcm<()>,
) -> anyhow::Result<Vec<u8>> {
anyhow::ensure!(
target == CustomNetworkId::Millau.as_network_id(),
anyhow::format_err!("Unsupported target chain: {:?}", target)
);

Ok(rialto_parachain_runtime::millau_messages::ToMillauBlobExporter::validate(
target,
0,
&mut Some(Self::dummy_universal_source()?),
&mut Some(target.into()),
&mut Some(at_target_xcm),
)
.map_err(|e| anyhow::format_err!("Failed to prepare outbound message: {:?}", e))?
.0
.0)
}

fn encode_execute_xcm(
message: xcm::VersionedXcm<Self::Call>,
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
Expand Down
Loading

0 comments on commit 557ecbc

Please sign in to comment.