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

Weight v1.5: Opaque Struct #12138

Merged
merged 60 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
78f8104
initial idea
shawntabrizi Aug 28, 2022
7f01ecd
update frame_support
shawntabrizi Aug 28, 2022
3125a97
update a bunch more
shawntabrizi Aug 28, 2022
c6f9e89
add ord
shawntabrizi Aug 28, 2022
1ff21f3
adjust RuntimeDbWeight
shawntabrizi Aug 28, 2022
1b750b6
frame_system builds
shawntabrizi Aug 28, 2022
927cbfc
re-export
shawntabrizi Aug 28, 2022
abef86e
frame_support tests pass
shawntabrizi Aug 28, 2022
505291e
frame_executive compile
shawntabrizi Aug 28, 2022
58ca521
frame_executive builds
shawntabrizi Aug 29, 2022
155247e
frame_system tests passing
shawntabrizi Aug 29, 2022
57a9608
pallet-utility tests pass
shawntabrizi Aug 29, 2022
43a9822
fix a bunch of pallets
shawntabrizi Aug 29, 2022
18d13aa
more
shawntabrizi Aug 29, 2022
9c7e3c8
phragmen
shawntabrizi Aug 29, 2022
690b2d8
state-trie-migration
shawntabrizi Aug 29, 2022
694d8fc
scheduler and referenda
shawntabrizi Aug 29, 2022
2cf7413
pallet-election-provider-multi-phase
shawntabrizi Aug 29, 2022
32537ca
aura
shawntabrizi Aug 29, 2022
11ee8ae
staking
shawntabrizi Aug 29, 2022
58c95ee
more
shawntabrizi Aug 29, 2022
1568fe5
babe
shawntabrizi Aug 29, 2022
431085f
balances
shawntabrizi Aug 29, 2022
ee8d842
Merge branch 'master' into shawntabrizi-weight-v1.5
shawntabrizi Aug 29, 2022
afca016
bunch more
shawntabrizi Aug 29, 2022
6137298
sudo
shawntabrizi Aug 29, 2022
0ccec6d
transaction-payment
shawntabrizi Aug 29, 2022
9fb9378
asset-tx-payment
shawntabrizi Aug 29, 2022
4d6df92
last pallets
shawntabrizi Aug 29, 2022
06979b6
fix alliance merge
shawntabrizi Aug 29, 2022
06b0b50
fix node template runtime
shawntabrizi Aug 29, 2022
062e866
fix pallet-contracts cc @athei
shawntabrizi Aug 29, 2022
9c7f09a
fix node runtime
shawntabrizi Aug 29, 2022
7261a05
fix compile on runtime-benchmarks feature
shawntabrizi Aug 29, 2022
5a35f8d
comment
shawntabrizi Aug 29, 2022
6bc74aa
fix frame-support-test
shawntabrizi Aug 29, 2022
8a0a0c7
fix more tests
shawntabrizi Aug 29, 2022
ce87ef8
weight regex
shawntabrizi Aug 29, 2022
aed139b
frame system works
shawntabrizi Aug 29, 2022
d63e922
fix a bunch
shawntabrizi Aug 29, 2022
a9a6c66
more
shawntabrizi Aug 29, 2022
8adb1a4
more
shawntabrizi Aug 29, 2022
2d9d5a2
more
shawntabrizi Aug 30, 2022
2df2d77
more
shawntabrizi Aug 30, 2022
f5b5a77
more
shawntabrizi Aug 30, 2022
00a4d13
more fixes
shawntabrizi Aug 30, 2022
3694224
update templates
shawntabrizi Aug 30, 2022
5053f80
fix contracts benchmarks
shawntabrizi Aug 30, 2022
8df72dc
Update lib.rs
shawntabrizi Aug 30, 2022
3f00bff
Update lib.rs
shawntabrizi Aug 30, 2022
7c853e4
fix ui
shawntabrizi Aug 30, 2022
dfdbc3b
make scalar saturating mul const
shawntabrizi Aug 30, 2022
04fd22c
more const functions
shawntabrizi Aug 30, 2022
b0c262b
scalar div
shawntabrizi Aug 30, 2022
5c37fb8
refactor using constant functions
shawntabrizi Aug 31, 2022
8e973c0
move impl
shawntabrizi Aug 31, 2022
44246b5
fix overhead template
shawntabrizi Aug 31, 2022
e698cfe
Merge branch 'master' into shawntabrizi-weight-v1.5
shawntabrizi Aug 31, 2022
b6eb595
use compactas
shawntabrizi Aug 31, 2022
6b3a7d2
Update lib.rs
shawntabrizi Aug 31, 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
Prev Previous commit
Next Next commit
pallet-election-provider-multi-phase
  • Loading branch information
shawntabrizi committed Aug 29, 2022
commit 2cf7413e7f5a86ac11d93e9e7d027f8c01a92708
2 changes: 1 addition & 1 deletion frame/contracts/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
///
/// Passing `0` as amount is interpreted as "all remaining gas".
pub fn nested(&mut self, amount: Weight) -> Result<Self, DispatchError> {
let amount = if amount == 0 { self.gas_left } else { amount };
let amount = if amount == Weight::zero() { self.gas_left } else { amount };

// NOTE that it is ok to allocate all available gas since it still ensured
// by `charge` that it doesn't reach zero.
Expand Down
8 changes: 5 additions & 3 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1778,11 +1778,13 @@ impl<T: Config> Pallet<T> {
if Self::launch_next(now).is_ok() {
weight = max_block_weight;
} else {
weight =
weight.saturating_add(T::WeightInfo::on_initialize_base_with_launch_period(r));
weight = weight.saturating_add(Weight::from_ref_time(
T::WeightInfo::on_initialize_base_with_launch_period(r),
));
}
} else {
weight = weight.saturating_add(T::WeightInfo::on_initialize_base(r));
weight =
weight.saturating_add(Weight::from_ref_time(T::WeightInfo::on_initialize_base(r)));
}

// tally up votes for any expiring referenda.
Expand Down
4 changes: 2 additions & 2 deletions frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Contains<Call> for BaseFilter {

parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1_000_000);
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1_000_000));
}
impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter;
Expand Down Expand Up @@ -107,7 +107,7 @@ impl frame_system::Config for Test {
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Weight::from_ref_time(Perbill::from_percent(80) * BlockWeights::get().max_block);
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
}
impl pallet_scheduler::Config for Test {
type Event = Event;
Expand Down
34 changes: 19 additions & 15 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ use frame_election_provider_support::{
ElectionDataProvider, ElectionProvider, InstantElectionProvider, NposSolution,
};
use frame_support::{
dispatch::DispatchResultWithPostInfo,
ensure,
traits::{Currency, Get, OnUnbalanced, ReservableCurrency},
weights::{DispatchClass, Weight},
Expand Down Expand Up @@ -731,12 +730,12 @@ pub mod pallet {
match Self::create_snapshot() {
Ok(_) => {
Self::on_initialize_open_signed();
T::WeightInfo::on_initialize_open_signed()
Weight::from_ref_time(T::WeightInfo::on_initialize_open_signed())
},
Err(why) => {
// Not much we can do about this at this point.
log!(warn, "failed to open signed phase due to {:?}", why);
T::WeightInfo::on_initialize_nothing()
Weight::from_ref_time(T::WeightInfo::on_initialize_nothing())
},
}
},
Expand Down Expand Up @@ -770,19 +769,19 @@ pub mod pallet {
match Self::create_snapshot() {
Ok(_) => {
Self::on_initialize_open_unsigned(enabled, now);
T::WeightInfo::on_initialize_open_unsigned()
Weight::from_ref_time(T::WeightInfo::on_initialize_open_unsigned())
},
Err(why) => {
log!(warn, "failed to open unsigned phase due to {:?}", why);
T::WeightInfo::on_initialize_nothing()
Weight::from_ref_time(T::WeightInfo::on_initialize_nothing())
},
}
} else {
Self::on_initialize_open_unsigned(enabled, now);
T::WeightInfo::on_initialize_open_unsigned()
Weight::from_ref_time(T::WeightInfo::on_initialize_open_unsigned())
}
},
_ => T::WeightInfo::on_initialize_nothing(),
_ => Weight::from_ref_time(T::WeightInfo::on_initialize_nothing()),
}
}

