Skip to content

Commit

Permalink
fix bridge byte fee: use TransactionByteFee of the bridged chain
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed Feb 1, 2024
1 parent 16635f6 commit 0d0b951
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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,
};
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -731,7 +731,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())));
Expand Down
8 changes: 6 additions & 2 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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,
};
Expand Down Expand Up @@ -246,7 +250,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -626,7 +626,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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.0" }
Expand All @@ -36,4 +37,5 @@ std = [
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"system-parachains-constants/std",
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ use parachains_common::{
impls::DealWithFees, AccountId, Balance, BlockNumber, Hash, Header, Nonce, 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,
};

Expand Down Expand Up @@ -269,7 +273,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.0" }
Expand All @@ -36,4 +37,5 @@ std = [
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
"system-parachains-constants/std",
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ use parachains_common::{
impls::DealWithFees, AccountId, Balance, BlockNumber, Hash, Header, Nonce, 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
Expand Down Expand Up @@ -269,7 +273,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 {
Expand Down
9 changes: 7 additions & 2 deletions system-parachains/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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,
};
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions system-parachains/constants/src/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
5 changes: 5 additions & 0 deletions system-parachains/constants/src/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
8 changes: 6 additions & 2 deletions system-parachains/encointer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
Expand Down Expand Up @@ -327,7 +331,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;
}

Expand Down

0 comments on commit 0d0b951

Please sign in to comment.