Skip to content

Commit

Permalink
Remove prune_registration extrinsic (#1022)
Browse files Browse the repository at this point in the history
* Remove `prune_registration` extrinsic

* Update call indices

* Remove test code

* Remove benchmarking code

* Remove unused import

* Add `CHANGELOG` entry

* Bump metadata
  • Loading branch information
HCastano authored Aug 22, 2024
1 parent 43123e7 commit 260e953
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 146 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ At the moment this project **does not** adhere to
### Changed
- Fix TSS `AccountId` keys in chainspec ([#993](https://github.com/entropyxyz/entropy-core/pull/993))

### Removed
- Remove `prune_registration` extrinsic ([#1022](https://github.com/entropyxyz/entropy-core/pull/1022))

## [0.2.0](https://github.com/entropyxyz/entropy-core/compare/release/v0.1.0...release/v0.2.0) - 2024-07-11

### Breaking Changes
Expand Down
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
28 changes: 0 additions & 28 deletions pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,34 +251,6 @@ benchmarks! {
assert!(RegisteredOnChain::<T>::contains_key(expected_verifying_key));
}

prune_registration {
let p in 1 .. T::MaxProgramHashes::get();
let program_modification_account: T::AccountId = whitelisted_caller();
let program = vec![0u8];
let configuration_schema = vec![1u8];
let auxiliary_data_schema = vec![2u8];
let oracle_data_pointer = vec![3u8];
let program_hash = T::Hashing::hash(&program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
program_pointer: program_hash,
program_config: vec![],
}]).unwrap();
Programs::<T>::insert(program_hash, ProgramInfo {bytecode: program, configuration_schema, auxiliary_data_schema, oracle_data_pointer, deployer: program_modification_account.clone(), ref_counter: 1});
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![],
programs_data: programs_info,
verifying_key: Some(BoundedVec::default()),
version_number: T::KeyVersionNumber::get()
});
}: _(RawOrigin::Signed(sig_req_account.clone()))
verify {
assert_last_event::<T>(Event::RegistrationCancelled(sig_req_account.clone()).into());
}

change_program_instance {
let n in 1 .. T::MaxProgramHashes::get();
let o in 1 .. T::MaxProgramHashes::get();
Expand Down
32 changes: 4 additions & 28 deletions pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,32 +447,8 @@ pub mod pallet {
Ok(Some(<T as Config>::WeightInfo::register(programs_data.len() as u32)).into())
}

/// Allows a user to remove themselves from registering state if it has been longer than prune block
#[pallet::call_index(3)]
#[pallet::weight({
<T as Config>::WeightInfo::prune_registration(<T as Config>::MaxProgramHashes::get())
})]
pub fn prune_registration(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let registering_info = Self::registering(&who).ok_or(Error::<T>::NotRegistering)?;
for program_instance in &registering_info.programs_data {
pallet_programs::Programs::<T>::mutate(
program_instance.program_pointer,
|maybe_program_info| {
if let Some(program_info) = maybe_program_info {
program_info.ref_counter = program_info.ref_counter.saturating_sub(1);
}
},
);
}
let program_length = registering_info.programs_data.len();
Registering::<T>::remove(&who);
Self::deposit_event(Event::RegistrationCancelled(who));
Ok(Some(<T as Config>::WeightInfo::register(program_length as u32)).into())
}

/// Allows a user's program modification account to change their program pointer
#[pallet::call_index(4)]
#[pallet::call_index(3)]
#[pallet::weight({
<T as Config>::WeightInfo::change_program_instance(<T as Config>::MaxProgramHashes::get(), <T as Config>::MaxProgramHashes::get())
})]
Expand Down Expand Up @@ -533,7 +509,7 @@ pub mod pallet {
}

/// Allows a user's program modification account to change itself.
#[pallet::call_index(5)]
#[pallet::call_index(4)]
#[pallet::weight({
<T as Config>::WeightInfo::change_program_modification_account(MAX_MODIFIABLE_KEYS)
})]
Expand Down Expand Up @@ -592,7 +568,7 @@ pub mod pallet {
///
/// After a validator from each partition confirms they have a keyshare the user will be
/// considered as registered on the network.
#[pallet::call_index(6)]
#[pallet::call_index(5)]
#[pallet::weight({
let weight =
<T as Config>::WeightInfo::confirm_register_registering(pallet_session::Pallet::<T>::validators().len() as u32)
Expand Down Expand Up @@ -701,7 +677,7 @@ pub mod pallet {
///
/// Note: Substrate origins are allowed to register as many accounts as they wish. Each
/// registration request will produce a different verifying key.
#[pallet::call_index(7)]
#[pallet::call_index(6)]
#[pallet::weight({
<T as Config>::WeightInfo::register_on_chain(<T as Config>::MaxProgramHashes::get())
})]
Expand Down
42 changes: 0 additions & 42 deletions pallets/registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use entropy_shared::{NETWORK_PARENT_KEY, VERIFICATION_KEY_LENGTH};
use frame_support::{
assert_noop, assert_ok,
dispatch::{GetDispatchInfo, Pays},
traits::Currency,
BoundedVec,
};
use pallet_programs::ProgramInfo;
Expand Down Expand Up @@ -824,47 +823,6 @@ fn it_fails_empty_program_list() {
});
}

