Skip to content

Follow-up on #1518#1546

Merged
svyatonik merged 5 commits into
paritytech:masterfrom
serban300:refactoring
Aug 12, 2022
Merged

Follow-up on #1518#1546
svyatonik merged 5 commits into
paritytech:masterfrom
serban300:refactoring

Conversation

@serban300
Copy link
Copy Markdown
Collaborator

Addressing the comments in #1518

The last commit is something that we didn't discuss in the comments, but it seemed like a good idea. It felt easier to me to work with the CustomNetworkId. I can drop it if it doesn't make sense.

Signed-off-by: Serban Iorga <serban@parity.io>
Signed-off-by: Serban Iorga <serban@parity.io>
Signed-off-by: Serban Iorga <serban@parity.io>
Right now we use some associations between Rialto, RialtoParachain and
Millau chains and chains defined in the NetworkId enum. But if we are
not carreful we might do mistakes like:
In Millau:
pub const ThisNetwork: NetworkId = Kusama;
pub const RialtoNetwork: NetworkId = Polkadot;
In Rialto:
pub const ThisNetwork: NetworkId = Kusama;
pub const MillauNetwork: NetworkId = Polkadot;

We're introducing CustomNetworkId to have a centralized mapping between
NetworkId chains and our custom chains.

Signed-off-by: Serban Iorga <serban@parity.io>
@serban300 serban300 requested a review from svyatonik August 11, 2022 14:06
@serban300 serban300 self-assigned this Aug 11, 2022
Comment thread bin/runtime-common/src/messages.rs Outdated
/// Our location within the Consensus Universe.
fn universal_location() -> InteriorMultiLocation;
/// Build absolute route to the XCM destination.
fn absolute_destination() -> MultiLocation;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wouldn't add this function, because this code will be (I hope) used in the Rococo/Wococo/Kusama/Polkadot bridge hubs and (again - that' how I understand that) we'll be able to send XCM message from e.g. some Kusama parachain (Westmine) to other Polkadot parachain (e.g. Westmint). So the final destination isn't always the other side of the bridge - it may be any destination, which is routed by this router (verify_destination)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I can remove if it doesn't make sense. But I'm not sure if I understand what this scenario would suppose. So I have a couple of questions.

I added this function to deduplicate some code in verify_destination() and encode_send_xcm() (maybe absolute_destination() is not the right name also). For example

impl XcmBridge for ToRialtoParachainBridge {
        ...
	fn verify_destination(dest: &MultiLocation) -> bool {
		matches!(*dest, MultiLocation { parents: 1, interior: X2(GlobalConsensus(r), Parachain(RIALTO_PARACHAIN_ID)) } if r == RialtoNetwork::get())
	}
        ...
}

vs

impl CliEncodeMessage for Millau {
	fn encode_send_xcm(
		message: xcm::VersionedXcm<()>,
		bridge_instance_index: u8,
	) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
		let dest = match bridge_instance_index {
			...
			bridge::MILLAU_TO_RIALTO_PARACHAIN_INDEX => (
				Parent,
				X2(
					GlobalConsensus(millau_runtime::xcm_config::RialtoNetwork::get()),
					Parachain(RIALTO_PARACHAIN_ID),
				),
			),
			...
		};

		...
	}
       ...
}

How will these 2 pieces of code look like in the scenario that you mentioned ? Will there be any resemblance between them ? Or anything that we could reuse ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The idea (again - that's my impression in how bridge would work) is that we need to build bridge between two bridge hubs, e.g. KusamaBridgeHub and PolkadotBridgeHub and then all Polkadot parachains will be able to "talk" to all Kusama parachains. So destination may be e.g. MultiLocation { parents: 1, interior: X2(GlobalConsensus(r), Parachain(WESTMINT_PARACHAIN_ID)) instead of MultiLocation { parents: 1, interior: X2(GlobalConsensus(r), Parachain(RIALTO_PARACHAIN_ID)) and still the message will be sent through the bridge and reach RIALTO_PARACHAIN_ID first. In some extreme cases we may even talk to other top-level chains using our bridge - e.g. (just an imaginary example, don't take it as a real world example) - we may bridge Bitcoin with Polkadot and Kusama with Ethereum. Then we may be able to send XCM messages from Bitcoin to Ethereum using Kusama <> Polkadot bridge.

TLDR: there's no single XCM destination for the bridge

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you want to keep it, then, please, change fn absolute_destination documentation, so that it states that it will return XCM destination of the other side of the bridge + probably change the function/name/documentation of the verify_absolute_destination method - it may handle any destinations, not only destinations "covered" by what the "absolute_destination" returns. It shall work :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh ok, I think I understood. And in this case verify_destination() will become:

matches!(*dest, MultiLocation { parents: 1, interior: X2(GlobalConsensus(r), Parachain(_)) } if r == RialtoNetwork::get())

while encode_send_xcm() will stay the same.

So the code can't be reused. Makes sesnse. I will remove the function.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. I reverted that commit.

Copy link
Copy Markdown
Contributor

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

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

One tiny comment (may be opionated - feel free to ignore), otherwise seems good

@svyatonik svyatonik merged commit 9dbad39 into paritytech:master Aug 12, 2022
@serban300 serban300 mentioned this pull request Aug 12, 2022
5 tasks
jiguantong pushed a commit to darwinia-network/darwinia-messages-substrate that referenced this pull request Apr 13, 2023
serban300 added a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
* Adjustments for the xcm messages sending logic

Signed-off-by: Serban Iorga <serban@parity.io>

* Deduplicate XCM destination

Signed-off-by: Serban Iorga <serban@parity.io>

* [send_message] small changes

Signed-off-by: Serban Iorga <serban@parity.io>

* Define CustomNetworkId

Right now we use some associations between Rialto, RialtoParachain and
Millau chains and chains defined in the NetworkId enum. But if we are
not carreful we might do mistakes like:
In Millau:
pub const ThisNetwork: NetworkId = Kusama;
pub const RialtoNetwork: NetworkId = Polkadot;
In Rialto:
pub const ThisNetwork: NetworkId = Kusama;
pub const MillauNetwork: NetworkId = Polkadot;

We're introducing CustomNetworkId to have a centralized mapping between
NetworkId chains and our custom chains.

Signed-off-by: Serban Iorga <serban@parity.io>

* Revert "Deduplicate XCM destination"

This reverts commit 3a0a950.

Signed-off-by: Serban Iorga <serban@parity.io>
serban300 added a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
* Adjustments for the xcm messages sending logic

Signed-off-by: Serban Iorga <serban@parity.io>

* Deduplicate XCM destination

Signed-off-by: Serban Iorga <serban@parity.io>

* [send_message] small changes

Signed-off-by: Serban Iorga <serban@parity.io>

* Define CustomNetworkId

Right now we use some associations between Rialto, RialtoParachain and
Millau chains and chains defined in the NetworkId enum. But if we are
not carreful we might do mistakes like:
In Millau:
pub const ThisNetwork: NetworkId = Kusama;
pub const RialtoNetwork: NetworkId = Polkadot;
In Rialto:
pub const ThisNetwork: NetworkId = Kusama;
pub const MillauNetwork: NetworkId = Polkadot;

We're introducing CustomNetworkId to have a centralized mapping between
NetworkId chains and our custom chains.

Signed-off-by: Serban Iorga <serban@parity.io>

* Revert "Deduplicate XCM destination"

This reverts commit 3a0a950.

Signed-off-by: Serban Iorga <serban@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants