Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

availability-distribution: look for leaf ancestors within the same session #4596

Merged
merged 5 commits into from
Jan 26, 2022

Conversation

slumber
Copy link
Contributor

@slumber slumber commented Dec 23, 2021

Restores the behavior that was removed in #2423
Resolves #2513

  • tests

@slumber slumber requested a review from eskimor December 23, 2021 20:39
@github-actions github-actions bot added the A3-in_progress Pull request is in progress. No review needed at this stage. label Dec 23, 2021
@slumber slumber added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. A3-in_progress Pull request is in progress. No review needed at this stage. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Dec 23, 2021
Copy link
Member

@eskimor eskimor left a comment

Choose a reason for hiding this comment

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

Looks good overall!

But I noticed a bug, that is not related to your changes but would be nice to be fixed in the course of this PR:

Here we are not actually using the SessionInfo for the leaf, but the SessionInfo for the leaf's child. Therefore, at session boundaries we will look up the backing group in the wrong session.

I'll tell @sandreim - would be good to have this fixed in the course of his PR.

@eskimor
Copy link
Member

eskimor commented Jan 20, 2022

Some tests would be nice - especially for behavior at session boundaries, other than that - good to go.

@slumber slumber force-pushed the slumber-av-distribution-ancestors-lookup branch from 725e8f0 to 0f54ea3 Compare January 21, 2022 17:26
@slumber slumber marked this pull request as ready for review January 21, 2022 17:38
@github-actions github-actions bot added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jan 21, 2022
Copy link
Contributor

@Lldenaurois Lldenaurois left a comment

Choose a reason for hiding this comment

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

I still need to review the tests, but the code itself lgtm

@@ -91,43 +100,72 @@ impl Requester {
ctx: &mut Context,
runtime: &mut RuntimeInfo,
update: ActiveLeavesUpdate,
) -> super::Result<()>
) -> Result<()>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment on lines +111 to +113
if let Some(activated) = activated {
// Stale leaves happen after a reversion - we don't want to re-run availability there.
if let LeafStatus::Fresh = activated.status {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there really no better way to do this check??

Maybe this is more elegant than two if let's or the ugly thing that was there before:

match activated {
    Some(act) if act.status == LeafStatus::Fresh => { ... },
    _ => {},
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can also express it with

if matches!(activated, Some(activated) if activated.status == LeafStatus::Fresh) {

(provided one derives the PartialEq for status)
But to be honest nested if let is the most readable option to me, 2 more lines is not a big deal

Vec::new()
});
// Also spawn or bump tasks for candidates in ancestry in the same session.
for hash in std::iter::once(leaf).chain(ancestors_in_session) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@@ -215,3 +253,69 @@ impl Stream for Requester {
}
}
}

/// Requests up to `limit` ancestor hashes of relay parent in the same session.
async fn get_block_ancestors_in_same_session<Context>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic here seems accurate accounting for the fact that get_session_index is actually returning the session index of the child. Nice

tracing::trace!(
target: LOG_TARGET,
occupied_cores = ?cores,
"Query occupied core"
);
// Important:
// We mark the whole ancestry as live in the **leaf** hash, so we don't need to track
Copy link
Contributor

@rphmeier rphmeier Jan 26, 2022

Choose a reason for hiding this comment

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

This comment is great and seems to be correct behavior. I had noticed that add_cores might race with remove_leaf if you used hash.

It would be even more clear if you wrote "We invoke add_cores with the leaf and not with the ancestor hash to avoid a race condition and avoid requesting chunks multiple times" or something like that.

Copy link
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

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

Looks good. Very much up to standard of neatness, correctness, and testing. Thank you.

@rphmeier rphmeier merged commit 02508b4 into master Jan 26, 2022
@rphmeier rphmeier deleted the slumber-av-distribution-ancestors-lookup branch January 26, 2022 04:52
ordian added a commit that referenced this pull request Jan 27, 2022
* master:
  Fix incomplete sorting. (#4795)
  Companion for better way to resolve `Phase::Emergency` via governance #10663 (#4757)
  Refactor and fix usage of `get_session_index()` and `get_session_info_by_index()` (#4735)
  `relay chain selection` and `dispute-coordinator` fixes and improvements (#4752)
  Fix tests (#4787)
  log concluded disputes (#4785)
  availability-distribution: look for leaf ancestors within the same session (#4596)
  Companion for Use proper bounded vector type for nominations #10601 (#4709)
  Fix release profile (#4778)
  [ci] remove publish-s3-release (#4779)
  Companion for substrate#10632 (#4689)
  [ci] pipeline chores (#4775)
  New changelog scripts (#4491)
Wizdave97 pushed a commit to ComposableFi/polkadot that referenced this pull request Feb 3, 2022
…ssion (paritytech#4596)

* availability-distribution: look for leaf ancestors

* Re-use subsystem-util

* Rework ancestry tasks scheduling

* Requester tests

* Improve readability for ancestors lookup
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Availability Distribution: Consider occupied cores from last k blocks within same session
4 participants