Weights to u64 + Balances Weights (#5446)

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2020-04-16 10:43:18 +02:00
committed by GitHub
parent 1c7525fd4b
commit 980b635c8d
82 changed files with 636 additions and 428 deletions
+31 -31
View File
@@ -171,7 +171,7 @@ use sp_runtime::{
use codec::{Ref, Encode, Decode};
use frame_support::{
decl_module, decl_storage, decl_event, decl_error, ensure, Parameter,
weights::{SimpleDispatchInfo, Weight, WeighData},
weights::{SimpleDispatchInfo, Weight, MINIMUM_WEIGHT},
traits::{
Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get,
OnUnbalanced, BalanceStatus, schedule::Named as ScheduleNamed, EnsureOrigin
@@ -528,7 +528,7 @@ decl_module! {
fn on_runtime_upgrade() -> Weight {
Self::migrate();
SimpleDispatchInfo::default().weigh_data(())
MINIMUM_WEIGHT
}
/// Propose a sensitive action to be taken.
@@ -546,7 +546,7 @@ decl_module! {
/// - P is the number proposals in the `PublicProps` vec.
/// - Two DB changes, one DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
fn propose(origin,
proposal_hash: T::Hash,
#[compact] value: BalanceOf<T>
@@ -577,7 +577,7 @@ decl_module! {
/// - S is the number of seconds a proposal already has.
/// - One DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
fn second(origin, #[compact] proposal: PropIndex) {
let who = ensure_signed(origin)?;
let mut deposit = Self::deposit_of(proposal)
@@ -600,7 +600,7 @@ decl_module! {
/// - R is the number of referendums the voter has voted on.
/// - One DB change, one DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(200_000)]
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
fn vote(origin,
#[compact] ref_index: ReferendumIndex,
vote: AccountVote<BalanceOf<T>>,
@@ -621,7 +621,7 @@ decl_module! {
/// - `O(1)`.
/// - One DB change, one DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(200_000)]
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
fn proxy_vote(origin,
#[compact] ref_index: ReferendumIndex,
vote: AccountVote<BalanceOf<T>>,
@@ -641,7 +641,7 @@ decl_module! {
/// # <weight>
/// - `O(1)`.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedOperational(500_000)]
#[weight = SimpleDispatchInfo::FixedOperational(500_000_000)]
fn emergency_cancel(origin, ref_index: ReferendumIndex) {
T::CancellationOrigin::ensure_origin(origin)?;
@@ -664,7 +664,7 @@ decl_module! {
/// - `O(1)`.
/// - One DB change.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
fn external_propose(origin, proposal_hash: T::Hash) {
T::ExternalOrigin::ensure_origin(origin)?;
ensure!(!<NextExternal<T>>::exists(), Error::<T>::DuplicateProposal);
@@ -691,7 +691,7 @@ decl_module! {
/// - `O(1)`.
/// - One DB change.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
fn external_propose_majority(origin, proposal_hash: T::Hash) {
T::ExternalMajorityOrigin::ensure_origin(origin)?;
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SimpleMajority));
@@ -711,7 +711,7 @@ decl_module! {
/// - `O(1)`.
/// - One DB change.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000)]
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
fn external_propose_default(origin, proposal_hash: T::Hash) {
T::ExternalDefaultOrigin::ensure_origin(origin)?;
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SuperMajorityAgainst));
@@ -736,7 +736,7 @@ decl_module! {
/// - One DB change.
/// - One extra DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(200_000)]
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
fn fast_track(origin,
proposal_hash: T::Hash,
voting_period: T::BlockNumber,
@@ -787,7 +787,7 @@ decl_module! {
/// be very large.
/// - O(log v), v is number of `existing_vetoers`
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(200_000)]
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
fn veto_external(origin, proposal_hash: T::Hash) {
let who = T::VetoOrigin::ensure_origin(origin)?;
@@ -820,7 +820,7 @@ decl_module! {
/// # <weight>
/// - `O(1)`.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedOperational(10_000)]
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) {
ensure_root(origin)?;
Self::internal_cancel_referendum(ref_index);
@@ -836,7 +836,7 @@ decl_module! {
/// - One DB change.
/// - O(d) where d is the items in the dispatch queue.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedOperational(10_000)]
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
fn cancel_queued(origin, which: ReferendumIndex) {
ensure_root(origin)?;
T::Scheduler::cancel_named((DEMOCRACY_ID, which))
@@ -848,7 +848,7 @@ decl_module! {
sp_runtime::print(e);
}
SimpleDispatchInfo::default().weigh_data(())
MINIMUM_WEIGHT
}
/// Specify a proxy that is already open to us. Called by the stash.
@@ -862,7 +862,7 @@ decl_module! {
/// # <weight>
/// - One extra DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
fn activate_proxy(origin, proxy: T::AccountId) {
let who = ensure_signed(origin)?;
Proxy::<T>::try_mutate(&proxy, |a| match a.take() {
@@ -885,7 +885,7 @@ decl_module! {
/// # <weight>
/// - One DB clear.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
fn close_proxy(origin) {
let who = ensure_signed(origin)?;
Proxy::<T>::mutate(&who, |a| {
@@ -909,7 +909,7 @@ decl_module! {
/// # <weight>
/// - One DB clear.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
fn deactivate_proxy(origin, proxy: T::AccountId) {
let who = ensure_signed(origin)?;
Proxy::<T>::try_mutate(&proxy, |a| match a.take() {
@@ -942,7 +942,7 @@ decl_module! {
///
/// # <weight>
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(500_000)]
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
pub fn delegate(origin, to: T::AccountId, conviction: Conviction, balance: BalanceOf<T>) {
let who = ensure_signed(origin)?;
Self::try_delegate(who, to, conviction, balance)?;
@@ -961,7 +961,7 @@ decl_module! {
/// # <weight>
/// - O(1).
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(500_000)]
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
fn undelegate(origin) {
let who = ensure_signed(origin)?;
Self::try_undelegate(who)?;
@@ -975,7 +975,7 @@ decl_module! {
/// - `O(1)`.
/// - One DB clear.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn clear_public_proposals(origin) {
ensure_root(origin)?;
@@ -995,7 +995,7 @@ decl_module! {
/// - Dependent on the size of `encoded_proposal` but protected by a
/// required deposit.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
fn note_preimage(origin, encoded_proposal: Vec<u8>) {
let who = ensure_signed(origin)?;
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
@@ -1030,7 +1030,7 @@ decl_module! {
/// # <weight>
/// - Dependent on the size of `encoded_proposal` and length of dispatch queue.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) {
let who = ensure_signed(origin)?;
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
@@ -1066,7 +1066,7 @@ decl_module! {
/// # <weight>
/// - One DB clear.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn reap_preimage(origin, proposal_hash: T::Hash) {
let who = ensure_signed(origin)?;
let (provider, deposit, since, expiry) = <Preimages<T>>::get(&proposal_hash)
@@ -1096,7 +1096,7 @@ decl_module! {
/// # <weight>
/// - `O(1)`.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn unlock(origin, target: T::AccountId) {
ensure_signed(origin)?;
Self::update_lock(&target);
@@ -1115,7 +1115,7 @@ decl_module! {
/// # <weight>
/// - One extra DB entry.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
fn open_proxy(origin, target: T::AccountId) {
let who = ensure_signed(origin)?;
Proxy::<T>::mutate(&who, |a| {
@@ -1154,7 +1154,7 @@ decl_module! {
/// # <weight>
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult {
let who = ensure_signed(origin)?;
Self::try_remove_vote(&who, index, UnvoteScope::Any)
@@ -1176,7 +1176,7 @@ decl_module! {
/// # <weight>
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn remove_other_vote(origin, target: T::AccountId, index: ReferendumIndex) -> DispatchResult {
let who = ensure_signed(origin)?;
let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired };
@@ -1207,7 +1207,7 @@ decl_module! {
///
/// # <weight>
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(500_000)]
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
pub fn proxy_delegate(origin,
to: T::AccountId,
conviction: Conviction,
@@ -1231,7 +1231,7 @@ decl_module! {
/// # <weight>
/// - O(1).
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(500_000)]
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
fn proxy_undelegate(origin) {
let who = ensure_signed(origin)?;
let target = Self::proxy(who).and_then(|a| a.as_active()).ok_or(Error::<T>::NotProxy)?;
@@ -1251,7 +1251,7 @@ decl_module! {
/// # <weight>
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
/// # </weight>
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
fn proxy_remove_vote(origin, index: ReferendumIndex) -> DispatchResult {
let who = ensure_signed(origin)?;
let target = Self::proxy(who).and_then(|a| a.as_active()).ok_or(Error::<T>::NotProxy)?;
+1
View File
@@ -80,6 +80,7 @@ impl frame_system::Trait for Test {
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();