Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: remove ttl #5461

Merged
merged 195 commits into from
Oct 21, 2024
Merged

runtime: remove ttl #5461

merged 195 commits into from
Oct 21, 2024

Conversation

alindima
Copy link
Contributor

@alindima alindima commented Aug 26, 2024

Resolves #4776

This will enable proper core-sharing between paras, even if one of them is not producing blocks.

TODO:

  • duplicate first entry in the claim queue if the queue used to be empty
  • don't back anything if at the end of the block there'll be a session change
  • write migration for removing the availability core storage
  • update and write unit tests
  • prdoc
  • add zombienet test for synchronous backing
  • add zombienet test for core-sharing paras where one of them is not producing any blocks

Important note:
The ttl and max_availability_timeouts fields of the HostConfiguration are not removed in this PR, due to #64.
Adding the workaround with the storage version check for every use of the active HostConfiguration in all runtime APIs would be insane, as it's used in almost all runtime APIs.

So even though the ttl and max_availability_timeouts fields will now be unused, they will remain part of the host configuration.

These will be removed in a separate PR once #64 is fixed. Tracked by #6067

Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
Signed-off-by: Andrei Sandu <[email protected]>
@command-bot
Copy link

command-bot bot commented Oct 17, 2024

@alindima https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7591514 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 14-25b27c8e-2ab2-4725-b285-d343fd881212 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Oct 17, 2024

@alindima Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7591514 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7591514/artifacts/download.

@alindima
Copy link
Contributor Author

bot bench polkadot-pallet --pallet=polkadot_runtime_parachains::paras_inherent --runtime=westend -v UPSTREAM_MERGE=n

@command-bot
Copy link

command-bot bot commented Oct 17, 2024

@alindima https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7595155 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 19-557204d2-9955-4c63-ad77-ae8044403d48 to cancel this command or bot cancel to cancel all commands in this pull request.

…=westend --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent
@command-bot
Copy link

command-bot bot commented Oct 17, 2024

@alindima Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7595155 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7595155/artifacts/download.

@alindima
Copy link
Contributor Author

bot bench polkadot-pallet --pallet=polkadot_runtime_parachains::paras_inherent --runtime=rococo -v UPSTREAM_MERGE=n

@command-bot
Copy link

command-bot bot commented Oct 21, 2024

@alindima https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7607482 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=rococo --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent. Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 1-19553a01-d9e9-4e77-8c4c-b745786ff00a to cancel this command or bot cancel to cancel all commands in this pull request.

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!

polkadot/runtime/parachains/src/disputes.rs Outdated Show resolved Hide resolved
@@ -514,6 +486,14 @@ impl<T: Config> Pallet<T> {
T::MessageQueue::sweep_queue(AggregateMessageOrigin::Ump(UmpQueueId::Para(para)));
}

pub(crate) fn get_occupied_cores(
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Who to ask for occupied cores ... inclusion! ;-)

@@ -1173,7 +1151,7 @@ impl<T: Config> Pallet<T> {

/// Returns the first `CommittedCandidateReceipt` pending availability for the para provided, if
/// any.
pub(crate) fn candidate_pending_availability(
pub(crate) fn first_candidate_pending_availability(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: What does "first" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added an explanation in the doc block


Self::process_inherent_data(data, ProcessInherentDataContext::Enter)
.map(|(_processed, post_info)| post_info)
Self::process_inherent_data(data).and_then(|(processed, post_info)| {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! :-)

Future optimization possibilities, if we ever needed to:

  • Hashing instead of full cloning.
  • Counting bytes/vec sizes and only compare total size in the end.

let mut eligible: BTreeMap<ParaId, BTreeSet<CoreIndex>> = BTreeMap::new();
let mut total_eligible_cores = 0;

for (core_idx, para_id) in Self::eligible_paras(&occupied_cores) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I follow the reasoning.

pub(crate) fn eligible_paras<'a>(
occupied_cores: &'a BTreeSet<CoreIndex>,
) -> impl Iterator<Item = (CoreIndex, ParaId)> + 'a {
scheduler::ClaimQueue::<T>::get().into_iter().filter_map(|(core_idx, queue)| {
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but for the future: Let's aim to have a proper API for modules. Accessing another pallet's storage directly is code smell: We apparently don't have clear responsibilities nor an API that is sufficient to communicate with that component.

@@ -133,6 +127,13 @@ mod enter {
}
}

// Clear the on-chain dispute data.
fn clear_dispute_storage<Test: disputes::Config>() {
Copy link
Member

Choose a reason for hiding this comment

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

This could be a cfg-test only clear_dispute_storage() function in the disputes module (avoiding making storage public).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -826,6 +919,8 @@ mod enter {
// over weight
assert_eq!(limit_inherent_data.backed_candidates.len(), 0);

clear_dispute_storage::<Test>();
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to just create a new test environment before the enter call?

CoreOccupied::Free => {
if let Some(para_id) = scheduled.get(&CoreIndex(i as _)).cloned() {
} else {
if let Some(assignment) = scheduler::Pallet::<T>::peek_claim_queue(&core_idx) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Fetching the entire claim queue on each iteration is rather inefficient.

Copy link
Member

Choose a reason for hiding this comment

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

That's were the iterator idea came from. With this we could just zip the two iterators and loop through both just once.

Anyhow, this call is actually obsolete and only exists for backwards compatibility? If so, we can just not bother and also mark the runtime api as deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not realy obsolete, as there's no other runtime API we can use to find out the state of a core (whether it's occupied or not). And this is still needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nit: Fetching the entire claim queue on each iteration is rather inefficient.

True, I can change it to only query once

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -1710,7 +1710,8 @@ pub mod migrations {
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
parachains_inclusion::migration::MigrateToV1<Runtime>,
parachains_shared::migration::MigrateToV1<Runtime>,
parachains_shared::migration::MigrateToV1<Runtime>,
Copy link
Member

Choose a reason for hiding this comment

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

Formatting looks off?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks fine to me

alindima and others added 3 commits October 21, 2024 16:28
…=rococo --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent
@command-bot
Copy link

command-bot bot commented Oct 21, 2024

@alindima Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=rococo --target_dir=polkadot --pallet=polkadot_runtime_parachains::paras_inherent has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7607482 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7607482/artifacts/download.

@alindima alindima added this pull request to the merge queue Oct 21, 2024
Merged via the queue into master with commit ee803b7 Oct 21, 2024
192 of 195 checks passed
@alindima alindima deleted the alindima/remove-ttl branch October 21, 2024 19:55
@alindima alindima mentioned this pull request Oct 28, 2024
2 tasks
github-merge-queue bot pushed a commit that referenced this pull request Nov 4, 2024
Reported in
#6161 (comment)

Fixes a bug introduced in
#5461, where the claim
queue would contain entries even if the validator groups storage is
empty (which happens during the first session).

This PR sets the claim queue core count to be the minimum between the
num_cores param and the number of validator groups

TODO:
- [x] prdoc
- [x] unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T8-polkadot This PR/Issue is related to/affects the Polkadot network.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Claim queue: Remove TTL
5 participants