mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 14:25:41 +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:
@@ -326,18 +326,6 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
tracker.into_iter().collect()
|
||||
}
|
||||
|
||||
/// Current lease index and how many blocks we are already in.
|
||||
pub fn lease_period_index_plus_progress(
|
||||
b: BlockNumberFor<T>,
|
||||
) -> Option<(<Self as Leaser<BlockNumberFor<T>>>::LeasePeriod, BlockNumberFor<T>)> {
|
||||
// Note that blocks before `LeaseOffset` do not count as any lease period.
|
||||
let offset_block_now = b.checked_sub(&T::LeaseOffset::get())?;
|
||||
let lease_period = offset_block_now / T::LeasePeriod::get();
|
||||
let in_lease = offset_block_now % T::LeasePeriod::get();
|
||||
|
||||
Some((lease_period, in_lease))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> crate::traits::OnSwap for Pallet<T> {
|
||||
@@ -461,8 +449,12 @@ impl<T: Config> Leaser<BlockNumberFor<T>> for Pallet<T> {
|
||||
}
|
||||
|
||||
fn lease_period_index(b: BlockNumberFor<T>) -> Option<(Self::LeasePeriod, bool)> {
|
||||
Self::lease_period_index_plus_progress(b)
|
||||
.map(|(period, progress)| (period, progress.is_zero()))
|
||||
// Note that blocks before `LeaseOffset` do not count as any lease period.
|
||||
let offset_block_now = b.checked_sub(&T::LeaseOffset::get())?;
|
||||
let lease_period = offset_block_now / T::LeasePeriod::get();
|
||||
let at_begin = (offset_block_now % T::LeasePeriod::get()).is_zero();
|
||||
|
||||
Some((lease_period, at_begin))
|
||||
}
|
||||
|
||||
fn already_leased(
|
||||
|
||||
@@ -245,7 +245,9 @@ impl<T: Config> OnNewSession<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> {
|
||||
Instruction::Transact {
|
||||
origin_kind: OriginKind::Superuser,
|
||||
require_weight_at_most: Weight::from_parts(1000000000, 200000),
|
||||
// Largest call is set_lease with 1526 byte:
|
||||
// Longest call is reserve() with 31_000_000
|
||||
require_weight_at_most: Weight::from_parts(100_000_000, 20_000),
|
||||
call: BrokerRuntimePallets::Broker(call).encode().into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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