From ee48e6bede74582346c465d2f0a3c97192a48d7b Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 2 Nov 2023 13:43:51 -0400 Subject: [PATCH 01/14] add prune registration extrinsic --- crypto/server/entropy_metadata.scale | Bin 187161 -> 187178 bytes crypto/server/src/helpers/substrate.rs | 2 +- pallets/relayer/src/lib.rs | 31 ++++++++++++++++++++++--- pallets/relayer/src/tests.rs | 26 +++++++++++++++++++-- runtime/src/lib.rs | 2 +- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/crypto/server/entropy_metadata.scale b/crypto/server/entropy_metadata.scale index 7d9f1d9421cf3fdf2ac603e05c2a62f093d7a934..ebfaaa77c715c4e6f44efe6a6fd1f49c320af858 100644 GIT binary patch delta 45 zcmV+|0Mh@NwhOAZ3xKo%gtHDva%E>}b98cHbZKvHUzh(C0UMLhge-^1vjMlrvjR~k D!o3rV delta 49 zcmZ3rjeF)c?uIRlEt|zHGK=GjQqwbwOHzw6^U@bE3MA#{=P*n@-=f=ob2H=io12*e F)d2&F6rcbA diff --git a/crypto/server/src/helpers/substrate.rs b/crypto/server/src/helpers/substrate.rs index e88c48adb..765ba3bcd 100644 --- a/crypto/server/src/helpers/substrate.rs +++ b/crypto/server/src/helpers/substrate.rs @@ -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(®istering_query).await; - assert!(query_registering_status.unwrap().unwrap().is_registering); + assert!(query_registering_status.unwrap().is_some()); } /// Returns wether an account is registered diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index c37e7efa1..a01689a5c 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -48,7 +48,10 @@ pub mod pallet { use pallet_programs::{AllowedToModifyProgram, Pallet as ProgramsPallet}; use pallet_staking_extension::ServerInfo; use scale_info::TypeInfo; - use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; + use sp_runtime::{ + traits::{DispatchInfoOf, SignedExtension}, + Saturating, + }; use sp_std::{fmt::Debug, vec}; pub use crate::weights::WeightInfo; @@ -74,7 +77,7 @@ pub mod pallet { #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] pub struct RegisteringDetails { - pub is_registering: bool, + pub registration_block: BlockNumberFor, pub program_modification_account: T::AccountId, pub confirmations: Vec, pub program: Vec, @@ -153,6 +156,8 @@ pub mod pallet { AccountRegistered(T::AccountId), /// An account registration has failed FailedRegistration(T::AccountId), + /// An account cancelled their registraiton + RegistrationCancelled(T::AccountId), /// An account has been registered. [who, block_number, failures] ConfirmedDone(T::AccountId, BlockNumberFor, Vec), } @@ -172,6 +177,7 @@ pub mod pallet { NoSyncedValidators, MaxProgramLengthExceeded, NoVerifyingKey, + NotLongEnough, } #[pallet::call] @@ -226,7 +232,7 @@ pub mod pallet { Registering::::insert( &sig_req_account, RegisteringDetails:: { - is_registering: true, + registration_block: block_number, program_modification_account, confirmations: vec![], program: initial_program, @@ -243,6 +249,25 @@ pub mod pallet { Ok(()) } + #[pallet::call_index(1)] + // TODO benchmark + #[pallet::weight({ + ::WeightInfo::register(0u32) + })] + pub fn prune_registration(origin: OriginFor) -> DispatchResult { + let who = ensure_signed(origin)?; + let registering_info = Self::registering(&who).ok_or(Error::::NotRegistering)?; + let block_number = >::block_number(); + ensure!( + block_number.saturating_sub(registering_info.registration_block) + >= T::PruneBlock::get(), + Error::::NotLongEnough + ); + Registering::::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. /// diff --git a/pallets/relayer/src/tests.rs b/pallets/relayer/src/tests.rs index 952a49231..b7dac8abc 100644 --- a/pallets/relayer/src/tests.rs +++ b/pallets/relayer/src/tests.rs @@ -65,7 +65,7 @@ fn it_registers_a_user() { empty_program, )); - assert!(Relayer::registering(1).unwrap().is_registering); + assert_eq!(Relayer::registering(1).unwrap().registration_block, 0); assert_eq!(Relayer::dkg(0), vec![1u64.encode()]); }); } @@ -153,7 +153,7 @@ fn it_confirms_registers_a_user() { ); let registering_info = RegisteringDetails:: { - is_registering: true, + registration_block: 0, program_modification_account: 2 as ::AccountId, confirmations: vec![0], program: vec![], @@ -239,6 +239,28 @@ fn it_doesnt_allow_double_registering() { }); } +#[test] +fn it_tests_prune_registration() { + new_test_ext().execute_with(|| { + // register a user + let empty_program = vec![]; + assert_ok!(Relayer::register( + RuntimeOrigin::signed(1), + 2, + KeyVisibility::Permissioned, + empty_program, + )); + + assert_noop!( + Relayer::prune_registration(RuntimeOrigin::signed(1)), + Error::::NotLongEnough + ); + assert!(Relayer::registering(1).is_some()); + System::set_block_number(5); + assert_ok!(Relayer::prune_registration(RuntimeOrigin::signed(1))); + assert_eq!(Relayer::registering(1), None); + }); +} #[test] fn it_provides_free_txs_confirm_done() { new_test_ext().execute_with(|| { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 33b80de6a..e56ebc8c7 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1272,7 +1272,7 @@ impl pallet_slashing::Config for Runtime { } parameter_types! { - pub const PruneBlock: BlockNumber = 10; + pub const PruneBlock: BlockNumber = 20; pub const SigningPartySize: usize = SIGNING_PARTY_SIZE; } From b90c44b65ff35304f0f3489aeae36f353cb8bce1 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 2 Nov 2023 15:05:15 -0400 Subject: [PATCH 02/14] add benchmarks --- pallets/relayer/src/benchmarking.rs | 25 +++++++++++-- pallets/relayer/src/lib.rs | 2 +- pallets/relayer/src/weights.rs | 25 +++++++++++++ runtime/src/weights/pallet_relayer.rs | 54 ++++++++++++++++----------- scripts/benchmarks.sh | 9 +---- 5 files changed, 82 insertions(+), 33 deletions(-) diff --git a/pallets/relayer/src/benchmarking.rs b/pallets/relayer/src/benchmarking.rs index a3a3aaef9..e4937c63c 100644 --- a/pallets/relayer/src/benchmarking.rs +++ b/pallets/relayer/src/benchmarking.rs @@ -69,6 +69,25 @@ benchmarks! { assert!(Registering::::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 = ::Currency::minimum_balance() * 100u32.into(); + let _ = ::Currency::make_free_balance_be(&sig_req_account, balance); + >::insert(&sig_req_account, RegisteringDetails:: { + registration_block: 0u32.into(), + program_modification_account: sig_req_account.clone(), + confirmations: vec![], + program: vec![], + key_visibility: KeyVisibility::Public, + verifying_key: Some(BoundedVec::default()) + }); + frame_system::Pallet::::set_block_number(25u32.into()); + }: _(RawOrigin::Signed(sig_req_account.clone())) + verify { + assert_last_event::(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(); @@ -82,7 +101,7 @@ benchmarks! { } >::insert(&sig_req_account, RegisteringDetails:: { - is_registering: true, + registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: vec![], program: vec![], @@ -111,7 +130,7 @@ benchmarks! { let adjusted_sig_size = SIG_PARTIES - 1; let confirmation: Vec = (1u8..=adjusted_sig_size.try_into().unwrap()).collect(); >::insert(&sig_req_account, RegisteringDetails:: { - is_registering: true, + registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: confirmation, program: vec![], @@ -140,7 +159,7 @@ confirm_register_registered { let adjusted_sig_size = SIG_PARTIES - 1; let confirmation: Vec = (1u8..=adjusted_sig_size.try_into().unwrap()).collect(); >::insert(&sig_req_account, RegisteringDetails:: { - is_registering: true, + registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: confirmation, program: vec![], diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index a01689a5c..57bca487e 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -252,7 +252,7 @@ pub mod pallet { #[pallet::call_index(1)] // TODO benchmark #[pallet::weight({ - ::WeightInfo::register(0u32) + ::WeightInfo::prune_registration() })] pub fn prune_registration(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; diff --git a/pallets/relayer/src/weights.rs b/pallets/relayer/src/weights.rs index 4f8eb9956..242e38d00 100644 --- a/pallets/relayer/src/weights.rs +++ b/pallets/relayer/src/weights.rs @@ -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; @@ -65,6 +66,18 @@ impl WeightInfo for SubstrateWeight { .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) @@ -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) diff --git a/runtime/src/weights/pallet_relayer.rs b/runtime/src/weights/pallet_relayer.rs index 00a20099a..3930fccbc 100644 --- a/runtime/src/weights/pallet_relayer.rs +++ b/runtime/src/weights/pallet_relayer.rs @@ -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-02, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `Jesses-MacBook-Pro.local`, CPU: `` //! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -44,14 +44,26 @@ impl pallet_relayer::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `133` // Estimated: `3598` - // Minimum execution time: 17_000_000 picoseconds. - Weight::from_parts(15_700_000, 0) + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(15_100_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: 67 + .saturating_add(Weight::from_parts(586, 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: 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: `StakingExtension::ThresholdToStash` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `Relayer::Registering` (r:1 w:1) @@ -61,12 +73,12 @@ impl pallet_relayer::WeightInfo for WeightInfo { /// The range of component `c` is `[0, 2]`. fn confirm_register_registering(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16499` - // Estimated: `19964` + // Measured: `16502` + // Estimated: `19967` // 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 + Weight::from_parts(25_666_666, 0) + .saturating_add(Weight::from_parts(0, 19967)) + // Standard Error: 338_501 .saturating_add(Weight::from_parts(500_000, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -78,15 +90,13 @@ impl pallet_relayer::WeightInfo for WeightInfo { /// 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(26_916_666, 0) + .saturating_add(Weight::from_parts(0, 19969)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -105,11 +115,11 @@ impl pallet_relayer::WeightInfo for WeightInfo { /// The range of component `c` is `[0, 2]`. fn confirm_register_registered(_c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16500` - // Estimated: `19965` + // Measured: `16503` + // Estimated: `19968` // Minimum execution time: 29_000_000 picoseconds. - Weight::from_parts(29_833_333, 0) - .saturating_add(Weight::from_parts(0, 19965)) + Weight::from_parts(30_583_333, 0) + .saturating_add(Weight::from_parts(0, 19968)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) } diff --git a/scripts/benchmarks.sh b/scripts/benchmarks.sh index 7f507dfcd..623884c85 100755 --- a/scripts/benchmarks.sh +++ b/scripts/benchmarks.sh @@ -1,22 +1,17 @@ #!/bin/bash -steps=50 -repeat=20 +steps=5 +repeat=2 entropyOutput=./runtime/src/weights/ entropyChain=dev pallets=( pallet_relayer - pallet_staking_extension - pallet_programs - pallet_transaction_pause - pallet_free_tx ) for p in ${pallets[@]} do ./target/release/entropy benchmark pallet \ --chain $entropyChain \ - --execution=wasm \ --wasm-execution=compiled \ --pallet=$p \ --extrinsic='*' \ From f3b7fcb9df00881c7d85812ddd77073d0312eb6f Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 2 Nov 2023 15:09:48 -0400 Subject: [PATCH 03/14] fix benchmark script --- scripts/benchmarks.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/benchmarks.sh b/scripts/benchmarks.sh index 623884c85..4c6a19a2e 100755 --- a/scripts/benchmarks.sh +++ b/scripts/benchmarks.sh @@ -1,11 +1,15 @@ #!/bin/bash -steps=5 -repeat=2 +steps=50 +repeat=20 entropyOutput=./runtime/src/weights/ entropyChain=dev pallets=( pallet_relayer + pallet_staking_extension + pallet_programs + pallet_transaction_pause + pallet_free_tx ) for p in ${pallets[@]} From 01566ff1d679fae6ce3f51f8c2c138a733ccab64 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Thu, 2 Nov 2023 15:14:16 -0400 Subject: [PATCH 04/14] inline docs --- pallets/relayer/src/lib.rs | 2 +- pallets/relayer/src/tests.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index 57bca487e..fc2252fdd 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -249,8 +249,8 @@ 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)] - // TODO benchmark #[pallet::weight({ ::WeightInfo::prune_registration() })] diff --git a/pallets/relayer/src/tests.rs b/pallets/relayer/src/tests.rs index b7dac8abc..8406b1da3 100644 --- a/pallets/relayer/src/tests.rs +++ b/pallets/relayer/src/tests.rs @@ -242,23 +242,23 @@ fn it_doesnt_allow_double_registering() { #[test] fn it_tests_prune_registration() { new_test_ext().execute_with(|| { - // register a user let empty_program = vec![]; + // register a user assert_ok!(Relayer::register( RuntimeOrigin::signed(1), 2, KeyVisibility::Permissioned, empty_program, )); - + // checks to make sure it is not long enough assert_noop!( Relayer::prune_registration(RuntimeOrigin::signed(1)), Error::::NotLongEnough ); - assert!(Relayer::registering(1).is_some()); + assert!(Relayer::registering(1).is_some(), "Make sure there is registering state"); System::set_block_number(5); assert_ok!(Relayer::prune_registration(RuntimeOrigin::signed(1))); - assert_eq!(Relayer::registering(1), None); + assert_eq!(Relayer::registering(1), None, "Make sure registering is pruned"); }); } #[test] From 8e296f3259383e23ec56a19d5e62fc4e56d409d5 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 3 Nov 2023 11:41:05 -0400 Subject: [PATCH 05/14] add to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e4b658b1..6ad901f99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Some notables changes introduced in [#428](https://github.com/entropyxyz/entropy - The Constraints pallet has been renamed to the Programs pallet ### Added +- Add a prune_registration extrinsic in relayer that allows for accounts to be moved out of registering state if dkg fails ([#472](https://github.com/entropyxyz/entropy-core/pull/472)) - 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. From c2bbd6483a25a5e59695f7747a0bc86488934e72 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:21:47 -0700 Subject: [PATCH 06/14] Update pallets/relayer/src/lib.rs Co-authored-by: Hernando Castano --- pallets/relayer/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index fc2252fdd..0e381a3db 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -156,7 +156,7 @@ pub mod pallet { AccountRegistered(T::AccountId), /// An account registration has failed FailedRegistration(T::AccountId), - /// An account cancelled their registraiton + /// An account cancelled their registration RegistrationCancelled(T::AccountId), /// An account has been registered. [who, block_number, failures] ConfirmedDone(T::AccountId, BlockNumberFor, Vec), From 4114d34794222989aa6034347bfc94420be7c8c5 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 3 Nov 2023 16:29:11 -0400 Subject: [PATCH 07/14] fix changelog --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ad901f99..d51908244 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,15 +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 a prune_registration extrinsic in relayer that allows for accounts to be moved out of registering state if dkg fails ([#472](https://github.com/entropyxyz/entropy-core/pull/472)) -- 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 if dkg fails ### Changed - Replace outdated `--ws-external` with `--rpc-external` ([#424](https://github.com/entropyxyz/entropy-core/pull/424)) From 4f01ce39fbcdb8816a0426be3ff2de26a6254f47 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 3 Nov 2023 17:16:10 -0400 Subject: [PATCH 08/14] return program deposit --- pallets/relayer/src/lib.rs | 7 +++++++ pallets/relayer/src/tests.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index 0e381a3db..0fec0521b 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -263,6 +263,13 @@ pub mod pallet { >= T::PruneBlock::get(), Error::::NotLongEnough ); + + // return program deposit + ProgramsPallet::::update_program_storage_deposit( + ®istering_info.program_modification_account, + registering_info.program.len(), + 0, + )?; Registering::::remove(&who); Self::deposit_event(Event::RegistrationCancelled(who)); Ok(()) diff --git a/pallets/relayer/src/tests.rs b/pallets/relayer/src/tests.rs index 8406b1da3..6e20e0db5 100644 --- a/pallets/relayer/src/tests.rs +++ b/pallets/relayer/src/tests.rs @@ -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; @@ -242,14 +243,17 @@ fn it_doesnt_allow_double_registering() { #[test] fn it_tests_prune_registration() { new_test_ext().execute_with(|| { - let empty_program = vec![]; + 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, - empty_program, + inital_program, )); + assert_eq!(Balances::free_balance(2), 95, "Deposit is charged"); + // checks to make sure it is not long enough assert_noop!( Relayer::prune_registration(RuntimeOrigin::signed(1)), @@ -259,6 +263,7 @@ fn it_tests_prune_registration() { System::set_block_number(5); 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] From b7c077ab939f3ba8f9454038af1d9a82eb2512bb Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 3 Nov 2023 17:28:16 -0400 Subject: [PATCH 09/14] remove prune block --- pallets/propagation/src/mock.rs | 2 -- pallets/relayer/src/benchmarking.rs | 1 - pallets/relayer/src/lib.rs | 13 +------------ pallets/relayer/src/mock.rs | 2 -- pallets/relayer/src/tests.rs | 7 ------- runtime/src/lib.rs | 2 -- runtime/src/weights/pallet_relayer.rs | 28 +++++++++++++-------------- 7 files changed, 15 insertions(+), 40 deletions(-) diff --git a/pallets/propagation/src/mock.rs b/pallets/propagation/src/mock.rs index 5c4b750fc..654eb32c1 100644 --- a/pallets/propagation/src/mock.rs +++ b/pallets/propagation/src/mock.rs @@ -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 = (); diff --git a/pallets/relayer/src/benchmarking.rs b/pallets/relayer/src/benchmarking.rs index e4937c63c..9fe11dbd4 100644 --- a/pallets/relayer/src/benchmarking.rs +++ b/pallets/relayer/src/benchmarking.rs @@ -82,7 +82,6 @@ benchmarks! { key_visibility: KeyVisibility::Public, verifying_key: Some(BoundedVec::default()) }); - frame_system::Pallet::::set_block_number(25u32.into()); }: _(RawOrigin::Signed(sig_req_account.clone())) verify { assert_last_event::(Event::RegistrationCancelled(sig_req_account.clone()).into()); diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index 0fec0521b..cf741ec02 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -48,10 +48,7 @@ pub mod pallet { use pallet_programs::{AllowedToModifyProgram, Pallet as ProgramsPallet}; use pallet_staking_extension::ServerInfo; use scale_info::TypeInfo; - use sp_runtime::{ - traits::{DispatchInfoOf, SignedExtension}, - Saturating, - }; + use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use sp_std::{fmt::Debug, vec}; pub use crate::weights::WeightInfo; @@ -68,7 +65,6 @@ pub mod pallet { { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type PruneBlock: Get>; type SigningPartySize: Get; /// The weight information of this pallet. type WeightInfo: WeightInfo; @@ -257,13 +253,6 @@ pub mod pallet { pub fn prune_registration(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; let registering_info = Self::registering(&who).ok_or(Error::::NotRegistering)?; - let block_number = >::block_number(); - ensure!( - block_number.saturating_sub(registering_info.registration_block) - >= T::PruneBlock::get(), - Error::::NotLongEnough - ); - // return program deposit ProgramsPallet::::update_program_storage_deposit( ®istering_info.program_modification_account, diff --git a/pallets/relayer/src/mock.rs b/pallets/relayer/src/mock.rs index 742ba492d..d4fe60060 100644 --- a/pallets/relayer/src/mock.rs +++ b/pallets/relayer/src/mock.rs @@ -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 = (); diff --git a/pallets/relayer/src/tests.rs b/pallets/relayer/src/tests.rs index 6e20e0db5..43021e990 100644 --- a/pallets/relayer/src/tests.rs +++ b/pallets/relayer/src/tests.rs @@ -253,14 +253,7 @@ fn it_tests_prune_registration() { inital_program, )); assert_eq!(Balances::free_balance(2), 95, "Deposit is charged"); - - // checks to make sure it is not long enough - assert_noop!( - Relayer::prune_registration(RuntimeOrigin::signed(1)), - Error::::NotLongEnough - ); assert!(Relayer::registering(1).is_some(), "Make sure there is registering state"); - System::set_block_number(5); 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"); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index e56ebc8c7..a914dc1fe 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1272,12 +1272,10 @@ impl pallet_slashing::Config for Runtime { } parameter_types! { - pub const PruneBlock: BlockNumber = 20; 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; diff --git a/runtime/src/weights/pallet_relayer.rs b/runtime/src/weights/pallet_relayer.rs index 3930fccbc..4864447a2 100644 --- a/runtime/src/weights/pallet_relayer.rs +++ b/runtime/src/weights/pallet_relayer.rs @@ -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-11-02, 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: `` //! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -44,11 +44,11 @@ impl pallet_relayer::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `133` // Estimated: `3598` - // Minimum execution time: 20_000_000 picoseconds. - Weight::from_parts(15_100_000, 0) + // Minimum execution time: 17_000_000 picoseconds. + Weight::from_parts(16_300_000, 0) .saturating_add(Weight::from_parts(0, 3598)) - // Standard Error: 67 - .saturating_add(Weight::from_parts(586, 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)) } @@ -58,8 +58,8 @@ impl pallet_relayer::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `171` // Estimated: `3636` - // Minimum execution time: 12_000_000 picoseconds. - Weight::from_parts(12_000_000, 0) + // 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)) @@ -75,11 +75,11 @@ impl pallet_relayer::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `16502` // Estimated: `19967` - // Minimum execution time: 25_000_000 picoseconds. - Weight::from_parts(25_666_666, 0) + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(28_083_333, 0) .saturating_add(Weight::from_parts(0, 19967)) - // Standard Error: 338_501 - .saturating_add(Weight::from_parts(500_000, 0).saturating_mul(c.into())) + // 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)) } @@ -95,7 +95,7 @@ impl pallet_relayer::WeightInfo for WeightInfo { // Measured: `16504` // Estimated: `19969` // Minimum execution time: 25_000_000 picoseconds. - Weight::from_parts(26_916_666, 0) + 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)) @@ -117,8 +117,8 @@ impl pallet_relayer::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `16503` // Estimated: `19968` - // Minimum execution time: 29_000_000 picoseconds. - Weight::from_parts(30_583_333, 0) + // 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)) From 262303c4f34ae375cd5ba7417fa1e531437c2bb7 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:28:58 -0700 Subject: [PATCH 10/14] Update CHANGELOG.md Co-authored-by: Hernando Castano --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d51908244..e2eabd7d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,8 +36,8 @@ Some notables changes introduced in [#428](https://github.com/entropyxyz/entropy - 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 if dkg fails +- Add `prune_registration` extrinsic ([#472](https://github.com/entropyxyz/entropy-core/pull/472)) + - Allows for accounts to be moved out of registering state if DKG fails. ### Changed - Replace outdated `--ws-external` with `--rpc-external` ([#424](https://github.com/entropyxyz/entropy-core/pull/424)) From 58510b147d45580a667c97e6cc737174c17db83c Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:46:46 -0700 Subject: [PATCH 11/14] Update CHANGELOG.md Co-authored-by: Hernando Castano --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2eabd7d6..be501333c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ Some notables changes introduced in [#428](https://github.com/entropyxyz/entropy - 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 if DKG fails. + - 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)) From 8c7a0093be70ed53baf59727b972577cf273e6b6 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:46:54 -0700 Subject: [PATCH 12/14] Update pallets/relayer/src/lib.rs Co-authored-by: Hernando Castano --- pallets/relayer/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index cf741ec02..df47c4c87 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -254,11 +254,10 @@ pub mod pallet { let who = ensure_signed(origin)?; let registering_info = Self::registering(&who).ok_or(Error::::NotRegistering)?; // return program deposit - ProgramsPallet::::update_program_storage_deposit( + ProgramsPallet::::unreserve_program_deposit( ®istering_info.program_modification_account, registering_info.program.len(), - 0, - )?; + ); Registering::::remove(&who); Self::deposit_event(Event::RegistrationCancelled(who)); Ok(()) From 94c73b2facc56df05773f91f67cd889372adeb49 Mon Sep 17 00:00:00 2001 From: JesseAbram <33698952+JesseAbram@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:47:01 -0700 Subject: [PATCH 13/14] Update pallets/relayer/src/lib.rs Co-authored-by: Hernando Castano --- pallets/relayer/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index df47c4c87..e8bd3b760 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -173,7 +173,6 @@ pub mod pallet { NoSyncedValidators, MaxProgramLengthExceeded, NoVerifyingKey, - NotLongEnough, } #[pallet::call] From e4f71a895493813b995ab9a4874296e6b082a372 Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Fri, 3 Nov 2023 19:52:07 -0400 Subject: [PATCH 14/14] refactor --- crypto/server/entropy_metadata.scale | Bin 187178 -> 187277 bytes pallets/relayer/src/benchmarking.rs | 4 ---- pallets/relayer/src/lib.rs | 2 -- pallets/relayer/src/tests.rs | 3 --- 4 files changed, 9 deletions(-) diff --git a/crypto/server/entropy_metadata.scale b/crypto/server/entropy_metadata.scale index ebfaaa77c715c4e6f44efe6a6fd1f49c320af858..126bf3118f9834031cadc644e6d2036d829a228b 100644 GIT binary patch delta 180 zcmZ3rjk|X{_lC=jj1rr#G^R3&gaoCgXBL+fC6;97=Q$_lC8y@(Oy1ZeqQ$~8$1zVK zF*!NEG_OP<86uOKqEM2Nnpvb!grsY-WwQ$->*l)VdkYwOrpKxC@RfMjYn3+ vz{t`QoSLc-oe+?ilapFvWre9``x_O;X?=_$lh3#4w%^>$xc%m4ra*N7!RJPQ delta 76 zcmV-S0JHy%w+pJa3$W9H0Ti>;fn@=ci-SY~1hdeC-k<>pm#-uNlDB&$0h5jp7y(Ff iWoKz~baG*IX>V>{mr)i08::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&sig_req_account, balance); >::insert(&sig_req_account, RegisteringDetails:: { - registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: vec![], program: vec![], @@ -100,7 +99,6 @@ benchmarks! { } >::insert(&sig_req_account, RegisteringDetails:: { - registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: vec![], program: vec![], @@ -129,7 +127,6 @@ benchmarks! { let adjusted_sig_size = SIG_PARTIES - 1; let confirmation: Vec = (1u8..=adjusted_sig_size.try_into().unwrap()).collect(); >::insert(&sig_req_account, RegisteringDetails:: { - registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: confirmation, program: vec![], @@ -158,7 +155,6 @@ confirm_register_registered { let adjusted_sig_size = SIG_PARTIES - 1; let confirmation: Vec = (1u8..=adjusted_sig_size.try_into().unwrap()).collect(); >::insert(&sig_req_account, RegisteringDetails:: { - registration_block: 0u32.into(), program_modification_account: sig_req_account.clone(), confirmations: confirmation, program: vec![], diff --git a/pallets/relayer/src/lib.rs b/pallets/relayer/src/lib.rs index e8bd3b760..3a7433374 100644 --- a/pallets/relayer/src/lib.rs +++ b/pallets/relayer/src/lib.rs @@ -73,7 +73,6 @@ pub mod pallet { #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] pub struct RegisteringDetails { - pub registration_block: BlockNumberFor, pub program_modification_account: T::AccountId, pub confirmations: Vec, pub program: Vec, @@ -227,7 +226,6 @@ pub mod pallet { Registering::::insert( &sig_req_account, RegisteringDetails:: { - registration_block: block_number, program_modification_account, confirmations: vec![], program: initial_program, diff --git a/pallets/relayer/src/tests.rs b/pallets/relayer/src/tests.rs index 43021e990..d2879d3bf 100644 --- a/pallets/relayer/src/tests.rs +++ b/pallets/relayer/src/tests.rs @@ -65,8 +65,6 @@ fn it_registers_a_user() { KeyVisibility::Public, empty_program, )); - - assert_eq!(Relayer::registering(1).unwrap().registration_block, 0); assert_eq!(Relayer::dkg(0), vec![1u64.encode()]); }); } @@ -154,7 +152,6 @@ fn it_confirms_registers_a_user() { ); let registering_info = RegisteringDetails:: { - registration_block: 0, program_modification_account: 2 as ::AccountId, confirmations: vec![0], program: vec![],