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 is_swapping from registration details #437

Merged
merged 4 commits into from
Oct 20, 2023
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
Binary file modified crypto/server/entropy_metadata.scale
Binary file not shown.
3 changes: 0 additions & 3 deletions crypto/server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@ pub async fn get_registering_user_details(
.fetch(&registering_info_query)
.await?
.ok_or_else(|| UserErr::NotRegistering("Register Onchain first"))?;
if !register_info.is_swapping && !register_info.is_registering {
JesseAbram marked this conversation as resolved.
Show resolved Hide resolved
return Err(UserErr::NotRegistering("Declare swap Onchain first"));
}

Ok(register_info)
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ async fn test_store_share() {
let alice_account_id: <EntropyConfig as Config>::AccountId = alice.to_account_id().into();
let registered_query = entropy::storage().relayer().registered(alice_account_id);
for _ in 0..10 {
std::thread::sleep(std::time::Duration::from_millis(500));
std::thread::sleep(std::time::Duration::from_millis(1000));
let query_registered_status =
api.storage().at_latest().await.unwrap().fetch(&registered_query).await;
if query_registered_status.unwrap().is_some() {
Expand Down
27 changes: 0 additions & 27 deletions pallets/relayer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ benchmarks! {
<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
is_registering: true,
constraint_account: sig_req_account.clone(),
is_swapping: false,
confirmations: vec![],
constraints: None,
key_visibility: KeyVisibility::Public,
Expand All @@ -105,32 +104,6 @@ confirm_register_registered {
<Registering<T>>::insert(&sig_req_account, RegisteringDetails::<T> {
is_registering: true,
constraint_account: sig_req_account.clone(),
is_swapping: false,
confirmations: confirmation,
constraints: None,
key_visibility: KeyVisibility::Public,
});
}: confirm_register(RawOrigin::Signed(threshold_account), sig_req_account.clone(), 0, BoundedVec::default())
verify {
assert_last_event::<T>(Event::<T>::AccountRegistered(sig_req_account).into());
}

confirm_register_swapping {
let c in 0 .. SIG_PARTIES as u32;
let sig_req_account: T::AccountId = whitelisted_caller();
let validator_account: T::AccountId = whitelisted_caller();
let threshold_account: T::AccountId = whitelisted_caller();
let sig_party_size = MaxValidators::<T>::get() / SIG_PARTIES as u32;
for i in 0..SIG_PARTIES {
let validators = add_non_syncing_validators::<T>(sig_party_size, 0, i as u8);
<ThresholdToStash<T>>::insert(&threshold_account, &validators[i]);
}
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,
constraint_account: sig_req_account.clone(),
is_swapping: true,
confirmations: confirmation,
constraints: None,
key_visibility: KeyVisibility::Public,
Expand Down
40 changes: 20 additions & 20 deletions pallets/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pub mod pallet {
pub struct RegisteringDetails<T: Config> {
pub is_registering: bool,
pub constraint_account: T::AccountId,
pub is_swapping: bool,
pub confirmations: Vec<u8>,
pub constraints: Option<Constraints>,
pub key_visibility: KeyVisibility,
Expand Down Expand Up @@ -209,7 +208,6 @@ pub mod pallet {
RegisteringDetails::<T> {
is_registering: true,
constraint_account: constraint_account.clone(),
is_swapping: false,
confirmations: vec![],
constraints: initial_constraints,
key_visibility,
Expand All @@ -228,7 +226,12 @@ pub mod pallet {
/// registering. After a validator from each partition confirms they have a
/// keyshare, this should get the user to a `Registered` state
#[pallet::call_index(2)]
#[pallet::weight((<T as Config>::WeightInfo::confirm_register_swapping(SIGNING_PARTY_SIZE as u32), Pays::No))]
#[pallet::weight({
let weight =
<T as Config>::WeightInfo::confirm_register_registering(SIGNING_PARTY_SIZE as u32)
.max(<T as Config>::WeightInfo::confirm_register_registered(SIGNING_PARTY_SIZE as u32));
(weight, Pays::No)
})]
pub fn confirm_register(
origin: OriginFor<T>,
sig_req_account: T::AccountId,
Expand Down Expand Up @@ -257,7 +260,6 @@ pub mod pallet {
);

if registering_info.confirmations.len() == T::SigningPartySize::get() - 1 {
let mut weight;
// just inserts last validator's verifying_key, need to do dispute resolution
Registered::<T>::insert(
&sig_req_account,
Expand All @@ -267,25 +269,23 @@ pub mod pallet {
},
);
Registering::<T>::remove(&sig_req_account);
weight =
<T as Config>::WeightInfo::confirm_register_registered(confirmation_length);
if !registering_info.is_swapping {
AllowedToModifyConstraints::<T>::insert(
&registering_info.constraint_account,
sig_req_account.clone(),
(),
);

if let Some(constraints) = registering_info.constraints {
ConstraintsPallet::<T>::set_constraints_unchecked(
&sig_req_account,
&constraints,
);
}
weight =
<T as Config>::WeightInfo::confirm_register_swapping(confirmation_length);
AllowedToModifyConstraints::<T>::insert(
&registering_info.constraint_account,
sig_req_account.clone(),
(),
);

if let Some(constraints) = registering_info.constraints {
ConstraintsPallet::<T>::set_constraints_unchecked(
&sig_req_account,
&constraints,
);
}

let weight =
<T as Config>::WeightInfo::confirm_register_registered(confirmation_length);

Self::deposit_event(Event::AccountRegistered(sig_req_account));
Ok(Some(weight).into())
} else {
Expand Down
3 changes: 1 addition & 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() {
}

#[test]
fn it_confirms_registers_a_user_then_swap() {
fn it_confirms_registers_a_user() {
new_test_ext().execute_with(|| {
assert_noop!(
Relayer::confirm_register(RuntimeOrigin::signed(1), 1, 0, BoundedVec::default()),
Expand Down Expand Up @@ -115,7 +115,6 @@ fn it_confirms_registers_a_user_then_swap() {
let registering_info = RegisteringDetails::<Test> {
is_registering: true,
constraint_account: 2 as <Test as frame_system::Config>::AccountId,
is_swapping: false,
confirmations: vec![0],
constraints: Some(Constraints::default()),
key_visibility: KeyVisibility::Private([0; 32]),
Expand Down
45 changes: 0 additions & 45 deletions pallets/relayer/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use sp_std::marker::PhantomData;
// The weight info trait for `pallet_realyer`.
pub trait WeightInfo {
fn register(evm_acl_len: u32, btc_acl_len: u32) -> Weight;
fn confirm_register_swapping(c: u32) -> Weight;
fn confirm_register_registered(c: u32) -> Weight;
fn confirm_register_registering(c: u32) -> Weight;
}
Expand Down Expand Up @@ -80,28 +79,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}

/// 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)
/// Proof Skipped: Relayer Registering (max_values: None, max_size: None, mode: Measured)
/// Storage: StakingExtension SigningGroups (r:1 w:0)
/// Proof Skipped: StakingExtension SigningGroups (max_values: None, max_size: None, mode:
/// Measured) Storage: Relayer Registered (r:0 w:1)
/// Proof Skipped: Relayer Registered (max_values: None, max_size: None, mode: Measured)
/// The range of component `c` is `[0, 2]`.
fn confirm_register_swapping(c: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `16479`
// Estimated: `19944`
// Minimum execution time: 50_000_000 picoseconds.
Weight::from_parts(54_109_392, 0)
.saturating_add(Weight::from_parts(0, 19944))
// Standard Error: 105_147
.saturating_add(Weight::from_parts(712_707, 0).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -168,26 +145,4 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(3))
}

/// 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)
/// Proof Skipped: Relayer Registering (max_values: None, max_size: None, mode: Measured)
/// Storage: StakingExtension SigningGroups (r:1 w:0)
/// Proof Skipped: StakingExtension SigningGroups (max_values: None, max_size: None, mode:
/// Measured) Storage: Relayer Registered (r:0 w:1)
/// Proof Skipped: Relayer Registered (max_values: None, max_size: None, mode: Measured)
/// The range of component `c` is `[0, 2]`.
fn confirm_register_swapping(c: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `16479`
// Estimated: `19944`
// Minimum execution time: 50_000_000 picoseconds.
Weight::from_parts(54_109_392, 0)
.saturating_add(Weight::from_parts(0, 19944))
// Standard Error: 105_147
.saturating_add(Weight::from_parts(712_707, 0).saturating_mul(c.into()))
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(2))
}
}
21 changes: 0 additions & 21 deletions runtime/src/weights/pallet_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,4 @@ impl<T: frame_system::Config> pallet_relayer::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
/// 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)
/// Proof Skipped: Relayer Registering (max_values: None, max_size: None, mode: Measured)
/// Storage: StakingExtension SigningGroups (r:1 w:0)
/// Proof Skipped: StakingExtension SigningGroups (max_values: None, max_size: None, mode: Measured)
/// Storage: Relayer Registered (r:0 w:1)
/// Proof Skipped: Relayer Registered (max_values: None, max_size: None, mode: Measured)
/// The range of component `c` is `[0, 2]`.
fn confirm_register_swapping(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `16480`
// Estimated: `19945`
// Minimum execution time: 51_000_000 picoseconds.
Weight::from_parts(54_653_314, 0)
.saturating_add(Weight::from_parts(0, 19945))
// Standard Error: 80_615
.saturating_add(Weight::from_parts(289_779, 0).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(2))
}
}