Skip to content

Commit

Permalink
Remove declare synced
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Oct 23, 2024
1 parent 49db744 commit 19ebc47
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 111 deletions.
11 changes: 2 additions & 9 deletions pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use frame_system::{EventRecord, RawOrigin};
use pallet_programs::{ProgramInfo, Programs};
use pallet_session::Validators;
use pallet_staking_extension::{
benchmarking::create_validators, IsValidatorSynced, JumpStartDetails, JumpStartProgress,
JumpStartStatus, ServerInfo, ThresholdServers, ThresholdToStash,
benchmarking::create_validators, JumpStartDetails, JumpStartProgress, JumpStartStatus,
ServerInfo, ThresholdServers, ThresholdToStash,
};
use sp_runtime::traits::Hash;
use sp_std::{vec, vec::Vec};
Expand All @@ -48,7 +48,6 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {

pub fn add_non_syncing_validators<T: Config>(
validator_amount: u32,
syncing_validators: u32,
) -> Vec<<T as pallet_session::Config>::ValidatorId> {
let validators = create_validators::<T>(validator_amount, SEED);
let account = account::<T::AccountId>("ts_account", 1, SEED);
Expand All @@ -60,12 +59,6 @@ pub fn add_non_syncing_validators<T: Config>(
};
for (c, validator) in validators.iter().enumerate() {
<ThresholdServers<T>>::insert(validator, server_info.clone());
if c >= syncing_validators.try_into().unwrap() {
<IsValidatorSynced<T>>::insert(validator, true);
}
}
if syncing_validators == validator_amount {
<IsValidatorSynced<T>>::insert(&validators[0], true);
}
validators
}
Expand Down
12 changes: 1 addition & 11 deletions pallets/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ benchmarks! {
let block_number = 1;
let nonce = NULL_ARR;
let x25519_public_key = NULL_ARR;
let endpoint = b"http://localhost:3001".to_vec();
let endpoint = vec![];
let validate_also = false;

prep_bond_and_validate::<T>(
Expand Down Expand Up @@ -336,16 +336,6 @@ benchmarks! {
);
}

declare_synced {
let caller: T::AccountId = whitelisted_caller();
let validator_id_res = <T as pallet_session::Config>::ValidatorId::try_from(caller.clone()).or(Err(Error::<T>::InvalidValidatorId)).unwrap();
ThresholdToStash::<T>::insert(caller.clone(), validator_id_res.clone());

}: _(RawOrigin::Signed(caller.clone()), true)
verify {
assert_last_event::<T>(Event::<T>::ValidatorSyncStatus(validator_id_res, true).into());
}

confirm_key_reshare_confirmed {
let c in 0 .. MAX_SIGNERS as u32;
// leave a space for two as not to rotate and only confirm rotation
Expand Down
25 changes: 0 additions & 25 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ pub mod pallet {
pub type ThresholdToStash<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::ValidatorId, OptionQuery>;

/// Tracks wether the validator's kvdb is synced using a stash key as an identifier
#[pallet::storage]
#[pallet::getter(fn is_validator_synced)]
pub type IsValidatorSynced<T: Config> = StorageMap<
_,
Blake2_128Concat,
<T as pallet_session::Config>::ValidatorId,
bool,
ValueQuery,
>;

#[derive(
Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen, Default,
)]
Expand Down Expand Up @@ -278,7 +267,6 @@ pub mod pallet {

ThresholdServers::<T>::insert(validator_stash, server_info.clone());
ThresholdToStash::<T>::insert(&server_info.tss_account, validator_stash);
IsValidatorSynced::<T>::insert(validator_stash, true);
}

let refresh_info = RefreshInfo {
Expand Down Expand Up @@ -485,7 +473,6 @@ pub mod pallet {
let server_info =
ThresholdServers::<T>::take(&validator_id).ok_or(Error::<T>::NoThresholdKey)?;
ThresholdToStash::<T>::remove(&server_info.tss_account);
IsValidatorSynced::<T>::remove(&validator_id);
Self::deposit_event(Event::NodeInfoRemoved(controller));
}
Ok(Some(<T as Config>::WeightInfo::withdraw_unbonded(
Expand Down Expand Up @@ -559,18 +546,6 @@ pub mod pallet {
Ok(())
}

/// Let a validator declare if their kvdb is synced or not synced
/// `synced`: State of validator's kvdb
#[pallet::call_index(6)]
#[pallet::weight(<T as Config>::WeightInfo::declare_synced())]
pub fn declare_synced(origin: OriginFor<T>, synced: bool) -> DispatchResult {
let who = ensure_signed(origin.clone())?;
let stash = Self::threshold_to_stash(who).ok_or(Error::<T>::NoThresholdKey)?;
IsValidatorSynced::<T>::insert(&stash, synced);
Self::deposit_event(Event::ValidatorSyncStatus(stash, synced));
Ok(())
}

#[pallet::call_index(7)]
#[pallet::weight(({
<T as Config>::WeightInfo::confirm_key_reshare_confirmed(MAX_SIGNERS as u32)
Expand Down
26 changes: 1 addition & 25 deletions pallets/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
mock::*, tests::RuntimeEvent, Error, IsValidatorSynced, NextSignerInfo, NextSigners,
ServerInfo, Signers, ThresholdToStash,
mock::*, tests::RuntimeEvent, Error, NextSignerInfo, NextSigners, ServerInfo, Signers,
};
use codec::Encode;
use frame_support::{assert_noop, assert_ok};
Expand Down Expand Up @@ -49,8 +48,6 @@ fn basic_setup_works() {
);
assert_eq!(Staking::threshold_to_stash(7).unwrap(), 5);
assert_eq!(Staking::threshold_to_stash(8).unwrap(), 6);
assert!(Staking::is_validator_synced(5));
assert!(Staking::is_validator_synced(6));
});
}

Expand Down Expand Up @@ -325,8 +322,6 @@ fn it_deletes_when_no_bond_left() {
VALID_QUOTE.to_vec(),
));

IsValidatorSynced::<Test>::insert(2, true);

let ServerInfo { tss_account, endpoint, .. } = Staking::threshold_server(2).unwrap();
assert_eq!(endpoint, vec![20]);
assert_eq!(tss_account, 3);
Expand Down Expand Up @@ -359,8 +354,6 @@ fn it_deletes_when_no_bond_left() {
lock = Balances::locks(2);
assert_eq!(lock[0].amount, 50);
assert_eq!(lock.len(), 1);
// validator still synced
assert_eq!(Staking::is_validator_synced(2), true);

let ServerInfo { tss_account, endpoint, .. } = Staking::threshold_server(2).unwrap();
assert_eq!(endpoint, vec![20]);
Expand All @@ -377,8 +370,6 @@ fn it_deletes_when_no_bond_left() {
assert_eq!(lock.len(), 0);
assert_eq!(Staking::threshold_server(2), None);
assert_eq!(Staking::threshold_to_stash(3), None);
// validator no longer synced
assert_eq!(Staking::is_validator_synced(2), false);

assert_ok!(FrameStaking::bond(
RuntimeOrigin::signed(7),
Expand Down Expand Up @@ -425,21 +416,6 @@ fn it_deletes_when_no_bond_left() {
});
}

#[test]
fn it_declares_synced() {
new_test_ext().execute_with(|| {
assert_noop!(
Staking::declare_synced(RuntimeOrigin::signed(5), true),
Error::<Test>::NoThresholdKey
);

ThresholdToStash::<Test>::insert(5, 5);

assert_ok!(Staking::declare_synced(RuntimeOrigin::signed(5), true));
assert!(Staking::is_validator_synced(5));
});
}

#[test]
fn it_tests_new_session_handler() {
new_test_ext().execute_with(|| {
Expand Down
27 changes: 0 additions & 27 deletions pallets/staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub trait WeightInfo {
fn unbond(c: u32, n: u32) -> Weight;
fn withdraw_unbonded(c: u32, n: u32) -> Weight;
fn validate() -> Weight;
fn declare_synced() -> Weight;
fn confirm_key_reshare_confirmed(c: u32) -> Weight;
fn confirm_key_reshare_completed() -> Weight;
fn new_session_base_weight(s: u32) -> Weight;
Expand Down Expand Up @@ -254,19 +253,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::IsValidatorSynced` (r:0 w:1)
/// Proof: `StakingExtension::IsValidatorSynced` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn declare_synced() -> Weight {
// Proof Size summary in bytes:
// Measured: `285`
// Estimated: `3750`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(13_000_000, 3750)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::NextSigners` (r:1 w:1)
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 2]`.
Expand Down Expand Up @@ -529,19 +515,6 @@ impl WeightInfo for () {
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::IsValidatorSynced` (r:0 w:1)
/// Proof: `StakingExtension::IsValidatorSynced` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn declare_synced() -> Weight {
// Proof Size summary in bytes:
// Measured: `285`
// Estimated: `3750`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(13_000_000, 3750)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::NextSigners` (r:1 w:1)
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 2]`.
Expand Down
14 changes: 0 additions & 14 deletions runtime/src/weights/pallet_staking_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,6 @@ impl<T: frame_system::Config> pallet_staking_extension::WeightInfo for WeightInf
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::IsValidatorSynced` (r:0 w:1)
/// Proof: `StakingExtension::IsValidatorSynced` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn declare_synced() -> Weight {
// Proof Size summary in bytes:
// Measured: `353`
// Estimated: `3818`
// Minimum execution time: 16_110_000 picoseconds.
Weight::from_parts(16_488_000, 0)
.saturating_add(Weight::from_parts(0, 3818))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `StakingExtension::ThresholdToStash` (r:1 w:0)
/// Proof: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `StakingExtension::NextSigners` (r:1 w:1)
/// Proof: `StakingExtension::NextSigners` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 15]`.
Expand Down

0 comments on commit 19ebc47

Please sign in to comment.