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

Parachains: Use relay chain slot for velocity measurement #6825

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

Conversation

skunert
Copy link
Contributor

@skunert skunert commented Dec 10, 2024

closes #3967

Changes

We now use relay chain slots to measure velocity on chain. Previously we were storing the current parachain slot. Then in on_state_proof of the ConsensusHook we were checking how many blocks were athored in the current parachain slot. This works well when the parachain slot time and relay chain slot time is the same. With elastic scaling, we can have parachain slot times lower than that of the relay chain. In these cases we want to measure velocity in relation to the relay chain. This PR adjusts that.

Migration

This PR includes a migration. Storage item SlotInfo of pallet aura-ext is renamed to RelaySlotInfo to better reflect its new content. A migration has been added that just kills the old storage item. RelaySlotInfo will be None initially but its value will be adjusted after one new relay chain slot arrives.

@skunert skunert added the T9-cumulus This PR/Issue is related to cumulus. label Dec 10, 2024
@skunert
Copy link
Contributor Author

skunert commented Dec 10, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented Dec 10, 2024

@skunert https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7892036 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". 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 23-6352bad6-c9e1-4490-bf52-e6b6f707a5f3 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Dec 10, 2024

@skunert Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7892036 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7892036/artifacts/download.

@skunert
Copy link
Contributor Author

skunert commented Dec 11, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented Dec 11, 2024

@skunert https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7898854 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". 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 26-f389b4df-c557-4572-a276-5937d6dc8d7d to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Dec 11, 2024

@skunert Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7898854 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7898854/artifacts/download.

@skunert
Copy link
Contributor Author

skunert commented Dec 13, 2024

/cmd prdoc --bump patch --audience runtime_dev,node_dev

@skunert skunert marked this pull request as ready for review December 13, 2024 16:12
@skunert skunert requested review from bkchr and alindima December 13, 2024 16:13
Copy link
Contributor

@alindima alindima left a comment

Choose a reason for hiding this comment

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

LGTM overall!

let Ok(Some(api_version)) =
runtime_api.api_version::<dyn AuraUnincludedSegmentApi<Block>>(parent_hash)
else {
return Some(SlotClaim::unchecked::<P>(author_pub, para_slot, timestamp))
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we return None if we couldn't get the api version?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we have None, it means the api doesn't exist and we should return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to be backward compatible with the previous behaviour. If we are building on top of the included block, the previous implementation would return Some. I don't think it is likely that someone runs this with a runtime without AuraUnincludedSegmentApi, but technically its possible.

@@ -70,20 +74,7 @@ pub mod pallet {
// Fetch the authorities once to get them into the storage proof of the PoV.
Authorities::<T>::get();

let new_slot = pallet_aura::CurrentSlot::<T>::get();
Copy link
Contributor

Choose a reason for hiding this comment

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

it feels a bit weird that the pallet now has a RelaySlotInfo storage item that is never updated by the pallet (but only in an optional ConsensusHook, which parachains could in theory overwrite). Not a big deal though

cumulus/pallets/aura-ext/src/test.rs Outdated Show resolved Hide resolved
@@ -110,7 +121,7 @@ impl<
/// is more recent than the included block itself.
pub fn can_build_upon(included_hash: T::Hash, new_slot: Slot) -> bool {
let velocity = V.max(1);
let (last_slot, authored_so_far) = match pallet::SlotInfo::<T>::get() {
let (last_slot, authored_so_far) = match pallet::RelaySlotInfo::<T>::get() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think can this be affected by #64, which leads to reading corrupted data here.

if block N updates the runtime, the code is overwritten immediately. The migration is run at the beginning of block N+1. Therefore, when we'll call can_build_upon at the end of block N, we'll use the new code with the old state

Copy link
Member

Choose a reason for hiding this comment

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

It will not read corrupted state, as RelaySlotInfo doesn't exist yet.

let Ok(Some(api_version)) =
runtime_api.api_version::<dyn AuraUnincludedSegmentApi<Block>>(parent_hash)
else {
return Some(SlotClaim::unchecked::<P>(author_pub, para_slot, timestamp))
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if we have None, it means the api doesn't exist and we should return an error.

cumulus/pallets/aura-ext/src/consensus_hook.rs Outdated Show resolved Hide resolved
cumulus/pallets/aura-ext/src/consensus_hook.rs Outdated Show resolved Hide resolved
@@ -110,7 +121,7 @@ impl<
/// is more recent than the included block itself.
pub fn can_build_upon(included_hash: T::Hash, new_slot: Slot) -> bool {
let velocity = V.max(1);
let (last_slot, authored_so_far) = match pallet::SlotInfo::<T>::get() {
let (last_slot, authored_so_far) = match pallet::RelaySlotInfo::<T>::get() {
Copy link
Member

Choose a reason for hiding this comment

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

It will not read corrupted state, as RelaySlotInfo doesn't exist yet.

}

pub fn migrate<T: Config>() -> Weight {
v0::SlotInfo::<T>::kill();
Copy link
Member

Choose a reason for hiding this comment

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

By just killing this item and not setting RelaySlotInfo, collators will produce len(UnincludedSegements) * 2 blocks ahead. But yeah, this should then go back to normal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I don't agree. Collators could in theory build up to velocity blocks, since we will reset only the velocity counter. If they already have build some blocks during the current relay parent, they would be able to build too much. But currently none of our collator implementations really try to build as many blocks as they can.

# Conflicts:
#	cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs
#	cumulus/client/parachain-inherent/src/mock.rs
@skunert
Copy link
Contributor Author

skunert commented Dec 18, 2024

bot fmt

@command-bot

This comment was marked as resolved.

@command-bot

This comment was marked as resolved.

@paritytech-workflow-stopper

This comment was marked as resolved.

@skunert
Copy link
Contributor Author

skunert commented Dec 19, 2024

bot fmt

@command-bot

This comment was marked as resolved.

@command-bot

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T9-cumulus This PR/Issue is related to cumulus.
Projects
Status: backlog
Development

Successfully merging this pull request may close these issues.

slot-based-collator: Adjust ConsensusHook and parent search
3 participants