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

Add ValidatorSubgroupRotated event #618

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ At the moment this project **does not** adhere to

## [[Unreleased]](https://github.com/entropyxyz/entropy-core/compare/release/v0.0.10...master)

### Added
- Add ValidatorSubgroupRotated event ([#618](https://github.com/entropyxyz/entropy-core/pull/618))

## [0.0.10](https://github.com/entropyxyz/entropy-core/compare/release/v0.0.9...release/v0.0.10) - 2024-01-24

A lot of the changes introduced in this release are program related.
Expand Down
13 changes: 12 additions & 1 deletion pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

//! Benchmarking setup for pallet-propgation
#![allow(unused_imports)]
use entropy_shared::SIGNING_PARTY_SIZE;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
assert_ok, ensure,
Expand Down Expand Up @@ -178,7 +179,11 @@ benchmarks! {
let current_validators = create_validators::<T>(c, SEED);
let new_validators = create_validators::<T>(n, SEED_2);
let _ =Staking::<T>::new_session_handler(&current_validators);

let mut current_subgroups: Vec<Vec<<T as pallet_session::Config>::ValidatorId>> = vec![];
for signing_group in 0..SIGNING_PARTY_SIZE {
let current_subgroup = SigningGroups::<T>::get(signing_group as u8).unwrap();
current_subgroups.push(current_subgroup)
};
Comment on lines +182 to +186
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to update the benches in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

2 reasons, one is we test events in benchmarks but the second and worse reason is that john wrote these tests in python and the rust test is gone, imma rewrite the test in rust but that I wanna get this in fast to fix testnet things so made an issue #620

}: {
let _ = Staking::<T>::new_session_handler(&new_validators);
} verify {
Expand All @@ -188,6 +193,12 @@ benchmarks! {
assert!(!new_validators.contains(&one_current_validator[0]));
}
} else {
let mut new_subgroups: Vec<Vec<<T as pallet_session::Config>::ValidatorId>> = vec![];
for signing_group in 0..SIGNING_PARTY_SIZE {
let new_subgroup = SigningGroups::<T>::get(signing_group as u8).unwrap();
new_subgroups.push(new_subgroup)
};
assert_last_event::<T>(Event::<T>::ValidatorSubgroupsRotated(current_subgroups, new_subgroups).into());
assert!(new_validators.contains(&one_current_validator[0]));
}
}
Expand Down
10 changes: 9 additions & 1 deletion pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ pub mod pallet {
NodeInfoRemoved(T::AccountId),
/// Validator sync status changed [who, sync_status]
ValidatorSyncStatus(<T as pallet_session::Config>::ValidatorId, bool),
/// Validators subgroups rotated [old, new]
ValidatorSubgroupsRotated(
Vec<Vec<<T as pallet_session::Config>::ValidatorId>>,
Vec<Vec<<T as pallet_session::Config>::ValidatorId>>,
),
}

#[pallet::call]
Expand Down Expand Up @@ -425,7 +430,6 @@ pub mod pallet {
unplaced_validators_set.push(new_validator.clone());
}
}

// Evenly distribute new validators.
while let Some(curr) = unplaced_validators_set.pop() {
let mut min_sg_len = u64::MAX;
Expand All @@ -445,6 +449,10 @@ pub mod pallet {
pallet_staking_extension::SigningGroups::<T>::remove(sg as u8);
pallet_staking_extension::SigningGroups::<T>::insert(sg as u8, vs);
}
Self::deposit_event(Event::ValidatorSubgroupsRotated(
curr_validators_set.clone(),
new_validators_set.clone(),
));
frame_system::Pallet::<T>::register_extra_weight_unchecked(
<T as pallet::Config>::WeightInfo::new_session_handler_helper(
curr_validators_set.len() as u32,
Expand Down