This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Companion for Weight V2 #5435
Closed
Closed
Companion for Weight V2 #5435
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,7 @@ use codec::{Decode, Encode}; | |
| use frame_support::{ | ||
| fail, | ||
| traits::Get, | ||
| weights::{Pays, PostDispatchInfo}, | ||
| weights::{Pays, PostDispatchInfo, Weight}, | ||
| }; | ||
| use frame_system::RawOrigin; | ||
| use num_traits::{SaturatingAdd, Zero}; | ||
|
|
@@ -349,15 +349,18 @@ pub mod pallet { | |
| T::WeightInfo::increase_message_fee(message_size as _), | ||
| ); | ||
|
|
||
| Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes }) | ||
| Ok(PostDispatchInfo { | ||
| actual_weight: Some(Weight::from_computation(actual_weight)), | ||
| pays_fee: Pays::Yes, | ||
| }) | ||
| } | ||
|
|
||
| /// Receive messages proof from bridged chain. | ||
| /// | ||
| /// The weight of the call assumes that the transaction always brings outbound lane | ||
| /// state update. Because of that, the submitter (relayer) has no benefit of not including | ||
| /// this data in the transaction, so reward confirmations lags should be minimal. | ||
| #[pallet::weight(T::WeightInfo::receive_messages_proof_weight(proof, *messages_count, *dispatch_weight))] | ||
| #[pallet::weight(T::WeightInfo::receive_messages_proof_weight(proof, *messages_count, dispatch_weight.computation()))] | ||
| pub fn receive_messages_proof( | ||
| origin: OriginFor<T>, | ||
| relayer_id_at_bridged_chain: T::InboundRelayer, | ||
|
|
@@ -387,7 +390,7 @@ pub mod pallet { | |
| let declared_weight = T::WeightInfo::receive_messages_proof_weight( | ||
| &proof, | ||
| messages_count, | ||
| dispatch_weight, | ||
| dispatch_weight.computation(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| ); | ||
| let mut actual_weight = declared_weight; | ||
|
|
||
|
|
@@ -433,7 +436,7 @@ pub mod pallet { | |
| // on this lane. We can't dispatch lane messages out-of-order, so if declared | ||
| // weight is not enough, let's move to next lane | ||
| let dispatch_weight = T::MessageDispatch::dispatch_weight(&message); | ||
| if dispatch_weight > dispatch_weight_left { | ||
| if dispatch_weight.is_strictly_greater_than(&dispatch_weight_left) { | ||
| log::trace!( | ||
| target: "runtime::bridge-messages", | ||
| "Cannot dispatch any more messages on lane {:?}. Weight: declared={}, left={}", | ||
|
|
@@ -471,18 +474,19 @@ pub mod pallet { | |
| ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true), | ||
| }; | ||
|
|
||
| let unspent_weight = sp_std::cmp::min(unspent_weight, dispatch_weight); | ||
| let unspent_weight = unspent_weight.min(dispatch_weight); | ||
| dispatch_weight_left -= dispatch_weight - unspent_weight; | ||
| actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub( | ||
| // delivery call weight formula assumes that the fee is paid at | ||
| // this (target) chain. If the message is prepaid at the source | ||
| // chain, let's refund relayer with this extra cost. | ||
| if refund_pay_dispatch_fee { | ||
| T::WeightInfo::pay_inbound_dispatch_fee_overhead() | ||
| } else { | ||
| 0 | ||
| }, | ||
| ); | ||
| actual_weight = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also here. we seem to be disregarding PoV weight. |
||
| actual_weight.saturating_sub(unspent_weight.computation()).saturating_sub( | ||
| // delivery call weight formula assumes that the fee is paid at | ||
| // this (target) chain. If the message is prepaid at the source | ||
| // chain, let's refund relayer with this extra cost. | ||
| if refund_pay_dispatch_fee { | ||
| T::WeightInfo::pay_inbound_dispatch_fee_overhead() | ||
| } else { | ||
| 0 | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -495,7 +499,10 @@ pub mod pallet { | |
| declared_weight, | ||
| ); | ||
|
|
||
| Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes }) | ||
| Ok(PostDispatchInfo { | ||
| actual_weight: Some(Weight::from_computation(actual_weight)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also here? |
||
| pays_fee: Pays::Yes, | ||
| }) | ||
| } | ||
|
|
||
| /// Receive messages delivery proof from bridged chain. | ||
|
|
@@ -592,7 +599,9 @@ pub mod pallet { | |
| relayers_state.total_messages.saturating_mul(single_message_callback_overhead); | ||
| let actual_callback_weight = | ||
| T::OnDeliveryConfirmed::on_messages_delivered(&lane_id, &confirmed_messages); | ||
| match preliminary_callback_overhead.checked_sub(actual_callback_weight) { | ||
| match preliminary_callback_overhead | ||
| .checked_sub(actual_callback_weight.computation()) | ||
| { | ||
| Some(difference) if difference == 0 => (), | ||
| Some(difference) => { | ||
| log::trace!( | ||
|
|
@@ -646,7 +655,10 @@ pub mod pallet { | |
| lane_id, | ||
| ); | ||
|
|
||
| Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes }) | ||
| Ok(PostDispatchInfo { | ||
| actual_weight: Some(Weight::from_computation(actual_weight)), | ||
| pays_fee: Pays::Yes, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -877,7 +889,7 @@ fn send_message<T: Config<I>, I: 'static>( | |
| let single_message_callback_overhead = | ||
| T::WeightInfo::single_message_callback_overhead(T::DbWeight::get()); | ||
| let actual_callback_weight = T::OnMessageAccepted::on_messages_accepted(&lane_id, &nonce); | ||
| match single_message_callback_overhead.checked_sub(actual_callback_weight) { | ||
| match single_message_callback_overhead.checked_sub(actual_callback_weight.computation()) { | ||
| Some(difference) if difference == 0 => (), | ||
| Some(difference) => { | ||
| log::trace!( | ||
|
|
@@ -921,7 +933,7 @@ fn send_message<T: Config<I>, I: 'static>( | |
|
|
||
| Pallet::<T, I>::deposit_event(Event::MessageAccepted { lane_id, nonce }); | ||
|
|
||
| Ok(SendMessageArtifacts { nonce, weight: actual_weight }) | ||
| Ok(SendMessageArtifacts { nonce, weight: Weight::from_computation(actual_weight) }) | ||
| } | ||
|
|
||
| /// Ensure that the origin is either root, or `PalletOwner`. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -285,7 +285,9 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber | |||||
| hrmp_max_parachain_outbound_channels: Default::default(), | ||||||
| hrmp_max_parathread_outbound_channels: Default::default(), | ||||||
| hrmp_max_message_num_per_candidate: Default::default(), | ||||||
| ump_max_individual_weight: 20 * WEIGHT_PER_MILLIS, | ||||||
| ump_max_individual_weight: Weight::new() | ||||||
| .set_computation(20 * WEIGHT_PER_MILLIS) | ||||||
| .set_bandwidth(5 * 1024 * 1024), | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 20 ms is ~1% of the 2s expected maximum. 50KB should be about the same proportion of the maximum PoV size.
Suggested change
|
||||||
| pvf_checking_enabled: false, | ||||||
| pvf_voting_ttl: 2u32.into(), | ||||||
| minimum_validation_upgrade_delay: 2.into(), | ||||||
|
|
@@ -1136,7 +1138,7 @@ pub struct SessionChangeOutcome<BlockNumber> { | |||||
| impl<T: Config> Pallet<T> { | ||||||
| /// Called by the initializer to initialize the configuration pallet. | ||||||
| pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight { | ||||||
| 0 | ||||||
| Weight::zero() | ||||||
| } | ||||||
|
|
||||||
| /// Called by the initializer to finalize the configuration pallet. | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is surely wrong. the dispatch will also have a PoV component which should be added in, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is handled by the
receive_messages_proof_weight.dispatch_weightargument means is a pure dispatch weight - e.g. for call it needs to becall.get_dispatch_info().weight.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see. is there some reason they're not being handled together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dispatch weight is declared by the message sender when message is sent from the source (here: bridged) chain. Relay computes this argument by summing weights of all delivered messages. Why: originally we've been delivering encoded calls with prepaid (at the source chain) dispatch. Since we can't call
call.get_dispatch_info().weightat the bridged chain (because it don't know thecalltype + it don't know weights of the other chain), it was provided by the message sender.Other weight components (like cost of proof verification and others) depend on this chain (here: target) and are computed using regular auto benchmarks.
There's an open issue, related to this
dispatch_weightargument and ongoing XCM integration. But overall, scheme will stay the same (separate argument for pure dispatch weight and auto-benchmarks for everything else).