Skip to content

Get dispatch weight from the target chain (when DispatchFeePayment::AtTargetChain is used)#1430

Merged
svyatonik merged 7 commits into
masterfrom
inbound-message-details-runtime-api
Jun 1, 2022
Merged

Get dispatch weight from the target chain (when DispatchFeePayment::AtTargetChain is used)#1430
svyatonik merged 7 commits into
masterfrom
inbound-message-details-runtime-api

Conversation

@svyatonik
Copy link
Copy Markdown
Contributor

@svyatonik svyatonik commented May 31, 2022

closes #1417

  • reintroduce From<SourceChain>InboundLaneApi with inbound_message_details method;
  • implement From<SourceChain>InboundLaneApi in runtimes;
  • use From<SourceChain>InboundLaneApi from relay;
  • tests (where possible :/).

@svyatonik svyatonik marked this pull request as ready for review June 1, 2022 09:46
@svyatonik svyatonik enabled auto-merge (squash) June 1, 2022 10:00
@svyatonik svyatonik merged commit 2fd8d66 into master Jun 1, 2022
@svyatonik svyatonik deleted the inbound-message-details-runtime-api branch June 1, 2022 10:01
Comment on lines +219 to +237
let message_key = bp_messages::storage_keys::message_key(
P::TargetChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
*message_nonce,
);
let message_data: MessageData<BalanceOf<P::SourceChain>> =
self.source_client.storage_value(message_key, Some(id.1)).await?.ok_or_else(
|| {
SubstrateError::Custom(format!(
"Message to {} {:?}/{} is missing from runtime the storage of {} at {:?}",
P::TargetChain::NAME,
self.lane_id,
message_nonce,
P::SourceChain::NAME,
id,
))
},
)?;
let message_payload = message_data.payload;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, this call and extra logic is needed only to access the payload. I was wondering if we could avoid this somehow since TO_CHAIN_MESSAGE_DETAILS_METHOD seems to have access to the payload from the start. For example would it make sense to add the payload as a parameter to the DispatchFeePayment::AtTargetChain option ? I mean redefining the DispatchFeePayment enum as:

pub enum DispatchFeePayment {
	AtSourceChain,
	AtTargetChain(MessagePayload),
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't rather touch this enum, since e.g. in encoded-call messaging it is stored as a part of message payload. The alternative would be to add message payload to the message_details method result. But messages may be large and probably can cause a oom in WASM, if we're calling message_details for some range that includes multiple large messages (and we can't know if it'll oom in advance). So probably better to leave it as is (imo)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sure, it's better to keep it as it is if it's safer. But just one more question:

But messages may be large and probably can cause a oom in WASM, if we're calling message_details for some range that includes multiple large messages (and we can't know if it'll oom in advance)

Than is it possible for WASM to oom when calling the following as well ?

			let refined_messages_encoded = self
				.target_client
				.state_call(
					P::SourceChain::FROM_CHAIN_MESSAGE_DETAILS_METHOD.into(),
					Bytes((self.lane_id, messages_to_refine.values().collect::<Vec<_>>()).encode()),
					None,
				)
				.await?;

Since messages_to_refine contains the payloads.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a valid concern. Then it worth to change FROM_CHAIN_MESSAGE_DETAILS_METHOD runtime API method so that it'll accept single message only. Could you, please, file an issue for that?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sure. Also I'd be happy to assign it to me if that's ok for you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, go on! :) Thank you!

.await?;

make_message_details_map::<P::SourceChain>(
let mut messages = make_message_details_map::<P::SourceChain>(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Would it make sense to have the logic above (the call to TO_CHAIN_MESSAGE_DETAILS_METHOD) and the decode logic inside make_message_details_map() ? Is there any scenario where we would want to call make_message_details_map without using the output of TO_CHAIN_MESSAGE_DETAILS_METHOD ? Also would it be a lot harder to unit test it this way ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need to call make_message_details_map without calling TO_CHAIN_MESSAGE_DETAILS_METHOD before. But yeah - we don't have mocked version of Client right now, so it'll make testing this function much harder.

)))
}

for (nonce, refined_message) in messages_to_refine.keys().zip(refined_messages) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, one more thing. If I understand correctly, here we rely on the assumption that the order of the refined_messages returned by the API call is the same as the order of the keys in messages_to_refine, which should be true, but I think it would be safer to test this somehow. Otherwise in case of an unexpected event we may assign a wrong weight to a message. Would it be acceptable to also add the message nonce to the InboundMessageDetails ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've mentioned this explicitly in the fn message_details documentation. Imo it should be enough, but feel free to add nonce if you think it is better (I'd leave it as is tbh).

wuminzhe pushed a commit to darwinia-network/darwinia-messages-substrate that referenced this pull request Aug 8, 2022
@serban300
Copy link
Copy Markdown
Collaborator

Some changes related to the comments were proposed in #1545 . Marking this as reviewed.

jiguantong pushed a commit to darwinia-network/darwinia-messages-substrate that referenced this pull request Apr 12, 2023
svyatonik pushed a commit that referenced this pull request Jul 17, 2023
* standard way to get at the docs

* Update README.md
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
…tTargetChain is used) (paritytech#1430)

* reintroduce From<SourceChain>InboundLaneApi

* impl From<Chain>InboundLaneApi for testnet runtimes

* use inboundlaneapi in relay

* remove unused OutboundXcmWeigher

* spelling

* added the only test to messages pallet

* fmt
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
…tTargetChain is used) (paritytech#1430)

* reintroduce From<SourceChain>InboundLaneApi

* impl From<Chain>InboundLaneApi for testnet runtimes

* use inboundlaneapi in relay

* remove unused OutboundXcmWeigher

* spelling

* added the only test to messages pallet

* fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XCM message weight computation must give the same result at both sides of the bridge

2 participants