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.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::marker::PhantomData;2021use frame_support::{22 pallet,23 weights::{WeightToFeePolynomial, WeightToFeeCoefficients, WeightToFeeCoefficient, Weight},24 traits::Get,25};26use parity_scale_codec::{Decode, Encode, MaxEncodedLen};27use scale_info::TypeInfo;28use sp_arithmetic::{29 per_things::{Perbill, PerThing},30 traits::{BaseArithmetic, Unsigned},31};32use smallvec::smallvec;3334pub use pallet::*;35use sp_core::U256;3637#[pallet]38mod pallet {39 use super::*;40 use frame_support::{41 traits::{Get, ReservableCurrency, Currency},42 pallet_prelude::{StorageValue, ValueQuery, DispatchResult, IsType, OptionQuery},43 BoundedVec, log,44 };45 use frame_system::{pallet_prelude::OriginFor, ensure_root, Config as SystemConfig};46 use xcm::v1::MultiLocation;4748 pub type BalanceOf<T> =49 <<T as Config>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;5051 #[pallet::config]52 pub trait Config: frame_system::Config {53 /// Overarching event type.54 type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;5556 /// The currency mechanism.57 type Currency: ReservableCurrency<Self::AccountId>;5859 #[pallet::constant]60 type DefaultWeightToFeeCoefficient: Get<u64>;61 #[pallet::constant]62 type DefaultMinGasPrice: Get<u64>;6364 #[pallet::constant]65 type MaxXcmAllowedLocations: Get<u32>;66 #[pallet::constant]67 type AppPromotionDailyRate: Get<Perbill>;68 #[pallet::constant]69 type DayRelayBlocks: Get<Self::BlockNumber>;7071 #[pallet::constant]72 type DefaultCollatorSelectionMaxCollators: Get<u32>;73 #[pallet::constant]74 type DefaultCollatorSelectionLicenseBond: Get<BalanceOf<Self>>;75 #[pallet::constant]76 type DefaultCollatorSelectionKickThreshold: Get<Self::BlockNumber>;77 }7879 #[pallet::event]80 #[pallet::generate_deposit(pub(super) fn deposit_event)]81 pub enum Event<T: Config> {82 NewDesiredCollators {83 desired_collators: Option<u32>,84 },85 NewCollatorLicenseBond {86 bond_cost: Option<BalanceOf<T>>,87 },88 NewCollatorKickThreshold {89 length_in_blocks: Option<T::BlockNumber>,90 },91 }9293 #[pallet::error]94 pub enum Error<T> {95 InconsistentConfiguration,96 }9798 #[pallet::storage]99 pub type WeightToFeeCoefficientOverride<T: Config> = StorageValue<100 Value = u64,101 QueryKind = ValueQuery,102 OnEmpty = T::DefaultWeightToFeeCoefficient,103 >;104105 #[pallet::storage]106 pub type MinGasPriceOverride<T: Config> =107 StorageValue<Value = u64, QueryKind = ValueQuery, OnEmpty = T::DefaultMinGasPrice>;108109 #[pallet::storage]110 pub type XcmAllowedLocationsOverride<T: Config> = StorageValue<111 Value = BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>,112 QueryKind = OptionQuery,113 >;114115 #[pallet::storage]116 pub type AppPromomotionConfigurationOverride<T: Config> =117 StorageValue<Value = AppPromotionConfiguration<T::BlockNumber>, QueryKind = ValueQuery>;118119 #[pallet::storage]120 pub type CollatorSelectionDesiredCollatorsOverride<T: Config> = StorageValue<121 Value = u32,122 QueryKind = ValueQuery,123 OnEmpty = T::DefaultCollatorSelectionMaxCollators,124 >;125126 #[pallet::storage]127 pub type CollatorSelectionLicenseBondOverride<T: Config> = StorageValue<128 Value = BalanceOf<T>,129 QueryKind = ValueQuery,130 OnEmpty = T::DefaultCollatorSelectionLicenseBond,131 >;132133 #[pallet::storage]134 pub type CollatorSelectionKickThresholdOverride<T: Config> = StorageValue<135 Value = T::BlockNumber,136 QueryKind = ValueQuery,137 OnEmpty = T::DefaultCollatorSelectionKickThreshold,138 >;139140 #[pallet::call]141 impl<T: Config> Pallet<T> {142 #[pallet::call_index(0)]143 #[pallet::weight(T::DbWeight::get().writes(1))]144 pub fn set_weight_to_fee_coefficient_override(145 origin: OriginFor<T>,146 coeff: Option<u64>,147 ) -> DispatchResult {148 ensure_root(origin)?;149 if let Some(coeff) = coeff {150 <WeightToFeeCoefficientOverride<T>>::set(coeff);151 } else {152 <WeightToFeeCoefficientOverride<T>>::kill();153 }154 Ok(())155 }156157 #[pallet::call_index(1)]158 #[pallet::weight(T::DbWeight::get().writes(1))]159 pub fn set_min_gas_price_override(160 origin: OriginFor<T>,161 coeff: Option<u64>,162 ) -> DispatchResult {163 ensure_root(origin)?;164 if let Some(coeff) = coeff {165 <MinGasPriceOverride<T>>::set(coeff);166 } else {167 <MinGasPriceOverride<T>>::kill();168 }169 Ok(())170 }171172 #[pallet::call_index(2)]173 #[pallet::weight(T::DbWeight::get().writes(1))]174 pub fn set_xcm_allowed_locations(175 origin: OriginFor<T>,176 locations: Option<BoundedVec<MultiLocation, T::MaxXcmAllowedLocations>>,177 ) -> DispatchResult {178 ensure_root(origin)?;179 <XcmAllowedLocationsOverride<T>>::set(locations);180 Ok(())181 }182183 #[pallet::call_index(3)]184 #[pallet::weight(T::DbWeight::get().writes(1))]185 pub fn set_app_promotion_configuration_override(186 origin: OriginFor<T>,187 mut configuration: AppPromotionConfiguration<T::BlockNumber>,188 ) -> DispatchResult {189 ensure_root(origin)?;190 if configuration.interval_income.is_some() {191 return Err(<Error<T>>::InconsistentConfiguration.into());192 }193194 configuration.interval_income = configuration.recalculation_interval.map(|b| {195 Perbill::from_rational(b, T::DayRelayBlocks::get())196 * T::AppPromotionDailyRate::get()197 });198199 <AppPromomotionConfigurationOverride<T>>::set(configuration);200201 Ok(())202 }203204 #[pallet::weight(T::DbWeight::get().writes(1))]205 pub fn set_collator_selection_desired_collators(206 origin: OriginFor<T>,207 max: Option<u32>,208 ) -> DispatchResult {209 ensure_root(origin)?;210 if let Some(max) = max {211 // we trust origin calls, this is just a for more accurate benchmarking212 if max > T::DefaultCollatorSelectionMaxCollators::get() {213 log::warn!("max > T::DefaultCollatorSelectionMaxCollators; you might need to run benchmarks again");214 }215 <CollatorSelectionDesiredCollatorsOverride<T>>::set(max);216 } else {217 <CollatorSelectionDesiredCollatorsOverride<T>>::kill();218 }219 Self::deposit_event(Event::NewDesiredCollators { desired_collators: max });220 Ok(())221 }222223 #[pallet::weight(T::DbWeight::get().writes(1))]224 pub fn set_collator_selection_license_bond(225 origin: OriginFor<T>,226 amount: Option<BalanceOf<T>>,227 ) -> DispatchResult {228 ensure_root(origin)?;229 if let Some(amount) = amount {230 <CollatorSelectionLicenseBondOverride<T>>::set(amount);231 } else {232 <CollatorSelectionLicenseBondOverride<T>>::kill();233 }234 Self::deposit_event(Event::NewCollatorLicenseBond { bond_cost: amount });235 Ok(())236 }237238 #[pallet::weight(T::DbWeight::get().writes(1))]239 pub fn set_collator_selection_kick_threshold(240 origin: OriginFor<T>,241 threshold: Option<T::BlockNumber>,242 ) -> DispatchResult {243 ensure_root(origin)?;244 if let Some(threshold) = threshold {245 <CollatorSelectionKickThresholdOverride<T>>::set(threshold);246 } else {247 <CollatorSelectionKickThresholdOverride<T>>::kill();248 }249 Self::deposit_event(Event::NewCollatorKickThreshold { length_in_blocks: threshold });250 Ok(())251 }252 }253254 #[pallet::pallet]255 #[pallet::generate_store(pub(super) trait Store)]256 pub struct Pallet<T>(_);257}258259pub struct WeightToFee<T, B>(PhantomData<(T, B)>);260261impl<T, B> WeightToFeePolynomial for WeightToFee<T, B>262where263 T: Config,264 B: BaseArithmetic + From<u32> + From<u64> + Copy + Unsigned,265{266 type Balance = B;267268 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {269 smallvec!(WeightToFeeCoefficient {270 coeff_integer: (<WeightToFeeCoefficientOverride<T>>::get() / Perbill::ACCURACY as u64)271 .into(),272 coeff_frac: Perbill::from_parts(273 (<WeightToFeeCoefficientOverride<T>>::get() % Perbill::ACCURACY as u64) as u32274 ),275 negative: false,276 degree: 1,277 })278 }279}280281pub struct FeeCalculator<T>(PhantomData<T>);282impl<T: Config> fp_evm::FeeCalculator for FeeCalculator<T> {283 fn min_gas_price() -> (U256, Weight) {284 (285 <MinGasPriceOverride<T>>::get().into(),286 T::DbWeight::get().reads(1),287 )288 }289}290291#[derive(Encode, Decode, Clone, Debug, Default, TypeInfo, MaxEncodedLen, PartialEq, PartialOrd)]292pub struct AppPromotionConfiguration<BlockNumber> {293 /// In relay blocks.294 pub recalculation_interval: Option<BlockNumber>,295 /// In parachain blocks.296 pub pending_interval: Option<BlockNumber>,297 /// Value for `RecalculationInterval` based on 0.05% per 24h.298 pub interval_income: Option<Perbill>,299 /// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.300 pub max_stakers_per_calculation: Option<u8>,301}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.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> {