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 prune_registration extrinsic #472

Merged
merged 14 commits into from
Nov 4, 2023
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ Some notables changes introduced in [#428](https://github.com/entropyxyz/entropy
- The Constraints pallet has been renamed to the Programs pallet

### Added
- Add way for validators to resolve diff verifying keys ([#460](https://github.com/entropyxyz/entropy-core/pull/460))
- This introduces a new `FailedRegistration` event which might be of interest to consumers of this
pallet.
- Proactive refresh ([#413](https://github.com/entropyxyz/entropy-core/pull/413))
- Write a Dockerfile that can build both `entropy` and `server`. ([#430](https://github.com/entropyxyz/entropy-core/pull/430))
- Developer experience improvements: SSH auth from workstations, entirely local "devnet"
functionality with Compose ([#434](https://github.com/entropyxyz/entropy-core/pull/434))
- Allow local host pass for offchain url ([#443](https://github.com/entropyxyz/entropy-core/pull/443))
- Add way for validators to resolve diff verifying keys ([#460](https://github.com/entropyxyz/entropy-core/pull/460))
- This introduces a new `FailedRegistration` event which might be of interest to consumers of this
pallet.
- Add prune_registration extrinsic ([#472](https://github.com/entropyxyz/entropy-core/pull/472))
- allows for accounts to be moved out of registering state if dkg fails
JesseAbram marked this conversation as resolved.
Show resolved Hide resolved

### Changed
- Replace outdated `--ws-external` with `--rpc-external` ([#424](https://github.com/entropyxyz/entropy-core/pull/424))
Expand Down
Binary file modified crypto/server/entropy_metadata.scale
Binary file not shown.
2 changes: 1 addition & 1 deletion crypto/server/src/helpers/substrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub async fn make_register(
let block_hash_2 = rpc.chain_get_block_hash(None).await.unwrap().unwrap();

let query_registering_status = api.storage().at(block_hash_2).fetch(&registering_query).await;
assert!(query_registering_status.unwrap().unwrap().is_registering);
assert!(query_registering_status.unwrap().is_some());
}

/// Returns wether an account is registered
Expand Down
25 changes: 22 additions & 3 deletions pallets/relayer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ benchmarks! {
assert!(Registering::<T>::contains_key(sig_req_account));
}

prune_registration {
let program_modification_account: T::AccountId = whitelisted_caller();
let sig_req_account: T::AccountId = whitelisted_caller();
let balance = <T as pallet_staking_extension::Config>::Currency::minimum_balance() * 100u32.into();
let _ = <T as pallet_staking_extension::Config>::Currency::make_free_balance_be(&sig_req_account, balance);
<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
registration_block: 0u32.into(),
program_modification_account: sig_req_account.clone(),
confirmations: vec![],
program: vec![],
key_visibility: KeyVisibility::Public,
verifying_key: Some(BoundedVec::default())
});
frame_system::Pallet::<T>::set_block_number(25u32.into());
}: _(RawOrigin::Signed(sig_req_account.clone()))
verify {
assert_last_event::<T>(Event::RegistrationCancelled(sig_req_account.clone()).into());
}

confirm_register_registering {
let c in 0 .. SIG_PARTIES as u32;
let sig_req_account: T::AccountId = whitelisted_caller();
Expand All @@ -82,7 +101,7 @@ benchmarks! {
}

<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
is_registering: true,
registration_block: 0u32.into(),
program_modification_account: sig_req_account.clone(),
confirmations: vec![],
program: vec![],
Expand Down Expand Up @@ -111,7 +130,7 @@ benchmarks! {
let adjusted_sig_size = SIG_PARTIES - 1;
let confirmation: Vec<u8> = (1u8..=adjusted_sig_size.try_into().unwrap()).collect();
<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
is_registering: true,
registration_block: 0u32.into(),
program_modification_account: sig_req_account.clone(),
confirmations: confirmation,
program: vec![],
Expand Down Expand Up @@ -140,7 +159,7 @@ confirm_register_registered {
let adjusted_sig_size = SIG_PARTIES - 1;
let confirmation: Vec<u8> = (1u8..=adjusted_sig_size.try_into().unwrap()).collect();
<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
is_registering: true,
registration_block: 0u32.into(),
program_modification_account: sig_req_account.clone(),
confirmations: confirmation,
program: vec![],
Expand Down
31 changes: 28 additions & 3 deletions pallets/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ pub mod pallet {
use pallet_programs::{AllowedToModifyProgram, Pallet as ProgramsPallet};
use pallet_staking_extension::ServerInfo;
use scale_info::TypeInfo;
use sp_runtime::traits::{DispatchInfoOf, SignedExtension};
use sp_runtime::{
traits::{DispatchInfoOf, SignedExtension},
Saturating,
};
use sp_std::{fmt::Debug, vec};

pub use crate::weights::WeightInfo;
Expand All @@ -74,7 +77,7 @@ pub mod pallet {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct RegisteringDetails<T: Config> {
pub is_registering: bool,
pub registration_block: BlockNumberFor<T>,
HCastano marked this conversation as resolved.
Show resolved Hide resolved
pub program_modification_account: T::AccountId,
pub confirmations: Vec<u8>,
pub program: Vec<u8>,
Expand Down Expand Up @@ -153,6 +156,8 @@ pub mod pallet {
AccountRegistered(T::AccountId),
/// An account registration has failed
FailedRegistration(T::AccountId),
/// An account cancelled their registration
RegistrationCancelled(T::AccountId),
/// An account has been registered. [who, block_number, failures]
ConfirmedDone(T::AccountId, BlockNumberFor<T>, Vec<u32>),
}
Expand All @@ -172,6 +177,7 @@ pub mod pallet {
NoSyncedValidators,
MaxProgramLengthExceeded,
NoVerifyingKey,
NotLongEnough,
JesseAbram marked this conversation as resolved.
Show resolved Hide resolved
}

#[pallet::call]
Expand Down Expand Up @@ -226,7 +232,7 @@ pub mod pallet {
Registering::<T>::insert(
&sig_req_account,
RegisteringDetails::<T> {
is_registering: true,
registration_block: block_number,
program_modification_account,
confirmations: vec![],
program: initial_program,
Expand All @@ -243,6 +249,25 @@ pub mod pallet {
Ok(())
}

/// Allows a user to remove themselves from registering state if it has been longer than prune block
#[pallet::call_index(1)]
#[pallet::weight({
<T as Config>::WeightInfo::prune_registration()
})]
pub fn prune_registration(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
let registering_info = Self::registering(&who).ok_or(Error::<T>::NotRegistering)?;
let block_number = <frame_system::Pallet<T>>::block_number();
ensure!(
block_number.saturating_sub(registering_info.registration_block)
>= T::PruneBlock::get(),
Error::<T>::NotLongEnough
);
HCastano marked this conversation as resolved.
Show resolved Hide resolved
Registering::<T>::remove(&who);
Self::deposit_event(Event::RegistrationCancelled(who));
Ok(())
}

/// Allows validators to confirm that they have received a key-share from a user that is
/// in the process of registering.
///
Expand Down
26 changes: 24 additions & 2 deletions pallets/relayer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn it_registers_a_user() {
empty_program,
));

assert!(Relayer::registering(1).unwrap().is_registering);
assert_eq!(Relayer::registering(1).unwrap().registration_block, 0);
assert_eq!(Relayer::dkg(0), vec![1u64.encode()]);
});
}
Expand Down Expand Up @@ -153,7 +153,7 @@ fn it_confirms_registers_a_user() {
);

let registering_info = RegisteringDetails::<Test> {
is_registering: true,
registration_block: 0,
program_modification_account: 2 as <Test as frame_system::Config>::AccountId,
confirmations: vec![0],
program: vec![],
Expand Down Expand Up @@ -239,6 +239,28 @@ fn it_doesnt_allow_double_registering() {
});
}

#[test]
fn it_tests_prune_registration() {
new_test_ext().execute_with(|| {
let empty_program = vec![];
// register a user
assert_ok!(Relayer::register(
RuntimeOrigin::signed(1),
2,
KeyVisibility::Permissioned,
empty_program,
));
// checks to make sure it is not long enough
assert_noop!(
Relayer::prune_registration(RuntimeOrigin::signed(1)),
Error::<Test>::NotLongEnough
);
assert!(Relayer::registering(1).is_some(), "Make sure there is registering state");
System::set_block_number(5);
assert_ok!(Relayer::prune_registration(RuntimeOrigin::signed(1)));
assert_eq!(Relayer::registering(1), None, "Make sure registering is pruned");
});
}
#[test]
fn it_provides_free_txs_confirm_done() {
new_test_ext().execute_with(|| {
Expand Down
25 changes: 25 additions & 0 deletions pallets/relayer/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use core::marker::PhantomData;
/// Weight functions needed for pallet_relayer.
pub trait WeightInfo {
fn register(p: u32, ) -> Weight;
fn prune_registration() -> Weight;
fn confirm_register_registering(c: u32, ) -> Weight;
fn confirm_register_registered(c: u32, ) -> Weight;
fn confirm_register_failed_registering(c: u32, ) -> Weight;
Expand All @@ -65,6 +66,18 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `Relayer::Registering` (r:1 w:1)
/// Proof: `Relayer::Registering` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn prune_registration() -> Weight {
// Proof Size summary in bytes:
// Measured: `171`
// Estimated: `3636`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
.saturating_add(Weight::from_parts(0, 3636))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: StakingExtension ThresholdToStash (r:1 w:0)
/// Proof Skipped: StakingExtension ThresholdToStash (max_values: None, max_size: None, mode: Measured)
/// Storage: Relayer Registering (r:1 w:1)
Expand Down Expand Up @@ -144,6 +157,18 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: `Relayer::Registering` (r:1 w:1)
/// Proof: `Relayer::Registering` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn prune_registration() -> Weight {
// Proof Size summary in bytes:
// Measured: `171`
// Estimated: `3636`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
.saturating_add(Weight::from_parts(0, 3636))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
/// Storage: StakingExtension ThresholdToStash (r:1 w:0)
/// Proof Skipped: StakingExtension ThresholdToStash (max_values: None, max_size: None, mode: Measured)
/// Storage: Relayer Registering (r:1 w:1)
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ impl pallet_slashing::Config for Runtime {
}

parameter_types! {
pub const PruneBlock: BlockNumber = 10;
pub const PruneBlock: BlockNumber = 20;
HCastano marked this conversation as resolved.
Show resolved Hide resolved
pub const SigningPartySize: usize = SIGNING_PARTY_SIZE;
}

Expand Down
54 changes: 32 additions & 22 deletions runtime/src/weights/pallet_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Autogenerated weights for `pallet_relayer`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-10-30, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-02, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024
Expand Down Expand Up @@ -44,14 +44,26 @@ impl<T: frame_system::Config> pallet_relayer::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `133`
// Estimated: `3598`
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(15_700_000, 0)
// Minimum execution time: 20_000_000 picoseconds.
Weight::from_parts(15_100_000, 0)
.saturating_add(Weight::from_parts(0, 3598))
// Standard Error: 58
.saturating_add(Weight::from_parts(600, 0).saturating_mul(p.into()))
// Standard Error: 67
.saturating_add(Weight::from_parts(586, 0).saturating_mul(p.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Relayer::Registering` (r:1 w:1)
/// Proof: `Relayer::Registering` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn prune_registration() -> Weight {
// Proof Size summary in bytes:
// Measured: `171`
// Estimated: `3636`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 0)
.saturating_add(Weight::from_parts(0, 3636))
.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: `Relayer::Registering` (r:1 w:1)
Expand All @@ -61,12 +73,12 @@ impl<T: frame_system::Config> pallet_relayer::WeightInfo for WeightInfo<T> {
/// The range of component `c` is `[0, 2]`.
fn confirm_register_registering(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `16499`
// Estimated: `19964`
// Measured: `16502`
// Estimated: `19967`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(25_833_333, 0)
.saturating_add(Weight::from_parts(0, 19964))
// Standard Error: 721_687
Weight::from_parts(25_666_666, 0)
.saturating_add(Weight::from_parts(0, 19967))
// Standard Error: 338_501
.saturating_add(Weight::from_parts(500_000, 0).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -78,15 +90,13 @@ impl<T: frame_system::Config> pallet_relayer::WeightInfo for WeightInfo<T> {
/// Storage: `StakingExtension::SigningGroups` (r:1 w:0)
/// Proof: `StakingExtension::SigningGroups` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `c` is `[0, 2]`.
fn confirm_register_failed_registering(c: u32, ) -> Weight {
fn confirm_register_failed_registering(_c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `16501`
// Estimated: `19966`
// Minimum execution time: 24_000_000 picoseconds.
Weight::from_parts(24_583_333, 0)
.saturating_add(Weight::from_parts(0, 19966))
// Standard Error: 954_703
.saturating_add(Weight::from_parts(1_250_000, 0).saturating_mul(c.into()))
// Measured: `16504`
// Estimated: `19969`
// Minimum execution time: 25_000_000 picoseconds.
Weight::from_parts(26_916_666, 0)
.saturating_add(Weight::from_parts(0, 19969))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -105,11 +115,11 @@ impl<T: frame_system::Config> pallet_relayer::WeightInfo for WeightInfo<T> {
/// The range of component `c` is `[0, 2]`.
fn confirm_register_registered(_c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `16500`
// Estimated: `19965`
// Measured: `16503`
// Estimated: `19968`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(29_833_333, 0)
.saturating_add(Weight::from_parts(0, 19965))
Weight::from_parts(30_583_333, 0)
.saturating_add(Weight::from_parts(0, 19968))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(4))
}
Expand Down
1 change: 0 additions & 1 deletion scripts/benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ for p in ${pallets[@]}
do
./target/release/entropy benchmark pallet \
--chain $entropyChain \
--execution=wasm \
HCastano marked this conversation as resolved.
Show resolved Hide resolved
--wasm-execution=compiled \
--pallet=$p \
--extrinsic='*' \
Expand Down