#[test]
fn it_tests_prune_registration() {
new_test_ext().execute_with(|| {
let inital_program = vec![10];
let program_hash = <Test as frame_system::Config>::Hashing::hash(&inital_program);
let programs_info = BoundedVec::try_from(vec![ProgramInstance {
program_pointer: program_hash,
program_config: vec![],
}])
.unwrap();

pallet_programs::Programs::<Test>::insert(
program_hash,
ProgramInfo {
bytecode: inital_program.clone(),
configuration_schema: inital_program.clone(),
auxiliary_data_schema: inital_program.clone(),
oracle_data_pointer: inital_program.clone(),
deployer: 1,
ref_counter: 1,
},
);

Balances::make_free_balance_be(&2, 100);
// register a user
assert_ok!(Registry::register(RuntimeOrigin::signed(1), 2, programs_info,));
assert_eq!(
pallet_programs::Programs::<Test>::get(program_hash).unwrap().ref_counter,
2,
"ref counter is increment"
);
assert!(Registry::registering(1).is_some(), "Make sure there is registering state");
assert_ok!(Registry::prune_registration(RuntimeOrigin::signed(1)));
assert_eq!(Registry::registering(1), None, "Make sure registering is pruned");
assert_eq!(
pallet_programs::Programs::<Test>::get(program_hash).unwrap().ref_counter,
1,
"ref counter is decremented"
);
});
}
#[test]
fn it_provides_free_txs_confirm_done() {
new_test_ext().execute_with(|| {
Expand Down
31 changes: 0 additions & 31 deletions pallets/registry/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub trait WeightInfo {
fn register(p: u32) -> Weight;
fn register_on_chain(_p: u32) -> Weight;
fn jump_start_network() -> Weight;
fn prune_registration(p: u32) -> Weight;
fn confirm_jump_start_done(c: u32, ) -> Weight;
fn confirm_jump_start_confirm(c: u32, ) -> Weight;
fn change_program_instance(n: u32, o:u32) -> Weight;
Expand Down Expand Up @@ -157,21 +156,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: `Registry::Registering` (r:1 w:1)
/// Proof: `Registry::Registering` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Programs::Programs` (r:1 w:1)
/// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `p` is `[1, 5]`.
fn prune_registration(_p: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `468`
// Estimated: `3933`
// Minimum execution time: 15_000_000 picoseconds.
Weight::from_parts(16_500_000, 0)
.saturating_add(Weight::from_parts(0, 3933))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Programs::Programs` (r:2 w:2)
/// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Registry::Registered` (r:1 w:1)
Expand Down Expand Up @@ -355,21 +339,6 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(4))
}
/// Storage: `Registry::Registering` (r:1 w:1)
/// Proof: `Registry::Registering` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Programs::Programs` (r:1 w:1)
/// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `p` is `[1, 5]`.
fn prune_registration(_p: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `468`
// Estimated: `3933`
// Minimum execution time: 15_000_000 picoseconds.
Weight::from_parts(16_500_000, 0)
.saturating_add(Weight::from_parts(0, 3933))
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(2))
}
/// Storage: `Programs::Programs` (r:2 w:2)
/// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Registry::Registered` (r:1 w:1)
Expand Down
17 changes: 0 additions & 17 deletions runtime/src/weights/pallet_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ impl<T: frame_system::Config> pallet_registry::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: `Registry::Registering` (r:1 w:1)
/// Proof: `Registry::Registering` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Programs::Programs` (r:1 w:1)
/// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// The range of component `p` is `[1, 5]`.
fn prune_registration(p: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `540`
// Estimated: `4005`
// Minimum execution time: 17_000_000 picoseconds.
Weight::from_parts(17_300_000, 0)
.saturating_add(Weight::from_parts(0, 4005))
// Standard Error: 117_260
.saturating_add(Weight::from_parts(100_000, 0).saturating_mul(p.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: `Programs::Programs` (r:2 w:2)
/// Proof: `Programs::Programs` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Registry::Registered` (r:1 w:1)
Expand Down

0 comments on commit 260e953

Please sign in to comment.