mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Introduce BlockExecutionWeight and ExtrinsicBaseWeight (#5722)
* Introduce `BlockExectionWeight` and `ExtrinsicBaseWeight` * Add new traits everywhere * Missed one update * fix tests * Update `check_weight` logic * introduce `max_extrinsic_weight` function * fix + add tests * format nits * remove println * make test a bit more clear * Remove minimum weight * newlines left over from find/replace * Fix test, improve clarity * Fix executor tests * Extrinsic base weight same as old `MINIMUM_WEIGHT` * fix example test * Expose constants * Add test for full block with operational and normal * Initiate test environment with `BlockExecutionWeight` weight * format nit * Update frame/system/src/lib.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Replace `TransactionBaseFee` with `ExtrinsicBaseWeight` (#5761) * Replace `TransactionBaseFee` with `ExtrinsicBaseFee` * Fix stuff * Fix and make tests better * Forgot to update this test * Fix priority number in test * Remove minimum weight from merge * Fix weight in contracts * remove `TransactionBaseFee` from contract tests * Let `register_extra_weight_unchecked` go past `MaximumBlockWeight` * address feedback Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -33,7 +33,7 @@ use frame_system::{self, EventRecord, Phase};
|
||||
|
||||
use node_runtime::{
|
||||
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
|
||||
System, TransactionPayment, Event, TransactionBaseFee, TransactionByteFee,
|
||||
System, TransactionPayment, Event, TransactionByteFee, ExtrinsicBaseWeight,
|
||||
constants::currency::*,
|
||||
};
|
||||
use node_primitives::{Balance, Hash};
|
||||
@@ -54,11 +54,11 @@ pub const BLOATY_CODE: &[u8] = node_runtime::WASM_BINARY_BLOATY;
|
||||
fn transfer_fee<E: Encode>(extrinsic: &E, fee_multiplier: Fixed128) -> Balance {
|
||||
let length_fee = TransactionByteFee::get() * (extrinsic.encode().len() as Balance);
|
||||
|
||||
let base_weight = ExtrinsicBaseWeight::get();
|
||||
let base_fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(base_weight);
|
||||
let weight = default_transfer_call().get_dispatch_info().weight;
|
||||
let weight_fee = <Runtime as pallet_transaction_payment::Trait>
|
||||
::WeightToFee::convert(weight);
|
||||
let weight_fee = <Runtime as pallet_transaction_payment::Trait>::WeightToFee::convert(weight);
|
||||
|
||||
let base_fee = TransactionBaseFee::get();
|
||||
base_fee + fee_multiplier.saturated_multiply_accumulate(length_fee + weight_fee)
|
||||
}
|
||||
|
||||
@@ -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: 10_000_000, class: DispatchClass::Mandatory, ..Default::default() }
|
||||
DispatchInfo { weight: 0, class: DispatchClass::Mandatory, ..Default::default() }
|
||||
)),
|
||||
topics: vec![],
|
||||
},
|
||||
@@ -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: 10_000_000, class: DispatchClass::Mandatory, pays_fee: Pays::Yes }
|
||||
DispatchInfo { weight: 0, class: DispatchClass::Mandatory, pays_fee: Pays::Yes }
|
||||
)),
|
||||
topics: vec![],
|
||||
},
|
||||
|
||||
@@ -23,9 +23,9 @@ use frame_support::{
|
||||
use sp_core::{NeverNativeValue, map, storage::Storage};
|
||||
use sp_runtime::{Fixed128, Perbill, traits::{Convert, BlakeTwo256}};
|
||||
use node_runtime::{
|
||||
CheckedExtrinsic, Call, Runtime, Balances, TransactionPayment, TransactionBaseFee,
|
||||
CheckedExtrinsic, Call, Runtime, Balances, TransactionPayment,
|
||||
TransactionByteFee, WeightFeeCoefficient,
|
||||
constants::currency::*,
|
||||
constants::currency::*, ExtrinsicBaseWeight,
|
||||
};
|
||||
use node_runtime::impls::LinearWeightToFee;
|
||||
use node_primitives::Balance;
|
||||
@@ -173,15 +173,17 @@ fn transaction_fee_is_correct_ultimate() {
|
||||
t.execute_with(|| {
|
||||
assert_eq!(Balances::total_balance(&bob()), (10 + 69) * DOLLARS);
|
||||
// Components deducted from alice's balances:
|
||||
// - Base fee
|
||||
// - Weight fee
|
||||
// - Length fee
|
||||
// - Tip
|
||||
// - Creation-fee of bob's account.
|
||||
let mut balance_alice = (100 - 69) * DOLLARS;
|
||||
|
||||
let length_fee = TransactionBaseFee::get() +
|
||||
TransactionByteFee::get() *
|
||||
(xt.clone().encode().len() as Balance);
|
||||
let base_weight = ExtrinsicBaseWeight::get();
|
||||
let base_fee = LinearWeightToFee::<WeightFeeCoefficient>::convert(base_weight);
|
||||
|
||||
let length_fee = TransactionByteFee::get() * (xt.clone().encode().len() as Balance);
|
||||
balance_alice -= length_fee;
|
||||
|
||||
let weight = default_transfer_call().get_dispatch_info().weight;
|
||||
@@ -191,6 +193,7 @@ fn transaction_fee_is_correct_ultimate() {
|
||||
// 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 -= base_fee;
|
||||
balance_alice -= weight_fee;
|
||||
balance_alice -= tip;
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ fn submitted_transaction_should_be_valid() {
|
||||
let res = Executive::validate_transaction(source, extrinsic);
|
||||
|
||||
assert_eq!(res.unwrap(), ValidTransaction {
|
||||
priority: 2_411_380_000_000,
|
||||
priority: 1_411_390_000_000,
|
||||
requires: vec![],
|
||||
provides: vec![(address, 0).encode()],
|
||||
longevity: 128,
|
||||
|
||||
Reference in New Issue
Block a user