Skip to content

Commit

Permalink
Weights to u64 + Balances Weights (paritytech#5446)
Browse files Browse the repository at this point in the history
Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
shawntabrizi and kianenigma authored Apr 16, 2020
1 parent 6dc23fe commit 2051ecb
Show file tree
Hide file tree
Showing 82 changed files with 636 additions and 428 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions bin/node-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs
use frame_support::{decl_module, decl_storage, decl_event, decl_error, dispatch};
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
use frame_system::{self as system, ensure_signed};

#[cfg(test)]
Expand Down Expand Up @@ -75,7 +76,7 @@ decl_module! {
/// Just a dummy entry point.
/// function that can be called by the external world as an extrinsics call
/// takes a parameter of the type `AccountId`, stores it, and emits an event
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
pub fn do_something(origin, something: u32) -> dispatch::DispatchResult {
// Check it was signed and get the signer. See also: ensure_root and ensure_none
let who = ensure_signed(origin)?;
Expand All @@ -91,7 +92,7 @@ decl_module! {

/// Another dummy entry point.
/// takes no parameters, attempts to increment storage value, and possibly throws an error
#[weight = frame_support::weights::SimpleDispatchInfo::default()]
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
pub fn cause_error(origin) -> dispatch::DispatchResult {
// Check it was signed and get the signer. See also: ensure_root and ensure_none
let _who = ensure_signed(origin)?;
Expand Down
1 change: 1 addition & 0 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl system::Trait for Test {
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type MaximumBlockLength = MaximumBlockLength;
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
Expand Down
5 changes: 4 additions & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1_000_000_000;
/// We allow for 2 seconds of compute with a 6 second average block time.
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 Version: RuntimeVersion = VERSION;
Expand Down Expand Up @@ -151,6 +152,8 @@ impl system::Trait for Runtime {
type BlockHashCount = BlockHashCount;
/// Maximum weight of each block.
type MaximumBlockWeight = MaximumBlockWeight;
/// The weight of database operations that the runtime can invoke.
type DbWeight = ();
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions.
Expand Down
16 changes: 7 additions & 9 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_core::{
NeverNativeValue, map, traits::Externalities, storage::{well_known_keys, Storage},
};
use sp_runtime::{
ApplyExtrinsicResult, Fixed64,
ApplyExtrinsicResult, Fixed128,
traits::{Hash as HashT, Convert, BlakeTwo256},
transaction_validity::InvalidTransaction,
};
Expand All @@ -51,7 +51,7 @@ use self::common::{*, sign};
pub const BLOATY_CODE: &[u8] = node_runtime::WASM_BINARY_BLOATY;

/// Default transfer fee
fn transfer_fee<E: Encode>(extrinsic: &E, fee_multiplier: Fixed64) -> Balance {
fn transfer_fee<E: Encode>(extrinsic: &E, fee_multiplier: Fixed128) -> Balance {
let length_fee = TransactionByteFee::get() * (extrinsic.encode().len() as Balance);

let weight = default_transfer_call().get_dispatch_info().weight;
Expand Down Expand Up @@ -338,7 +338,7 @@ fn full_native_block_import_works() {
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 10000, class: DispatchClass::Mandatory, pays_fee: true }
DispatchInfo { weight: 10_000_000, class: DispatchClass::Mandatory, pays_fee: true }
)),
topics: vec![],
},
Expand All @@ -359,7 +359,7 @@ fn full_native_block_import_works() {
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
DispatchInfo { weight: 200_000_000, class: DispatchClass::Normal, pays_fee: true }
)),
topics: vec![],
},
Expand Down Expand Up @@ -391,7 +391,7 @@ fn full_native_block_import_works() {
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 10000, class: DispatchClass::Mandatory, pays_fee: true }
DispatchInfo { weight: 10_000_000, class: DispatchClass::Mandatory, pays_fee: true }
)),
topics: vec![],
},
Expand All @@ -414,7 +414,7 @@ fn full_native_block_import_works() {
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
DispatchInfo { weight: 200_000_000, class: DispatchClass::Normal, pays_fee: true }
)),
topics: vec![],
},
Expand All @@ -437,7 +437,7 @@ fn full_native_block_import_works() {
EventRecord {
phase: Phase::ApplyExtrinsic(2),
event: Event::frame_system(frame_system::RawEvent::ExtrinsicSuccess(
DispatchInfo { weight: 1000000, class: DispatchClass::Normal, pays_fee: true }
DispatchInfo { weight: 200_000_000, class: DispatchClass::Normal, pays_fee: true }
)),
topics: vec![],
},
Expand Down Expand Up @@ -817,5 +817,3 @@ fn should_import_block_with_test_client() {

client.import(BlockOrigin::Own, block).unwrap();
}


8 changes: 5 additions & 3 deletions bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use frame_support::{
weights::GetDispatchInfo,
};
use sp_core::{NeverNativeValue, map, storage::Storage};
use sp_runtime::{Fixed64, Perbill, traits::{Convert, BlakeTwo256}};
use sp_runtime::{Fixed128, Perbill, traits::{Convert, BlakeTwo256}};
use node_runtime::{
CheckedExtrinsic, Call, Runtime, Balances, TransactionPayment, TransactionBaseFee,
TransactionByteFee, WeightFeeCoefficient,
Expand All @@ -39,7 +39,7 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
let mut t = new_test_ext(COMPACT_CODE, false);

// initial fee multiplier must be zero
let mut prev_multiplier = Fixed64::from_parts(0);
let mut prev_multiplier = Fixed128::from_parts(0);

t.execute_with(|| {
assert_eq!(TransactionPayment::next_fee_multiplier(), prev_multiplier);
Expand Down Expand Up @@ -188,7 +188,9 @@ fn transaction_fee_is_correct_ultimate() {
let weight_fee = LinearWeightToFee::<WeightFeeCoefficient>::convert(weight);

// we know that weight to fee multiplier is effect-less in block 1.
assert_eq!(weight_fee as Balance, MILLICENTS);
// current weight of transfer = 200_000_000
// Linear weight to fee is 1:1 right now (1 weight = 1 unit of balance)
assert_eq!(weight_fee, weight as Balance);
balance_alice -= weight_fee;
balance_alice -= tip;

Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn submitted_transaction_should_be_valid() {
let res = Executive::validate_transaction(source, extrinsic);

assert_eq!(res.unwrap(), ValidTransaction {
priority: 2_411_002_000_000,
priority: 2_410_600_000_000,
requires: vec![],
provides: vec![(address, 0).encode()],
longevity: 128,
Expand Down
Loading

0 comments on commit 2051ecb

Please sign in to comment.