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

[pallet-broker] add extrinsic to remove a lease #7026

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ethernomad
Copy link

@ethernomad ethernomad commented Jan 2, 2025

Description

#6929 requests more extrinsics for "managing the network's coretime allocations without needing to dabble with migration+runtime upgrade or set/kill storage patterns"

This pull request implements the remove_lease() extrinsic.

Integration

Downstream projects need to benchmark the weight for the remove_lease() extrinsic.

Review Notes

Mentorship is requested to ensure this is implemented correctly.

The lease is removed from state using the TaskId as a key. Is this sufficient. Does the extrinsic need to do anything else?

@ethernomad ethernomad requested a review from a team as a code owner January 2, 2025 09:15
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Misses a benchmark for remove_lease, otherwise looks good to me.

substrate/frame/broker/src/lib.rs Outdated Show resolved Hide resolved
@bkchr bkchr added the T2-pallets This PR/Issue is related to a particular pallet. label Jan 2, 2025
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 2, 2025 10:03
Copy link
Contributor

@seadanda seadanda left a comment

Choose a reason for hiding this comment

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

Functionality wise, this looks good for this extrinsic.

If somebody wants to do more, for example remove a lease AND remove the associated task from its core in the next sale, they can pair remove_lease with remove_from_workplan (or whatever that extrinsic will be called).

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 3, 2025 05:01
@ethernomad
Copy link
Author

bot bench substrate-pallet --pallet=pallet_broker
bot bench cumulus-coretime --pallet=pallet_broker --runtime=coretime-rococo
bot bench cumulus-coretime --pallet=pallet_broker --runtime=coretime-westend

@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@ethernomad Requester could not be detected as a member of an allowed organization.

@ethernomad
Copy link
Author

Can someone run the bench bot for me?

@re-gius
Copy link
Contributor

re-gius commented Jan 3, 2025

bot bench substrate-pallet --pallet=pallet_broker
bot bench cumulus-coretime --pallet=pallet_broker --runtime=coretime-rococo
bot bench cumulus-coretime --pallet=pallet_broker --runtime=coretime-westend

@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@re-gius https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966356 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_broker. 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 27-b51ea54a-5117-4dfb-8dfc-0336d89d1cde to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@re-gius https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966357 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=coretime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker. 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 28-9a8dd030-225c-4c85-8e84-63823f26f1ff to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@re-gius https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966358 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=coretime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker. 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 29-ed7e8b1e-ea32-42d1-a4a6-92e6526aa487 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@re-gius Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --features=riscv --pallet=pallet_broker has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966356 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966356/artifacts/download.

…=coretime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker
@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@re-gius Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=coretime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966357 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966357/artifacts/download.

…=coretime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker
@command-bot
Copy link

command-bot bot commented Jan 3, 2025

@re-gius Command "$PIPELINE_SCRIPTS_DIR/commands/bench/bench.sh" --subcommand=pallet --runtime=coretime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966358 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7966358/artifacts/download.

prdoc/pr_7026.prdoc Outdated Show resolved Hide resolved
prdoc/pr_7026.prdoc Outdated Show resolved Hide resolved
ethernomad and others added 2 commits January 6, 2025 18:55
Co-authored-by: Dónal Murray <[email protected]>
Co-authored-by: Dónal Murray <[email protected]>
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 6, 2025 11:56
@gui1117
Copy link
Contributor

gui1117 commented Jan 25, 2025

/cmd bench --runtime dev --pallet pallet_broker

Copy link
Contributor

Command "bench --runtime dev --pallet pallet_broker" has started 🚀 See logs here

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

I see nothing wrong with the code, but I don't know much about broker pallet.

T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, task);
Copy link
Contributor

Choose a reason for hiding this comment

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

the worst case would be removing the last task in the vec. Here it removes the first one.

Though in practice the cost should be negligible as MaxLeasedCores isn't so big.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, would be nice to target the worst case, especially here where it's as straightforward as just changing the task id.

Copy link
Contributor

Command "bench --runtime dev --pallet pallet_broker" has finished ✅ See logs here

Subweight results:
File Extrinsic Old New Change [%]
cumulus/pallets/collator-selection/src/weights.rs leave_intent - - ERROR
cumulus/pallets/collator-selection/src/weights.rs new_session - - ERROR
cumulus/pallets/collator-selection/src/weights.rs register_as_candidate - - ERROR
cumulus/pallets/collator-selection/src/weights.rs set_invulnerables - - ERROR
cumulus/pallets/collator-selection/src/weights.rs take_candidate_slot - - ERROR
cumulus/pallets/collator-selection/src/weights.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_ambassador_core.rs promote_fast - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_fellowship_core.rs promote_fast - - ERROR
cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-rococo/src/weights/pallet_collator_selection.rs update_bond - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs take_candidate_slot - - ERROR
cumulus/parachains/runtimes/people/people-westend/src/weights/pallet_collator_selection.rs update_bond - - ERROR
polkadot/runtime/westend/src/weights/pallet_preimage.rs ensure_updated - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmen - - ERROR
substrate/frame/election-provider-support/src/weights.rs phragmms - - ERROR
substrate/frame/broker/src/weights.rs on_new_timeslice 290.00ns 272.00ns -6.21
substrate/frame/broker/src/weights.rs request_revenue_info_at 183.00ns 164.00ns -10.38
cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs drop_region 215.33us 191.41us -11.11
cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs drop_contribution 305.32us 264.73us -13.29
substrate/frame/broker/src/weights.rs remove_lease 140.29us Added
cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs remove_lease 136.50us Added
cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs remove_lease 136.90us Added
Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_broker']

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 25, 2025 03:35
Copy link
Contributor

@seadanda seadanda left a comment

Choose a reason for hiding this comment

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

Nice, looks close

/// Remove a lease.
///
/// - `origin`: Must be Root or pass `AdminOrigin`.
/// - `task`: The workload of the lease which should be removed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// - `task`: The workload of the lease which should be removed.
/// - `task`: The task id of the lease which should be removed.

Also from memory there can be multiple leases for a given task_id, although not how this is intended to be used in the system. I don't think it's worth complicating the extrinsic to also check timeslice etc. You should however include in the docs that it removes the first in the vector, which is not necessarily the first to end in time. I'm AFK so can't check right now, but would be good to also cover this behaviour in the test.

T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, task);
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, would be nice to target the worst case, especially here where it's as straightforward as just changing the task id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants