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

[AHM] Replace Validator FullIdentification from Exposure to Existence #7936

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

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Mar 15, 2025

closes #6344.

TODO

  • TryStateCheck to see existing offence report decodes correctly.

@Ank4n Ank4n changed the title Change full identification of Validator from its exposure to just existence [AHM] Replace Validator FullIdentification from Exposure to Existence Mar 15, 2025
@Ank4n Ank4n added I4-refactor Code needs refactoring. T8-polkadot This PR/Issue is related to/affects the Polkadot network. labels Mar 15, 2025
@Ank4n
Copy link
Contributor Author

Ank4n commented Mar 15, 2025

/cmd prdoc --force

@Ank4n Ank4n marked this pull request as ready for review March 15, 2025 19:30
@Ank4n Ank4n requested review from acatangiu and a team as code owners March 15, 2025 19:30
@Ank4n Ank4n removed request for a team and acatangiu March 15, 2025 19:31
@paritytech-review-bot paritytech-review-bot bot requested a review from a team March 15, 2025 19:32
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/13876711927
Failed job name: test-linux-stable-no-try-runtime

fn convert(_: T) -> Option<()> {
Some(())
/// A marker type representing the presence of a validator. Encodes as a unit type.
pub type Existence = ();
Copy link
Contributor

@kianenigma kianenigma Mar 16, 2025

Choose a reason for hiding this comment

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

fwiw this is a type alias to (), what we usually call a marker type is actually a different type, which doesn't inherit any of the impls of the original type, such as pub struct Existence

/// Encodes as type [`Existence`] but can decode from legacy [`Exposure`] values for backward
/// compatibility.
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, RuntimeDebug, TypeInfo, DecodeWithMemTracking)]
pub enum ExistenceOrLegacyExposure<A, B: HasCompact> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could have just used Option but this is more readable.


/// A converter type that returns `Some(())` if the validator exists in the current active era,
/// otherwise `None`. This serves as a lightweight presence check for validators.
pub struct ExistenceOf<T>(core::marker::PhantomData<T>);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move this to stkaing-next branch, right?

staking-classic only needs ExistenceOrLegacyExposureOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need them only in staking-classic, right? Staking-next does not interact with historical sessions atleast directly?

We don't strictly need ExistenceOf. But seemed a nice thing to have. New solo chains can choose ExistenceOf instead of ExistenceOrLegacyExposureOf .

@@ -1775,12 +1756,12 @@ impl<T: Config> historical::SessionManager<T::AccountId, Exposure<T::AccountId,
}
}

impl<T: Config> historical::SessionManager<T::AccountId, ()> for Pallet<T> {
fn new_session(new_index: SessionIndex) -> Option<Vec<(T::AccountId, ())>> {
impl<T: Config> historical::SessionManager<T::AccountId, Existence> for Pallet<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, this code will be removed once we revert #7937

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 can get rid of them here as well. They are used by the test runtimes.

kianenigma
kianenigma previously approved these changes Mar 16, 2025
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Should wait for #7937 before being merged, otherwise LGTM.

Comment on lines +1515 to +1522
assert!(matches!(
decoded_legacy_exposure,
ExistenceOrLegacyExposure::Exposure(Exposure {
total: 1,
own: 2,
others: ref i
}) if *i == vec![IndividualExposure { who: 3, value: 4 }]
));
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
assert!(matches!(
decoded_legacy_exposure,
ExistenceOrLegacyExposure::Exposure(Exposure {
total: 1,
own: 2,
others: ref i
}) if *i == vec![IndividualExposure { who: 3, value: 4 }]
));
assert_eq!(
decoded_legacy_exposure,
ExistenceOrLegacyExposure::Exposure(Exposure {
total: 1,
own: 2,
others: vec![IndividualExposure { who: 3, value: 4 }]
}
));

nit: I think marches! gives worst errors messages + is harder to write and read, unless if you want to skip some fields, which makes it worthwhile.

}

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

Choose a reason for hiding this comment

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

Also you are missing a test to make sure () can be decoded as ExistenceOrLegacyExposure


impl<A, B: HasCompact> MaxEncodedLen for ExistenceOrLegacyExposure<A, B> {
fn max_encoded_len() -> usize {
0
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
0
Exposure::<A, B>::max_encoded_len()

}

impl<A, B: HasCompact> Encode for ExistenceOrLegacyExposure<A, B> {
fn encode_to<T: Output + ?Sized>(&self, _: &mut T) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should encode it the same as Exposure<A, B> right?

@kianenigma kianenigma dismissed their stale review March 16, 2025 10:32

Encoding still has issues.

AFAIK ExistenceOrLegacyExposure should:

  1. Encode equal to the old Exposure
  2. Decode both into Existence, or itself.

Namely, such that if any historical offences come in with the old proof that contains exposure, it can be decoded.

Any new offence will be generated with Existence

@iulianbarbu
Copy link
Contributor

#j uky lgsn gtop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I4-refactor Code needs refactoring. 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.

[AHM] Remove dependency to full exposure for validator identification on RC pallets
3 participants