git.delta.rocks / unique-network / refs/commits / 3ce5f80a2a4f

difftreelog

refactor(collator-selection) rename revoke to release + update tx + cargo fmt

Fahrrader2022-12-27parent: #8de2dcb.patch.diff
in: master

13 files changed

modifiedpallets/collator-selection/src/lib.rsdiffbeforeafterboth
284 #[pallet::call]284 #[pallet::call]
285 impl<T: Config> Pallet<T> {285 impl<T: Config> Pallet<T> {
286 /// Add a collator to the list of invulnerable (fixed) collators.286 /// Add a collator to the list of invulnerable (fixed) collators.
287 #[pallet::call_index(0)]
287 #[pallet::weight(T::WeightInfo::set_invulnerables(1u32))] // todo:collator weight288 #[pallet::weight(T::WeightInfo::set_invulnerables(1u32))] // todo:collator weight
288 pub fn add_invulnerable(289 pub fn add_invulnerable(
289 origin: OriginFor<T>,290 origin: OriginFor<T>,
313 }314 }
314315
315 /// Remove a collator from the list of invulnerable (fixed) collators.316 /// Remove a collator from the list of invulnerable (fixed) collators.
317 #[pallet::call_index(1)]
316 #[pallet::weight(T::WeightInfo::set_invulnerables(1))] // todo:collator weight318 #[pallet::weight(T::WeightInfo::set_invulnerables(1))] // todo:collator weight
317 pub fn remove_invulnerable(319 pub fn remove_invulnerable(
318 origin: OriginFor<T>,320 origin: OriginFor<T>,
341 /// (a) already have registered session keys and (b) be able to reserve the `LicenseBond`.343 /// (a) already have registered session keys and (b) be able to reserve the `LicenseBond`.
342 ///344 ///
343 /// This call is not available to `Invulnerable` collators.345 /// This call is not available to `Invulnerable` collators.
346 #[pallet::call_index(2)]
344 #[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight347 #[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight
345 pub fn get_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {348 pub fn get_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
346 // register_as_candidate349 // register_as_candidate
373 /// The account must already hold a license, and cannot offboard immediately during a session.376 /// The account must already hold a license, and cannot offboard immediately during a session.
374 ///377 ///
375 /// This call is not available to `Invulnerable` collators.378 /// This call is not available to `Invulnerable` collators.
379 #[pallet::call_index(3)]
376 #[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight380 #[pallet::weight(T::WeightInfo::register_as_candidate(T::MaxCollators::get()))] // todo:collator weight
377 pub fn onboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {381 pub fn onboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
378 // register_as_candidate382 // register_as_candidate
418422
419 /// Deregister `origin` as a collator candidate. Note that the collator can only leave on423 /// Deregister `origin` as a collator candidate. Note that the collator can only leave on
420 /// session change. The license to `onboard` later at any other time will remain.424 /// session change. The license to `onboard` later at any other time will remain.
425 #[pallet::call_index(4)]
421 #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight426 #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight
422 pub fn offboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {427 pub fn offboard(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
423 // leave_intent428 // leave_intent
430 /// Forfeit `origin`'s own license. The `LicenseBond` will be unreserved immediately.435 /// Forfeit `origin`'s own license. The `LicenseBond` will be unreserved immediately.
431 ///436 ///
432 /// This call is not available to `Invulnerable` collators.437 /// This call is not available to `Invulnerable` collators.
438 #[pallet::call_index(5)]
433 #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight439 #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight
434 pub fn release_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {440 pub fn release_license(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
435 // leave_intent441 // leave_intent
445 /// The `LicenseBond` will be unreserved and returned immediately.451 /// The `LicenseBond` will be unreserved and returned immediately.
446 ///452 ///
447 /// This call is, of course, not applicable to `Invulnerable` collators.453 /// This call is, of course, not applicable to `Invulnerable` collators.
454 #[pallet::call_index(6)]
448 #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight455 #[pallet::weight(T::WeightInfo::leave_intent(T::MaxCollators::get()))] // todo:collator weight
449 pub fn force_revoke_license(456 pub fn force_release_license(
450 origin: OriginFor<T>,457 origin: OriginFor<T>,
451 who: T::AccountId,458 who: T::AccountId,
452 ) -> DispatchResultWithPostInfo {459 ) -> DispatchResultWithPostInfo {
modifiedpallets/collator-selection/src/mock.rsdiffbeforeafterboth
282 })282 })
283 .collect::<Vec<_>>();283 .collect::<Vec<_>>();
284 let collator_selection = collator_selection::GenesisConfig::<Test> {284 let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };
285 invulnerables,
286 };
287 let session = pallet_session::GenesisConfig::<Test> { keys };285 let session = pallet_session::GenesisConfig::<Test> { keys };
288 pallet_balances::GenesisConfig::<Test> { balances }286 pallet_balances::GenesisConfig::<Test> { balances }
modifiedpallets/collator-selection/src/tests.rsdiffbeforeafterboth
380}380}
381381
382#[test]382#[test]
383fn force_revoke_license() {383fn force_release_license() {
384 new_test_ext().execute_with(|| {384 new_test_ext().execute_with(|| {
385 // obtain a license to collate and reserve the bond.385 // obtain a license to collate and reserve the bond.
386 assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(3)));386 assert_ok!(CollatorSelection::get_license(RuntimeOrigin::signed(3)));
387 assert_eq!(Balances::free_balance(3), 90);387 assert_eq!(Balances::free_balance(3), 90);
388388
389 // cannot execute the operation as non-root389 // cannot execute the operation as non-root
390 assert_noop!(390 assert_noop!(
391 CollatorSelection::force_revoke_license(RuntimeOrigin::signed(3), 3),391 CollatorSelection::force_release_license(RuntimeOrigin::signed(3), 3),
392 BadOrigin392 BadOrigin
393 );393 );
394394
395 // release the license and get the bond back.395 // release the license and get the bond back.
396 assert_ok!(CollatorSelection::force_revoke_license(396 assert_ok!(CollatorSelection::force_release_license(
397 RuntimeOrigin::signed(RootAccount::get()),397 RuntimeOrigin::signed(RootAccount::get()),
398 3398 3
399 ));399 ));
404 assert_eq!(Balances::free_balance(3), 90);404 assert_eq!(Balances::free_balance(3), 90);
405405
406 // can release license even if onboarded.406 // can release license even if onboarded.
407 assert_ok!(CollatorSelection::force_revoke_license(407 assert_ok!(CollatorSelection::force_release_license(
408 RuntimeOrigin::signed(RootAccount::get()),408 RuntimeOrigin::signed(RootAccount::get()),
409 3409 3
410 ));410 ));
533 let invulnerables = vec![1, 1];533 let invulnerables = vec![1, 1];
534534
535 let collator_selection = collator_selection::GenesisConfig::<Test> {535 let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };
536 invulnerables,
537 };
538 // collator selection must be initialized before session.536 // collator selection must be initialized before session.
539 collator_selection.assimilate_storage(&mut t).unwrap();537 collator_selection.assimilate_storage(&mut t).unwrap();
modifiedpallets/configuration/src/lib.rsdiffbeforeafterboth
201 Ok(())201 Ok(())
202 }202 }
203203
204 #[pallet::call_index(4)]
204 #[pallet::weight(T::DbWeight::get().writes(1))]205 #[pallet::weight(T::DbWeight::get().writes(1))]
205 pub fn set_collator_selection_desired_collators(206 pub fn set_collator_selection_desired_collators(
206 origin: OriginFor<T>,207 origin: OriginFor<T>,
217 <CollatorSelectionDesiredCollatorsOverride<T>>::kill();218 <CollatorSelectionDesiredCollatorsOverride<T>>::kill();
218 }219 }
219 Self::deposit_event(Event::NewDesiredCollators { desired_collators: max });220 Self::deposit_event(Event::NewDesiredCollators {
221 desired_collators: max,
222 });
220 Ok(())223 Ok(())
221 }224 }
222225
226 #[pallet::call_index(5)]
223 #[pallet::weight(T::DbWeight::get().writes(1))]227 #[pallet::weight(T::DbWeight::get().writes(1))]
224 pub fn set_collator_selection_license_bond(228 pub fn set_collator_selection_license_bond(
225 origin: OriginFor<T>,229 origin: OriginFor<T>,
235 Ok(())239 Ok(())
236 }240 }
237241
242 #[pallet::call_index(6)]
238 #[pallet::weight(T::DbWeight::get().writes(1))]243 #[pallet::weight(T::DbWeight::get().writes(1))]
239 pub fn set_collator_selection_kick_threshold(244 pub fn set_collator_selection_kick_threshold(
240 origin: OriginFor<T>,245 origin: OriginFor<T>,
247 <CollatorSelectionKickThresholdOverride<T>>::kill();252 <CollatorSelectionKickThresholdOverride<T>>::kill();
248 }253 }
249 Self::deposit_event(Event::NewCollatorKickThreshold { length_in_blocks: threshold });254 Self::deposit_event(Event::NewCollatorKickThreshold {
255 length_in_blocks: threshold,
256 });
250 Ok(())257 Ok(())
251 }258 }
modifiedruntime/common/data_management.rsdiffbeforeafterboth

no syntactic changes

modifiedruntime/common/mod.rsdiffbeforeafterboth
1616
17pub mod config;17pub mod config;
18pub mod construct_runtime;18pub mod construct_runtime;
19pub mod data_management;
19pub mod dispatch;20pub mod dispatch;
20pub mod ethereum;21pub mod ethereum;
21pub mod instance;22pub mod instance;
22pub mod maintenance;23pub mod maintenance;
23pub mod data_management;
24pub mod runtime_apis;24pub mod runtime_apis;
25pub mod xcm;25pub mod xcm;
2626
modifiedruntime/common/tests/mod.rsdiffbeforeafterboth
6464
65 let cfg = GenesisConfig {65 let cfg = GenesisConfig {
66 collator_selection: CollatorSelectionConfig {66 collator_selection: CollatorSelectionConfig { invulnerables },
67 invulnerables,
68 },
69 session: SessionConfig { keys },67 session: SessionConfig { keys },
70 parachain_info: ParachainInfoConfig {68 parachain_info: ParachainInfoConfig {
modifiedtests/src/collatorSelection.seqtest.tsdiffbeforeafterboth
209 expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(licenseBond);209 expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(licenseBond);
210210
211 // force-releasing a license un-reserves the license bond cost as well211 // force-releasing a license un-reserves the license bond cost as well
212 await helper.getSudo().collatorSelection.forceRevokeLicense(superuser, account.address);212 await helper.getSudo().collatorSelection.forceReleaseLicense(superuser, account.address);
213 expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(previousBalance.reserved);213 expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(previousBalance.reserved);
214214
215 const balance = await helper.balance.getSubstrateFull(account.address);215 const balance = await helper.balance.getSubstrateFull(account.address);
243 itSub('Cannot force revoke a license as non-sudo', async ({helper}) => {243 itSub('Cannot force revoke a license as non-sudo', async ({helper}) => {
244 const account = crowd.pop()!;244 const account = crowd.pop()!;
245 await helper.collatorSelection.obtainLicense(account);245 await helper.collatorSelection.obtainLicense(account);
246 await expect(helper.collatorSelection.forceRevokeLicense(superuser, account.address))246 await expect(helper.collatorSelection.forceReleaseLicense(superuser, account.address))
247 .to.be.rejectedWith(/BadOrigin/);247 .to.be.rejectedWith(/BadOrigin/);
248 });248 });
249 });249 });
459 const candidates = await helper.collatorSelection.getCandidates();459 const candidates = await helper.collatorSelection.getCandidates();
460 let nonce = await helper.chain.getNonce(superuser.address);460 let nonce = await helper.chain.getNonce(superuser.address);
461 await Promise.all(candidates.map(candidate =>461 await Promise.all(candidates.map(candidate =>
462 helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.forceRevokeLicense', [candidate], true, {nonce: nonce++})));462 helper.getSudo().executeExtrinsic(superuser, 'api.tx.collatorSelection.forceReleaseLicense', [candidate], true, {nonce: nonce++})));
463 });463 });
464 });464 });
465});465});
modifiedtests/src/interfaces/augment-api-tx.tsdiffbeforeafterboth
237 * 237 *
238 * This call is, of course, not applicable to `Invulnerable` collators.238 * This call is, of course, not applicable to `Invulnerable` collators.
239 **/239 **/
240 forceRevokeLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [AccountId32]>;240 forceReleaseLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [AccountId32]>;
241 /**241 /**
242 * Purchase a license on block collation for this account.242 * Purchase a license on block collation for this account.
243 * It does not make it a collator candidate, use `onboard` afterward. The account must243 * It does not make it a collator candidate, use `onboard` afterward. The account must
modifiedtests/src/interfaces/default/types.tsdiffbeforeafterboth
1243 readonly isOnboard: boolean;1243 readonly isOnboard: boolean;
1244 readonly isOffboard: boolean;1244 readonly isOffboard: boolean;
1245 readonly isReleaseLicense: boolean;1245 readonly isReleaseLicense: boolean;
1246 readonly isForceRevokeLicense: boolean;1246 readonly isForceReleaseLicense: boolean;
1247 readonly asForceRevokeLicense: {1247 readonly asForceReleaseLicense: {
1248 readonly who: AccountId32;1248 readonly who: AccountId32;
1249 } & Struct;1249 } & Struct;
1250 readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceRevokeLicense';1250 readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceReleaseLicense';
1251}1251}
12521252
1253/** @name PalletCollatorSelectionError */1253/** @name PalletCollatorSelectionError */
modifiedtests/src/interfaces/lookup.tsdiffbeforeafterboth
1692 onboard: 'Null',1692 onboard: 'Null',
1693 offboard: 'Null',1693 offboard: 'Null',
1694 release_license: 'Null',1694 release_license: 'Null',
1695 force_revoke_license: {1695 force_release_license: {
1696 who: 'AccountId32'1696 who: 'AccountId32'
1697 }1697 }
1698 }1698 }
modifiedtests/src/interfaces/types-lookup.tsdiffbeforeafterboth
1867 readonly isOnboard: boolean;1867 readonly isOnboard: boolean;
1868 readonly isOffboard: boolean;1868 readonly isOffboard: boolean;
1869 readonly isReleaseLicense: boolean;1869 readonly isReleaseLicense: boolean;
1870 readonly isForceRevokeLicense: boolean;1870 readonly isForceReleaseLicense: boolean;
1871 readonly asForceRevokeLicense: {1871 readonly asForceReleaseLicense: {
1872 readonly who: AccountId32;1872 readonly who: AccountId32;
1873 } & Struct;1873 } & Struct;
1874 readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceRevokeLicense';1874 readonly type: 'AddInvulnerable' | 'RemoveInvulnerable' | 'GetLicense' | 'Onboard' | 'Offboard' | 'ReleaseLicense' | 'ForceReleaseLicense';
1875 }1875 }
18761876
1877 /** @name PalletCollatorSelectionError (185) */1877 /** @name PalletCollatorSelectionError (185) */
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
2772 return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.releaseLicense', []);2772 return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.releaseLicense', []);
2773 }2773 }
27742774
2775 forceRevokeLicense(signer: TSigner, released: string) {2775 forceReleaseLicense(signer: TSigner, released: string) {
2776 return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.forceRevokeLicense', [released]);2776 return this.helper.executeExtrinsic(signer, 'api.tx.collatorSelection.forceReleaseLicense', [released]);
2777 }2777 }
27782778
2779 async hasLicense(address: string): Promise<bigint> {2779 async hasLicense(address: string): Promise<bigint> {