Skip to content

Commit

Permalink
Align all TransactionByteFee for SP + sanity test
Browse files Browse the repository at this point in the history
  • Loading branch information
bkontur committed Feb 28, 2024
1 parent 994d6e6 commit c5d2467
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions relay/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub mod fee {
/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Cost of every transaction byte at Kusama relay chain.
pub const TRANSACTION_BYTE_FEE: Balance = 10 * super::currency::MILLICENTS;

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
Expand Down
2 changes: 1 addition & 1 deletion relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl pallet_beefy_mmr::Config for Runtime {
}

parameter_types! {
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
pub const TransactionByteFee: Balance = kusama_runtime_constants::fee::TRANSACTION_BYTE_FEE;
/// This value increases the priority of `Operational` transactions by adding
/// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
pub const OperationalFeeMultiplier: u8 = 5;
Expand Down
3 changes: 3 additions & 0 deletions relay/polkadot/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub mod fee {
/// The block saturation level. Fees will be updates based on this value.
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);

/// Cost of every transaction byte at Kusama relay chain.
pub const TRANSACTION_BYTE_FEE: Balance = 10 * super::currency::MILLICENTS;

/// Handles converting a weight scalar to a fee value, based on the scale and granularity of the
/// node's balance type.
///
Expand Down
2 changes: 1 addition & 1 deletion relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl pallet_beefy_mmr::Config for Runtime {
}

parameter_types! {
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
pub const TransactionByteFee: Balance = polkadot_runtime_constants::fee::TRANSACTION_BYTE_FEE;
/// This value increases the priority of `Operational` transactions by adding
/// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
pub const OperationalFeeMultiplier: u8 = 5;
Expand Down
15 changes: 9 additions & 6 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ use parachains_common::{
};
use sp_runtime::RuntimeDebug;
use system_parachains_constants::{
kusama::{
consensus::*,
currency::*,
fee::{WeightToFee, TRANSACTION_BYTE_FEE},
},
kusama::{consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
SLOT_DURATION,
};
Expand Down Expand Up @@ -239,7 +235,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = kusama::fee::TRANSACTION_BYTE_FEE;
pub const TransactionByteFee: Balance = system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE;
}

impl pallet_transaction_payment::Config for Runtime {
Expand Down Expand Up @@ -1713,4 +1709,11 @@ mod tests {
let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default();
assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof);
}

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = kusama_runtime_constants::fee::TRANSACTION_BYTE_FEE;
let parachain_tbf = TransactionByteFee::get();
assert_eq!(relay_tbf / 10, parachain_tbf);
}
}
15 changes: 9 additions & 6 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ use parachains_common::{

use sp_runtime::RuntimeDebug;
use system_parachains_constants::{
polkadot::{
consensus::*,
currency::*,
fee::{WeightToFee, TRANSACTION_BYTE_FEE},
},
polkadot::{consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
SLOT_DURATION,
};
Expand Down Expand Up @@ -252,7 +248,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE;
pub const TransactionByteFee: Balance = system_parachains_constants::polkadot::fee::TRANSACTION_BYTE_FEE;
}

impl pallet_transaction_payment::Config for Runtime {
Expand Down Expand Up @@ -1541,4 +1537,11 @@ mod tests {
let time_o_proof = time_fee.checked_div(proof_fee).unwrap_or_default();
assert!(time_o_proof <= 30, "{} should be at most 30", time_o_proof);
}

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = polkadot_runtime_constants::fee::TRANSACTION_BYTE_FEE;
let parachain_tbf = TransactionByteFee::get();
assert_eq!(relay_tbf / 10, parachain_tbf);
}
}
20 changes: 14 additions & 6 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ use parachains_common::{
Signature,
};
use system_parachains_constants::{
kusama::{
consensus::*,
currency::*,
fee::{WeightToFee, TRANSACTION_BYTE_FEE},
},
kusama::{consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};

Expand Down Expand Up @@ -278,7 +274,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE;
pub const TransactionByteFee: Balance = system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE;
}

impl pallet_transaction_payment::Config for Runtime {
Expand Down Expand Up @@ -1120,3 +1116,15 @@ cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = kusama_runtime_constants::fee::TRANSACTION_BYTE_FEE;
let parachain_tbf = TransactionByteFee::get();
assert_eq!(relay_tbf / 10, parachain_tbf);
}
}
20 changes: 14 additions & 6 deletions system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ use parachains_common::{
Signature,
};
use system_parachains_constants::{
polkadot::{
consensus::*,
currency::*,
fee::{WeightToFee, TRANSACTION_BYTE_FEE},
},
polkadot::{consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION,
};
// XCM Imports
Expand Down Expand Up @@ -278,7 +274,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE;
pub const TransactionByteFee: Balance = system_parachains_constants::polkadot::fee::TRANSACTION_BYTE_FEE;
}

impl pallet_transaction_payment::Config for Runtime {
Expand Down Expand Up @@ -1120,3 +1116,15 @@ cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = polkadot_runtime_constants::fee::TRANSACTION_BYTE_FEE;
let parachain_tbf = TransactionByteFee::get();
assert_eq!(relay_tbf / 10, parachain_tbf);
}
}
16 changes: 9 additions & 7 deletions system-parachains/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,7 @@ use parachains_common::{
};
use sp_runtime::RuntimeDebug;
use system_parachains_constants::{
polkadot::{
account::*,
consensus::*,
currency::*,
fee::{WeightToFee, TRANSACTION_BYTE_FEE},
},
polkadot::{account::*, consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO,
SLOT_DURATION,
};
Expand Down Expand Up @@ -227,7 +222,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10
pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE;
pub const TransactionByteFee: Balance = system_parachains_constants::polkadot::fee::TRANSACTION_BYTE_FEE;
}

impl pallet_transaction_payment::Config for Runtime {
Expand Down Expand Up @@ -1066,3 +1061,10 @@ fn test_ed_is_one_tenth_of_relay() {
let collectives_ed = ExistentialDeposit::get();
assert_eq!(relay_ed / 10, collectives_ed);
}

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = polkadot_runtime_constants::fee::TRANSACTION_BYTE_FEE;
let parachain_tbf = TransactionByteFee::get();
assert_eq!(relay_tbf / 10, parachain_tbf);
}
15 changes: 9 additions & 6 deletions system-parachains/encointer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use system_parachains_constants::{
kusama::{
consensus::*,
currency::*,
fee::{WeightToFee, TRANSACTION_BYTE_FEE},
},
kusama::{consensus::*, currency::*, fee::WeightToFee},
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO,
SLOT_DURATION,
};
Expand Down Expand Up @@ -320,7 +316,7 @@ impl pallet_balances::Config for Runtime {

parameter_types! {
/// Relay Chain `TransactionByteFee` / 10, same as statemine
pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE;
pub const TransactionByteFee: Balance = system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE;
pub const OperationalFeeMultiplier: u8 = 5;
}

Expand Down Expand Up @@ -1134,6 +1130,13 @@ fn test_constants_compatiblity() {
);
}

#[test]
fn test_transasction_byte_fee_is_one_tenth_of_relay() {
let relay_tbf = ::kusama_runtime_constants::fee::TRANSACTION_BYTE_FEE;
let parachain_tbf = TransactionByteFee::get();
assert_eq!(relay_tbf / 10, parachain_tbf);
}

// The Encointer pallets do not have compatible versions with `polkadot-sdk`, making it difficult
// for us to reuse the `system-parachains-constants` module. Therefore, we have copies of it here
// with `test_constants_compatiblity`.
Expand Down

0 comments on commit c5d2467

Please sign in to comment.