Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Add storage size component to weights #12277

Merged
merged 41 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f8c395e
Add storage size component to weights
KiChjang Sep 15, 2022
779b815
Rename storage_size to proof_size
KiChjang Sep 15, 2022
f7b9346
Update primitives/weights/src/weight_v2.rs
KiChjang Sep 15, 2022
6c84cbd
Fixes
KiChjang Sep 16, 2022
96aa122
cargo fmt
KiChjang Sep 16, 2022
36c2d95
Implement custom Decode and CompactAs
KiChjang Sep 16, 2022
52c9d05
Add missing import
KiChjang Sep 16, 2022
9b1f37e
Fixes
KiChjang Sep 16, 2022
3438ada
Remove CompactAs implementation
KiChjang Sep 16, 2022
3b36396
Properly migrate from 1D weight
KiChjang Sep 16, 2022
7af788c
Remove #[pallet::compact] from Weight parameters
KiChjang Sep 16, 2022
f4b98aa
More #[pallet::compact] removals
KiChjang Sep 18, 2022
eefc1d7
Add unit tests
KiChjang Sep 18, 2022
109be74
Set appropriate default block proof size
KiChjang Sep 19, 2022
bbf072d
cargo fmt
KiChjang Sep 19, 2022
1a07286
Remove nonsensical weight constant
KiChjang Sep 19, 2022
10aed4c
Test only for the reference time weight in frame_system::limits
KiChjang Sep 19, 2022
be3d2f6
Only check for reference time weight on idle
KiChjang Sep 20, 2022
20ef5a3
Merge branch 'master' into kckyeung/storage-size-weights
KiChjang Sep 20, 2022
7908713
Use destructuring syntax
KiChjang Sep 22, 2022
e313544
Update test expectations
KiChjang Sep 22, 2022
9543674
Merge remote-tracking branch 'origin/master' into kckyeung/storage-si…
KiChjang Sep 22, 2022
91a03b2
Fixes
KiChjang Sep 22, 2022
e93dd45
Fixes
KiChjang Sep 22, 2022
9fe54f9
Fixes
KiChjang Sep 22, 2022
acd6d4b
Correctly migrate from 1D weights
KiChjang Sep 22, 2022
386d485
cargo fmt
KiChjang Sep 22, 2022
e85c05e
Migrate using extra extrinsics instead of custom Decode
KiChjang Sep 26, 2022
470e1bf
Merge remote-tracking branch 'origin/master' into kckyeung/storage-si…
KiChjang Sep 26, 2022
f541cb2
Fixes
KiChjang Sep 26, 2022
b34b49d
Silence dispatch call warnings that were previously allowed
KiChjang Sep 26, 2022
000ccad
Fix gas_left test
athei Sep 26, 2022
3c4ce94
Use OldWeight instead of u64
KiChjang Sep 26, 2022
d3b8a60
Fixes
KiChjang Sep 28, 2022
d3e9514
Only check for reference time weight in election provider
KiChjang Sep 28, 2022
4a9f631
Fix test expectations
KiChjang Sep 28, 2022
12b60f8
Fix test expectations
KiChjang Sep 28, 2022
b1a9125
Use only reference time weight in grandpa test
KiChjang Sep 28, 2022
3dec18b
Use only reference time weight in examples test
KiChjang Sep 28, 2022
8559428
Use only reference time weight in examples test
KiChjang Sep 28, 2022
4589902
Fix test expectations
KiChjang Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions frame/alliance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ use frame_support::{
ChangeMembers, Currency, Get, InitializeMembers, IsSubType, OnUnbalanced,
ReservableCurrency,
},
weights::Weight,
weights::{OldWeight, Weight},
};
use pallet_identity::IdentityField;

Expand Down Expand Up @@ -620,25 +620,22 @@ pub mod pallet {
.max(T::WeightInfo::close_early_disapproved(x, y, p2))
.max(T::WeightInfo::close_approved(b, x, y, p2))
.max(T::WeightInfo::close_disapproved(x, y, p2))
.saturating_add(p1)
.saturating_add(p1.into())
})]
pub fn close(
#[allow(deprecated)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to use `close`")]
pub fn close_old_weight(
origin: OriginFor<T>,
proposal_hash: T::Hash,
#[pallet::compact] index: ProposalIndex,
#[pallet::compact] proposal_weight_bound: Weight,
#[pallet::compact] proposal_weight_bound: OldWeight,
#[pallet::compact] length_bound: u32,
) -> DispatchResultWithPostInfo {
let proposal_weight_bound: Weight = proposal_weight_bound.into();
let who = ensure_signed(origin)?;
ensure!(Self::has_voting_rights(&who), Error::<T, I>::NoVotingRights);

let info = T::ProposalProvider::close_proposal(
proposal_hash,
index,
proposal_weight_bound,
length_bound,
)?;
Ok(info.into())
Self::do_close(proposal_hash, index, proposal_weight_bound, length_bound)
}

/// Initialize the Alliance, onboard founders, fellows, and allies.
Expand Down Expand Up @@ -985,6 +982,34 @@ pub mod pallet {
Self::deposit_event(Event::UnscrupulousItemRemoved { items });
Ok(())
}

/// Close a vote that is either approved, disapproved, or whose voting period has ended.
///
/// Requires the sender to be a founder or fellow.
#[pallet::weight({
let b = *length_bound;
let x = T::MaxFounders::get();
let y = T::MaxFellows::get();
let p1 = *proposal_weight_bound;
let p2 = T::MaxProposals::get();
T::WeightInfo::close_early_approved(b, x, y, p2)
.max(T::WeightInfo::close_early_disapproved(x, y, p2))
.max(T::WeightInfo::close_approved(b, x, y, p2))
.max(T::WeightInfo::close_disapproved(x, y, p2))
.saturating_add(p1)
})]
pub fn close(
origin: OriginFor<T>,
proposal_hash: T::Hash,
#[pallet::compact] index: ProposalIndex,
proposal_weight_bound: Weight,
#[pallet::compact] length_bound: u32,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
ensure!(Self::has_voting_rights(&who), Error::<T, I>::NoVotingRights);

Self::do_close(proposal_hash, index, proposal_weight_bound, length_bound)
}
}
}

