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

runtime/session_info: avoid heavy loop when introduced on a live chain #2099

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

ordian
Copy link
Member

@ordian ordian commented Dec 9, 2020

Addresses part 2 of #2093:

The SessionInfo module will initially have EarliestSession be 0, but when introduced on a live chain that's been around for several thousand sessions (Kusama, Polkadot), it'll end up in a potentially heavy loop trying to prune all session info from 0..some_high_session_number. We should work around this so enabling the SessionInfo module on existing chains is light.

@ordian ordian added A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. labels Dec 9, 2020
@@ -253,4 +256,26 @@ mod tests {
assert_eq!(session.needed_approvals, 42);
})
}

#[test]
fn session_pruning_avoids_heavy_loop() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't figure out how this test ensures that we don't call Sessions::remove for every n < start.

Copy link
Member Author

@ordian ordian Dec 9, 2020

Choose a reason for hiding this comment

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

My laptop froze when running this test without the fix (on 1046e95).
It calls SessionInfo::initializer_on_new_session(&notification) on a very high session index.

Copy link
Member Author

@ordian ordian Dec 9, 2020

Choose a reason for hiding this comment

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

Maybe relying on a cargo test timeout is not the most elegant way, but this test shouldn't normally fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could add an internal timeout with a few seconds' max time? Like wrap the whole closure in async_std::task::block_on(async move { ... }.timeout(Duration::from_secs(5)), using subsystem_util::TimeoutExt. It would mean adding async_std as a dev-dependency, but I don't think that should be a huge deal.

@ordian ordian added B0-silent Changes should not be mentioned in any release notes and removed A2-insubstantial Pull request requires no code review (e.g., a sub-repository hash update). labels Dec 9, 2020
@rphmeier rphmeier merged commit 7a0fcb0 into master Dec 9, 2020
@rphmeier rphmeier deleted the ao-avoid-heavy-loop-in-session-info branch December 9, 2020 15:34
tomusdrw pushed a commit that referenced this pull request Dec 9, 2020
#2099)

* session_info: a heavy loop test

* session_info: fix a typo

* session_info: fix heavy loop

* session_info: crank the iterations all the way up
drahnr pushed a commit that referenced this pull request Dec 10, 2020
#2099)

* session_info: a heavy loop test

* session_info: fix a typo

* session_info: fix heavy loop

* session_info: crank the iterations all the way up
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants