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

Remove declare synced #1134

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
17 changes: 5 additions & 12 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>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we rename this then to just add_validators?

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 @@ -58,14 +57,8 @@ pub fn add_non_syncing_validators<T: Config>(
endpoint: vec![20],
provisioning_certification_key: BoundedVec::with_max_capacity(),
};
for (c, validator) in validators.iter().enumerate() {
for validator in &validators {
<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 Expand Up @@ -93,7 +86,7 @@ benchmarks! {
accounts.push(account::<T::AccountId>("ts_account", i as u32, SEED));
}

let validators = add_non_syncing_validators::<T>(MAX_SIGNERS as u32, 0);
let validators = add_non_syncing_validators::<T>(MAX_SIGNERS as u32);
<Validators<T>>::set(validators.clone());

for i in 0..MAX_SIGNERS {
Expand Down Expand Up @@ -132,7 +125,7 @@ benchmarks! {

// add validators
for i in 0..MAX_SIGNERS {
let validators = add_non_syncing_validators::<T>(MAX_SIGNERS as u32, 0);
let validators = add_non_syncing_validators::<T>(MAX_SIGNERS as u32);
<Validators<T>>::set(validators.clone());
<ThresholdToStash<T>>::insert(&threshold_account, &validators[i as usize]);
}
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![];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

so there are two ways to run benches

compile then run them (like in our scripts) this is the more closer to production way
or the easier way run them with cargo test --features=runtime-benchmarks

the first uses the runtime config sets

the second uses the mocks

So this would pass the first not the second, now it passes both

Copy link
Collaborator

Choose a reason for hiding this comment

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

@JesseAbram I thought I bumped the max length to account for this, no? If not, can you bump it to like 25 bytes, it helps makes the test more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

mmm pretty sure that would effect other tests

Copy link
Member Author

Choose a reason for hiding this comment

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

also wtv, changed

Copy link
Collaborator

@HCastano HCastano Oct 23, 2024

Choose a reason for hiding this comment

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

Ah sorry, I did change this but in #1123 which is still a draft PR 😅

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)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might as well bite the bullet here and make it a transaction_version bump by changing this to 6

#[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
Loading