difftreelog
refactor(collator-selection) rename revoke to release + update tx + cargo fmt
in: master
13 files changed
pallets/collator-selection/src/lib.rsdiffbeforeafterboth--- 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");
-
+
<Invulnerables<T>>::put(bounded_invulnerables);
}
}
@@ -284,6 +284,7 @@
#[pallet::call]
impl<T: Config> Pallet<T> {
/// 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<T>,
@@ -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<T>,
@@ -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<T>) -> 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<T>) -> 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<T>) -> 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<T>) -> 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<T>,
who: T::AccountId,
) -> DispatchResultWithPostInfo {
pallets/collator-selection/src/mock.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/mock.rs
+++ b/pallets/collator-selection/src/mock.rs
@@ -281,9 +281,7 @@
)
})
.collect::<Vec<_>>();
- let collator_selection = collator_selection::GenesisConfig::<Test> {
- invulnerables,
- };
+ let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };
let session = pallet_session::GenesisConfig::<Test> { keys };
pallet_balances::GenesisConfig::<Test> { balances }
.assimilate_storage(&mut t)
pallets/collator-selection/src/tests.rsdiffbeforeafterboth--- 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::<Test> {
- invulnerables,
- };
+ let collator_selection = collator_selection::GenesisConfig::<Test> { invulnerables };
// collator selection must be initialized before session.
collator_selection.assimilate_storage(&mut t).unwrap();
}
pallets/configuration/src/lib.rsdiffbeforeafterboth--- 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<T>,
@@ -216,10 +217,13 @@
} else {
<CollatorSelectionDesiredCollatorsOverride<T>>::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<T>,
@@ -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<T>,
@@ -246,7 +251,9 @@
} else {
<CollatorSelectionKickThresholdOverride<T>>::kill();
}
- Self::deposit_event(Event::NewCollatorKickThreshold { length_in_blocks: threshold });
+ Self::deposit_event(Event::NewCollatorKickThreshold {
+ length_in_blocks: threshold,
+ });
Ok(())
}
}
runtime/common/data_management.rsdiffbeforeafterboth--- a/runtime/common/data_management.rs
+++ b/runtime/common/data_management.rs
@@ -58,10 +58,10 @@
_info: &DispatchInfoOf<Self::Call>,
_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()),
+ }
}
}
runtime/common/mod.rsdiffbeforeafterboth--- 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;
runtime/common/tests/mod.rsdiffbeforeafterboth--- a/runtime/common/tests/mod.rs
+++ b/runtime/common/tests/mod.rs
@@ -63,9 +63,7 @@
.collect::<Vec<_>>();
let cfg = GenesisConfig {
- collator_selection: CollatorSelectionConfig {
- invulnerables,
- },
+ collator_selection: CollatorSelectionConfig { invulnerables },
session: SessionConfig { keys },
parachain_info: ParachainInfoConfig {
parachain_id: para_id.into(),
tests/src/collatorSelection.seqtest.tsdiffbeforeafterboth209 expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(licenseBond);209 expect(await helper.collatorSelection.hasLicense(account.address)).to.be.equal(licenseBond);210210211 // force-releasing a license un-reserves the license bond cost as well211 // force-releasing a license un-reserves the license bond cost as well212 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);214214215 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});tests/src/interfaces/augment-api-tx.tsdiffbeforeafterboth--- 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<ApiType>, [AccountId32]>;
+ forceReleaseLicense: AugmentedSubmittable<(who: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [AccountId32]>;
/**
* Purchase a license on block collation for this account.
* It does not make it a collator candidate, use `onboard` afterward. The account must
tests/src/interfaces/default/types.tsdiffbeforeafterboth--- 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 */
tests/src/interfaces/lookup.tsdiffbeforeafterboth--- 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'
}
}
tests/src/interfaces/types-lookup.tsdiffbeforeafterboth--- 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) */
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- 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<bigint> {