mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 02:57:57 +00:00
Saner weights + lease calcuation fix. (#2778)
And have proper benchmarks. --------- Co-authored-by: eskimor <eskimor@no-such-url.com> Co-authored-by: command-bot <> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
@@ -37,8 +37,9 @@ use runtime_common::{
|
||||
impls::{
|
||||
LocatableAssetConverter, ToAuthor, VersionedLocatableAsset, VersionedMultiLocationConverter,
|
||||
},
|
||||
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots, BlockHashCount, BlockLength,
|
||||
SlowAdjustingFeeUpdate,
|
||||
paras_registrar, paras_sudo_wrapper, prod_or_fast, slots,
|
||||
traits::Leaser,
|
||||
BlockHashCount, BlockLength, SlowAdjustingFeeUpdate,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*};
|
||||
@@ -1494,7 +1495,6 @@ pub mod migrations {
|
||||
|
||||
use frame_support::traits::LockIdentifier;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use sp_arithmetic::traits::Zero;
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_core::crypto::ByteArray;
|
||||
|
||||
@@ -1502,28 +1502,17 @@ pub mod migrations {
|
||||
impl coretime::migration::GetLegacyLease<BlockNumber> for GetLegacyLeaseImpl {
|
||||
fn get_parachain_lease_in_blocks(para: ParaId) -> Option<BlockNumber> {
|
||||
let now = frame_system::Pallet::<Runtime>::block_number();
|
||||
let mut leases = slots::Pallet::<Runtime>::lease(para).into_iter();
|
||||
let initial_sum = if let Some(Some(_)) = leases.next() {
|
||||
let (_, progress) =
|
||||
slots::Pallet::<Runtime>::lease_period_index_plus_progress(now)?;
|
||||
LeasePeriod::get().saturating_sub(progress)
|
||||
} else {
|
||||
// The parachain lease did not yet start
|
||||
Zero::zero()
|
||||
};
|
||||
log::trace!(
|
||||
target: "coretime-migration",
|
||||
"Getting lease info for para {:?}:\n LEASE_PERIOD: {:?}, initial_sum: {:?}, number of leases: {:?}",
|
||||
para,
|
||||
LeasePeriod::get(),
|
||||
initial_sum,
|
||||
slots::Pallet::<Runtime>::lease(para).len(),
|
||||
);
|
||||
|
||||
Some(leases.into_iter().fold(initial_sum, |sum, lease| {
|
||||
// If the parachain lease did not yet start, we ignore them by multiplying by `0`.
|
||||
sum + LeasePeriod::get() * lease.map_or(0, |_| 1)
|
||||
}))
|
||||
let lease = slots::Pallet::<Runtime>::lease(para);
|
||||
if lease.is_empty() {
|
||||
return None
|
||||
}
|
||||
// Lease not yet started, ignore:
|
||||
if lease.iter().any(Option::is_none) {
|
||||
return None
|
||||
}
|
||||
let (index, _) =
|
||||
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
|
||||
Some(index.saturating_add(lease.len() as u32).saturating_mul(LeasePeriod::get()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user