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

Commit

Permalink
Make weights compatible with u64 (#4192)
Browse files Browse the repository at this point in the history
* Use Weight instead of u32 everywhere

* Revert Weight declaration

* Fix benches
  • Loading branch information
stanislav-tkach authored and bkchr committed Nov 29, 2019
1 parent bf15ecf commit d5e189e
Show file tree
Hide file tree
Showing 32 changed files with 73 additions and 62 deletions.
2 changes: 1 addition & 1 deletion bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ mod tests {
mb,
10 * mb,
Weight::max_value() / 2,
Weight::max_value()
Weight::max_value(),
].into_iter().for_each(|i| {
run_with_system_weight(i, || {
let next = TargetedFeeAdjustment::<TargetBlockFullness>::convert(Fixed64::default());
Expand Down
4 changes: 2 additions & 2 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<T: Trait> Module<T> {
mod tests {
use super::*;

use support::{impl_outer_origin, assert_ok, assert_noop, parameter_types};
use support::{impl_outer_origin, assert_ok, assert_noop, parameter_types, weights::Weight};
use primitives::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
Expand All @@ -257,7 +257,7 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sr_primitives::{
traits::IdentityLookup, Perbill,
testing::{Header, UintAuthorityId},
};
use support::{impl_outer_origin, parameter_types};
use support::{impl_outer_origin, parameter_types, weights::Weight};
use runtime_io;
use primitives::H256;

Expand All @@ -38,7 +38,7 @@ pub struct Test;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const MinimumPeriod: u64 = 1;
Expand Down
4 changes: 2 additions & 2 deletions frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod tests {
testing::{Header, UintAuthorityId}, traits::{ConvertInto, IdentityLookup, OpaqueKeys},
Perbill, KeyTypeId,
};
use support::{impl_outer_origin, parameter_types};
use support::{impl_outer_origin, parameter_types, weights::Weight};

type AuthorityDiscovery = Module<Test>;
type SessionIndex = u32;
Expand Down Expand Up @@ -144,7 +144,7 @@ mod tests {
pub const Offset: BlockNumber = 0;
pub const UncleGenerations: u64 = 0;
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mod tests {
use sr_primitives::{
traits::{BlakeTwo256, IdentityLookup}, testing::Header, generic::DigestItem, Perbill,
};
use support::{parameter_types, impl_outer_origin, ConsensusEngineId};
use support::{parameter_types, impl_outer_origin, ConsensusEngineId, weights::Weight};

impl_outer_origin!{
pub enum Origin for Test {}
Expand All @@ -376,7 +376,7 @@ mod tests {

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sr_primitives::{
traits::IdentityLookup, Perbill, testing::{Header, UintAuthorityId}, impl_opaque_keys,
};
use sr_version::RuntimeVersion;
use support::{impl_outer_origin, parameter_types};
use support::{impl_outer_origin, parameter_types, weights::Weight};
use runtime_io;
use primitives::{H256, Blake2Hasher};

Expand All @@ -39,7 +39,7 @@ pub struct Test;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
pub const MinimumPeriod: u64 = 1;
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Get<u64> for CreationFee {
pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<
#[cfg(test)]
mod tests {
use super::*;
use support::{Hashable, assert_ok, assert_noop, parameter_types};
use support::{Hashable, assert_ok, assert_noop, parameter_types, weights::Weight};
use system::{EventRecord, Phase};
use hex_literal::hex;
use primitives::H256;
Expand All @@ -390,7 +390,7 @@ mod tests {

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sr_primitives::{
use support::{
assert_ok, assert_err, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types,
storage::child, StorageMap, StorageValue, traits::{Currency, Get},
weights::{DispatchInfo, DispatchClass},
weights::{DispatchInfo, DispatchClass, Weight},
};
use std::{cell::RefCell, sync::atomic::{AtomicUsize, Ordering}};
use primitives::storage::well_known_keys;
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Get<u64> for BlockGasLimit {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
5 changes: 3 additions & 2 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ mod tests {
use super::*;
use support::{
impl_outer_origin, impl_outer_dispatch, assert_noop, assert_ok, parameter_types,
traits::Contains
traits::Contains,
weights::Weight,
};
use primitives::H256;
use sr_primitives::{traits::{BlakeTwo256, IdentityLookup, Bounded}, testing::Header, Perbill};
Expand Down Expand Up @@ -1000,7 +1001,7 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ impl<T: Trait> Module<T> {
mod tests {
use super::*;
use std::cell::RefCell;
use support::{assert_ok, assert_noop, parameter_types};
use support::{assert_ok, assert_noop, parameter_types, weights::Weight};
use substrate_test_utils::assert_eq_uvec;
use primitives::H256;
use sr_primitives::{
Expand All @@ -754,7 +754,7 @@ mod tests {

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
5 changes: 3 additions & 2 deletions frame/elections/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
use std::cell::RefCell;
use support::{
StorageValue, StorageMap, parameter_types, assert_ok,
traits::{Get, ChangeMembers, Currency}
traits::{Get, ChangeMembers, Currency},
weights::Weight,
};
use primitives::H256;
use sr_primitives::{
Expand All @@ -32,7 +33,7 @@ use crate as elections;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<T: balances::Trait> WeighData<(&BalanceOf<T>,)> for WeightForSetDummy<T>
{
fn weigh_data(&self, target: (&BalanceOf<T>,)) -> Weight {
let multiplier = self.0;
(*target.0 * multiplier).saturated_into::<u32>()
(*target.0 * multiplier).saturated_into::<Weight>()
}
}

Expand Down Expand Up @@ -665,7 +665,7 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ mod tests {
pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down Expand Up @@ -641,7 +641,7 @@ mod tests {
assert!(Executive::apply_extrinsic(x2.clone()).unwrap().is_ok());

// default weight for `TestXt` == encoded length.
assert_eq!(<system::Module<Runtime>>::all_extrinsics_weight(), (3 * len) as u32);
assert_eq!(<system::Module<Runtime>>::all_extrinsics_weight(), (3 * len) as Weight);
assert_eq!(<system::Module<Runtime>>::all_extrinsics_len(), 3 * len);

let _ = <system::Module<Runtime>>::finalize();
Expand Down
4 changes: 2 additions & 2 deletions frame/finality-tracker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ mod tests {
testing::Header, Perbill,
traits::{BlakeTwo256, IdentityLookup, OnFinalize, Header as HeaderT},
};
use support::{assert_ok, impl_outer_origin, parameter_types};
use support::{assert_ok, impl_outer_origin, parameter_types, weights::Weight};
use frame_system as system;
use std::cell::RefCell;

Expand Down Expand Up @@ -230,7 +230,7 @@ mod tests {

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/generic-asset/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sr_primitives::{
traits::{BlakeTwo256, IdentityLookup},
};
use primitives::H256;
use support::{parameter_types, impl_outer_event, impl_outer_origin};
use support::{parameter_types, impl_outer_event, impl_outer_origin, weights::Weight};

use super::*;

Expand All @@ -41,7 +41,7 @@ impl_outer_origin! {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use sr_primitives::{Perbill, DigestItem, traits::IdentityLookup, testing::{Header, UintAuthorityId}};
use runtime_io;
use support::{impl_outer_origin, impl_outer_event, parameter_types};
use support::{impl_outer_origin, impl_outer_event, parameter_types, weights::Weight};
use primitives::H256;
use codec::{Encode, Decode};
use crate::{AuthorityId, AuthorityList, GenesisConfig, Trait, Module, ConsensusLog};
Expand All @@ -43,7 +43,7 @@ impl Trait for Test {
}
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sr_staking_primitives::{SessionIndex, offence::ReportOffence};
use sr_primitives::testing::{Header, UintAuthorityId, TestXt};
use sr_primitives::traits::{IdentityLookup, BlakeTwo256, ConvertInto};
use primitives::H256;
use support::{impl_outer_origin, impl_outer_dispatch, parameter_types};
use support::{impl_outer_origin, impl_outer_dispatch, parameter_types, weights::Weight};
use {runtime_io, system};

impl_outer_origin!{
Expand Down Expand Up @@ -96,7 +96,7 @@ pub struct Runtime;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/indices/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ref_thread_local::{ref_thread_local, RefThreadLocal};
use sr_primitives::testing::Header;
use sr_primitives::Perbill;
use primitives::H256;
use support::{impl_outer_origin, parameter_types};
use support::{impl_outer_origin, parameter_types, weights::Weight};
use {runtime_io, system};
use crate::{GenesisConfig, Module, Trait, IsDeadAccount, OnNewAccount, ResolveHint};

Expand Down Expand Up @@ -67,7 +67,7 @@ impl ResolveHint<u64, u64> for TestResolveHint {
pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod tests {
use super::*;

use std::cell::RefCell;
use support::{assert_ok, assert_noop, impl_outer_origin, parameter_types};
use support::{assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight};
use primitives::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
Expand All @@ -212,7 +212,7 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
4 changes: 2 additions & 2 deletions frame/nicks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ decl_module! {
mod tests {
use super::*;

use support::{assert_ok, assert_noop, impl_outer_origin, parameter_types};
use support::{assert_ok, assert_noop, impl_outer_origin, parameter_types, weights::Weight};
use primitives::H256;
use system::EnsureSignedBy;
// The testing primitives are very useful for avoiding having to work with signatures
Expand All @@ -249,7 +249,7 @@ mod tests {
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
7 changes: 5 additions & 2 deletions frame/offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ use sr_staking_primitives::{
use sr_primitives::testing::Header;
use sr_primitives::traits::{IdentityLookup, BlakeTwo256};
use substrate_primitives::H256;
use support::{impl_outer_origin, impl_outer_event, parameter_types, StorageMap, StorageDoubleMap};
use support::{
impl_outer_origin, impl_outer_event, parameter_types, StorageMap, StorageDoubleMap,
weights::Weight,
};
use {runtime_io, system};

impl_outer_origin!{
Expand Down Expand Up @@ -65,7 +68,7 @@ pub fn with_on_offence_fractions<R, F: FnOnce(&mut Vec<Perbill>) -> R>(f: F) ->
pub struct Runtime;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down
Loading

0 comments on commit d5e189e

Please sign in to comment.