mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 19:45:41 +00:00
enable weight fee adjustent in Rialto/Millau (#1044)
This commit is contained in:
committed by
Bastian Köcher
parent
88ee6bd6a0
commit
4e18bff37c
@@ -37,7 +37,7 @@ use crate::rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge};
|
|||||||
use bridge_runtime_common::messages::{source::estimate_message_dispatch_and_delivery_fee, MessageBridge};
|
use bridge_runtime_common::messages::{source::estimate_message_dispatch_and_delivery_fee, MessageBridge};
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
||||||
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
|
use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
|
||||||
use sp_api::impl_runtime_apis;
|
use sp_api::impl_runtime_apis;
|
||||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||||
@@ -45,7 +45,7 @@ use sp_runtime::traits::{Block as BlockT, IdentityLookup, NumberFor, OpaqueKeys}
|
|||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
transaction_validity::{TransactionSource, TransactionValidity},
|
transaction_validity::{TransactionSource, TransactionValidity},
|
||||||
ApplyExtrinsicResult, MultiSignature, MultiSigner,
|
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -273,13 +273,23 @@ impl pallet_balances::Config for Runtime {
|
|||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const TransactionBaseFee: Balance = 0;
|
pub const TransactionBaseFee: Balance = 0;
|
||||||
pub const TransactionByteFee: Balance = 1;
|
pub const TransactionByteFee: Balance = 1;
|
||||||
|
// values for following parameters are copypasted from polkadot repo, but it is fine
|
||||||
|
// not to sync them - we're not going to make Rialto a full copy of one of Polkadot-like chains
|
||||||
|
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
|
||||||
|
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
|
||||||
|
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_transaction_payment::Config for Runtime {
|
impl pallet_transaction_payment::Config for Runtime {
|
||||||
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
||||||
type TransactionByteFee = TransactionByteFee;
|
type TransactionByteFee = TransactionByteFee;
|
||||||
type WeightToFee = IdentityFee<Balance>;
|
type WeightToFee = IdentityFee<Balance>;
|
||||||
type FeeMultiplierUpdate = ();
|
type FeeMultiplierUpdate = pallet_transaction_payment::TargetedFeeAdjustment<
|
||||||
|
Runtime,
|
||||||
|
TargetBlockFullness,
|
||||||
|
AdjustmentVariable,
|
||||||
|
MinimumMultiplier,
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_sudo::Config for Runtime {
|
impl pallet_sudo::Config for Runtime {
|
||||||
|
|||||||
@@ -31,15 +31,19 @@ use frame_support::{
|
|||||||
weights::{DispatchClass, Weight},
|
weights::{DispatchClass, Weight},
|
||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128};
|
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
|
||||||
use sp_std::{convert::TryFrom, ops::RangeInclusive};
|
use sp_std::{convert::TryFrom, ops::RangeInclusive};
|
||||||
|
|
||||||
/// Initial value of `RialtoToMillauConversionRate` parameter.
|
/// Initial value of `RialtoToMillauConversionRate` parameter.
|
||||||
pub const INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
pub const INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
||||||
|
/// Initial value of `RialtoFeeMultiplier` parameter.
|
||||||
|
pub const INITIAL_RIALTO_FEE_MULTIPLIER: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
/// Rialto to Millau conversion rate. Initially we treat both tokens as equal.
|
/// Rialto to Millau conversion rate. Initially we treat both tokens as equal.
|
||||||
pub storage RialtoToMillauConversionRate: FixedU128 = INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE;
|
pub storage RialtoToMillauConversionRate: FixedU128 = INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE;
|
||||||
|
/// Fee multiplier value at Rialto chain.
|
||||||
|
pub storage RialtoFeeMultiplier: FixedU128 = INITIAL_RIALTO_FEE_MULTIPLIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Message payload for Millau -> Rialto messages.
|
/// Message payload for Millau -> Rialto messages.
|
||||||
@@ -128,11 +132,15 @@ impl messages::ThisChainWithMessages for Millau {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_millau::Balance {
|
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_millau::Balance {
|
||||||
|
// `transaction` may represent transaction from the future, when multiplier value will
|
||||||
|
// be larger, so let's use slightly increased value
|
||||||
|
let multiplier = FixedU128::saturating_from_rational(110, 100)
|
||||||
|
.saturating_mul(pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier());
|
||||||
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
||||||
messages::transaction_payment(
|
messages::transaction_payment(
|
||||||
bp_millau::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
bp_millau::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||||
1,
|
1,
|
||||||
FixedU128::zero(),
|
multiplier,
|
||||||
|weight| weight as _,
|
|weight| weight as _,
|
||||||
transaction,
|
transaction,
|
||||||
)
|
)
|
||||||
@@ -195,11 +203,14 @@ impl messages::BridgedChainWithMessages for Rialto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_rialto::Balance {
|
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_rialto::Balance {
|
||||||
|
// we don't have a direct access to the value of multiplier at Rialto chain
|
||||||
|
// => it is a messages module parameter
|
||||||
|
let multiplier = RialtoFeeMultiplier::get();
|
||||||
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
||||||
messages::transaction_payment(
|
messages::transaction_payment(
|
||||||
bp_rialto::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
bp_rialto::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||||
1,
|
1,
|
||||||
FixedU128::zero(),
|
multiplier,
|
||||||
|weight| weight as _,
|
|weight| weight as _,
|
||||||
transaction,
|
transaction,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ use crate::millau_messages::{ToMillauMessagePayload, WithMillauMessageBridge};
|
|||||||
use bridge_runtime_common::messages::{source::estimate_message_dispatch_and_delivery_fee, MessageBridge};
|
use bridge_runtime_common::messages::{source::estimate_message_dispatch_and_delivery_fee, MessageBridge};
|
||||||
use codec::Decode;
|
use codec::Decode;
|
||||||
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
|
||||||
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
|
use pallet_transaction_payment::{FeeDetails, Multiplier, RuntimeDispatchInfo};
|
||||||
use sp_api::impl_runtime_apis;
|
use sp_api::impl_runtime_apis;
|
||||||
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||||
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
|
||||||
@@ -51,7 +51,7 @@ use sp_runtime::traits::{Block as BlockT, IdentityLookup, NumberFor, OpaqueKeys}
|
|||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
create_runtime_str, generic, impl_opaque_keys,
|
create_runtime_str, generic, impl_opaque_keys,
|
||||||
transaction_validity::{TransactionSource, TransactionValidity},
|
transaction_validity::{TransactionSource, TransactionValidity},
|
||||||
ApplyExtrinsicResult, MultiSignature, MultiSigner,
|
ApplyExtrinsicResult, FixedPointNumber, MultiSignature, MultiSigner, Perquintill,
|
||||||
};
|
};
|
||||||
use sp_std::prelude::*;
|
use sp_std::prelude::*;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@@ -380,13 +380,23 @@ impl pallet_balances::Config for Runtime {
|
|||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const TransactionBaseFee: Balance = 0;
|
pub const TransactionBaseFee: Balance = 0;
|
||||||
pub const TransactionByteFee: Balance = 1;
|
pub const TransactionByteFee: Balance = 1;
|
||||||
|
// values for following parameters are copypasted from polkadot repo, but it is fine
|
||||||
|
// not to sync them - we're not going to make Rialto a full copy of one of Polkadot-like chains
|
||||||
|
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
|
||||||
|
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
|
||||||
|
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_transaction_payment::Config for Runtime {
|
impl pallet_transaction_payment::Config for Runtime {
|
||||||
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
||||||
type TransactionByteFee = TransactionByteFee;
|
type TransactionByteFee = TransactionByteFee;
|
||||||
type WeightToFee = IdentityFee<Balance>;
|
type WeightToFee = IdentityFee<Balance>;
|
||||||
type FeeMultiplierUpdate = ();
|
type FeeMultiplierUpdate = pallet_transaction_payment::TargetedFeeAdjustment<
|
||||||
|
Runtime,
|
||||||
|
TargetBlockFullness,
|
||||||
|
AdjustmentVariable,
|
||||||
|
MinimumMultiplier,
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_sudo::Config for Runtime {
|
impl pallet_sudo::Config for Runtime {
|
||||||
|
|||||||
@@ -31,15 +31,19 @@ use frame_support::{
|
|||||||
weights::{DispatchClass, Weight},
|
weights::{DispatchClass, Weight},
|
||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
use sp_runtime::{traits::Zero, FixedPointNumber, FixedU128};
|
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
|
||||||
use sp_std::{convert::TryFrom, ops::RangeInclusive};
|
use sp_std::{convert::TryFrom, ops::RangeInclusive};
|
||||||
|
|
||||||
/// Initial value of `MillauToRialtoConversionRate` parameter.
|
/// Initial value of `MillauToRialtoConversionRate` parameter.
|
||||||
pub const INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
pub const INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
||||||
|
/// Initial value of `MillauFeeMultiplier` parameter.
|
||||||
|
pub const INITIAL_MILLAU_FEE_MULTIPLIER: FixedU128 = FixedU128::from_inner(FixedU128::DIV);
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
/// Millau to Rialto conversion rate. Initially we treat both tokens as equal.
|
/// Millau to Rialto conversion rate. Initially we treat both tokens as equal.
|
||||||
pub storage MillauToRialtoConversionRate: FixedU128 = INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE;
|
pub storage MillauToRialtoConversionRate: FixedU128 = INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE;
|
||||||
|
/// Fee multiplier value at Millau chain.
|
||||||
|
pub storage MillauFeeMultiplier: FixedU128 = INITIAL_MILLAU_FEE_MULTIPLIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Message payload for Rialto -> Millau messages.
|
/// Message payload for Rialto -> Millau messages.
|
||||||
@@ -128,11 +132,15 @@ impl messages::ThisChainWithMessages for Rialto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_rialto::Balance {
|
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_rialto::Balance {
|
||||||
|
// `transaction` may represent transaction from the future, when multiplier value will
|
||||||
|
// be larger, so let's use slightly increased value
|
||||||
|
let multiplier = FixedU128::saturating_from_rational(110, 100)
|
||||||
|
.saturating_mul(pallet_transaction_payment::Pallet::<Runtime>::next_fee_multiplier());
|
||||||
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
||||||
messages::transaction_payment(
|
messages::transaction_payment(
|
||||||
bp_rialto::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
bp_rialto::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||||
1,
|
1,
|
||||||
FixedU128::zero(),
|
multiplier,
|
||||||
|weight| weight as _,
|
|weight| weight as _,
|
||||||
transaction,
|
transaction,
|
||||||
)
|
)
|
||||||
@@ -195,11 +203,14 @@ impl messages::BridgedChainWithMessages for Millau {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_millau::Balance {
|
fn transaction_payment(transaction: MessageTransaction<Weight>) -> bp_millau::Balance {
|
||||||
|
// we don't have a direct access to the value of multiplier at Millau chain
|
||||||
|
// => it is a messages module parameter
|
||||||
|
let multiplier = MillauFeeMultiplier::get();
|
||||||
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
||||||
messages::transaction_payment(
|
messages::transaction_payment(
|
||||||
bp_millau::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
bp_millau::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||||
1,
|
1,
|
||||||
FixedU128::zero(),
|
multiplier,
|
||||||
|weight| weight as _,
|
|weight| weight as _,
|
||||||
transaction,
|
transaction,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ use frame_support::{
|
|||||||
};
|
};
|
||||||
use hash_db::Hasher;
|
use hash_db::Hasher;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedDiv, CheckedMul},
|
traits::{AtLeast32BitUnsigned, CheckedAdd, CheckedDiv, CheckedMul, Saturating, Zero},
|
||||||
FixedPointNumber, FixedPointOperand, FixedU128,
|
FixedPointNumber, FixedPointOperand, FixedU128,
|
||||||
};
|
};
|
||||||
use sp_std::{cmp::PartialOrd, convert::TryFrom, fmt::Debug, marker::PhantomData, ops::RangeInclusive, vec::Vec};
|
use sp_std::{cmp::PartialOrd, convert::TryFrom, fmt::Debug, marker::PhantomData, ops::RangeInclusive, vec::Vec};
|
||||||
@@ -491,6 +491,7 @@ pub mod target {
|
|||||||
MessageDispatch<AccountIdOf<ThisChain<B>>, BalanceOf<BridgedChain<B>>>
|
MessageDispatch<AccountIdOf<ThisChain<B>>, BalanceOf<BridgedChain<B>>>
|
||||||
for FromBridgedChainMessageDispatch<B, ThisRuntime, ThisCurrency, ThisDispatchInstance>
|
for FromBridgedChainMessageDispatch<B, ThisRuntime, ThisCurrency, ThisDispatchInstance>
|
||||||
where
|
where
|
||||||
|
BalanceOf<ThisChain<B>>: Saturating + FixedPointOperand,
|
||||||
ThisDispatchInstance: frame_support::traits::Instance,
|
ThisDispatchInstance: frame_support::traits::Instance,
|
||||||
ThisRuntime: pallet_bridge_dispatch::Config<ThisDispatchInstance, MessageId = (LaneId, MessageNonce)>
|
ThisRuntime: pallet_bridge_dispatch::Config<ThisDispatchInstance, MessageId = (LaneId, MessageNonce)>
|
||||||
+ pallet_transaction_payment::Config,
|
+ pallet_transaction_payment::Config,
|
||||||
@@ -525,13 +526,20 @@ pub mod target {
|
|||||||
message_id,
|
message_id,
|
||||||
message.data.payload.map_err(drop),
|
message.data.payload.map_err(drop),
|
||||||
|dispatch_origin, dispatch_weight| {
|
|dispatch_origin, dispatch_weight| {
|
||||||
ThisCurrency::transfer(
|
let unadjusted_weight_fee = ThisRuntime::WeightToFee::calc(&dispatch_weight);
|
||||||
dispatch_origin,
|
let fee_multiplier = pallet_transaction_payment::Pallet::<ThisRuntime>::next_fee_multiplier();
|
||||||
relayer_account,
|
let adjusted_weight_fee = fee_multiplier.saturating_mul_int(unadjusted_weight_fee);
|
||||||
ThisRuntime::WeightToFee::calc(&dispatch_weight),
|
if !adjusted_weight_fee.is_zero() {
|
||||||
ExistenceRequirement::AllowDeath,
|
ThisCurrency::transfer(
|
||||||
)
|
dispatch_origin,
|
||||||
.map_err(drop)
|
relayer_account,
|
||||||
|
adjusted_weight_fee,
|
||||||
|
ExistenceRequirement::AllowDeath,
|
||||||
|
)
|
||||||
|
.map_err(drop)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user