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 confirm_registered extrinsic #1025

Merged
merged 16 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ At the moment this project **does not** adhere to

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

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

Expand Down
Binary file modified crates/client/entropy_metadata.scale
Binary file not shown.
34 changes: 1 addition & 33 deletions crates/threshold-signature-server/src/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
ValidatorName, DEFAULT_ENDPOINT,
},
logger::{Instrumentation, Logger},
substrate::{query_chain, submit_transaction},
substrate::submit_transaction,
validator::get_signer_and_x25519_secret_from_mnemonic,
},
signing_client::ListenerState,
Expand Down Expand Up @@ -212,38 +212,6 @@ pub async fn remove_program(
submit_transaction(entropy_api, rpc, &deployer, &remove_program_tx, None).await.unwrap();
}

/// Verify that a Registering account has all confirmation, and that it is registered.
pub async fn check_if_confirmation(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
key: &sr25519::Pair,
verifying_key: Vec<u8>,
) {
let signer = PairSigner::<EntropyConfig, sr25519::Pair>::new(key.clone());
let registering_query = entropy::storage().registry().registering(signer.account_id());
let registered_query = entropy::storage().registry().registered(BoundedVec(verifying_key));
let block_hash = rpc.chain_get_block_hash(None).await.unwrap();
let is_registering = query_chain(api, rpc, registering_query, block_hash).await;
// cleared from is_registering state
assert!(is_registering.unwrap().is_none());
let is_registered = query_chain(api, rpc, registered_query, block_hash).await.unwrap();
//TODO assert something here
assert_eq!(is_registered.unwrap().version_number, 1);
}

/// Verify that an account got one confirmation.
pub async fn check_has_confirmation(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
key: &sr25519::Pair,
) {
let signer = PairSigner::<EntropyConfig, sr25519::Pair>::new(key.clone());
let registering_query = entropy::storage().registry().registering(signer.account_id());
// cleared from is_registering state
let is_registering = query_chain(api, rpc, registering_query, None).await.unwrap();
assert_eq!(is_registering.unwrap().confirmations.len(), 1);
}

