Unverified Commit 0806d596 authored by Shawn Tabrizi's avatar Shawn Tabrizi Committed by GitHub
Browse files

Introduce `BlockExecutionWeight` and `ExtrinsicBaseWeight` (#1023)

* Update to changes in Substrate

* Fix trait

* Remove `TransactionBaseFee`

* add temporary values for extrinsic base weight and block execution weight

* Update Cargo.lock
parent 826a9837
Pipeline #89720 passed with stages
in 26 minutes and 48 seconds
This diff is collapsed.
......@@ -25,7 +25,7 @@ use frame_support::{
decl_storage, decl_module, decl_error, ensure,
dispatch::DispatchResult,
traits::Get,
weights::{MINIMUM_WEIGHT, DispatchClass},
weights::DispatchClass,
};
use primitives::{Hash, parachain::{AttestedCandidate, AbridgedCandidateReceipt, Id as ParaId}};
......@@ -134,7 +134,7 @@ decl_module! {
type Error = Error<T>;
/// Provide candidate receipts for parachains, in ascending order by id.
#[weight = (MINIMUM_WEIGHT, DispatchClass::Mandatory)]
#[weight = (0, DispatchClass::Mandatory)]
fn more_attestations(origin, _more: MoreAttestations) -> DispatchResult {
ensure_none(origin)?;
ensure!(!DidUpdate::exists(), Error::<T>::TooManyAttestations);
......
......@@ -390,6 +390,8 @@ mod tests {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
......
......@@ -71,7 +71,6 @@ use frame_support::{
traits::{
Currency, Get, OnUnbalanced, WithdrawReason, ExistenceRequirement::AllowDeath
},
weights::MINIMUM_WEIGHT,
};
use system::ensure_signed;
use sp_runtime::{ModuleId,
......@@ -297,7 +296,7 @@ decl_module! {
/// Contribute to a crowd sale. This will transfer some balance over to fund a parachain
/// slot. It will be withdrawable in two instances: the parachain becomes retired; or the
/// slot is unable to be purchased and the timeout expires.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn contribute(origin, #[compact] index: FundIndex, #[compact] value: BalanceOf<T>) {
let who = ensure_signed(origin)?;
......@@ -356,7 +355,7 @@ decl_module! {
/// - `index` is the fund index that `origin` owns and whose deploy data will be set.
/// - `code_hash` is the hash of the parachain's Wasm validation function.
/// - `initial_head_data` is the parachain's initial head data.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn fix_deploy_data(origin,
#[compact] index: FundIndex,
code_hash: T::Hash,
......@@ -382,7 +381,7 @@ decl_module! {
///
/// - `index` is the fund index that `origin` owns and whose deploy data will be set.
/// - `para_id` is the parachain index that this fund won.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn onboard(origin,
#[compact] index: FundIndex,
#[compact] para_id: ParaId
......@@ -411,7 +410,7 @@ decl_module! {
}
/// Note that a successful fund has lost its parachain slot, and place it into retirement.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn begin_retirement(origin, #[compact] index: FundIndex) {
let _ = ensure_signed(origin)?;
......@@ -433,7 +432,7 @@ decl_module! {
}
/// Withdraw full balance of a contributor to an unsuccessful or off-boarded fund.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn withdraw(origin, #[compact] index: FundIndex) {
let who = ensure_signed(origin)?;
......@@ -464,7 +463,7 @@ decl_module! {
/// Remove a fund after either: it was unsuccessful and it timed out; or it was successful
/// but it has been retired from its parachain slot. This places any deposits that were not
/// withdrawn into the treasury.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn dissolve(origin, #[compact] index: FundIndex) {
let _ = ensure_signed(origin)?;
......@@ -607,6 +606,8 @@ mod tests {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
......
......@@ -53,4 +53,6 @@ parameter_types! {
pub const MaximumBlockWeight: Weight = 2_000_000_000_000;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const ExtrinsicBaseWeight: Weight = 100_000_000; // TODO: Confirm/Update
pub const BlockExecutionWeight: Weight = 1_000_000_000; // TODO: Confirm/Update
}
......@@ -36,7 +36,7 @@ use sp_staking::{
use frame_support::{
traits::KeyOwnerProofSystem,
dispatch::{IsSubType},
weights::{DispatchClass, Weight, MINIMUM_WEIGHT},
weights::{DispatchClass, Weight},
};
use primitives::{
Balance,
......@@ -556,7 +556,7 @@ decl_module! {
Self::do_old_code_pruning(now);
// TODO https://github.com/paritytech/polkadot/issues/977: set correctly
MINIMUM_WEIGHT
0
}
fn on_finalize() {
......@@ -1633,6 +1633,8 @@ mod tests {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
......
......@@ -31,7 +31,7 @@ use sp_runtime::{
use frame_support::{
decl_storage, decl_module, decl_event, decl_error, ensure,
dispatch::{DispatchResult, IsSubType}, traits::{Get, Currency, ReservableCurrency},
weights::{DispatchClass, Weight, MINIMUM_WEIGHT},
weights::{DispatchClass, Weight},
};
use system::{self, ensure_root, ensure_signed};
use primitives::parachain::{
......@@ -300,7 +300,7 @@ decl_module! {
/// - `count`: The number of parathreads.
///
/// Must be called from Root origin.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn set_thread_count(origin, count: u32) {
ensure_root(origin)?;
ThreadCount::put(count);
......@@ -314,7 +314,7 @@ decl_module! {
/// Unlike `register_para`, this function does check that the maximum code size
/// and head data size are respected, as parathread registration is an atomic
/// action.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn register_parathread(origin,
code: ValidationCode,
initial_head_data: HeadData,
......@@ -354,7 +354,7 @@ decl_module! {
/// This is a kind of special transaction that should be heavily prioritized in the
/// transaction pool according to the `value`; only `ThreadCount` of them may be presented
/// in any single block.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn select_parathread(origin,
#[compact] _id: ParaId,
_collator: CollatorId,
......@@ -371,7 +371,7 @@ decl_module! {
/// Ensure that before calling this that any funds you want emptied from the parathread's
/// account is moved out; after this it will be impossible to retrieve them (without
/// governance intervention).
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn deregister_parathread(origin) {
let id = parachains::ensure_parachain(<T as Trait>::Origin::from(origin))?;
......@@ -395,7 +395,7 @@ decl_module! {
/// `ParaId` to be a long-term identifier of a notional "parachain". However, their
/// scheduling info (i.e. whether they're a parathread or parachain), auction information
/// and the auction deposit are switched.
#[weight = MINIMUM_WEIGHT]
#[weight = 0]
fn swap(origin, #[compact] other: ParaId) {
let id = parachains::ensure_parachain(<T as Trait>::Origin::from(origin))?;
......@@ -466,7 +466,7 @@ decl_module! {
Active::put(paras);
MINIMUM_WEIGHT
0
}
fn on_finalize() {
......@@ -736,6 +736,8 @@ mod tests {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
......
......@@ -26,7 +26,7 @@ use codec::{Encode, Decode, Codec};
use frame_support::{
decl_module, decl_storage, decl_event, decl_error, ensure, dispatch::DispatchResult,
traits::{Currency, ReservableCurrency, WithdrawReason, ExistenceRequirement, Get, Randomness},
weights::{MINIMUM_WEIGHT, DispatchClass, Weight},
weights::{DispatchClass, Weight},
};
use primitives::parachain::{
SwapAux, PARACHAIN_INFO, Id as ParaId, ValidationCode, HeadData,
......@@ -286,7 +286,7 @@ decl_module! {
Self::manage_lease_period_start(lease_period_index);
}
MINIMUM_WEIGHT
0
}
fn on_finalize(now: T::BlockNumber) {
......@@ -922,6 +922,8 @@ mod tests {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
......
......@@ -30,7 +30,7 @@ use primitives::{
use runtime_common::{attestations, claims, parachains, registrar, slots,
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, ModuleId,
......@@ -145,6 +145,8 @@ impl system::Trait for Runtime {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
......@@ -206,7 +208,6 @@ impl balances::Trait for Runtime {
}
parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
......@@ -215,7 +216,6 @@ parameter_types! {
impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = TargetedFeeAdjustment<TargetBlockFullness, Self>;
......
......@@ -23,7 +23,7 @@
use runtime_common::{attestations, claims, parachains, registrar, slots,
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight,
};
use sp_std::prelude::*;
......@@ -151,6 +151,8 @@ impl system::Trait for Runtime {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
......@@ -212,7 +214,6 @@ impl balances::Trait for Runtime {
}
parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
......@@ -221,7 +222,6 @@ parameter_types! {
impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = TargetedFeeAdjustment<TargetBlockFullness, Self>;
......
......@@ -29,7 +29,7 @@ use primitives::{
use runtime_common::{attestations, claims, parachains, registrar, slots,
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment},
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight,
};
use sp_core::sr25519;
use sp_runtime::{
......@@ -143,6 +143,8 @@ impl system::Trait for Runtime {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
......@@ -196,7 +198,6 @@ impl balances::Trait for Runtime {
}
parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
......@@ -205,7 +206,6 @@ parameter_types! {
impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = ();
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = TargetedFeeAdjustment<TargetBlockFullness, Self>;
......
......@@ -29,6 +29,7 @@ use primitives::{
use runtime_common::{attestations, parachains, registrar,
impls::{CurrencyToVoteHandler, TargetedFeeAdjustment, ToAuthor},
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
BlockExecutionWeight, ExtrinsicBaseWeight
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
......@@ -144,6 +145,8 @@ impl system::Trait for Runtime {
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = BlockExecutionWeight;
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = Version;
......@@ -197,7 +200,6 @@ impl balances::Trait for Runtime {
}
parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
......@@ -206,7 +208,6 @@ parameter_types! {
impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = ToAuthor<Runtime>;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = TargetedFeeAdjustment<TargetBlockFullness, Self>;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment