mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 13:21:10 +00:00
Update lowest unbaked storage. (#9750)
* update lowest unbaked * fix format * add note * fmt
This commit is contained in:
committed by
GitHub
parent
d25d3896d7
commit
403b348d19
@@ -613,10 +613,7 @@ pub mod pallet {
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
/// Weight: see `begin_block`
|
||||
fn on_initialize(n: T::BlockNumber) -> Weight {
|
||||
Self::begin_block(n).unwrap_or_else(|e| {
|
||||
sp_runtime::print(e);
|
||||
0
|
||||
})
|
||||
Self::begin_block(n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1682,7 +1679,7 @@ impl<T: Config> Pallet<T> {
|
||||
now: T::BlockNumber,
|
||||
index: ReferendumIndex,
|
||||
status: ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>,
|
||||
) -> Result<bool, DispatchError> {
|
||||
) -> bool {
|
||||
let total_issuance = T::Currency::total_issuance();
|
||||
let approved = status.threshold.approved(status.tally, total_issuance);
|
||||
|
||||
@@ -1719,7 +1716,7 @@ impl<T: Config> Pallet<T> {
|
||||
Self::deposit_event(Event::<T>::NotPassed(index));
|
||||
}
|
||||
|
||||
Ok(approved)
|
||||
approved
|
||||
}
|
||||
|
||||
/// Current era is ending; we should finish up any proposals.
|
||||
@@ -1734,7 +1731,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// - Db writes: `PublicProps`, `account`, `ReferendumCount`, `DepositOf`, `ReferendumInfoOf`
|
||||
/// - Db reads per R: `DepositOf`, `ReferendumInfoOf`
|
||||
/// # </weight>
|
||||
fn begin_block(now: T::BlockNumber) -> Result<Weight, DispatchError> {
|
||||
fn begin_block(now: T::BlockNumber) -> Weight {
|
||||
let max_block_weight = T::BlockWeights::get().max_block;
|
||||
let mut weight = 0;
|
||||
|
||||
@@ -1758,12 +1755,29 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// tally up votes for any expiring referenda.
|
||||
for (index, info) in Self::maturing_referenda_at_inner(now, next..last).into_iter() {
|
||||
let approved = Self::bake_referendum(now, index, info)?;
|
||||
let approved = Self::bake_referendum(now, index, info);
|
||||
ReferendumInfoOf::<T>::insert(index, ReferendumInfo::Finished { end: now, approved });
|
||||
weight = max_block_weight;
|
||||
}
|
||||
|
||||
Ok(weight)
|
||||
// Notes:
|
||||
// * We don't consider the lowest unbaked to be the last maturing in case some refendum have
|
||||
// longer voting period than others.
|
||||
// * The iteration here shouldn't trigger any storage read that are not in cache, due to
|
||||
// `maturing_referenda_at_inner` having already read them.
|
||||
// * We shouldn't iterate more than `LaunchPeriod/VotingPeriod + 1` times because the number
|
||||
// of unbaked referendum is bounded by this number. In case those number have changed in a
|
||||
// runtime upgrade the formula should be adjusted but the bound should still be sensible.
|
||||
<LowestUnbaked<T>>::mutate(|ref_index| {
|
||||
while *ref_index < last &&
|
||||
Self::referendum_info(*ref_index)
|
||||
.map_or(true, |info| matches!(info, ReferendumInfo::Finished { .. }))
|
||||
{
|
||||
*ref_index += 1
|
||||
}
|
||||
});
|
||||
|
||||
weight
|
||||
}
|
||||
|
||||
/// Reads the length of account in DepositOf without getting the complete value in the runtime.
|
||||
|
||||
Reference in New Issue
Block a user