mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Use same fmt and clippy configs as in Substrate (#7611)
* Use same rustfmt.toml as Substrate Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * format format file Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Format with new config Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Add Substrate Clippy config Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Print Clippy version in CI Otherwise its difficult to reproduce locally. Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Make fmt happy Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update node/core/pvf/src/error.rs Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io> * Update node/core/pvf/src/error.rs Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
This commit is contained in:
committed by
GitHub
parent
ac435c96cf
commit
342d720573
@@ -322,7 +322,8 @@ pub mod pallet {
|
||||
},
|
||||
Err(err) => {
|
||||
// Treat failed lease creation as warning .. slot will be allocated a lease
|
||||
// in a subsequent lease period by the `allocate_temporary_slot_leases` function.
|
||||
// in a subsequent lease period by the `allocate_temporary_slot_leases`
|
||||
// function.
|
||||
log::warn!(target: "assigned_slots",
|
||||
"Failed to allocate a temp slot for para {:?} at period {:?}: {:?}",
|
||||
id, current_lease_period, err
|
||||
@@ -398,7 +399,8 @@ impl<T: Config> Pallet<T> {
|
||||
/// total number of lease (lower first), and then when they last a turn (older ones first).
|
||||
/// If any remaining ex-aequo, we just take the para ID in ascending order as discriminator.
|
||||
///
|
||||
/// Assigned slots with a `period_begin` bigger than current lease period are not considered (yet).
|
||||
/// Assigned slots with a `period_begin` bigger than current lease period are not considered
|
||||
/// (yet).
|
||||
///
|
||||
/// The function will call out to `Leaser::lease_out` to create the appropriate slot leases.
|
||||
fn allocate_temporary_slot_leases(lease_period_index: LeasePeriodOf<T>) -> DispatchResult {
|
||||
@@ -525,7 +527,8 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Handles start of a lease period.
|
||||
fn manage_lease_period_start(lease_period_index: LeasePeriodOf<T>) -> Weight {
|
||||
// Note: leases that have ended in previous lease period, should have been cleaned in slots pallet.
|
||||
// Note: leases that have ended in previous lease period, should have been cleaned in slots
|
||||
// pallet.
|
||||
if let Err(err) = Self::allocate_temporary_slot_leases(lease_period_index) {
|
||||
log::error!(target: "assigned_slots",
|
||||
"Allocating slots failed for lease period {:?}, with: {:?}",
|
||||
|
||||
@@ -138,8 +138,8 @@ pub mod pallet {
|
||||
Reserved { bidder: T::AccountId, extra_reserved: BalanceOf<T>, total_amount: BalanceOf<T> },
|
||||
/// Funds were unreserved since bidder is no longer active. `[bidder, amount]`
|
||||
Unreserved { bidder: T::AccountId, amount: BalanceOf<T> },
|
||||
/// Someone attempted to lease the same slot twice for a parachain. The amount is held in reserve
|
||||
/// but no parachain slot has been leased.
|
||||
/// Someone attempted to lease the same slot twice for a parachain. The amount is held in
|
||||
/// reserve but no parachain slot has been leased.
|
||||
ReserveConfiscated { para_id: ParaId, leaser: T::AccountId, amount: BalanceOf<T> },
|
||||
/// A new bid has been accepted as the current winner.
|
||||
BidAccepted {
|
||||
@@ -149,7 +149,8 @@ pub mod pallet {
|
||||
first_slot: LeasePeriodOf<T>,
|
||||
last_slot: LeasePeriodOf<T>,
|
||||
},
|
||||
/// The winning offset was chosen for an auction. This will map into the `Winning` storage map.
|
||||
/// The winning offset was chosen for an auction. This will map into the `Winning` storage
|
||||
/// map.
|
||||
WinningOffset { auction_index: AuctionIndex, block_number: BlockNumberFor<T> },
|
||||
}
|
||||
|
||||
@@ -217,9 +218,9 @@ pub mod pallet {
|
||||
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
|
||||
// If the current auction was in its ending period last block, then ensure that the (sub-)range
|
||||
// winner information is duplicated from the previous block in case no bids happened in the
|
||||
// last block.
|
||||
// If the current auction was in its ending period last block, then ensure that the
|
||||
// (sub-)range winner information is duplicated from the previous block in case no bids
|
||||
// happened in the last block.
|
||||
if let AuctionStatus::EndingPeriod(offset, _sub_sample) = Self::auction_status(n) {
|
||||
weight = weight.saturating_add(T::DbWeight::get().reads(1));
|
||||
if !Winning::<T>::contains_key(&offset) {
|
||||
@@ -555,8 +556,9 @@ impl<T: Config> Pallet<T> {
|
||||
});
|
||||
let res = Winning::<T>::get(offset)
|
||||
.unwrap_or([Self::EMPTY; SlotRange::SLOT_RANGE_COUNT]);
|
||||
// This `remove_all` statement should remove at most `EndingPeriod` / `SampleLength` items,
|
||||
// which should be bounded and sensibly configured in the runtime.
|
||||
// This `remove_all` statement should remove at most `EndingPeriod` /
|
||||
// `SampleLength` items, which should be bounded and sensibly configured in the
|
||||
// runtime.
|
||||
#[allow(deprecated)]
|
||||
Winning::<T>::remove_all(None);
|
||||
AuctionInfo::<T>::kill();
|
||||
@@ -574,8 +576,8 @@ impl<T: Config> Pallet<T> {
|
||||
auction_lease_period_index: LeasePeriodOf<T>,
|
||||
winning_ranges: WinningData<T>,
|
||||
) {
|
||||
// First, unreserve all amounts that were reserved for the bids. We will later re-reserve the
|
||||
// amounts from the bidders that ended up being assigned the slot so there's no need to
|
||||
// First, unreserve all amounts that were reserved for the bids. We will later re-reserve
|
||||
// the amounts from the bidders that ended up being assigned the slot so there's no need to
|
||||
// special-case them here.
|
||||
for ((bidder, _), amount) in ReservedAmounts::<T>::drain() {
|
||||
CurrencyOf::<T>::unreserve(&bidder, amount);
|
||||
@@ -596,12 +598,12 @@ impl<T: Config> Pallet<T> {
|
||||
Err(LeaseError::ReserveFailed) |
|
||||
Err(LeaseError::AlreadyEnded) |
|
||||
Err(LeaseError::NoLeasePeriod) => {
|
||||
// Should never happen since we just unreserved this amount (and our offset is from the
|
||||
// present period). But if it does, there's not much we can do.
|
||||
// Should never happen since we just unreserved this amount (and our offset is
|
||||
// from the present period). But if it does, there's not much we can do.
|
||||
},
|
||||
Err(LeaseError::AlreadyLeased) => {
|
||||
// The leaser attempted to get a second lease on the same para ID, possibly griefing us. Let's
|
||||
// keep the amount reserved and let governance sort it out.
|
||||
// The leaser attempted to get a second lease on the same para ID, possibly
|
||||
// griefing us. Let's keep the amount reserved and let governance sort it out.
|
||||
if CurrencyOf::<T>::reserve(&leaser, amount).is_ok() {
|
||||
Self::deposit_event(Event::<T>::ReserveConfiscated {
|
||||
para_id: para,
|
||||
@@ -1123,11 +1125,11 @@ mod tests {
|
||||
Auctions::auction_status(System::block_number()),
|
||||
AuctionStatus::<u32>::EndingPeriod(2, 0)
|
||||
);
|
||||
// This will prevent the auction's winner from being decided in the next block, since the random
|
||||
// seed was known before the final bids were made.
|
||||
// This will prevent the auction's winner from being decided in the next block, since
|
||||
// the random seed was known before the final bids were made.
|
||||
set_last_random(H256::zero(), 8);
|
||||
// Auction definitely ended now, but we don't know exactly when in the last 3 blocks yet since
|
||||
// no randomness available yet.
|
||||
// Auction definitely ended now, but we don't know exactly when in the last 3 blocks yet
|
||||
// since no randomness available yet.
|
||||
run_to_block(9);
|
||||
// Auction has now ended... But auction winner still not yet decided, so no leases yet.
|
||||
assert_eq!(
|
||||
@@ -1136,8 +1138,8 @@ mod tests {
|
||||
);
|
||||
assert_eq!(leases(), vec![]);
|
||||
|
||||
// Random seed now updated to a value known at block 9, when the auction ended. This means
|
||||
// that the winner can now be chosen.
|
||||
// Random seed now updated to a value known at block 9, when the auction ended. This
|
||||
// means that the winner can now be chosen.
|
||||
set_last_random(H256::zero(), 9);
|
||||
run_to_block(10);
|
||||
// Auction ended and winner selected
|
||||
|
||||
@@ -193,8 +193,8 @@ pub mod pallet {
|
||||
SignerHasNoClaim,
|
||||
/// Account ID sending transaction has no claim.
|
||||
SenderHasNoClaim,
|
||||
/// There's not enough in the pot to pay out some unvested amount. Generally implies a logic
|
||||
/// error.
|
||||
/// There's not enough in the pot to pay out some unvested amount. Generally implies a
|
||||
/// logic error.
|
||||
PotUnderflow,
|
||||
/// A needed statement was not included.
|
||||
InvalidStatement,
|
||||
@@ -288,8 +288,8 @@ pub mod pallet {
|
||||
///
|
||||
/// Parameters:
|
||||
/// - `dest`: The destination account to payout the claim.
|
||||
/// - `ethereum_signature`: The signature of an ethereum signed message
|
||||
/// matching the format described above.
|
||||
/// - `ethereum_signature`: The signature of an ethereum signed message matching the format
|
||||
/// described above.
|
||||
///
|
||||
/// <weight>
|
||||
/// The weight of this call is invariant over the input parameters.
|
||||
@@ -368,9 +368,10 @@ pub mod pallet {
|
||||
///
|
||||
/// Parameters:
|
||||
/// - `dest`: The destination account to payout the claim.
|
||||
/// - `ethereum_signature`: The signature of an ethereum signed message
|
||||
/// matching the format described above.
|
||||
/// - `statement`: The identity of the statement which is being attested to in the signature.
|
||||
/// - `ethereum_signature`: The signature of an ethereum signed message matching the format
|
||||
/// described above.
|
||||
/// - `statement`: The identity of the statement which is being attested to in the
|
||||
/// signature.
|
||||
///
|
||||
/// <weight>
|
||||
/// The weight of this call is invariant over the input parameters.
|
||||
@@ -400,14 +401,16 @@ pub mod pallet {
|
||||
|
||||
/// Attest to a statement, needed to finalize the claims process.
|
||||
///
|
||||
/// WARNING: Insecure unless your chain includes `PrevalidateAttests` as a `SignedExtension`.
|
||||
/// WARNING: Insecure unless your chain includes `PrevalidateAttests` as a
|
||||
/// `SignedExtension`.
|
||||
///
|
||||
/// Unsigned Validation:
|
||||
/// A call to attest is deemed valid if the sender has a `Preclaim` registered
|
||||
/// and provides a `statement` which is expected for the account.
|
||||
///
|
||||
/// Parameters:
|
||||
/// - `statement`: The identity of the statement which is being attested to in the signature.
|
||||
/// - `statement`: The identity of the statement which is being attested to in the
|
||||
/// signature.
|
||||
///
|
||||
/// <weight>
|
||||
/// The weight of this call is invariant over the input parameters.
|
||||
|
||||
@@ -134,8 +134,8 @@ pub mod crowdloan_index_migration {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This migration converts crowdloans to use a crowdloan index rather than the parachain id as a
|
||||
/// unique identifier. This makes it easier to swap two crowdloans between parachains.
|
||||
/// This migration converts crowdloans to use a crowdloan index rather than the parachain id as
|
||||
/// a unique identifier. This makes it easier to swap two crowdloans between parachains.
|
||||
pub fn migrate<T: Config>() -> frame_support::weights::Weight {
|
||||
let mut weight = Weight::zero();
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@
|
||||
//! slot auction enters its ending period, then parachains will each place a bid; the bid will be
|
||||
//! raised once per block if the parachain had additional funds contributed since the last bid.
|
||||
//!
|
||||
//! Successful funds remain tracked (in the `Funds` storage item and the associated child trie) as long as
|
||||
//! the parachain remains active. Users can withdraw their funds once the slot is completed and funds are
|
||||
//! returned to the crowdloan account.
|
||||
//! Successful funds remain tracked (in the `Funds` storage item and the associated child trie) as
|
||||
//! long as the parachain remains active. Users can withdraw their funds once the slot is completed
|
||||
//! and funds are returned to the crowdloan account.
|
||||
|
||||
pub mod migration;
|
||||
|
||||
@@ -164,11 +164,11 @@ pub struct FundInfo<AccountId, Balance, BlockNumber, LeasePeriod> {
|
||||
/// If this is `Ending(n)`, this fund received a contribution during the current ending period,
|
||||
/// where `n` is how far into the ending period the contribution was made.
|
||||
pub last_contribution: LastContribution<BlockNumber>,
|
||||
/// First lease period in range to bid on; it's actually a `LeasePeriod`, but that's the same type
|
||||
/// as `BlockNumber`.
|
||||
/// First lease period in range to bid on; it's actually a `LeasePeriod`, but that's the same
|
||||
/// type as `BlockNumber`.
|
||||
pub first_period: LeasePeriod,
|
||||
/// Last lease period in range to bid on; it's actually a `LeasePeriod`, but that's the same type
|
||||
/// as `BlockNumber`.
|
||||
/// Last lease period in range to bid on; it's actually a `LeasePeriod`, but that's the same
|
||||
/// type as `BlockNumber`.
|
||||
pub last_period: LeasePeriod,
|
||||
/// Unique index used to represent this fund.
|
||||
pub fund_index: FundIndex,
|
||||
@@ -192,15 +192,16 @@ pub mod pallet {
|
||||
pub trait Config: frame_system::Config {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// `PalletId` for the crowdloan pallet. An appropriate value could be `PalletId(*b"py/cfund")`
|
||||
/// `PalletId` for the crowdloan pallet. An appropriate value could be
|
||||
/// `PalletId(*b"py/cfund")`
|
||||
#[pallet::constant]
|
||||
type PalletId: Get<PalletId>;
|
||||
|
||||
/// The amount to be held on deposit by the depositor of a crowdloan.
|
||||
type SubmissionDeposit: Get<BalanceOf<Self>>;
|
||||
|
||||
/// The minimum amount that may be contributed into a crowdloan. Should almost certainly be at
|
||||
/// least `ExistentialDeposit`.
|
||||
/// The minimum amount that may be contributed into a crowdloan. Should almost certainly be
|
||||
/// at least `ExistentialDeposit`.
|
||||
#[pallet::constant]
|
||||
type MinContribution: Get<BalanceOf<Self>>;
|
||||
|
||||
@@ -208,8 +209,8 @@ pub mod pallet {
|
||||
#[pallet::constant]
|
||||
type RemoveKeysLimit: Get<u32>;
|
||||
|
||||
/// The parachain registrar type. We just use this to ensure that only the manager of a para is able to
|
||||
/// start a crowdloan for its slot.
|
||||
/// The parachain registrar type. We just use this to ensure that only the manager of a para
|
||||
/// is able to start a crowdloan for its slot.
|
||||
type Registrar: Registrar<AccountId = Self::AccountId>;
|
||||
|
||||
/// The type representing the auctioning system.
|
||||
@@ -314,7 +315,8 @@ pub mod pallet {
|
||||
FundNotEnded,
|
||||
/// There are no contributions stored in this crowdloan.
|
||||
NoContributions,
|
||||
/// The crowdloan is not ready to dissolve. Potentially still has a slot or in retirement period.
|
||||
/// The crowdloan is not ready to dissolve. Potentially still has a slot or in retirement
|
||||
/// period.
|
||||
NotReadyToDissolve,
|
||||
/// Invalid signature.
|
||||
InvalidSignature,
|
||||
@@ -342,8 +344,9 @@ pub mod pallet {
|
||||
for (fund, para_id) in
|
||||
new_raise.into_iter().filter_map(|i| Self::funds(i).map(|f| (f, i)))
|
||||
{
|
||||
// Care needs to be taken by the crowdloan creator that this function will succeed given
|
||||
// the crowdloaning configuration. We do some checks ahead of time in crowdloan `create`.
|
||||
// Care needs to be taken by the crowdloan creator that this function will
|
||||
// succeed given the crowdloaning configuration. We do some checks ahead of time
|
||||
// in crowdloan `create`.
|
||||
let result = T::Auctioneer::place_bid(
|
||||
Self::fund_account_id(fund.fund_index),
|
||||
para_id,
|
||||
@@ -363,7 +366,8 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Create a new crowdloaning campaign for a parachain slot with the given lease period range.
|
||||
/// Create a new crowdloaning campaign for a parachain slot with the given lease period
|
||||
/// range.
|
||||
///
|
||||
/// This applies a lock to your parachain configuration, ensuring that it cannot be changed
|
||||
/// by the parachain manager.
|
||||
@@ -462,16 +466,16 @@ pub mod pallet {
|
||||
///
|
||||
/// Origin must be signed, but can come from anyone.
|
||||
///
|
||||
/// The fund must be either in, or ready for, retirement. For a fund to be *in* retirement, then the retirement
|
||||
/// flag must be set. For a fund to be ready for retirement, then:
|
||||
/// The fund must be either in, or ready for, retirement. For a fund to be *in* retirement,
|
||||
/// then the retirement flag must be set. For a fund to be ready for retirement, then:
|
||||
/// - it must not already be in retirement;
|
||||
/// - the amount of raised funds must be bigger than the _free_ balance of the account;
|
||||
/// - and either:
|
||||
/// - the block number must be at least `end`; or
|
||||
/// - the current lease period must be greater than the fund's `last_period`.
|
||||
///
|
||||
/// In this case, the fund's retirement flag is set and its `end` is reset to the current block
|
||||
/// number.
|
||||
/// In this case, the fund's retirement flag is set and its `end` is reset to the current
|
||||
/// block number.
|
||||
///
|
||||
/// - `who`: The account whose contribution should be withdrawn.
|
||||
/// - `index`: The parachain to whose crowdloan the contribution was made.
|
||||
@@ -653,8 +657,9 @@ pub mod pallet {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Contribute your entire balance to a crowd sale. This will transfer the entire balance of a user over to fund a parachain
|
||||
/// slot. It will be withdrawable when the crowdloan has ended and the funds are unused.
|
||||
/// Contribute your entire balance to a crowd sale. This will transfer the entire balance of
|
||||
/// a user over to fund a parachain slot. It will be withdrawable when the crowdloan has
|
||||
/// ended and the funds are unused.
|
||||
#[pallet::call_index(8)]
|
||||
#[pallet::weight(T::WeightInfo::contribute())]
|
||||
pub fn contribute_all(
|
||||
@@ -719,8 +724,8 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// This function checks all conditions which would qualify a crowdloan has ended.
|
||||
/// * If we have reached the `fund.end` block OR the first lease period the fund is
|
||||
/// trying to bid for has started already.
|
||||
/// * If we have reached the `fund.end` block OR the first lease period the fund is trying to
|
||||
/// bid for has started already.
|
||||
/// * And, if the fund has enough free funds to refund full raised amount.
|
||||
fn ensure_crowdloan_ended(
|
||||
now: BlockNumberFor<T>,
|
||||
@@ -775,8 +780,8 @@ impl<T: Config> Pallet<T> {
|
||||
Error::<T>::BidOrLeaseActive
|
||||
);
|
||||
|
||||
// We disallow any crowdloan contributions during the VRF Period, so that people do not sneak their
|
||||
// contributions into the auction when it would not impact the outcome.
|
||||
// We disallow any crowdloan contributions during the VRF Period, so that people do not
|
||||
// sneak their contributions into the auction when it would not impact the outcome.
|
||||
ensure!(!T::Auctioneer::auction_status(now).is_vrf(), Error::<T>::VrfDelayInProgress);
|
||||
|
||||
let (old_balance, memo) = Self::contribution_get(fund.fund_index, &who);
|
||||
@@ -1287,7 +1292,8 @@ mod tests {
|
||||
);
|
||||
|
||||
// Cannot create a crowdloan with nonsense end date
|
||||
// This crowdloan would end in lease period 2, but is bidding for some slot that starts in lease period 1.
|
||||
// This crowdloan would end in lease period 2, but is bidding for some slot that starts
|
||||
// in lease period 1.
|
||||
assert_noop!(
|
||||
Crowdloan::create(RuntimeOrigin::signed(1), para, 1000, 1, 4, 41, None),
|
||||
Error::<Test>::EndTooFarInFuture
|
||||
@@ -1457,7 +1463,8 @@ mod tests {
|
||||
let para_2 = new_para();
|
||||
let index = NextFundIndex::<Test>::get();
|
||||
assert_ok!(Crowdloan::create(RuntimeOrigin::signed(1), para_2, 1000, 1, 4, 40, None));
|
||||
// Emulate a win by leasing out and putting a deposit. Slots pallet would normally do this.
|
||||
// Emulate a win by leasing out and putting a deposit. Slots pallet would normally do
|
||||
// this.
|
||||
let crowdloan_account = Crowdloan::fund_account_id(index);
|
||||
set_winner(para_2, crowdloan_account, true);
|
||||
assert_noop!(
|
||||
@@ -1465,8 +1472,8 @@ mod tests {
|
||||
Error::<Test>::BidOrLeaseActive
|
||||
);
|
||||
|
||||
// Move past lease period 1, should not be allowed to have further contributions with a crowdloan
|
||||
// that has starting period 1.
|
||||
// Move past lease period 1, should not be allowed to have further contributions with a
|
||||
// crowdloan that has starting period 1.
|
||||
let para_3 = new_para();
|
||||
assert_ok!(Crowdloan::create(RuntimeOrigin::signed(1), para_3, 1000, 1, 4, 40, None));
|
||||
run_to_block(40);
|
||||
|
||||
@@ -471,7 +471,8 @@ fn basic_end_to_end_works() {
|
||||
);
|
||||
assert_eq!(
|
||||
slots::Leases::<Test>::get(ParaId::from(para_2)),
|
||||
// -- 1 --- 2 --- 3 --- 4 --- 5 ---------------- 6 --------------------------- 7 ----------------
|
||||
// -- 1 --- 2 --- 3 --- 4 --- 5 ---------------- 6 --------------------------- 7
|
||||
// ----------------
|
||||
vec![
|
||||
None,
|
||||
None,
|
||||
@@ -599,7 +600,8 @@ fn basic_errors_fail() {
|
||||
|
||||
#[test]
|
||||
fn competing_slots() {
|
||||
// This test will verify that competing slots, from different sources will resolve appropriately.
|
||||
// This test will verify that competing slots, from different sources will resolve
|
||||
// appropriately.
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(System::block_number().is_one());
|
||||
let max_bids = 10u32;
|
||||
@@ -789,7 +791,8 @@ fn competing_bids() {
|
||||
let crowdloan_1 = Crowdloan::fund_account_id(fund_1.fund_index);
|
||||
assert_eq!(
|
||||
slots::Leases::<Test>::get(ParaId::from(2000)),
|
||||
// -- 1 --- 2 --- 3 --- 4 --- 5 ------------- 6 ------------------------ 7 -------------
|
||||
// -- 1 --- 2 --- 3 --- 4 --- 5 ------------- 6 ------------------------ 7
|
||||
// -------------
|
||||
vec![
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -107,9 +107,9 @@ pub mod pallet {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The aggregated origin type must support the `parachains` origin. We require that we can
|
||||
/// infallibly convert between this origin and the system origin, but in reality, they're the
|
||||
/// same type, we just can't express that to the Rust type system without writing a `where`
|
||||
/// clause everywhere.
|
||||
/// infallibly convert between this origin and the system origin, but in reality, they're
|
||||
/// the same type, we just can't express that to the Rust type system without writing a
|
||||
/// `where` clause everywhere.
|
||||
type RuntimeOrigin: From<<Self as frame_system::Config>::RuntimeOrigin>
|
||||
+ Into<result::Result<Origin, <Self as Config>::RuntimeOrigin>>;
|
||||
|
||||
@@ -163,14 +163,15 @@ pub mod pallet {
|
||||
CannotDowngrade,
|
||||
/// Cannot schedule upgrade of parathread to parachain
|
||||
CannotUpgrade,
|
||||
/// Para is locked from manipulation by the manager. Must use parachain or relay chain governance.
|
||||
/// Para is locked from manipulation by the manager. Must use parachain or relay chain
|
||||
/// governance.
|
||||
ParaLocked,
|
||||
/// The ID given for registration has not been reserved.
|
||||
NotReserved,
|
||||
/// Registering parachain with empty code is not allowed.
|
||||
EmptyCode,
|
||||
/// Cannot perform a parachain slot / lifecycle swap. Check that the state of both paras are
|
||||
/// correct for the swap to work.
|
||||
/// Cannot perform a parachain slot / lifecycle swap. Check that the state of both paras
|
||||
/// are correct for the swap to work.
|
||||
CannotSwap,
|
||||
}
|
||||
|
||||
@@ -180,8 +181,8 @@ pub mod pallet {
|
||||
|
||||
/// Amount held on deposit for each para and the original depositor.
|
||||
///
|
||||
/// The given account ID is responsible for registering the code and initial head data, but may only do
|
||||
/// so if it isn't yet registered. (After that, it's up to governance to do so.)
|
||||
/// The given account ID is responsible for registering the code and initial head data, but may
|
||||
/// only do so if it isn't yet registered. (After that, it's up to governance to do so.)
|
||||
#[pallet::storage]
|
||||
pub type Paras<T: Config> =
|
||||
StorageMap<_, Twox64Concat, ParaId, ParaInfo<T::AccountId, BalanceOf<T>>>;
|
||||
@@ -224,8 +225,8 @@ pub mod pallet {
|
||||
/// - `validation_code`: The initial validation code of the parachain/thread.
|
||||
///
|
||||
/// ## Deposits/Fees
|
||||
/// The origin signed account must reserve a corresponding deposit for the registration. Anything already
|
||||
/// reserved previously for this para ID is accounted for.
|
||||
/// The origin signed account must reserve a corresponding deposit for the registration.
|
||||
/// Anything already reserved previously for this para ID is accounted for.
|
||||
///
|
||||
/// ## Events
|
||||
/// The `Registered` event is emitted in case of success.
|
||||
@@ -264,7 +265,8 @@ pub mod pallet {
|
||||
|
||||
/// Deregister a Para Id, freeing all data and returning any deposit.
|
||||
///
|
||||
/// The caller must be Root, the `para` owner, or the `para` itself. The para must be a parathread.
|
||||
/// The caller must be Root, the `para` owner, or the `para` itself. The para must be a
|
||||
/// parathread.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::deregister())]
|
||||
pub fn deregister(origin: OriginFor<T>, id: ParaId) -> DispatchResult {
|
||||
@@ -345,17 +347,20 @@ pub mod pallet {
|
||||
/// Reserve a Para Id on the relay chain.
|
||||
///
|
||||
/// This function will reserve a new Para Id to be owned/managed by the origin account.
|
||||
/// The origin account is able to register head data and validation code using `register` to create
|
||||
/// a parathread. Using the Slots pallet, a parathread can then be upgraded to get a parachain slot.
|
||||
/// The origin account is able to register head data and validation code using `register` to
|
||||
/// create a parathread. Using the Slots pallet, a parathread can then be upgraded to get a
|
||||
/// parachain slot.
|
||||
///
|
||||
/// ## Arguments
|
||||
/// - `origin`: Must be called by a `Signed` origin. Becomes the manager/owner of the new para ID.
|
||||
/// - `origin`: Must be called by a `Signed` origin. Becomes the manager/owner of the new
|
||||
/// para ID.
|
||||
///
|
||||
/// ## Deposits/Fees
|
||||
/// The origin must reserve a deposit of `ParaDeposit` for the registration.
|
||||
///
|
||||
/// ## Events
|
||||
/// The `Reserved` event is emitted in case of success, which provides the ID reserved for use.
|
||||
/// The `Reserved` event is emitted in case of success, which provides the ID reserved for
|
||||
/// use.
|
||||
#[pallet::call_index(5)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::reserve())]
|
||||
pub fn reserve(origin: OriginFor<T>) -> DispatchResult {
|
||||
@@ -369,7 +374,8 @@ pub mod pallet {
|
||||
/// Add a manager lock from a para. This will prevent the manager of a
|
||||
/// para to deregister or swap a para.
|
||||
///
|
||||
/// Can be called by Root, the parachain, or the parachain manager if the parachain is unlocked.
|
||||
/// Can be called by Root, the parachain, or the parachain manager if the parachain is
|
||||
/// unlocked.
|
||||
#[pallet::call_index(6)]
|
||||
#[pallet::weight(T::DbWeight::get().reads_writes(1, 1))]
|
||||
pub fn add_lock(origin: OriginFor<T>, para: ParaId) -> DispatchResult {
|
||||
@@ -380,7 +386,8 @@ pub mod pallet {
|
||||
|
||||
/// Schedule a parachain upgrade.
|
||||
///
|
||||
/// Can be called by Root, the parachain, or the parachain manager if the parachain is unlocked.
|
||||
/// Can be called by Root, the parachain, or the parachain manager if the parachain is
|
||||
/// unlocked.
|
||||
#[pallet::call_index(7)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::schedule_code_upgrade(new_code.0.len() as u32))]
|
||||
pub fn schedule_code_upgrade(
|
||||
@@ -395,7 +402,8 @@ pub mod pallet {
|
||||
|
||||
/// Set the parachain's current head.
|
||||
///
|
||||
/// Can be called by Root, the parachain, or the parachain manager if the parachain is unlocked.
|
||||
/// Can be called by Root, the parachain, or the parachain manager if the parachain is
|
||||
/// unlocked.
|
||||
#[pallet::call_index(8)]
|
||||
#[pallet::weight(<T as Config>::WeightInfo::set_current_head(new_head.0.len() as u32))]
|
||||
pub fn set_current_head(
|
||||
|
||||
@@ -45,8 +45,8 @@ pub mod pallet {
|
||||
ParaDoesntExist,
|
||||
/// The specified parachain or parathread is already registered.
|
||||
ParaAlreadyExists,
|
||||
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a downward
|
||||
/// message.
|
||||
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a
|
||||
/// downward message.
|
||||
ExceedsMaxMessageSize,
|
||||
/// Could not schedule para cleanup.
|
||||
CouldntCleanup,
|
||||
@@ -127,8 +127,8 @@ pub mod pallet {
|
||||
|
||||
/// Send a downward XCM to the given para.
|
||||
///
|
||||
/// The given parachain should exist and the payload should not exceed the preconfigured size
|
||||
/// `config.max_downward_message_size`.
|
||||
/// The given parachain should exist and the payload should not exceed the preconfigured
|
||||
/// size `config.max_downward_message_size`.
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||
pub fn sudo_queue_downward_xcm(
|
||||
|
||||
@@ -82,7 +82,8 @@ pub struct AccountStatus<Balance> {
|
||||
locked_balance: Balance,
|
||||
/// Their sr25519/ed25519 signature verifying they have signed our required statement.
|
||||
signature: Vec<u8>,
|
||||
/// The percentage of VAT the purchaser is responsible for. This is already factored into account balance.
|
||||
/// The percentage of VAT the purchaser is responsible for. This is already factored into
|
||||
/// account balance.
|
||||
vat: Permill,
|
||||
}
|
||||
|
||||
@@ -333,12 +334,14 @@ pub mod pallet {
|
||||
|
||||
if !status.locked_balance.is_zero() {
|
||||
let unlock_block = UnlockBlock::<T>::get();
|
||||
// We allow some configurable portion of the purchased locked DOTs to be unlocked for basic usage.
|
||||
// We allow some configurable portion of the purchased locked DOTs to be
|
||||
// unlocked for basic usage.
|
||||
let unlocked = (T::UnlockedProportion::get() * status.locked_balance)
|
||||
.min(T::MaxUnlocked::get());
|
||||
let locked = status.locked_balance.saturating_sub(unlocked);
|
||||
// We checked that this account has no existing vesting schedule. So this function should
|
||||
// never fail, however if it does, not much we can do about it at this point.
|
||||
// We checked that this account has no existing vesting schedule. So this
|
||||
// function should never fail, however if it does, not much we can do about
|
||||
// it at this point.
|
||||
let _ = T::VestingSchedule::add_vesting_schedule(
|
||||
// Apply vesting schedule to this user
|
||||
&who,
|
||||
@@ -351,7 +354,8 @@ pub mod pallet {
|
||||
);
|
||||
}
|
||||
|
||||
// Setting the user account to `Completed` ends the purchase process for this user.
|
||||
// Setting the user account to `Completed` ends the purchase process for this
|
||||
// user.
|
||||
status.validity = AccountValidity::Completed;
|
||||
Self::deposit_event(Event::<T>::PaymentComplete {
|
||||
who: who.clone(),
|
||||
@@ -645,17 +649,20 @@ mod tests {
|
||||
}
|
||||
|
||||
fn alice_signature() -> [u8; 64] {
|
||||
// echo -n "Hello, World" | subkey -s sign "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice"
|
||||
// echo -n "Hello, World" | subkey -s sign "bottom drive obey lake curtain smoke basket hold
|
||||
// race lonely fit walk//Alice"
|
||||
hex_literal::hex!("20e0faffdf4dfe939f2faa560f73b1d01cde8472e2b690b7b40606a374244c3a2e9eb9c8107c10b605138374003af8819bd4387d7c24a66ee9253c2e688ab881")
|
||||
}
|
||||
|
||||
fn bob_signature() -> [u8; 64] {
|
||||
// echo -n "Hello, World" | subkey -s sign "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Bob"
|
||||
// echo -n "Hello, World" | subkey -s sign "bottom drive obey lake curtain smoke basket hold
|
||||
// race lonely fit walk//Bob"
|
||||
hex_literal::hex!("d6d460187ecf530f3ec2d6e3ac91b9d083c8fbd8f1112d92a82e4d84df552d18d338e6da8944eba6e84afaacf8a9850f54e7b53a84530d649be2e0119c7ce889")
|
||||
}
|
||||
|
||||
fn alice_signature_ed25519() -> [u8; 64] {
|
||||
// echo -n "Hello, World" | subkey -e sign "bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice"
|
||||
// echo -n "Hello, World" | subkey -e sign "bottom drive obey lake curtain smoke basket hold
|
||||
// race lonely fit walk//Alice"
|
||||
hex_literal::hex!("ee3f5a6cbfc12a8f00c18b811dc921b550ddf272354cda4b9a57b1d06213fcd8509f5af18425d39a279d13622f14806c3e978e2163981f2ec1c06e9628460b0e")
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Parathread and parachains leasing system. Allows para IDs to be claimed, the code and data to be initialized and
|
||||
//! parachain slots (i.e. continuous scheduling) to be leased. Also allows for parachains and parathreads to be
|
||||
//! swapped.
|
||||
//! Parathread and parachains leasing system. Allows para IDs to be claimed, the code and data to be
|
||||
//! initialized and parachain slots (i.e. continuous scheduling) to be leased. Also allows for
|
||||
//! parachains and parathreads to be swapped.
|
||||
//!
|
||||
//! This doesn't handle the mechanics of determining which para ID actually ends up with a parachain lease. This
|
||||
//! must handled by a separately, through the trait interface that this pallet provides or the root dispatchables.
|
||||
//! This doesn't handle the mechanics of determining which para ID actually ends up with a parachain
|
||||
//! lease. This must handled by a separately, through the trait interface that this pallet provides
|
||||
//! or the root dispatchables.
|
||||
|
||||
pub mod migration;
|
||||
|
||||
@@ -98,8 +99,8 @@ pub mod pallet {
|
||||
|
||||
/// Amounts held on deposit for each (possibly future) leased parachain.
|
||||
///
|
||||
/// The actual amount locked on its behalf by any account at any time is the maximum of the second values
|
||||
/// of the items in this list whose first value is the account.
|
||||
/// The actual amount locked on its behalf by any account at any time is the maximum of the
|
||||
/// second values of the items in this list whose first value is the account.
|
||||
///
|
||||
/// The first item in the list is the amount locked for the current Lease Period. Following
|
||||
/// items are for the subsequent lease periods.
|
||||
@@ -160,8 +161,8 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Just a connect into the `lease_out` call, in case Root wants to force some lease to happen
|
||||
/// independently of any other on-chain mechanism to use it.
|
||||
/// Just a connect into the `lease_out` call, in case Root wants to force some lease to
|
||||
/// happen independently of any other on-chain mechanism to use it.
|
||||
///
|
||||
/// The dispatch origin for this call must match `T::ForceOrigin`.
|
||||
#[pallet::call_index(0)]
|
||||
@@ -268,8 +269,8 @@ impl<T: Config> Pallet<T> {
|
||||
// deposit for the parachain.
|
||||
let now_held = Self::deposit_held(para, &ended_lease.0);
|
||||
|
||||
// If this is less than what we were holding for this leaser's now-ended lease, then
|
||||
// unreserve it.
|
||||
// If this is less than what we were holding for this leaser's now-ended lease,
|
||||
// then unreserve it.
|
||||
if let Some(rebate) = ended_lease.1.checked_sub(&now_held) {
|
||||
T::Currency::unreserve(&ended_lease.0, rebate);
|
||||
}
|
||||
@@ -392,8 +393,8 @@ impl<T: Config> Leaser<BlockNumberFor<T>> for Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out whether we already have some funds of `leaser` held in reserve for `para_id`.
|
||||
// If so, then we can deduct those from the amount that we need to reserve.
|
||||
// Figure out whether we already have some funds of `leaser` held in reserve for
|
||||
// `para_id`. If so, then we can deduct those from the amount that we need to reserve.
|
||||
let maybe_additional = amount.checked_sub(&Self::deposit_held(para, &leaser));
|
||||
if let Some(ref additional) = maybe_additional {
|
||||
T::Currency::reserve(&leaser, *additional)
|
||||
@@ -403,7 +404,8 @@ impl<T: Config> Leaser<BlockNumberFor<T>> for Pallet<T> {
|
||||
let reserved = maybe_additional.unwrap_or_default();
|
||||
|
||||
// Check if current lease period is same as period begin, and onboard them directly.
|
||||
// This will allow us to support onboarding new parachains in the middle of a lease period.
|
||||
// This will allow us to support onboarding new parachains in the middle of a lease
|
||||
// period.
|
||||
if current_lease_period == period_begin {
|
||||
// Best effort. Not much we can do if this fails.
|
||||
let _ = T::Registrar::make_parachain(para);
|
||||
@@ -481,7 +483,8 @@ impl<T: Config> Leaser<BlockNumberFor<T>> for Pallet<T> {
|
||||
None => return true,
|
||||
};
|
||||
|
||||
// Get the leases, and check each item in the vec which is part of the range we are checking.
|
||||
// Get the leases, and check each item in the vec which is part of the range we are
|
||||
// checking.
|
||||
let leases = Leases::<T>::get(para_id);
|
||||
for slot in offset..=offset + period_count {
|
||||
if let Some(Some(_)) = leases.get(slot) {
|
||||
|
||||
@@ -113,11 +113,12 @@ pub trait Leaser<BlockNumber> {
|
||||
///
|
||||
/// `leaser` shall have a total of `amount` balance reserved by the implementer of this trait.
|
||||
///
|
||||
/// Note: The implementer of the trait (the leasing system) is expected to do all reserve/unreserve calls. The
|
||||
/// caller of this trait *SHOULD NOT* pre-reserve the deposit (though should ensure that it is reservable).
|
||||
/// Note: The implementer of the trait (the leasing system) is expected to do all
|
||||
/// reserve/unreserve calls. The caller of this trait *SHOULD NOT* pre-reserve the deposit
|
||||
/// (though should ensure that it is reservable).
|
||||
///
|
||||
/// The lease will last from `period_begin` for `period_count` lease periods. It is undefined if the `para`
|
||||
/// already has a slot leased during those periods.
|
||||
/// The lease will last from `period_begin` for `period_count` lease periods. It is undefined if
|
||||
/// the `para` already has a slot leased during those periods.
|
||||
///
|
||||
/// Returns `Err` in the case of an error, and in which case nothing is changed.
|
||||
fn lease_out(
|
||||
@@ -128,8 +129,8 @@ pub trait Leaser<BlockNumber> {
|
||||
period_count: Self::LeasePeriod,
|
||||
) -> Result<(), LeaseError>;
|
||||
|
||||
/// Return the amount of balance currently held in reserve on `leaser`'s account for leasing `para`. This won't
|
||||
/// go down outside a lease period.
|
||||
/// Return the amount of balance currently held in reserve on `leaser`'s account for leasing
|
||||
/// `para`. This won't go down outside a lease period.
|
||||
fn deposit_held(
|
||||
para: ParaId,
|
||||
leaser: &Self::AccountId,
|
||||
@@ -147,7 +148,8 @@ pub trait Leaser<BlockNumber> {
|
||||
fn lease_period_index(block: BlockNumber) -> Option<(Self::LeasePeriod, bool)>;
|
||||
|
||||
/// Returns true if the parachain already has a lease in any of lease periods in the inclusive
|
||||
/// range `[first_period, last_period]`, intersected with the unbounded range [`current_lease_period`..] .
|
||||
/// range `[first_period, last_period]`, intersected with the unbounded range
|
||||
/// [`current_lease_period`..] .
|
||||
fn already_leased(
|
||||
para_id: ParaId,
|
||||
first_period: Self::LeasePeriod,
|
||||
@@ -169,7 +171,8 @@ pub enum AuctionStatus<BlockNumber> {
|
||||
/// will be `EndingPeriod(1, 5)`.
|
||||
EndingPeriod(BlockNumber, BlockNumber),
|
||||
/// We have completed the bidding process and are waiting for the VRF to return some acceptable
|
||||
/// randomness to select the winner. The number represents how many blocks we have been waiting.
|
||||
/// randomness to select the winner. The number represents how many blocks we have been
|
||||
/// waiting.
|
||||
VrfDelay(BlockNumber),
|
||||
}
|
||||
|
||||
@@ -224,9 +227,9 @@ pub trait Auctioneer<BlockNumber> {
|
||||
/// - `last_slot`: The last lease period index of the range to be bid on (inclusive).
|
||||
/// - `amount`: The total amount to be the bid for deposit over the range.
|
||||
///
|
||||
/// The account `Bidder` must have at least `amount` available as a free balance in `Currency`. The
|
||||
/// implementation *MUST* remove or reserve `amount` funds from `bidder` and those funds should be returned
|
||||
/// or freed once the bid is rejected or lease has ended.
|
||||
/// The account `Bidder` must have at least `amount` available as a free balance in `Currency`.
|
||||
/// The implementation *MUST* remove or reserve `amount` funds from `bidder` and those funds
|
||||
/// should be returned or freed once the bid is rejected or lease has ended.
|
||||
fn place_bid(
|
||||
bidder: Self::AccountId,
|
||||
para: ParaId,
|
||||
|
||||
Reference in New Issue
Block a user