Expand Down Expand Up @@ -1197,4 +1222,19 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
res
}

fn do_close(
proposal_hash: T::Hash,
index: ProposalIndex,
proposal_weight_bound: Weight,
length_bound: u32,
) -> DispatchResultWithPostInfo {
let info = T::ProposalProvider::close_proposal(
proposal_hash,
index,
proposal_weight_bound,
length_bound,
)?;
Ok(info.into())
}
}
3 changes: 2 additions & 1 deletion frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ fn valid_equivocation_reports_dont_pay_fees() {
.get_dispatch_info();

// it should have non-zero weight and the fee has to be paid.
assert!(info.weight.all_gt(Weight::zero()));
// TODO: account for proof size weight
assert!(info.weight.ref_time() > 0);
assert_eq!(info.pays_fee, Pays::Yes);

// report the equivocation.
Expand Down
69 changes: 65 additions & 4 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use frame_support::{
traits::{
Backing, ChangeMembers, EnsureOrigin, Get, GetBacking, InitializeMembers, StorageVersion,
},
weights::Weight,
weights::{OldWeight, Weight},
};

#[cfg(test)]
Expand Down Expand Up @@ -620,17 +620,20 @@ pub mod pallet {
.max(T::WeightInfo::close_early_disapproved(m, p2))
.max(T::WeightInfo::close_approved(b, m, p2))
.max(T::WeightInfo::close_disapproved(m, p2))
.saturating_add(p1)
.saturating_add(p1.into())
},
DispatchClass::Operational
))]
pub fn close(
#[allow(deprecated)]
#[deprecated(note = "1D weight is used in this extrinsic, please migrate to `close`")]
pub fn close_old_weight(
origin: OriginFor<T>,
proposal_hash: T::Hash,
#[pallet::compact] index: ProposalIndex,
#[pallet::compact] proposal_weight_bound: Weight,
#[pallet::compact] proposal_weight_bound: OldWeight,
#[pallet::compact] length_bound: u32,
) -> DispatchResultWithPostInfo {
let proposal_weight_bound: Weight = proposal_weight_bound.into();
let _ = ensure_signed(origin)?;

Self::do_close(proposal_hash, index, proposal_weight_bound, length_bound)
Expand Down Expand Up @@ -659,6 +662,64 @@ pub mod pallet {
let proposal_count = Self::do_disapprove_proposal(proposal_hash);
Ok(Some(T::WeightInfo::disapprove_proposal(proposal_count)).into())
}

/// Close a vote that is either approved, disapproved or whose voting period has ended.
///
/// May be called by any signed account in order to finish voting and close the proposal.
///
/// If called before the end of the voting period it will only close the vote if it is
/// has enough votes to be approved or disapproved.
///
/// If called after the end of the voting period abstentions are counted as rejections
/// unless there is a prime member set and the prime member cast an approval.
///
/// If the close operation completes successfully with disapproval, the transaction fee will
/// be waived. Otherwise execution of the approved operation will be charged to the caller.
///
/// + `proposal_weight_bound`: The maximum amount of weight consumed by executing the closed
/// proposal.
/// + `length_bound`: The upper bound for the length of the proposal in storage. Checked via
/// `storage::read` so it is `size_of::<u32>() == 4` larger than the pure length.
///
/// # <weight>
/// ## Weight
/// - `O(B + M + P1 + P2)` where:
/// - `B` is `proposal` size in bytes (length-fee-bounded)
/// - `M` is members-count (code- and governance-bounded)
/// - `P1` is the complexity of `proposal` preimage.
/// - `P2` is proposal-count (code-bounded)
/// - DB:
/// - 2 storage reads (`Members`: codec `O(M)`, `Prime`: codec `O(1)`)
/// - 3 mutations (`Voting`: codec `O(M)`, `ProposalOf`: codec `O(B)`, `Proposals`: codec
/// `O(P2)`)
/// - any mutations done while executing `proposal` (`P1`)
/// - up to 3 events
/// # </weight>
#[pallet::weight((
{
let b = *length_bound;
let m = T::MaxMembers::get();
let p1 = *proposal_weight_bound;
let p2 = T::MaxProposals::get();
T::WeightInfo::close_early_approved(b, m, p2)
.max(T::WeightInfo::close_early_disapproved(m, p2))
.max(T::WeightInfo::close_approved(b, m, p2))
.max(T::WeightInfo::close_disapproved(m, p2))
.saturating_add(p1)
},
DispatchClass::Operational
))]
pub fn close(
origin: OriginFor<T>,
proposal_hash: T::Hash,
#[pallet::compact] index: ProposalIndex,
proposal_weight_bound: Weight,
#[pallet::compact] length_bound: u32,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;

Self::do_close(proposal_hash, index, proposal_weight_bound, length_bound)
}
}
}

Expand Down
Loading