Skip to content

Commit

Permalink
Add prune_registration extrinsic (#472)
Browse files Browse the repository at this point in the history
* add prune registration extrinsic

* add benchmarks

* fix benchmark script

* inline docs

* add to changelog

* Update pallets/relayer/src/lib.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* fix changelog

* return program deposit

* remove prune block

* Update CHANGELOG.md

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Update pallets/relayer/src/lib.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Update pallets/relayer/src/lib.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* refactor

---------

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
  • Loading branch information
JesseAbram and HCastano authored Nov 4, 2023
1 parent 90d5226 commit 5ea3ba1
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 44 deletions.
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 (e.g if DKG fails).

### 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
2 changes: 0 additions & 2 deletions pallets/propagation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,10 @@ impl pallet_authorship::Config for Test {
}

parameter_types! {
pub const PruneBlock: u64 = 2;
pub const SigningPartySize: usize = 2;
}

impl pallet_relayer::Config for Test {
type PruneBlock = PruneBlock;
type RuntimeEvent = RuntimeEvent;
type SigningPartySize = SigningPartySize;
type WeightInfo = ();
Expand Down
20 changes: 17 additions & 3 deletions pallets/relayer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ 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> {
program_modification_account: sig_req_account.clone(),
confirmations: vec![],
program: vec![],
key_visibility: KeyVisibility::Public,
verifying_key: Some(BoundedVec::default())
});
}: _(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 +99,6 @@ benchmarks! {
}

<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
is_registering: true,
program_modification_account: sig_req_account.clone(),
confirmations: vec![],
program: vec![],
Expand Down Expand Up @@ -111,7 +127,6 @@ 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,
program_modification_account: sig_req_account.clone(),
confirmations: confirmation,
program: vec![],
Expand Down Expand Up @@ -140,7 +155,6 @@ 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,
program_modification_account: sig_req_account.clone(),
confirmations: confirmation,
program: vec![],
Expand Down
23 changes: 20 additions & 3 deletions pallets/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub mod pallet {
{
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type PruneBlock: Get<BlockNumberFor<Self>>;
type SigningPartySize: Get<usize>;
/// The weight information of this pallet.
type WeightInfo: WeightInfo;
Expand All @@ -74,7 +73,6 @@ 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 program_modification_account: T::AccountId,
pub confirmations: Vec<u8>,
pub program: Vec<u8>,
Expand Down Expand Up @@ -153,6 +151,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 Down Expand Up @@ -226,7 +226,6 @@ pub mod pallet {
Registering::<T>::insert(
&sig_req_account,
RegisteringDetails::<T> {
is_registering: true,
program_modification_account,
confirmations: vec![],
program: initial_program,
Expand All @@ -243,6 +242,24 @@ 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)?;
// return program deposit
ProgramsPallet::<T>::unreserve_program_deposit(
&registering_info.program_modification_account,
registering_info.program.len(),
);
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
2 changes: 0 additions & 2 deletions pallets/relayer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,10 @@ impl pallet_authorship::Config for Test {
}

parameter_types! {
pub const PruneBlock: u64 = 3;
pub const SigningPartySize: usize = 2;
}

impl pallet_relayer::Config for Test {
type PruneBlock = PruneBlock;
type RuntimeEvent = RuntimeEvent;
type SigningPartySize = SigningPartySize;
type WeightInfo = ();
Expand Down
23 changes: 20 additions & 3 deletions pallets/relayer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use entropy_shared::KeyVisibility;
use frame_support::{
assert_noop, assert_ok,
dispatch::{GetDispatchInfo, Pays},
traits::Currency,
BoundedVec,
};
use pallet_programs::AllowedToModifyProgram;
Expand Down Expand Up @@ -64,8 +65,6 @@ fn it_registers_a_user() {
KeyVisibility::Public,
empty_program,
));

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

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

#[test]
fn it_tests_prune_registration() {
new_test_ext().execute_with(|| {
let inital_program = vec![10];
Balances::make_free_balance_be(&2, 100);
// register a user
assert_ok!(Relayer::register(
RuntimeOrigin::signed(1),
2,
KeyVisibility::Permissioned,
inital_program,
));
assert_eq!(Balances::free_balance(2), 95, "Deposit is charged");
assert!(Relayer::registering(1).is_some(), "Make sure there is registering state");
assert_ok!(Relayer::prune_registration(RuntimeOrigin::signed(1)));
assert_eq!(Relayer::registering(1), None, "Make sure registering is pruned");
assert_eq!(Balances::free_balance(2), 100, "Deposit is returned");
});
}
#[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: 0 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,12 +1272,10 @@ impl pallet_slashing::Config for Runtime {
}

parameter_types! {
pub const PruneBlock: BlockNumber = 10;
pub const SigningPartySize: usize = SIGNING_PARTY_SIZE;
}

impl pallet_relayer::Config for Runtime {
type PruneBlock = PruneBlock;
type RuntimeEvent = RuntimeEvent;
type SigningPartySize = SigningPartySize;
type WeightInfo = weights::pallet_relayer::WeightInfo<Runtime>;
Expand Down
58 changes: 34 additions & 24 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-03, 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 @@ -45,13 +45,25 @@ impl<T: frame_system::Config> pallet_relayer::WeightInfo for WeightInfo<T> {
// Measured: `133`
// Estimated: `3598`
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(15_700_000, 0)
Weight::from_parts(16_300_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: 55
.saturating_add(Weight::from_parts(563, 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: 13_000_000 picoseconds.
Weight::from_parts(15_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,13 +73,13 @@ 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`
// 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
.saturating_add(Weight::from_parts(500_000, 0).saturating_mul(c.into()))
// Measured: `16502`
// Estimated: `19967`
// Minimum execution time: 27_000_000 picoseconds.
Weight::from_parts(28_083_333, 0)
.saturating_add(Weight::from_parts(0, 19967))
// Standard Error: 401_818
.saturating_add(Weight::from_parts(750_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(28_583_333, 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`
// Minimum execution time: 29_000_000 picoseconds.
Weight::from_parts(29_833_333, 0)
.saturating_add(Weight::from_parts(0, 19965))
// Measured: `16503`
// Estimated: `19968`
// Minimum execution time: 31_000_000 picoseconds.
Weight::from_parts(33_750_000, 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 \
--wasm-execution=compiled \
--pallet=$p \
--extrinsic='*' \
Expand Down

0 comments on commit 5ea3ba1

Please sign in to comment.