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.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use sp_runtime::BuildStorage;18use sp_core::{Public, Pair};19use sp_std::vec;20use up_common::types::AuraId;21use crate::{GenesisConfig, ParachainInfoConfig};2223pub mod xcm;2425fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {26 TPublic::Pair::from_string(&format!("//{}", seed), None)27 .expect("static values are valid; qed")28 .public()29}3031#[cfg(feature = "collator-selection")]32fn new_test_ext(para_id: u32) -> sp_io::TestExternalities {33 use sp_core::{sr25519};34 use sp_runtime::traits::{IdentifyAccount, Verify};35 use crate::{AccountId, Signature, SessionKeys, CollatorSelectionConfig, SessionConfig};3637 type AccountPublic = <Signature as Verify>::Signer;3839 fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId40 where41 AccountPublic: From<<TPublic::Pair as Pair>::Public>,42 {43 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()44 }4546 let accounts = vec!["Alice", "Bob"];47 let keys = accounts48 .iter()49 .map(|&acc| {50 let account_id = get_account_id_from_seed::<sr25519::Public>(acc);51 (52 account_id.clone(),53 account_id,54 SessionKeys {55 aura: get_from_seed::<AuraId>(acc),56 },57 )58 })59 .collect::<Vec<_>>();60 let invulnerables = accounts61 .iter()62 .map(|acc| get_account_id_from_seed::<sr25519::Public>(acc))63 .collect::<Vec<_>>();6465 let cfg = GenesisConfig {66 collator_selection: CollatorSelectionConfig {67 invulnerables,68 },69 session: SessionConfig { keys },70 parachain_info: ParachainInfoConfig {71 parachain_id: para_id.into(),72 },73 ..GenesisConfig::default()74 };7576 cfg.build_storage().unwrap().into()77}7879#[cfg(not(feature = "collator-selection"))]80fn new_test_ext(para_id: u32) -> sp_io::TestExternalities {81 use crate::AuraConfig;8283 let cfg = GenesisConfig {84 aura: AuraConfig {85 authorities: vec![86 get_from_seed::<AuraId>("Alice"),87 get_from_seed::<AuraId>("Bob"),88 ],89 },90 parachain_info: ParachainInfoConfig {91 parachain_id: para_id.into(),92 },93 ..GenesisConfig::default()94 };9596 cfg.build_storage().unwrap().into()97}tests/src/collatorSelection.seqtest.tsdiffbeforeafterboth--- 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
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> {