From 6c3d69db1a4678a7d4fc87abb43323b4989172b5 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 1 Feb 2024 11:55:53 +0300 Subject: [PATCH 1/6] fix bridge byte fee: use TransactionByteFee of the bridged chain --- Cargo.lock | 44 ++++++++++++++++--- .../asset-hubs/asset-hub-kusama/src/lib.rs | 8 +++- .../asset-hub-kusama/src/xcm_config.rs | 6 +-- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 8 +++- .../asset-hub-polkadot/src/xcm_config.rs | 6 +-- .../bridge-hub-kusama/primitives/Cargo.toml | 6 ++- .../bridge-hub-kusama/primitives/src/lib.rs | 12 +++++ .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 8 +++- .../bridge-hub-polkadot/primitives/Cargo.toml | 6 ++- .../bridge-hub-polkadot/primitives/src/lib.rs | 12 +++++ .../bridge-hub-polkadot/src/lib.rs | 8 +++- .../collectives-polkadot/src/lib.rs | 9 +++- system-parachains/constants/src/kusama.rs | 5 +++ system-parachains/constants/src/polkadot.rs | 5 +++ system-parachains/encointer/src/lib.rs | 8 +++- 15 files changed, 123 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa1e3b9fae..36d234a6d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1081,9 +1081,10 @@ dependencies = [ "frame-support 27.0.0", "kusama-runtime-constants", "polkadot-runtime-constants", - "sp-api 25.0.0", - "sp-runtime 30.0.1", - "sp-std 13.0.0", + "sp-api", + "sp-runtime", + "sp-std", + "system-parachains-constants", ] [[package]] @@ -1096,9 +1097,40 @@ dependencies = [ "frame-support 27.0.0", "kusama-runtime-constants", "polkadot-runtime-constants", - "sp-api 25.0.0", - "sp-runtime 30.0.1", - "sp-std 13.0.0", + "sp-api", + "sp-runtime", + "sp-std", + "system-parachains-constants", +] + +[[package]] +name = "bp-bridge-hub-rococo" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcb3425030c446f51c0d9bc71605b42dc96acff94b2feff51cd09a5e58dc0dd" +dependencies = [ + "bp-bridge-hub-cumulus", + "bp-messages", + "bp-runtime", + "frame-support", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "bp-bridge-hub-wococo" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ecd2e53fcb7b489a544e27474839586b662bd0c5eea0a9bd21d5eaeae8e6b0b" +dependencies = [ + "bp-bridge-hub-cumulus", + "bp-messages", + "bp-runtime", + "frame-support", + "sp-api", + "sp-runtime", + "sp-std", ] [[package]] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 08b7b6d2b0..a0c87e665d 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -74,7 +74,11 @@ use parachains_common::{ }; use sp_runtime::RuntimeDebug; use system_parachains_constants::{ - kusama::{consensus::*, currency::*, fee::WeightToFee}, + kusama::{ + consensus::*, + currency::*, + fee::{WeightToFee, TRANSACTION_BYTE_FEE}, + }, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; @@ -236,7 +240,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = MILLICENTS; + pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; } impl pallet_transaction_payment::Config for Runtime { diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index dd6535b648..e37809db1a 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -16,8 +16,8 @@ use super::{ AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, ToPolkadotXcmRouter, TransactionByteFee, - TrustBackedAssetsInstance, WeightToFee, XcmpQueue, + RuntimeEvent, RuntimeOrigin, ToPolkadotXcmRouter, TrustBackedAssetsInstance, WeightToFee, + XcmpQueue, }; use crate::{ForeignAssets, ForeignAssetsInstance}; use assets_common::{ @@ -727,7 +727,7 @@ pub mod bridging { ); /// Price of every byte of the Kusama -> Polkadot message. Can be adjusted via /// governance `set_storage` call. - pub storage XcmBridgeHubRouterByteFee: Balance = TransactionByteFee::get(); + pub storage XcmBridgeHubRouterByteFee: Balance = bp_bridge_hub_kusama::estimate_kusama_to_polkadot_byte_fee(); pub SiblingBridgeHubParaId: u32 = bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID; pub SiblingBridgeHub: MultiLocation = MultiLocation::new(1, X1(Parachain(SiblingBridgeHubParaId::get()))); diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 95ec6add33..1cef4af22b 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -108,7 +108,11 @@ use parachains_common::{ use sp_runtime::RuntimeDebug; use system_parachains_constants::{ - polkadot::{consensus::*, currency::*, fee::WeightToFee}, + polkadot::{ + consensus::*, + currency::*, + fee::{WeightToFee, TRANSACTION_BYTE_FEE}, + }, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; @@ -247,7 +251,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = MILLICENTS; + pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; } impl pallet_transaction_payment::Config for Runtime { diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index 04469b3fcd..61c7429dc8 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -16,8 +16,8 @@ use super::{ AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, ForeignAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PriceForParentDelivery, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, ToKusamaXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, - WeightToFee, XcmpQueue, + RuntimeEvent, RuntimeOrigin, ToKusamaXcmRouter, TrustBackedAssetsInstance, WeightToFee, + XcmpQueue, }; use crate::ForeignAssetsInstance; use assets_common::matching::{FromSiblingParachain, IsForeignConcreteAsset}; @@ -622,7 +622,7 @@ pub mod bridging { ); /// Price of every byte of the Polkadot -> Kusama message. Can be adjusted via /// governance `set_storage` call. - pub storage XcmBridgeHubRouterByteFee: Balance = TransactionByteFee::get(); + pub storage XcmBridgeHubRouterByteFee: Balance = bp_bridge_hub_polkadot::estimate_polkadot_to_kusama_byte_fee(); pub SiblingBridgeHubParaId: u32 = bp_bridge_hub_polkadot::BRIDGE_HUB_POLKADOT_PARACHAIN_ID; pub SiblingBridgeHub: MultiLocation = MultiLocation::new(1, X1(Parachain(SiblingBridgeHubParaId::get()))); diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/Cargo.toml index fe96ffdfbe..ef7ba2ec42 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/Cargo.toml @@ -10,8 +10,9 @@ license.workspace = true [dependencies] # Local -kusama-runtime-constants = { path = "../../../../relay/kusama/constants", default-features = false} -polkadot-runtime-constants = { path = "../../../../relay/polkadot/constants", default-features = false} +kusama-runtime-constants = { path = "../../../../relay/kusama/constants", default-features = false } +polkadot-runtime-constants = { path = "../../../../relay/polkadot/constants", default-features = false } +system-parachains-constants = { path = "../../../constants", default-features = false } # Bridge Dependencies bp-bridge-hub-cumulus = { default-features = false , version = "0.6.0" } @@ -36,4 +37,5 @@ std = [ "sp-api/std", "sp-runtime/std", "sp-std/std", + "system-parachains-constants/std", ] diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/src/lib.rs index a746c2e022..7f2b9158fb 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/primitives/src/lib.rs @@ -118,6 +118,18 @@ pub fn estimate_kusama_to_polkadot_message_fee( .saturating_add(BridgeHubKusamaBaseConfirmationFeeInKsms::get()) } +/// Compute the per-byte fee that needs to be paid in KSMs by the sender when sending +/// message from Kusama Bridge Hub to Polkadot Bridge Hub. +pub fn estimate_kusama_to_polkadot_byte_fee() -> Balance { + // the sender pays for the same byte twice: + // 1) the first part comes from the HRMP, when message travels from Kusama Asset Hub to Kusama + // Bridge Hub; + // 2) the second part is the payment for bytes of the message delivery transaction, which is + // "mined" at Polkadot Bridge Hub. Hence, we need to use byte fees from that chain and + // convert it to KSMs here. + convert_from_udot_to_uksm(system_parachains_constants::polkadot::fee::TRANSACTION_BYTE_FEE) +} + /// Convert from uDOTs to uKSMs. fn convert_from_udot_to_uksm(price_in_udot: Balance) -> Balance { // assuming exchange rate is 5 DOTs for 1 KSM diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 92c2df46e2..1083c1f5a3 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -74,7 +74,11 @@ use parachains_common::{ Signature, }; use system_parachains_constants::{ - kusama::{consensus::*, currency::*, fee::WeightToFee}, + kusama::{ + consensus::*, + currency::*, + fee::{WeightToFee, TRANSACTION_BYTE_FEE}, + }, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; @@ -273,7 +277,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = MILLICENTS; + pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; } impl pallet_transaction_payment::Config for Runtime { diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml index 717310b606..3b680cddbf 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml @@ -10,8 +10,9 @@ license.workspace = true [dependencies] # Local -kusama-runtime-constants = { path = "../../../../relay/kusama/constants", default-features = false} -polkadot-runtime-constants = { path = "../../../../relay/polkadot/constants", default-features = false} +kusama-runtime-constants = { path = "../../../../relay/kusama/constants", default-features = false } +polkadot-runtime-constants = { path = "../../../../relay/polkadot/constants", default-features = false } +system-parachains-constants = { path = "../../../constants", default-features = false } # Bridge Dependencies bp-bridge-hub-cumulus = { default-features = false , version = "0.6.0" } @@ -36,4 +37,5 @@ std = [ "sp-api/std", "sp-runtime/std", "sp-std/std", + "system-parachains-constants/std", ] diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/src/lib.rs index b02f6107d6..e2a853aa89 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/src/lib.rs @@ -109,6 +109,18 @@ pub fn estimate_polkadot_to_kusama_message_fee( .saturating_add(BridgeHubPolkadotBaseConfirmationFeeInDots::get()) } +/// Compute the per-byte fee that needs to be paid in DOTs by the sender when sending +/// message from Polkadot Bridge Hub to Kusama Bridge Hub. +pub fn estimate_polkadot_to_kusama_byte_fee() -> Balance { + // the sender pays for the same byte twice: + // 1) the first part comes from the HRMP, when message travels from Polkadot Asset Hub to + // Polkadot Bridge Hub; + // 2) the second part is the payment for bytes of the message delivery transaction, which is + // "mined" at Kusama Bridge Hub. Hence, we need to use byte fees from that chain and convert + // it to DOTs here. + convert_from_uksm_to_udot(system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE) +} + /// Convert from uKSMs to uDOTs. fn convert_from_uksm_to_udot(price_in_uksm: Balance) -> Balance { // assuming exchange rate is 5 DOTs for 1 KSM diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index a656380a43..288164e51a 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -75,7 +75,11 @@ use parachains_common::{ Signature, }; use system_parachains_constants::{ - polkadot::{consensus::*, currency::*, fee::WeightToFee}, + polkadot::{ + consensus::*, + currency::*, + fee::{WeightToFee, TRANSACTION_BYTE_FEE}, + }, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; // XCM Imports @@ -273,7 +277,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = MILLICENTS; + pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; } impl pallet_transaction_payment::Config for Runtime { diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 2d876529bb..2ad4155375 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -84,7 +84,12 @@ use parachains_common::{ }; use sp_runtime::RuntimeDebug; use system_parachains_constants::{ - polkadot::{account::*, consensus::*, currency::*, fee::WeightToFee}, + polkadot::{ + account::*, + consensus::*, + currency::*, + fee::{WeightToFee, TRANSACTION_BYTE_FEE}, + }, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MINUTES, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; @@ -221,7 +226,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = MILLICENTS; + pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; } impl pallet_transaction_payment::Config for Runtime { diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index 428059794b..97ef0f189b 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -64,6 +64,11 @@ 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 system parachains. + /// + /// It is the Relay Chain (Kusama) `TransactionByteFee` / 10. + pub const TRANSACTION_BYTE_FEE: Balance = super::currency::MILLICENTS; + /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the /// node's balance type. /// diff --git a/system-parachains/constants/src/polkadot.rs b/system-parachains/constants/src/polkadot.rs index 932cf2c341..028784270c 100644 --- a/system-parachains/constants/src/polkadot.rs +++ b/system-parachains/constants/src/polkadot.rs @@ -86,6 +86,11 @@ 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 Polkadot system parachains. + /// + /// It is the Relay Chain (Polkadot) `TransactionByteFee` / 10. + pub const TRANSACTION_BYTE_FEE: Balance = super::currency::MILLICENTS; + /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the /// node's balance type. /// diff --git a/system-parachains/encointer/src/lib.rs b/system-parachains/encointer/src/lib.rs index eb04d4753d..99ecc582b9 100644 --- a/system-parachains/encointer/src/lib.rs +++ b/system-parachains/encointer/src/lib.rs @@ -91,7 +91,11 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; use system_parachains_constants::{ - kusama::{consensus::*, currency::*, fee::WeightToFee}, + kusama::{ + consensus::*, + currency::*, + fee::{WeightToFee, TRANSACTION_BYTE_FEE}, + }, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; @@ -312,7 +316,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10, same as statemine - pub const TransactionByteFee: Balance = MILLICENTS; + pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; pub const OperationalFeeMultiplier: u8 = 5; } From ca80d61780adcbfc37dbebd470bbe5b4009b3a63 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 1 Feb 2024 12:09:11 +0300 Subject: [PATCH 2/6] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11337e88b2..dc3c72a9bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Removed the `SafeCallFilter` from the Relay Chain XCM config ([polkadot-fellows/runtimes#172](https://github.com/polkadot-fellows/runtimes/pull/172)). +### Fixed + +- Fixed the cost of a single byte, sent over bridge to use the `TransactionByteFee` constant of the bridged chain [polkadot-fellows/runtimes#174](https://github.com/polkadot-fellows/runtimes/pull/174). + ## [1.1.1] 25.01.2024 ### Fixed From 07e0d276b173663adc479d7ccb52b9462f21e29e Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 15 Feb 2024 13:50:09 +0300 Subject: [PATCH 3/6] lost lock file --- Cargo.lock | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36d234a6d0..7b782d5e81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1081,9 +1081,9 @@ dependencies = [ "frame-support 27.0.0", "kusama-runtime-constants", "polkadot-runtime-constants", - "sp-api", - "sp-runtime", - "sp-std", + "sp-api 25.0.0", + "sp-runtime 30.0.1", + "sp-std 13.0.0", "system-parachains-constants", ] @@ -1097,42 +1097,12 @@ dependencies = [ "frame-support 27.0.0", "kusama-runtime-constants", "polkadot-runtime-constants", - "sp-api", - "sp-runtime", - "sp-std", + "sp-api 25.0.0", + "sp-runtime 30.0.1", + "sp-std 13.0.0", "system-parachains-constants", ] -[[package]] -name = "bp-bridge-hub-rococo" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcb3425030c446f51c0d9bc71605b42dc96acff94b2feff51cd09a5e58dc0dd" -dependencies = [ - "bp-bridge-hub-cumulus", - "bp-messages", - "bp-runtime", - "frame-support", - "sp-api", - "sp-runtime", - "sp-std", -] - -[[package]] -name = "bp-bridge-hub-wococo" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ecd2e53fcb7b489a544e27474839586b662bd0c5eea0a9bd21d5eaeae8e6b0b" -dependencies = [ - "bp-bridge-hub-cumulus", - "bp-messages", - "bp-runtime", - "frame-support", - "sp-api", - "sp-runtime", - "sp-std", -] - [[package]] name = "bp-header-chain" version = "0.6.0" From 752eb9ad50d21732d226f75f5260feb6f8f9d0c3 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 15 Feb 2024 15:04:58 +0300 Subject: [PATCH 4/6] fix encointer runtime --- system-parachains/encointer/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system-parachains/encointer/src/lib.rs b/system-parachains/encointer/src/lib.rs index 99ecc582b9..dcbc915d08 100644 --- a/system-parachains/encointer/src/lib.rs +++ b/system-parachains/encointer/src/lib.rs @@ -1064,6 +1064,10 @@ fn test_constants_compatiblity() { ::system_parachains_constants::kusama::currency::system_para_deposit(5, 3), system_parachains_constants::kusama::currency::system_para_deposit(5, 3) ); + assert_eq!( + ::system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE, + system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE + ); assert_eq!( ::system_parachains_constants::kusama::fee::calculate_weight_to_fee( &::system_parachains_constants::MAXIMUM_BLOCK_WEIGHT @@ -1156,6 +1160,11 @@ mod system_parachains_constants { use smallvec::smallvec; pub use sp_runtime::Perbill; + /// Cost of every transaction byte at Kusama system parachains. + /// + /// It is the Relay Chain (Kusama) `TransactionByteFee` / 10. + pub const TRANSACTION_BYTE_FEE: Balance = super::currency::MILLICENTS; + /// Handles converting a weight scalar to a fee value, based on the scale and /// granularity of the node's balance type. /// From 994d6e6718861072a4ca83280534654662e3b02f Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 28 Feb 2024 15:35:48 +0100 Subject: [PATCH 5/6] Update system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 7adbade0f6..a0486428cc 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -239,7 +239,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = TRANSACTION_BYTE_FEE; + pub const TransactionByteFee: Balance = kusama::fee::TRANSACTION_BYTE_FEE; } impl pallet_transaction_payment::Config for Runtime { From c5d2467e8e6004b7627ad5c18b25b36968217e12 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 28 Feb 2024 16:13:22 +0100 Subject: [PATCH 6/6] Align all `TransactionByteFee` for SP + sanity test --- Cargo.lock | 4 ++-- relay/kusama/constants/src/lib.rs | 3 +++ relay/kusama/src/lib.rs | 2 +- relay/polkadot/constants/src/lib.rs | 3 +++ relay/polkadot/src/lib.rs | 2 +- .../asset-hubs/asset-hub-kusama/src/lib.rs | 15 ++++++++------ .../asset-hubs/asset-hub-polkadot/src/lib.rs | 15 ++++++++------ .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 20 +++++++++++++------ .../bridge-hub-polkadot/src/lib.rs | 20 +++++++++++++------ .../collectives-polkadot/src/lib.rs | 16 ++++++++------- system-parachains/encointer/src/lib.rs | 15 ++++++++------ 11 files changed, 74 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dccb62845d..ce86e4d071 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1113,10 +1113,10 @@ dependencies = [ "frame-support", "kusama-runtime-constants", "polkadot-runtime-constants", - "system-parachains-constants", "sp-api", "sp-runtime", "sp-std", + "system-parachains-constants", ] [[package]] @@ -1129,10 +1129,10 @@ dependencies = [ "frame-support", "kusama-runtime-constants", "polkadot-runtime-constants", - "system-parachains-constants", "sp-api", "sp-runtime", "sp-std", + "system-parachains-constants", ] [[package]] diff --git a/relay/kusama/constants/src/lib.rs b/relay/kusama/constants/src/lib.rs index 68cad9c3b6..a5936fa21c 100644 --- a/relay/kusama/constants/src/lib.rs +++ b/relay/kusama/constants/src/lib.rs @@ -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. /// diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index bc813a2457..8293f4344d 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -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; diff --git a/relay/polkadot/constants/src/lib.rs b/relay/polkadot/constants/src/lib.rs index e2f413bbbd..f47d9e6a97 100644 --- a/relay/polkadot/constants/src/lib.rs +++ b/relay/polkadot/constants/src/lib.rs @@ -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. /// diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 6ff280ba8e..04867fa075 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -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; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index a0486428cc..02e8e149ee 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -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, }; @@ -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 { @@ -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); + } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 14e1b9b969..5164b307ae 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -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, }; @@ -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 { @@ -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); + } } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 2e19d51344..2c62efda01 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -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, }; @@ -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 { @@ -1120,3 +1116,15 @@ cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, } + +#[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); + } +} diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 903a2c9d3f..2b18d032cc 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -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 @@ -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 { @@ -1120,3 +1116,15 @@ cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, } + +#[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); + } +} diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 7ec3f60387..0145fb3659 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -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, }; @@ -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 { @@ -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); +} diff --git a/system-parachains/encointer/src/lib.rs b/system-parachains/encointer/src/lib.rs index 041c5883ed..c93278a7d8 100644 --- a/system-parachains/encointer/src/lib.rs +++ b/system-parachains/encointer/src/lib.rs @@ -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, }; @@ -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; } @@ -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`.