pub async fn run_to_block(rpc: &LegacyRpcMethods<EntropyConfig>, block_run: u32) {
let mut current_block = 0;
while current_block < block_run {
Expand Down
25 changes: 11 additions & 14 deletions crates/threshold-signature-server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ async fn setup_dkg(
let nonce = api.runtime_api().at(block_hash).call(nonce_call).await?;

// TODO: Error handling really complex needs to be thought about.
confirm_registered(&api, rpc, sig_request_address, &signer, verifying_key, nonce).await?;
confirm_jump_start(&api, rpc, sig_request_address, &signer, verifying_key, nonce).await?;
}
Ok(())
}
Expand Down Expand Up @@ -437,8 +437,8 @@ pub async fn is_registering(
Ok(register_info.is_some())
}

/// Confirms that a address has finished registering on chain.
pub async fn confirm_registered(
/// Confirms that the network wide distributed key generation process has taken place.
pub async fn confirm_jump_start(
api: &OnlineClient<EntropyConfig>,
rpc: &LegacyRpcMethods<EntropyConfig>,
who: SubxtAccountId32,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we still need this argument, or the check below since this should only ever be called with the network parent key but no harm in leaving it in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I think this can get cleaned up, but it'll be more clear how when I rip out the old registration flow

Expand All @@ -450,19 +450,16 @@ pub async fn confirm_registered(
// TODO fire and forget, or wait for in block maybe Ddos error
// TODO: Understand this better, potentially use sign_and_submit_default
// or other method under sign_and_*
if who.encode() == NETWORK_PARENT_KEY.encode() {
let jump_start_request = entropy::tx().registry().confirm_jump_start(
entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec(verifying_key),
);
submit_transaction(api, rpc, signer, &jump_start_request, Some(nonce)).await?;
} else {
let confirm_register_request = entropy::tx().registry().confirm_register(
who,
entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec(verifying_key),
);
submit_transaction(api, rpc, signer, &confirm_register_request, Some(nonce)).await?;

if who.encode() != NETWORK_PARENT_KEY.encode() {
return Err(UserErr::UnableToConfirmJumpStart);
}

let jump_start_request = entropy::tx().registry().confirm_jump_start(
entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec(verifying_key),
);
submit_transaction(api, rpc, signer, &jump_start_request, Some(nonce)).await?;

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions crates/threshold-signature-server/src/user/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub enum UserErr {
CustomHashOutOfBounds,
#[error("No signing from parent key")]
NoSigningFromParentKey,
#[error("The account being used is not allowed to confirm a network jump start.")]
UnableToConfirmJumpStart,
#[error("Listener: {0}")]
Listener(#[from] entropy_protocol::errors::ListenerErr),
#[error("Error creating sr25519 keypair from seed: {0}")]
Expand Down
85 changes: 5 additions & 80 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ use crate::{
signing::Hasher,
substrate::{get_oracle_data, query_chain, submit_transaction},
tests::{
check_has_confirmation, check_if_confirmation, create_clients, initialize_test_logger,
jump_start_network_with_signer, remove_program, run_to_block, setup_client,
spawn_testing_validators, unsafe_get,
create_clients, initialize_test_logger, jump_start_network_with_signer, remove_program,
run_to_block, setup_client, spawn_testing_validators, unsafe_get,
},
user::compute_hash,
validator::get_signer_and_x25519_secret_from_mnemonic,
Expand All @@ -132,9 +131,8 @@ use crate::{
signing_client::ListenerState,
user::{
api::{
check_hash_pointer_out_of_bounds, confirm_registered, increment_or_wipe_request_limit,
request_limit_check, request_limit_key, RequestLimitStorage, UserRegistrationInfo,
UserSignatureRequest,
check_hash_pointer_out_of_bounds, increment_or_wipe_request_limit, request_limit_check,
request_limit_key, RequestLimitStorage, UserRegistrationInfo, UserSignatureRequest,
},
UserErr,
},
Expand Down Expand Up @@ -684,6 +682,7 @@ async fn test_program_with_config() {
clean_tests();
}

#[ignore]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test fails because it depends on confirm_register working. I've ignored it for now because I want to use it as a reference when I start migrating the tests to use the new registration flow

Copy link
Contributor

Choose a reason for hiding this comment

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

omg i can't wait to see this test get deleted it has been a pita

do we not already have tests which use the new registration flow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do have them, but I want to go through the old tests to see if there are any failure conditions that I haven't checked in the new tests.

#[tokio::test]
#[serial]
async fn test_store_share() {
Expand Down Expand Up @@ -852,7 +851,6 @@ async fn test_store_share() {

assert_eq!(response_not_validator.status(), StatusCode::MISDIRECTED_REQUEST);

check_if_confirmation(&api, &rpc, &alice.pair(), new_verifying_key).await;
// TODO check if key is in other subgroup member
clean_tests();
}
Expand Down Expand Up @@ -1561,79 +1559,6 @@ async fn test_new_registration_flow() {
clean_tests();
}

#[tokio::test]
#[serial]
async fn test_mutiple_confirm_done() {
initialize_test_logger().await;
clean_tests();

let alice = AccountKeyring::Alice;
let bob = AccountKeyring::Bob;

let alice_program = AccountKeyring::Charlie;
let program_manager = AccountKeyring::Dave;

let cxt = test_context_stationary().await;
let api = get_api(&cxt.node_proc.ws_url).await.unwrap();
let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap();

let program_hash = store_program(
&api,
&rpc,
&program_manager.pair(),
TEST_PROGRAM_WASM_BYTECODE.to_owned(),
vec![],
vec![],
vec![],
)
.await
.unwrap();

put_register_request_on_chain(
&api,
&rpc,
&alice,
alice_program.to_account_id().into(),
BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]),
)
.await;

put_register_request_on_chain(
&api,
&rpc,
&bob,
alice_program.to_account_id().into(),
BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]),
)
.await;

let (signer_alice, _) = get_signer_and_x25519_secret_from_mnemonic(DEFAULT_MNEMONIC).unwrap();

confirm_registered(
&api,
&rpc,
alice.to_account_id().into(),
&signer_alice,
DEFAULT_VERIFYING_KEY.to_vec(),
0u32,
)
.await
.unwrap();
confirm_registered(
&api,
&rpc,
bob.to_account_id().into(),
&signer_alice,
DEFAULT_VERIFYING_KEY.to_vec(),
1u32,
)
.await
.unwrap();
check_has_confirmation(&api, &rpc, &alice.pair()).await;
check_has_confirmation(&api, &rpc, &bob.pair()).await;
clean_tests();
}

#[tokio::test]
#[serial]
async fn test_increment_or_wipe_request_limit() {
Expand Down
2 changes: 0 additions & 2 deletions node/cli/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ pub fn create_benchmark_extrinsic(
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
pallet_registry::ValidateConfirmRegistered::<runtime::Runtime>::new(),
);

let raw_payload = runtime::SignedPayload::from_raw(
Expand All @@ -161,7 +160,6 @@ pub fn create_benchmark_extrinsic(
(),
(),
(),
(),
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down
118 changes: 1 addition & 117 deletions pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Benchmarking setup for pallet-propgation
use entropy_shared::{MAX_SIGNERS, VERIFICATION_KEY_LENGTH};
use entropy_shared::MAX_SIGNERS;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_support::{
traits::{Currency, Get},
Expand All @@ -34,7 +34,6 @@ use super::*;
#[allow(unused)]
use crate::Pallet as Registry;

type MaxValidators<T> = <<T as pallet_staking::Config>::BenchmarkingConfig as pallet_staking::BenchmarkingConfig>::MaxValidators;
const SEED: u32 = 0;
const NULL_ARR: [u8; 32] = [0; 32];

Expand Down Expand Up @@ -326,121 +325,6 @@ benchmarks! {
verify {
assert_last_event::<T>(Event::ProgramModificationAccountChanged(sig_req_account.clone(), sig_req_account.clone(), BoundedVec::default()).into());
}

confirm_register_registering {
let c in 1 .. MaxValidators::<T>::get();
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();
let sig_req_account: T::AccountId = whitelisted_caller();
let validator_account: T::AccountId = whitelisted_caller();
let threshold_account: T::AccountId = whitelisted_caller();

// add validators and a registering user
// adds an extra validator so requires confirmations is > validators and doesn't confirm
let validators = add_non_syncing_validators::<T>(c + 1, 0);
<ThresholdToStash<T>>::insert(&threshold_account, &validators[(c -1) as usize]);

<Validators<T>>::set(validators);

<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
program_modification_account: sig_req_account.clone(),
confirmations: vec![],
programs_data: programs_info,
verifying_key: None,
version_number: T::KeyVersionNumber::get()
});
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(&threshold_account, balance);
}: confirm_register(RawOrigin::Signed(threshold_account.clone()), sig_req_account.clone(), BoundedVec::try_from(vec![3; VERIFICATION_KEY_LENGTH as usize]).unwrap())
verify {
assert_last_event::<T>(Event::<T>::RecievedConfirmation(sig_req_account, BoundedVec::try_from(vec![3; VERIFICATION_KEY_LENGTH as usize]).unwrap()).into());
}

confirm_register_failed_registering {
let c in 1 .. MaxValidators::<T>::get();

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();
let sig_req_account: T::AccountId = whitelisted_caller();
let validator_account: T::AccountId = whitelisted_caller();
let threshold_account: T::AccountId = whitelisted_caller();
let random_account = account::<T::AccountId>("ts_account", 10, SEED);
let invalid_verifying_key = BoundedVec::try_from(vec![2; VERIFICATION_KEY_LENGTH as usize]).unwrap();
// add validators and a registering user with different verifying key
let validators = add_non_syncing_validators::<T>(c, 0);
<ThresholdToStash<T>>::insert(&threshold_account, &validators[(c -1) as usize]);
let confirmations = vec![random_account.clone(); (c -1).try_into().unwrap()];

<Validators<T>>::set(validators);

<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
program_modification_account: sig_req_account.clone(),
confirmations,
programs_data: programs_info,
verifying_key: Some(BoundedVec::default()),
version_number: T::KeyVersionNumber::get()
});
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(&threshold_account, balance);
}: confirm_register(RawOrigin::Signed(threshold_account), sig_req_account.clone(), invalid_verifying_key)
verify {
assert_last_event::<T>(Event::<T>::FailedRegistration(sig_req_account).into());
}


confirm_register_registered {
let c in 1 .. MaxValidators::<T>::get();

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();
let sig_req_account: T::AccountId = whitelisted_caller();
let validator_account: T::AccountId = whitelisted_caller();
let threshold_account: T::AccountId = whitelisted_caller();
let random_account = account::<T::AccountId>("ts_account", 10, SEED);
// add validators, a registering user and one less than all confirmations
let validators = add_non_syncing_validators::<T>(c, 0);
<ThresholdToStash<T>>::insert(&threshold_account, &validators[(c -1) as usize]);
let confirmations = vec![random_account.clone(); (c -1).try_into().unwrap()];


<Validators<T>>::set(validators);

<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
program_modification_account: sig_req_account.clone(),
confirmations,
programs_data: programs_info,
verifying_key: None,
version_number: T::KeyVersionNumber::get()
});
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(&threshold_account, balance);
}: confirm_register(RawOrigin::Signed(threshold_account), sig_req_account.clone(), BoundedVec::try_from(vec![3; VERIFICATION_KEY_LENGTH as usize]).unwrap())
verify {
assert_last_event::<T>(Event::<T>::AccountRegistered(sig_req_account, BoundedVec::try_from(vec![3; VERIFICATION_KEY_LENGTH as usize]).unwrap()).into());
}
}

impl_benchmark_test_suite!(Registry, crate::mock::new_test_ext(), crate::mock::Test);
Loading
Loading