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 370
parachain-system: update RelevantMessagingState according to the unincluded segment #2948
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
22e92ae
mostly address 2471 with a bug introduced
rphmeier b4754d4
adjust relevant messaging state after computing total
rphmeier ad8c0e0
fmt
rphmeier b313339
max -> min
slumber 34499d5
fix test implementation of xcmp source
slumber 24082a5
add test
slumber 96179b2
fix test message sending logic
rphmeier 38de64c
fix + test
slumber be3069c
add more to unincluded segment test
rphmeier fcb9283
Merge branch 'rh-2471' of https://github.com/paritytech/cumulus into …
rphmeier 2286288
fmt
rphmeier 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,8 +240,12 @@ pub mod pallet { | |
| return | ||
| }, | ||
| }; | ||
| let relevant_messaging_state = match Self::relevant_messaging_state() { | ||
| Some(ok) => ok, | ||
|
|
||
| // Before updating the relevant messaging state, we need to extract | ||
| // the total bandwidth limits for the purpose of updating the unincluded | ||
| // segment. | ||
| let total_bandwidth_out = match Self::relevant_messaging_state() { | ||
| Some(s) => OutboundBandwidthLimits::from_relay_chain_state(&s), | ||
| None => { | ||
| debug_assert!( | ||
| false, | ||
|
|
@@ -252,22 +256,28 @@ pub mod pallet { | |
| }, | ||
| }; | ||
|
|
||
| let total_bandwidth_out = | ||
| OutboundBandwidthLimits::from_relay_chain_state(&relevant_messaging_state); | ||
| let bandwidth_out = AggregatedUnincludedSegment::<T>::get().map(|segment| { | ||
| let mut bandwidth_out = total_bandwidth_out.clone(); | ||
| bandwidth_out.subtract(segment.used_bandwidth()); | ||
| bandwidth_out | ||
| }); | ||
| // After this point, the `RelevantMessagingState` in storage reflects the | ||
| // unincluded segment. | ||
| Self::adjust_egress_bandwidth_limits(); | ||
|
|
||
| let (ump_msg_count, ump_total_bytes) = <PendingUpwardMessages<T>>::mutate(|up| { | ||
| let bandwidth_out = bandwidth_out.as_ref().unwrap_or(&total_bandwidth_out); | ||
| let available_capacity = cmp::min( | ||
| bandwidth_out.ump_messages_remaining, | ||
| host_config.max_upward_message_num_per_candidate, | ||
| ); | ||
|
|
||
| let available_size = bandwidth_out.ump_bytes_remaining; | ||
| let (available_capacity, available_size) = match Self::relevant_messaging_state() { | ||
| Some(limits) => ( | ||
| limits.relay_dispatch_queue_remaining_capacity.remaining_count, | ||
| limits.relay_dispatch_queue_remaining_capacity.remaining_size, | ||
| ), | ||
| None => { | ||
| debug_assert!( | ||
| false, | ||
| "relevant messaging state is promised to be set until `on_finalize`; \ | ||
| qed", | ||
| ); | ||
| return (0, 0) | ||
| }, | ||
| }; | ||
|
|
||
| let available_capacity = | ||
| cmp::min(available_capacity, host_config.max_upward_message_num_per_candidate); | ||
|
|
||
| // Count the number of messages we can possibly fit in the given constraints, i.e. | ||
| // available_capacity and available_size. | ||
|
|
@@ -312,8 +322,9 @@ pub mod pallet { | |
| .hrmp_max_message_num_per_candidate | ||
| .min(<AnnouncedHrmpMessagesPerCandidate<T>>::take()) as usize; | ||
|
|
||
| // TODO [now]: the `ChannelInfo` implementation for this pallet is what's | ||
| // important here for proper limiting. | ||
| // Note: this internally calls the `GetChannelInfo` implementation for this | ||
| // pallet, which draws on the `RelevantMessagingState`. That in turn has | ||
| // been adjusted above to reflect the correct limits in all channels. | ||
| let outbound_messages = | ||
| T::OutboundXcmpMessageSource::take_outbound_messages(maximum_channels) | ||
| .into_iter() | ||
|
|
@@ -351,9 +362,7 @@ pub mod pallet { | |
| let watermark = HrmpWatermark::<T>::get(); | ||
| let watermark_update = | ||
| HrmpWatermarkUpdate::new(watermark, LastRelayChainBlockNumber::<T>::get()); | ||
| // TODO: In order of this panic to be correct, outbound message source should | ||
| // respect bandwidth limits as well. | ||
| // <https://github.com/paritytech/cumulus/issues/2471> | ||
|
|
||
| aggregated_segment | ||
| .append(&ancestor, watermark_update, &total_bandwidth_out) | ||
| .expect("unincluded segment limits exceeded"); | ||
|
|
@@ -431,6 +440,9 @@ pub mod pallet { | |
| 4 + hrmp_max_message_num_per_candidate as u64, | ||
| ); | ||
|
|
||
| // Weight for adjusting the unincluded segment in `on_finalize`. | ||
| weight += T::DbWeight::get().reads_writes(6, 3); | ||
|
|
||
| // Always try to read `UpgradeGoAhead` in `on_finalize`. | ||
| weight += T::DbWeight::get().reads(1); | ||
|
|
||
|
|
@@ -557,6 +569,7 @@ pub mod pallet { | |
| let host_config = relay_state_proof | ||
| .read_abridged_host_configuration() | ||
| .expect("Invalid host configuration in relay chain state proof"); | ||
|
|
||
| let relevant_messaging_state = relay_state_proof | ||
| .read_messaging_state_snapshot(&host_config) | ||
| .expect("Invalid messaging state in relay chain state proof"); | ||
|
|
@@ -1227,6 +1240,46 @@ impl<T: Config> Pallet<T> { | |
| weight_used | ||
| } | ||
|
|
||
| /// This adjusts the `RelevantMessagingState` according to the bandwidth limits in the | ||
| /// unincluded segment. | ||
| // | ||
| // Reads: 2 | ||
| // Writes: 1 | ||
| fn adjust_egress_bandwidth_limits() { | ||
| let unincluded_segment = match AggregatedUnincludedSegment::<T>::get() { | ||
| None => return, | ||
| Some(s) => s, | ||
| }; | ||
|
|
||
| <RelevantMessagingState<T>>::mutate(|messaging_state| { | ||
| let messaging_state = match messaging_state { | ||
| None => return, | ||
| Some(s) => s, | ||
| }; | ||
|
|
||
| let used_bandwidth = unincluded_segment.used_bandwidth(); | ||
|
|
||
| let channels = &mut messaging_state.egress_channels; | ||
| for (para_id, used) in used_bandwidth.hrmp_outgoing.iter() { | ||
| let i = match channels.binary_search_by_key(para_id, |item| item.0) { | ||
| Ok(i) => i, | ||
| Err(_) => continue, // indicates channel closed. | ||
| }; | ||
|
|
||
| let c = &mut channels[i].1; | ||
|
|
||
| c.total_size = (c.total_size + used.total_bytes).min(c.max_total_size); | ||
| c.msg_count = (c.msg_count + used.msg_count).min(c.max_capacity); | ||
| } | ||
|
|
||
| let upward_capacity = &mut messaging_state.relay_dispatch_queue_remaining_capacity; | ||
| upward_capacity.remaining_count = | ||
| upward_capacity.remaining_count.saturating_sub(used_bandwidth.ump_msg_count); | ||
|
Contributor
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. Sanity checking, do we want to be subtracting the entire
Contributor
Author
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. Yeah. What we read from the relay-chain state is the total capacity as-of the most recently included block. We then subtract the used bandwidth in the unincluded segment from it to get the actual remaining channel capacity. |
||
| upward_capacity.remaining_size = | ||
| upward_capacity.remaining_size.saturating_sub(used_bandwidth.ump_total_bytes); | ||
| }); | ||
| } | ||
|
|
||
| /// Put a new validation function into a particular location where polkadot | ||
| /// monitors for updates. Calling this function notifies polkadot that a new | ||
| /// upgrade has been scheduled. | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.