From 3ce5f80a2a4fe1e92f6262c9e8db290dd59f0247 Mon Sep 17 00:00:00 2001 From: Fahrrader Date: Tue, 27 Dec 2022 13:09:20 +0000 Subject: [PATCH] refactor(collator-selection): rename revoke to release + update tx + cargo fmt --- --- a/pallets/collator-selection/src/lib.rs +++ b/pallets/collator-selection/src/lib.rs @@ -217,7 +217,7 @@ let bounded_invulnerables = BoundedVec::<_, T::MaxCollators>::try_from(self.invulnerables.clone()) .expect("genesis invulnerables are more than T::MaxCollators"); - + >::put(bounded_invulnerables); } } @@ -284,6 +284,7 @@ #[pallet::call] impl Pallet { /// Add a collator to the list of invulnerable (fixed) collators. + #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::set_invulnerables(1u32))] // todo:collator weight pub fn add_invulnerable( origin: OriginFor, @@ -313,6 +314,7 @@ } /// Remove a collator from the list of invulnerable (fixed) collators. + #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::set_invulnerables(1))] // todo:collator weight pub fn remove_invulnerable( origin: OriginFor, @@ -341,6 +343,7 @@ /// (a) already have registered session keys and (b) be able to reserve the `LicenseBond`. /// /// This call is not available to `Invulnerable` collators. + #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight pub fn get_license(origin: OriginFor) -> DispatchResultWithPostInfo { // register_as_candidate @@ -373,6 +376,7 @@ /// The account must already hold a license, and cannot offboard immediately during a session. /// /// This call is not available to `Invulnerable` collators. + #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight pub fn onboard(origin: OriginFor) -> DispatchResultWithPostInfo { // register_as_candidate @@ -418,6 +422,7 @@ /// Deregister `origin` as a collator candidate. Note that the collator can only leave on /// session change. The license to `onboard` later at any other time will remain. + #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight pub fn offboard(origin: OriginFor) -> DispatchResultWithPostInfo { // leave_intent @@ -430,6 +435,7 @@ /// Forfeit `origin`'s own license. The `LicenseBond` will be unreserved immediately. /// /// This call is not available to `Invulnerable` collators. + #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight pub fn release_license(origin: OriginFor) -> DispatchResultWithPostInfo { // leave_intent @@ -445,8 +451,9 @@ /// The `LicenseBond` will be unreserved and returned immediately. /// /// This call is, of course, not applicable to `Invulnerable` collators. + #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight - pub fn force_revoke_license( + pub fn force_release_license( origin: OriginFor, who: T::AccountId, ) -> DispatchResultWithPostInfo { --- a/pallets/collator-selection/src/mock.rs +++ b/pallets/collator-selection/src/mock.rs @@ -281,9 +281,7 @@ ) }) .collect::>(); - let collator_selection = collator_selection::GenesisConfig:: { - invulnerables, - }; + let collator_selection = collator_selection::GenesisConfig:: { invulnerables }; let session = pallet_session::GenesisConfig:: { keys }; pallet_balances::GenesisConfig:: { balances } .assimilate_storage(&mut t) --- a/pallets/collator-selection/src/tests.rs +++ b/pallets/collator-selection/src/tests.rs @@ -380,7 +380,7 @@ } #[test] -fn force_revoke_license() { +fn force_release_license() { new_test_ext().execute_with(|| { // obtain a license to collate and reserve the bond. assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(3))); @@ -388,12 +388,12 @@ // cannot execute the operation as non-root assert_noop!( - CollatorSelection::force_revoke_license(RuntimeOrigin::signed(3), 3), + CollatorSelection::force_release_license(RuntimeOrigin::signed(3), 3), BadOrigin ); // release the license and get the bond back. - assert_ok!(CollatorSelection::force_revoke_license( + assert_ok!(CollatorSelection::force_release_license( RuntimeOrigin::signed(RootAccount::get()), 3 )); @@ -404,7 +404,7 @@ assert_eq!(Balances::free_balance(3), 90); // can release license even if onboarded. - assert_ok!(CollatorSelection::force_revoke_license( + assert_ok!(CollatorSelection::force_release_license( RuntimeOrigin::signed(RootAccount::get()), 3 )); @@ -532,9 +532,7 @@ .unwrap(); let invulnerables = vec![1, 1]; - let collator_selection = collator_selection::GenesisConfig:: { - invulnerables, - }; + let collator_selection = collator_selection::GenesisConfig:: { invulnerables }; // collator selection must be initialized before session. collator_selection.assimilate_storage(&mut t).unwrap(); } --- a/pallets/configuration/src/lib.rs +++ b/pallets/configuration/src/lib.rs @@ -201,6 +201,7 @@ Ok(()) } + #[pallet::call_index(4)] #[pallet::weight(T::DbWeight::get().writes(1))] pub fn set_collator_selection_desired_collators( origin: OriginFor, @@ -216,10 +217,13 @@ } else { >::kill(); } - Self::deposit_event(Event::NewDesiredCollators { desired_collators: max }); + Self::deposit_event(Event::NewDesiredCollators { + desired_collators: max, + }); Ok(()) } + #[pallet::call_index(5)] #[pallet::weight(T::DbWeight::get().writes(1))] pub fn set_collator_selection_license_bond( origin: OriginFor, @@ -235,6 +239,7 @@ Ok(()) } + #[pallet::call_index(6)] #[pallet::weight(T::DbWeight::get().writes(1))] pub fn set_collator_selection_kick_threshold( origin: OriginFor, @@ -246,7 +251,9 @@ } else { >::kill(); } - Self::deposit_event(Event::NewCollatorKickThreshold { length_in_blocks: threshold }); + Self::deposit_event(Event::NewCollatorKickThreshold { + length_in_blocks: threshold, + }); Ok(()) } } --- a/runtime/common/data_management.rs +++ b/runtime/common/data_management.rs @@ -58,10 +58,10 @@ _info: &DispatchInfoOf, _len: usize, ) -> TransactionValidity { - match call { - #[cfg(feature = "collator-selection")] - RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), - _ => Ok(ValidTransaction::default()), - } + match call { + #[cfg(feature = "collator-selection")] + RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), + _ => Ok(ValidTransaction::default()), + } } } --- a/runtime/common/mod.rs +++ b/runtime/common/mod.rs @@ -16,11 +16,11 @@ pub mod config; pub mod construct_runtime; +pub mod data_management; pub mod dispatch; pub mod ethereum; pub mod instance; pub mod maintenance; -pub mod data_management; pub mod runtime_apis; pub mod xcm; --- a/runtime/common/tests/mod.rs +++ b/runtime/common/tests/mod.rs @@ -63,9 +63,7 @@ .collect::>(); let cfg = GenesisConfig { - collator_selection: CollatorSelectionConfig { - invulnerables, - }, + collator_selection: CollatorSelectionConfig { invulnerables }, session: SessionConfig { keys }, parachain_info: ParachainInfoConfig { parachain_id: para_id.into(), --- a/tests/src/collatorSelection.seqtest.ts +++ b/tests/src/collatorSelection.seqtest.ts @@ -209,7 +209,7 @@ expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(licenseBond); // force-releasing a license un-reserves the license bond cost as well - await helper.getSudo().collatorSelection.forceRevokeLicense(superuser, account.address); + await helper.getSudo().collatorSelection.forceReleaseLicense(superuser, account.address); expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(previousBalance.reserved); const balance = await helper.balance.getSubstrateFull(account.address); @@ -243,7 +243,7 @@ itSub('Cannot force revoke a license as non-sudo', async ({helper}) => { const account = crowd.pop()!; await helper.collatorSelection.obtainLicense(account); - await expect(helper.collatorSelection.forceRevokeLicense(superuser, account.address)) + await expect(helper.collatorSelection.forceReleaseLicense(superuser, account.address)) .to.be.rejectedWith(/BadOrigin/); }); }); @@ -459,7 +459,7 @@ const candidates = await helper.collatorSelection.getCandidates(); let nonce = await helper.chain.getNonce(superuser.address); await Promise.all(candidates.map(candidate => - helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.forceRevokeLicense', [candidate], true, {nonce: nonce++}))); + helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.forceReleaseLicense', [candidate], true, {nonce: nonce++}))); }); }); }); \ No newline at end of file --- a/tests/src/interfaces/augment-api-tx.ts +++ b/tests/src/interfaces/augment-api-tx.ts @@ -237,7 +237,7 @@ * * This call is, of course, not applicable to `Invulnerable` collators. **/ - forceRevokeLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic, [AccountId32]>; + forceReleaseLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic, [AccountId32]>; /** * Purchase a license on block collation for this account. * It does not make it a collator candidate, use `onboard` afterward. The account must --- a/tests/src/interfaces/default/types.ts +++ b/tests/src/interfaces/default/types.ts @@ -1243,11 +1243,11 @@ readonly isOnboard: boolean; readonly isOffboard: boolean; readonly isReleaseLicense: boolean; - readonly isForceRevokeLicense: boolean; - readonly asForceRevokeLicense: { + readonly isForceReleaseLicense: boolean; + readonly asForceReleaseLicense: { readonly who: AccountId32; } & Struct; - readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceRevokeLicense'; + readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceReleaseLicense'; } /** @name PalletCollatorSelectionError */ --- a/tests/src/interfaces/lookup.ts +++ b/tests/src/interfaces/lookup.ts @@ -1692,7 +1692,7 @@ onboard: 'Null', offboard: 'Null', release_license: 'Null', - force_revoke_license: { + force_release_license: { who: 'AccountId32' } } --- a/tests/src/interfaces/types-lookup.ts +++ b/tests/src/interfaces/types-lookup.ts @@ -1867,11 +1867,11 @@ readonly isOnboard: boolean; readonly isOffboard: boolean; readonly isReleaseLicense: boolean; - readonly isForceRevokeLicense: boolean; - readonly asForceRevokeLicense: { + readonly isForceReleaseLicense: boolean; + readonly asForceReleaseLicense: { readonly who: AccountId32; } & Struct; - readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceRevokeLicense'; + readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceReleaseLicense'; } /** @name PalletCollatorSelectionError (185) */ --- a/tests/src/util/playgrounds/unique.ts +++ b/tests/src/util/playgrounds/unique.ts @@ -2772,8 +2772,8 @@ return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.releaseLicense', []); } - forceRevokeLicense(signer: TSigner, released: string) { - return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.forceRevokeLicense', [released]); + forceReleaseLicense(signer: TSigner, released: string) { + return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.forceReleaseLicense', [released]); } async hasLicense(address: string): Promise { -- gitstuff