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

refactor: remove epoch authority count #3154

Merged
merged 3 commits into from
Apr 28, 2023
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
9 changes: 1 addition & 8 deletions state-chain/cf-integration-tests/src/signer_nomination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use cf_traits::{
ThresholdSignerNomination,
};
use pallet_cf_threshold_signature::PalletOffence;
use pallet_cf_validator::{
CurrentAuthorities, CurrentEpoch, EpochAuthorityCount, HistoricalAuthorities,
};
use pallet_cf_validator::{CurrentAuthorities, CurrentEpoch, HistoricalAuthorities};
use sp_runtime::AccountId32;
use state_chain_runtime::{EthereumInstance, Reputation, Runtime, Validator};

Expand All @@ -24,10 +22,6 @@ fn threshold_signer_nomination_respects_epoch() {
let genesis_epoch = Validator::epoch_index();

assert_eq!(genesis_authorities, HistoricalAuthorities::<Runtime>::get(genesis_epoch));
assert_eq!(
genesis_authorities.len() as u32,
EpochAuthorityCount::<Runtime>::get(genesis_epoch).unwrap()
);

assert!(RuntimeThresholdSignerNomination::threshold_nomination_with_seed(
(),
Expand All @@ -48,7 +42,6 @@ fn threshold_signer_nomination_respects_epoch() {
.collect();
CurrentAuthorities::<Runtime>::put(&new_authorities);
HistoricalAuthorities::<Runtime>::insert(next_epoch, &new_authorities);
EpochAuthorityCount::<Runtime>::insert(next_epoch, new_authorities.len() as u32);
assert!(Validator::current_authorities()
.into_iter()
.all(|n| !genesis_authorities.contains(&n)));
Expand Down
19 changes: 3 additions & 16 deletions state-chain/pallets/cf-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ pub mod pallet {
AuthorityCount,
>;

/// Track epochs and their associated authority count.
#[pallet::storage]
#[pallet::getter(fn epoch_authority_count)]
pub type EpochAuthorityCount<T: Config> =
StorageMap<_, Twox64Concat, EpochIndex, AuthorityCount>;

/// The rotation phase we are currently at.
#[pallet::storage]
#[pallet::getter(fn current_rotation_phase)]
Expand Down Expand Up @@ -400,11 +394,7 @@ pub mod pallet {
match T::VaultRotator::status() {
AsyncResult::Ready(VaultStatus::KeygenComplete) => {
let new_authorities = rotation_state.authority_candidates();
HistoricalAuthorities::<T>::insert(rotation_state.new_epoch_index, new_authorities.clone());
EpochAuthorityCount::<T>::insert(
rotation_state.new_epoch_index,
new_authorities.len() as AuthorityCount,
);
HistoricalAuthorities::<T>::insert(rotation_state.new_epoch_index, new_authorities);
T::VaultRotator::activate();
Self::set_rotation_phase(RotationPhase::ActivatingKeys(rotation_state));
},
Expand Down Expand Up @@ -912,16 +902,15 @@ impl<T: Config> EpochInfo for Pallet<T> {
) <= frame_system::Pallet::<T>::current_block_number()
}

fn authority_count_at_epoch(epoch: EpochIndex) -> Option<AuthorityCount> {
EpochAuthorityCount::<T>::get(epoch)
fn authority_count_at_epoch(epoch_index: EpochIndex) -> Option<AuthorityCount> {
HistoricalAuthorities::<T>::decode_len(epoch_index).map(|l| l as AuthorityCount)
}

#[cfg(feature = "runtime-benchmarks")]
fn add_authority_info_for_epoch(
epoch_index: EpochIndex,
new_authorities: BTreeSet<Self::ValidatorId>,
) {
EpochAuthorityCount::<T>::insert(epoch_index, new_authorities.len() as AuthorityCount);
for (i, authority) in new_authorities.iter().enumerate() {
AuthorityIndex::<T>::insert(epoch_index, authority, i as AuthorityCount);
HistoricalActiveEpochs::<T>::append(authority, epoch_index);
Expand Down Expand Up @@ -1028,8 +1017,6 @@ impl<T: Config> Pallet<T> {
T::Bonder::update_bond(account_id, EpochHistory::<T>::active_bond(account_id));
});

EpochAuthorityCount::<T>::insert(new_epoch, new_authorities.len() as AuthorityCount);

CurrentEpochStartedAt::<T>::set(frame_system::Pallet::<T>::current_block_number());

HistoricalBonds::<T>::insert(new_epoch, new_bond);
Expand Down
7 changes: 3 additions & 4 deletions state-chain/runtime/src/chainflip/decompose_recompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ mod tests {
(0..calls.len()).map(|i| [i as u8; 32].into()).collect::<BTreeSet<_>>();
let current_epoch = 1;
pallet_cf_validator::CurrentEpoch::<Runtime>::put(current_epoch);
pallet_cf_validator::CurrentAuthorities::<Runtime>::put(&authorities);
pallet_cf_validator::EpochAuthorityCount::<Runtime>::insert(
<Validator as EpochInfo>::epoch_index(),
authorities.len() as u32,
pallet_cf_validator::HistoricalAuthorities::<Runtime>::insert(
current_epoch,
&authorities,
);

for (index, authority_id) in authorities.into_iter().enumerate() {
Expand Down