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

Undo v4 changes, move them to vstaging #7103

Open
wants to merge 26 commits into
base: alex/parathreads_review
Choose a base branch
from

Conversation

ghost
Copy link

@ghost ghost commented Apr 19, 2023

No description provided.

@ghost ghost added A3-in_progress Pull request is in progress. No review needed at this stage. E0-runtime_migration PR introduces code that might require downstream chains to run a runtime upgrade. labels Apr 19, 2023
@ghost ghost force-pushed the alex/parathreads_vstaging branch from 8b03c90 to fc276d6 Compare April 25, 2023 10:05
@@ -123,7 +123,7 @@ use sp_std::{collections::btree_map::BTreeMap, prelude::*};

sp_api::decl_runtime_apis! {
/// The API for querying the state of parachains on-chain.
#[api_version(4)]
#[api_version(5)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good. You also need to add (can't leave a comment at the right):

#[changed_in(5)]
fn availability_cores() -> Vec<CoreState<H, N>>;

This way you can have two implementations - old and new ones. The intention of changed_in is to change the method signature. I'm not sure if it will work in the case 'same signature, different implementation'.

If this is the case - you can just add another function and handle the right one in the client code. This one breaks the semantics a little but imo it's fine. If pick this approach, you shouldn't touch base version here and just add another method:

#[api_version(5)]
fn availability_cores_with_parathreads() -> Vec<CoreState<H, N>>;

@ghost ghost requested review from tdimitrov and s0me0ne-unkn0wn June 1, 2023 12:44
@@ -819,121 +815,14 @@ pub struct ParathreadEntry {
pub retries: u32,
}

/// An Assignemnt for a paras going to produce a paras block.
#[derive(Clone, Encode, Decode, PartialEq, TypeInfo, RuntimeDebug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember these are actually not part of v4 at the moment and you are undoing previous work done in alex/parathreads_review, right?

Copy link
Author

Choose a reason for hiding this comment

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

Exactly! At the end of the day, we'll need to make sure v4 is just as it is on master. Which I think it is here but will confirm later down the road when we have the final feature branch with a diff to master.

@@ -252,7 +252,18 @@ where
&self,
at: Hash,
) -> Result<Vec<CoreState<Hash, BlockNumber>>, ApiError> {
self.runtime_api().availability_cores(at)
let version = self
Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed somewhere that such transformations in the client are not encouraged and we prefer doing this in the subsystem. Unfortunately I don't remember the exact reasons.

For your particular case I think it's okay though. Depending on the runtime api you call either the new or the old version of the function. And you do this workaround to avoid the changed_in issues with the runtime api.

Copy link
Author

Choose a reason for hiding this comment

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

Which file would this ideally go to then? What exactly is the subsystem again? I'm only aware of the node/client and runtime distinction.

Copy link
Contributor

Choose a reason for hiding this comment

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

Subsystem is a module (lets say) from the node - e.g. approval-voting, dispute-coordinator etc.
You can put a function in any helpers module (e.g. https://github.com/paritytech/polkadot/blob/dbae30efe080a1d41fe54ef4da8af47614c9ca93/node/subsystem-util/src/runtime/mod.rs) and call it each time you need the availability_cores.

But I'd suggest not to touch it for now.

@ghost ghost marked this pull request as ready for review June 2, 2023 17:33
@ghost ghost requested review from tdimitrov and eskimor June 2, 2023 17:33
@paritytech-ci paritytech-ci requested review from a team June 3, 2023 18:48
pub next_up_on_available: Option<ScheduledCore>,
/// The relay-chain block number this began occupying the core at.
pub occupied_since: N,
/// The relay-chain block this will time-out at, if any.
Copy link
Member

Choose a reason for hiding this comment

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

This is not an Option, so the if any seems odd.

Copy link
Author

Choose a reason for hiding this comment

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

This is a copy and paste from v4. Fixed.

/// The relay-chain block this will time-out at, if any.
pub time_out_at: N,
/// If this core is freed by being timed-out, this is the assignment that is next up on this
/// core. None if there is nothing queued for this core or there is no possibility of timing
Copy link
Member

Choose a reason for hiding this comment

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

There is always a possibility of timing out. What could be that there is no other assignment queued and the currently occupying assignment already has exhausted its retry counter.

Copy link
Author

Choose a reason for hiding this comment

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

This is a copy and paste from v4. Fixed.

/// validators has attested to availability on-chain. A 2/3+ majority of `1` bits means that
/// this will be available.
pub availability: BitVec<u8, bitvec::order::Lsb0>,
/// The group assigned to distribute availability pieces of this candidate.
Copy link
Member

Choose a reason for hiding this comment

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

And backing the candidate.

Copy link
Author

Choose a reason for hiding this comment

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

This is a copy and paste from v4. Fixed.

/// variant.
#[codec(index = 1)]
Scheduled(ScheduledCore),
/// The core is currently free and there is nothing scheduled. This can be the case for parathread
Copy link
Member

Choose a reason for hiding this comment

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

We should start using on-demand parachain.

/// Yields information on all availability cores as relevant to the child block.
/// Cores are either free or occupied. Free cores can have paras assigned to them.
#[api_version(5)]
fn availability_cores_on_demand() -> Vec<vstaging::CoreState<H, N>>;
Copy link
Member

Choose a reason for hiding this comment

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

So this only gets us on-demand availability cores? I guess not, from the docs and from my understanding. So where does the name come from?

Copy link
Author

Choose a reason for hiding this comment

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

It's supposed to be the v5 availability_cores call. I thought just calling it availability_cores_v5 would be a bit meaningless but I see how the current name is misleading as well.

// actively. We could even time out this block.
if time_out_at < current_window {
time_out_at
} else if time_out_at <= next_rotation {
Copy link
Member

Choose a reason for hiding this comment

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

This code is out of sync with the updated timeout predicate. It is bad that this can even happen, we should be using the same logic. DRY.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed! The issue is that the updated timeout predicate is in the scheduler itself. The runtime API uses its own implementation for reasons unknown to me. Will unify.

@paritytech-ci paritytech-ci requested review from a team June 7, 2023 10:53
@cla-bot-2021
Copy link

cla-bot-2021 bot commented Jul 21, 2023

User @ghost, please sign the CLA here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage. E0-runtime_migration PR introduces code that might require downstream chains to run a runtime upgrade.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants