Skip to content

Commit

Permalink
Merge branch 'master' into peg/remove-program-test
Browse files Browse the repository at this point in the history
* master:
  Clean up registration related tests in `pallet-registry` (#1021)
  Remove `prune_registration` extrinsic (#1022)
  Add benchmark for `new_session` hook (#1016)
  • Loading branch information
ameba23 committed Aug 23, 2024
2 parents 399d2d8 + 1202e02 commit a349405
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 323 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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.
5 changes: 5 additions & 0 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ async fn test_get_signer_does_not_throw_err() {
clean_tests();
}

#[ignore]
#[tokio::test]
#[serial]
async fn test_sign_tx_no_chain() {
Expand Down Expand Up @@ -490,6 +491,7 @@ async fn signature_request_with_derived_account_works() {
clean_tests();
}

#[ignore]
#[tokio::test]
#[serial]
async fn test_sign_tx_no_chain_fail() {
Expand Down Expand Up @@ -615,6 +617,7 @@ async fn test_sign_tx_no_chain_fail() {
clean_tests();
}

#[ignore]
#[tokio::test]
#[serial]
async fn test_program_with_config() {
Expand Down Expand Up @@ -1080,6 +1083,7 @@ pub async fn verify_signature(
}
}

#[ignore]
#[tokio::test]
#[serial]
async fn test_fail_infinite_program() {
Expand Down Expand Up @@ -1158,6 +1162,7 @@ async fn test_fail_infinite_program() {
}
}

#[ignore]
#[tokio::test]
#[serial]
async fn test_device_key_proxy() {
Expand Down
1 change: 1 addition & 0 deletions crates/threshold-signature-server/tests/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use serial_test::serial;
use sp_keyring::AccountKeyring;
use synedrion::k256::ecdsa::VerifyingKey;

#[ignore]
#[tokio::test]
#[serial]
async fn integration_test_sign_public() {
Expand Down
1 change: 1 addition & 0 deletions crates/threshold-signature-server/tests/sign_eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use synedrion::k256::ecdsa::VerifyingKey;

const GOERLI_CHAIN_ID: u64 = 5;

#[ignore]
#[tokio::test]
#[serial]
async fn integration_test_sign_eth_tx() {
Expand Down
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
48 changes: 17 additions & 31 deletions pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,34 +447,13 @@ 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())
<T as Config>::WeightInfo::change_program_instance(
<T as Config>::MaxProgramHashes::get(),
<T as Config>::MaxProgramHashes::get()
)
})]
pub fn change_program_instance(
origin: OriginFor<T>,
Expand All @@ -497,9 +476,10 @@ pub mod pallet {
},
)?;
}

let mut old_programs_length = 0;
let programs_data =
Registered::<T>::try_mutate(&verifying_key, |maybe_registered_details| {
RegisteredOnChain::<T>::try_mutate(&verifying_key, |maybe_registered_details| {
if let Some(registered_details) = maybe_registered_details {
ensure!(
who == registered_details.program_modification_account,
Expand All @@ -524,7 +504,9 @@ pub mod pallet {
Err(Error::<T>::NotRegistered)
}
})?;

Self::deposit_event(Event::ProgramInfoChanged(who, programs_data.clone()));

Ok(Some(<T as Config>::WeightInfo::change_program_instance(
programs_data.len() as u32,
old_programs_length as u32,
Expand All @@ -533,7 +515,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 All @@ -543,7 +525,8 @@ pub mod pallet {
new_program_mod_account: T::AccountId,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Registered::<T>::try_mutate(&verifying_key, |maybe_registered_details| {

RegisteredOnChain::<T>::try_mutate(&verifying_key, |maybe_registered_details| {
if let Some(registered_details) = maybe_registered_details {
ensure!(
who == registered_details.program_modification_account,
Expand All @@ -556,6 +539,7 @@ pub mod pallet {
Err(Error::<T>::NotRegistered)
}
})?;

let mut verifying_keys_len = 0;
ModifiableKeys::<T>::try_mutate(&who, |verifying_keys| -> Result<(), DispatchError> {
verifying_keys_len = verifying_keys.len();
Expand All @@ -576,6 +560,7 @@ pub mod pallet {
Ok(())
},
)?;

Self::deposit_event(Event::ProgramModificationAccountChanged(
who,
new_program_mod_account,
Expand All @@ -587,12 +572,13 @@ pub mod pallet {
))
.into())
}

/// Allows validators to confirm that they have received a key-share from a user that is
/// in the process of registering.
///
/// 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 +687,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
Loading

0 comments on commit a349405

Please sign in to comment.