-
Notifications
You must be signed in to change notification settings - Fork 857
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
base: master
Are you sure you want to change the base?
Conversation
Exposure
to Existence
/cmd prdoc --force |
All GitHub workflows were cancelled due to failure one of the required jobs. |
fn convert(_: T) -> Option<()> { | ||
Some(()) | ||
/// A marker type representing the presence of a validator. Encodes as a unit type. | ||
pub type Existence = (); |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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>); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
assert!(matches!( | ||
decoded_legacy_exposure, | ||
ExistenceOrLegacyExposure::Exposure(Exposure { | ||
total: 1, | ||
own: 2, | ||
others: ref i | ||
}) if *i == vec![IndividualExposure { who: 3, value: 4 }] | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) {} |
There was a problem hiding this comment.
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?
Encoding still has issues.
AFAIK ExistenceOrLegacyExposure
should:
- Encode equal to the old
Exposure
- 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
#j uky lgsn gtop |
closes #6344.
TODO