Expand Down Expand Up @@ -877,7 +876,7 @@ pub mod pallet {
origin: OriginFor<T>,
raw_solution: Box<RawSolution<SolutionOf<T::MinerConfig>>>,
witness: SolutionOrSnapshotSize,
) -> DispatchResultWithPostInfo {
) -> DispatchResult {
ensure_none(origin)?;
let error_message = "Invalid unsigned submission must produce invalid block and \
deprive validator from their authoring reward.";
Expand Down Expand Up @@ -905,7 +904,7 @@ pub mod pallet {
prev_ejected: ejected_a_solution,
});

Ok(None.into())
Ok(())
}

/// Set a new value for `MinimumUntrustedScore`.
Expand Down Expand Up @@ -992,7 +991,7 @@ pub mod pallet {
let deposit = Self::deposit_for(&raw_solution, size);
let call_fee = {
let call = Call::submit { raw_solution: raw_solution.clone() };
T::EstimateCallFee::estimate_call_fee(&call, None.into())
T::EstimateCallFee::estimate_call_fee(&call, None::<Weight>.into())
};

let submission = SignedSubmission {
Expand Down Expand Up @@ -1401,8 +1400,10 @@ impl<T: Config> Pallet<T> {
let (targets, voters, desired_targets) = Self::create_snapshot_external()?;

// ..therefore we only measure the weight of this and add it.
let internal_weight =
T::WeightInfo::create_snapshot_internal(voters.len() as u32, targets.len() as u32);
let internal_weight = Weight::from_ref_time(T::WeightInfo::create_snapshot_internal(
voters.len() as u32,
targets.len() as u32,
));
Self::create_snapshot_internal(targets, voters, desired_targets);
Self::register_weight(internal_weight);
Ok(())
Expand Down Expand Up @@ -1562,7 +1563,10 @@ impl<T: Config> Pallet<T> {
.map(|(_, x)| x)
.fold(Zero::zero(), |acc, next| acc + next.voters.len() as u32);
let desired_targets = supports.len() as u32;
Self::register_weight(T::WeightInfo::elect_queued(active_voters, desired_targets));
Self::register_weight(Weight::from_ref_time(T::WeightInfo::elect_queued(
active_voters,
desired_targets,
)));
}
}

Expand Down Expand Up @@ -2195,12 +2199,12 @@ mod tests {
let all_targets: u32 = 5_000;
let desired: u32 = 1_000;
let weight_with = |active| {
<Runtime as Config>::WeightInfo::submit_unsigned(
Weight::from_ref_time(<Runtime as Config>::WeightInfo::submit_unsigned(
all_voters,
all_targets,
active,
desired,
)
))
};

let mut active = 1;
Expand Down
16 changes: 9 additions & 7 deletions frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults(2 * frame_support::weights::constants::WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
::with_sensible_defaults(Weight::from_ref_time(2 * frame_support::weights::constants::WEIGHT_PER_SECOND), NORMAL_DISPATCH_RATIO);
}

impl pallet_balances::Config for Runtime {
Expand Down Expand Up @@ -271,12 +271,12 @@ parameter_types! {
pub static SignedDepositByte: Balance = 0;
pub static SignedDepositWeight: Balance = 0;
pub static SignedRewardBase: Balance = 7;
pub static SignedMaxWeight: Weight = Weight::from_ref_time(BlockWeights::get().max_block);
pub static SignedMaxWeight: Weight = BlockWeights::get().max_block;
pub static MinerTxPriority: u64 = 100;
pub static BetterSignedThreshold: Perbill = Perbill::zero();
pub static BetterUnsignedThreshold: Perbill = Perbill::zero();
pub static OffchainRepeat: BlockNumber = 5;
pub static MinerMaxWeight: Weight = Weight::from_ref_time(BlockWeights::get().max_block);
pub static MinerMaxWeight: Weight = BlockWeights::get().max_block;
pub static MinerMaxLength: u32 = 256;
pub static MockWeightInfo: MockedWeightInfo = MockedWeightInfo::Real;
pub static MaxElectingVoters: VoterIndex = u32::max_value();
Expand Down Expand Up @@ -348,13 +348,15 @@ impl MinerConfig for Runtime {
type Solution = TestNposSolution;

fn solution_weight(v: u32, t: u32, a: u32, d: u32) -> Weight {
match MockWeightInfo::get() {
let ref_time_weight = match MockWeightInfo::get() {
MockedWeightInfo::Basic =>
(10 as Weight).saturating_add((5 as Weight).saturating_mul(a as Weight)),
MockedWeightInfo::Complex => (0 * v + 0 * t + 1000 * a + 0 * d) as Weight,
(10 as u64).saturating_add((5 as u64).saturating_mul(a as u64)),
MockedWeightInfo::Complex => (0 * v + 0 * t + 1000 * a + 0 * d) as u64,
MockedWeightInfo::Real =>
<() as multi_phase::weights::WeightInfo>::feasibility_check(v, t, a, d),
}
};

Weight::from_ref_time(ref_time_weight)
}
}

Expand Down
14 changes: 7 additions & 7 deletions frame/election-provider-multi-phase/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl<T: Config> Pallet<T> {
discarded
);

(weight, found_solution)
(Weight::from_ref_time(weight), found_solution)
}
/// Helper function for the case where a solution is accepted in the signed phase.
///
Expand Down Expand Up @@ -514,8 +514,8 @@ impl<T: Config> Pallet<T> {
let feasibility_weight = Self::solution_weight_of(raw_solution, size);

let len_deposit = T::SignedDepositByte::get().saturating_mul(encoded_len);
let weight_deposit =
T::SignedDepositWeight::get().saturating_mul(feasibility_weight.saturated_into());
let weight_deposit = T::SignedDepositWeight::get()
.saturating_mul(feasibility_weight.ref_time().saturated_into());

T::SignedDepositBase::get()
.saturating_add(len_deposit)
Expand Down Expand Up @@ -957,7 +957,7 @@ mod tests {
#[test]
fn cannot_consume_too_much_future_weight() {
ExtBuilder::default()
.signed_weight(40)
.signed_weight(Weight::from_ref_time(40))
.mock_weight_info(MockedWeightInfo::Basic)
.build_and_execute(|| {
roll_to(15);
Expand All @@ -971,13 +971,13 @@ mod tests {
raw.solution.unique_targets().len() as u32,
);
// default solution will have 5 edges (5 * 5 + 10)
assert_eq!(solution_weight, 35);
assert_eq!(solution_weight, Weight::from_ref_time(35));
assert_eq!(raw.solution.voter_count(), 5);
assert_eq!(<Runtime as Config>::SignedMaxWeight::get(), 40);
assert_eq!(<Runtime as Config>::SignedMaxWeight::get(), Weight::from_ref_time(40));

assert_ok!(MultiPhase::submit(Origin::signed(99), Box::new(raw.clone())));

<SignedMaxWeight>::set(30);
<SignedMaxWeight>::set(Weight::from_ref_time(30));

// note: resubmitting the same solution is technically okay as long as the queue has
// space.
Expand Down
Loading