mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 12:11:09 +00:00
Slash and prove membership of prior sessions (#2970)
* skeleton for tracking historical sessions * refactor OpaqueKeys * some more skeleton work * adjust session to new OpaqueKeys API * further refactoring of key-type-ids * session gets validator ID parameter * run up against compiler * tweak staking to support new session changes * first run at child storage for deduplication * Make session use `AccountId` as `ValidatorId` * run up against child trie issues * switch to using normal trie but with a fixed prefix * clear out some println * add dedup test * flesh out historical module more * introduce ExposureOf for staking * test the historical module * WASM compiles * tests all compile * do some mock change * fix bulk of tests * fix staking tests * test obsolecence mechanic * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * some more style nits * a couple more nits * tweak tries * fix typo thie -> this
This commit is contained in:
committed by
GitHub
parent
bb7ff32e77
commit
7df8e52cfe
@@ -52,23 +52,24 @@ thread_local! {
|
||||
pub struct TestSessionHandler;
|
||||
impl session::SessionHandler<AccountId> for TestSessionHandler {
|
||||
fn on_new_session<Ks: OpaqueKeys>(_changed: bool, validators: &[(AccountId, Ks)]) {
|
||||
SESSION.with(|x|
|
||||
SESSION.with(|x| {
|
||||
let v = validators.iter().map(|(ref a, _)| a).cloned().collect::<Vec<_>>();
|
||||
*x.borrow_mut() = (validators.iter().map(|x| x.0.clone()).collect(), HashSet::new())
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
fn on_disabled(validator_index: usize) {
|
||||
SESSION.with(|d| {
|
||||
let mut d = d.borrow_mut();
|
||||
let value = d.0[validator_index];
|
||||
println!("on_disabled {} -> {}", validator_index, value);
|
||||
d.1.insert(value);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_disabled(validator: AccountId) -> bool {
|
||||
SESSION.with(|d| d.borrow().1.contains(&validator))
|
||||
let stash = Staking::ledger(&validator).unwrap().stash;
|
||||
SESSION.with(|d| d.borrow().1.contains(&stash))
|
||||
}
|
||||
|
||||
pub struct ExistentialDeposit;
|
||||
@@ -103,7 +104,7 @@ parameter_types! {
|
||||
pub const TransactionByteFee: u64 = 0;
|
||||
}
|
||||
impl balances::Trait for Test {
|
||||
type Balance = u64;
|
||||
type Balance = Balance;
|
||||
type OnFreeBalanceZero = Staking;
|
||||
type OnNewAccount = ();
|
||||
type Event = ();
|
||||
@@ -121,13 +122,21 @@ parameter_types! {
|
||||
pub const Offset: BlockNumber = 0;
|
||||
}
|
||||
impl session::Trait for Test {
|
||||
type OnSessionEnding = Staking;
|
||||
type OnSessionEnding = session::historical::NoteHistoricalRoot<Test, Staking>;
|
||||
type Keys = UintAuthorityId;
|
||||
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
|
||||
type SessionHandler = TestSessionHandler;
|
||||
type Event = ();
|
||||
type ValidatorId = AccountId;
|
||||
type ValidatorIdOf = crate::StashOf<Test>;
|
||||
type SelectInitialValidators = Staking;
|
||||
}
|
||||
|
||||
impl session::historical::Trait for Test {
|
||||
type FullIdentification = crate::Exposure<AccountId, Balance>;
|
||||
type FullIdentificationOf = crate::ExposureOf<Test>;
|
||||
}
|
||||
|
||||
impl timestamp::Trait for Test {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
@@ -145,6 +154,7 @@ impl Trait for Test {
|
||||
type Reward = ();
|
||||
type SessionsPerEra = SessionsPerEra;
|
||||
type BondingDuration = BondingDuration;
|
||||
type SessionInterface = Self;
|
||||
}
|
||||
|
||||
pub struct ExtBuilder {
|
||||
@@ -216,7 +226,7 @@ impl ExtBuilder {
|
||||
|
||||
let num_validators = self.num_validators.unwrap_or(self.validator_count);
|
||||
let validators = (0..num_validators)
|
||||
.map(|x| ((x + 1) * 10) as u64)
|
||||
.map(|x| ((x + 1) * 10 + 1) as u64)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let _ = balances::GenesisConfig::<Test>{
|
||||
@@ -360,6 +370,7 @@ pub fn start_session(session_index: session::SessionIndex) {
|
||||
System::set_block_number((i + 1).into());
|
||||
Session::on_initialize(System::block_number());
|
||||
}
|
||||
|
||||
assert_eq!(Session::current_index(), session_index);
|
||||
}
|
||||
|
||||
@@ -367,3 +378,7 @@ pub fn start_era(era_index: EraIndex) {
|
||||
start_session((era_index * 3).into());
|
||||
assert_eq!(Staking::current_era(), era_index);
|
||||
}
|
||||
|
||||
pub fn validator_controllers() -> Vec<AccountId> {
|
||||
Session::validators().into_iter().map(|s| Staking::bonded(&s).expect("no controller for validator")).collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user