mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
Remove message fee + message send calls (#1642)
* remove message fee * it is compiling! * fixes + fmt * more cleanup * more cleanup * restore MessageDeliveryAndDispatchPayment since we'll need relayer rewards * started rational relayer removal * more removal * removed estimate fee subcommand * remove DispatchFeePayment * more removals * removed conversion rates && some metrics * - unneeded associated type * - OutboundMessageFee * fix benchmarks compilation * fmt * test + fix benchmarks * fix send message * clippy
This commit is contained in:
committed by
Bastian Köcher
parent
1217b2cf80
commit
8c845602cf
@@ -32,18 +32,8 @@ pub mod rialto_messages;
|
||||
pub mod rialto_parachain_messages;
|
||||
pub mod xcm_config;
|
||||
|
||||
use crate::{
|
||||
rialto_messages::{ToRialtoMessagePayload, WithRialtoMessageBridge},
|
||||
rialto_parachain_messages::{
|
||||
ToRialtoParachainMessagePayload, WithRialtoParachainMessageBridge,
|
||||
},
|
||||
};
|
||||
|
||||
use beefy_primitives::{crypto::AuthorityId as BeefyId, mmr::MmrLeafVersion, ValidatorSet};
|
||||
use bp_runtime::{HeaderId, HeaderIdProvider};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::estimate_message_dispatch_and_delivery_fee, MessageBridge,
|
||||
};
|
||||
use codec::Decode;
|
||||
use pallet_grandpa::{
|
||||
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
|
||||
@@ -57,7 +47,7 @@ use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys,
|
||||
traits::{Block as BlockT, IdentityLookup, Keccak256, NumberFor, OpaqueKeys},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perquintill,
|
||||
ApplyExtrinsicResult, FixedPointNumber, Perquintill,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
#[cfg(feature = "std")]
|
||||
@@ -476,9 +466,6 @@ parameter_types! {
|
||||
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
|
||||
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
|
||||
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
|
||||
// `IdentityFee` is used by Millau => we may use weight directly
|
||||
pub const GetDeliveryConfirmationTransactionFee: Balance =
|
||||
bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() as _;
|
||||
pub const RootAccountForPayments: Option<AccountId> = None;
|
||||
pub const RialtoChainId: bp_runtime::ChainId = bp_runtime::RIALTO_CHAIN_ID;
|
||||
pub const RialtoParachainChainId: bp_runtime::ChainId = bp_runtime::RIALTO_PARACHAIN_CHAIN_ID;
|
||||
@@ -490,17 +477,14 @@ pub type WithRialtoMessagesInstance = ();
|
||||
impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
|
||||
type Parameter = rialto_messages::MillauToRialtoMessagesParameter;
|
||||
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
|
||||
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
|
||||
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
|
||||
|
||||
type MaximalOutboundPayloadSize = crate::rialto_messages::ToRialtoMaximalOutboundPayloadSize;
|
||||
type OutboundPayload = crate::rialto_messages::ToRialtoMessagePayload;
|
||||
type OutboundMessageFee = Balance;
|
||||
|
||||
type InboundPayload = crate::rialto_messages::FromRialtoMessagePayload;
|
||||
type InboundMessageFee = bp_rialto::Balance;
|
||||
type InboundRelayer = bp_rialto::AccountId;
|
||||
|
||||
type TargetHeaderChain = crate::rialto_messages::Rialto;
|
||||
@@ -509,7 +493,6 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
|
||||
pallet_bridge_relayers::MessageDeliveryAndDispatchPaymentAdapter<
|
||||
Runtime,
|
||||
WithRialtoMessagesInstance,
|
||||
GetDeliveryConfirmationTransactionFee,
|
||||
>;
|
||||
type OnMessageAccepted = ();
|
||||
type OnDeliveryConfirmed = ();
|
||||
@@ -525,7 +508,6 @@ pub type WithRialtoParachainMessagesInstance = pallet_bridge_messages::Instance1
|
||||
impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
|
||||
type Parameter = rialto_parachain_messages::MillauToRialtoParachainMessagesParameter;
|
||||
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
|
||||
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
|
||||
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
|
||||
@@ -533,10 +515,8 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
|
||||
type MaximalOutboundPayloadSize =
|
||||
crate::rialto_parachain_messages::ToRialtoParachainMaximalOutboundPayloadSize;
|
||||
type OutboundPayload = crate::rialto_parachain_messages::ToRialtoParachainMessagePayload;
|
||||
type OutboundMessageFee = Balance;
|
||||
|
||||
type InboundPayload = crate::rialto_parachain_messages::FromRialtoParachainMessagePayload;
|
||||
type InboundMessageFee = bp_rialto_parachain::Balance;
|
||||
type InboundRelayer = bp_rialto_parachain::AccountId;
|
||||
|
||||
type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachain;
|
||||
@@ -545,7 +525,6 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
|
||||
pallet_bridge_relayers::MessageDeliveryAndDispatchPaymentAdapter<
|
||||
Runtime,
|
||||
WithRialtoParachainMessagesInstance,
|
||||
GetDeliveryConfirmationTransactionFee,
|
||||
>;
|
||||
type OnMessageAccepted = ();
|
||||
type OnDeliveryConfirmed = ();
|
||||
@@ -941,24 +920,12 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl bp_rialto::ToRialtoOutboundLaneApi<Block, Balance, ToRialtoMessagePayload> for Runtime {
|
||||
fn estimate_message_delivery_and_dispatch_fee(
|
||||
_lane_id: bp_messages::LaneId,
|
||||
payload: ToRialtoMessagePayload,
|
||||
rialto_to_this_conversion_rate: Option<FixedU128>,
|
||||
) -> Option<Balance> {
|
||||
estimate_message_dispatch_and_delivery_fee::<WithRialtoMessageBridge>(
|
||||
&payload,
|
||||
WithRialtoMessageBridge::RELAYER_FEE_PERCENT,
|
||||
rialto_to_this_conversion_rate,
|
||||
).ok()
|
||||
}
|
||||
|
||||
impl bp_rialto::ToRialtoOutboundLaneApi<Block> for Runtime {
|
||||
fn message_details(
|
||||
lane: bp_messages::LaneId,
|
||||
begin: bp_messages::MessageNonce,
|
||||
end: bp_messages::MessageNonce,
|
||||
) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
|
||||
) -> Vec<bp_messages::OutboundMessageDetails> {
|
||||
bridge_runtime_common::messages_api::outbound_message_details::<
|
||||
Runtime,
|
||||
WithRialtoMessagesInstance,
|
||||
@@ -966,10 +933,10 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl bp_rialto::FromRialtoInboundLaneApi<Block, bp_rialto::Balance> for Runtime {
|
||||
impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime {
|
||||
fn message_details(
|
||||
lane: bp_messages::LaneId,
|
||||
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_rialto::Balance>)>,
|
||||
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
|
||||
) -> Vec<bp_messages::InboundMessageDetails> {
|
||||
bridge_runtime_common::messages_api::inbound_message_details::<
|
||||
Runtime,
|
||||
@@ -978,24 +945,12 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl bp_rialto_parachain::ToRialtoParachainOutboundLaneApi<Block, Balance, ToRialtoParachainMessagePayload> for Runtime {
|
||||
fn estimate_message_delivery_and_dispatch_fee(
|
||||
_lane_id: bp_messages::LaneId,
|
||||
payload: ToRialtoParachainMessagePayload,
|
||||
rialto_parachain_to_this_conversion_rate: Option<FixedU128>,
|
||||
) -> Option<Balance> {
|
||||
estimate_message_dispatch_and_delivery_fee::<WithRialtoParachainMessageBridge>(
|
||||
&payload,
|
||||
WithRialtoParachainMessageBridge::RELAYER_FEE_PERCENT,
|
||||
rialto_parachain_to_this_conversion_rate,
|
||||
).ok()
|
||||
}
|
||||
|
||||
impl bp_rialto_parachain::ToRialtoParachainOutboundLaneApi<Block> for Runtime {
|
||||
fn message_details(
|
||||
lane: bp_messages::LaneId,
|
||||
begin: bp_messages::MessageNonce,
|
||||
end: bp_messages::MessageNonce,
|
||||
) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
|
||||
) -> Vec<bp_messages::OutboundMessageDetails> {
|
||||
bridge_runtime_common::messages_api::outbound_message_details::<
|
||||
Runtime,
|
||||
WithRialtoParachainMessagesInstance,
|
||||
@@ -1003,10 +958,10 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl bp_rialto_parachain::FromRialtoParachainInboundLaneApi<Block, bp_rialto_parachain::Balance> for Runtime {
|
||||
impl bp_rialto_parachain::FromRialtoParachainInboundLaneApi<Block> for Runtime {
|
||||
fn message_details(
|
||||
lane: bp_messages::LaneId,
|
||||
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_rialto_parachain::Balance>)>,
|
||||
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
|
||||
) -> Vec<bp_messages::InboundMessageDetails> {
|
||||
bridge_runtime_common::messages_api::inbound_message_details::<
|
||||
Runtime,
|
||||
@@ -1060,13 +1015,11 @@ impl_runtime_apis! {
|
||||
let mut batches = Vec::<BenchmarkBatch>::new();
|
||||
let params = (&config, &whitelist);
|
||||
|
||||
use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof, prepare_message_proof, prepare_outbound_message};
|
||||
use bridge_runtime_common::messages;
|
||||
use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof, prepare_message_proof};
|
||||
use pallet_bridge_messages::benchmarking::{
|
||||
Pallet as MessagesBench,
|
||||
Config as MessagesConfig,
|
||||
MessageDeliveryProofParams,
|
||||
MessageParams,
|
||||
MessageProofParams,
|
||||
};
|
||||
use pallet_bridge_parachains::benchmarking::{
|
||||
@@ -1076,18 +1029,10 @@ impl_runtime_apis! {
|
||||
use rialto_messages::WithRialtoMessageBridge;
|
||||
|
||||
impl MessagesConfig<WithRialtoMessagesInstance> for Runtime {
|
||||
fn maximal_message_size() -> u32 {
|
||||
messages::source::maximal_message_size::<WithRialtoMessageBridge>()
|
||||
}
|
||||
|
||||
fn bridged_relayer_id() -> Self::InboundRelayer {
|
||||
[0u8; 32].into()
|
||||
}
|
||||
|
||||
fn account_balance(account: &Self::AccountId) -> Self::OutboundMessageFee {
|
||||
pallet_balances::Pallet::<Runtime>::free_balance(account)
|
||||
}
|
||||
|
||||
fn endow_account(account: &Self::AccountId) {
|
||||
pallet_balances::Pallet::<Runtime>::make_free_balance_be(
|
||||
account,
|
||||
@@ -1095,12 +1040,6 @@ impl_runtime_apis! {
|
||||
);
|
||||
}
|
||||
|
||||
fn prepare_outbound_message(
|
||||
params: MessageParams<Self::AccountId>,
|
||||
) -> (rialto_messages::ToRialtoMessagePayload, Balance) {
|
||||
(prepare_outbound_message::<WithRialtoMessageBridge>(params), Self::message_fee())
|
||||
}
|
||||
|
||||
fn prepare_message_proof(
|
||||
params: MessageProofParams,
|
||||
) -> (rialto_messages::FromRialtoMessagesProof, Weight) {
|
||||
|
||||
@@ -21,35 +21,20 @@ use crate::{OriginCaller, RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOr
|
||||
use bp_messages::{
|
||||
source_chain::TargetHeaderChain,
|
||||
target_chain::{ProvedMessages, SourceHeaderChain},
|
||||
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
|
||||
InboundLaneData, LaneId, Message, MessageNonce,
|
||||
};
|
||||
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
|
||||
use bridge_runtime_common::messages::{
|
||||
self, BasicConfirmationTransactionEstimation, MessageBridge, MessageTransaction,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{dispatch::DispatchClass, parameter_types, weights::Weight, RuntimeDebug};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
|
||||
use sp_std::convert::TryFrom;
|
||||
use bridge_runtime_common::messages::{self, MessageBridge};
|
||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||
|
||||
/// Default lane that is used to send messages to Rialto.
|
||||
pub const DEFAULT_XCM_LANE_TO_RIALTO: LaneId = [0, 0, 0, 0];
|
||||
/// Initial value of `RialtoToMillauConversionRate` parameter.
|
||||
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);
|
||||
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
|
||||
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
|
||||
/// tests, confirming that we don't break encoding somewhere between.
|
||||
pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT;
|
||||
|
||||
parameter_types! {
|
||||
/// Rialto to Millau conversion rate. Initially we treat both tokens as equal.
|
||||
pub storage RialtoToMillauConversionRate: FixedU128 = INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE;
|
||||
/// Fee multiplier value at Rialto chain.
|
||||
pub storage RialtoFeeMultiplier: FixedU128 = INITIAL_RIALTO_FEE_MULTIPLIER;
|
||||
/// Weight credit for our test messages.
|
||||
///
|
||||
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
|
||||
@@ -91,7 +76,6 @@ pub type ToRialtoMaximalOutboundPayloadSize =
|
||||
pub struct WithRialtoMessageBridge;
|
||||
|
||||
impl MessageBridge for WithRialtoMessageBridge {
|
||||
const RELAYER_FEE_PERCENT: u32 = 10;
|
||||
const THIS_CHAIN_ID: ChainId = MILLAU_CHAIN_ID;
|
||||
const BRIDGED_CHAIN_ID: ChainId = RIALTO_CHAIN_ID;
|
||||
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;
|
||||
@@ -100,16 +84,6 @@ impl MessageBridge for WithRialtoMessageBridge {
|
||||
type BridgedChain = Rialto;
|
||||
type BridgedHeaderChain =
|
||||
pallet_bridge_grandpa::GrandpaChainHeaders<Runtime, RialtoGrandpaInstance>;
|
||||
|
||||
fn bridged_balance_to_this_balance(
|
||||
bridged_balance: bp_rialto::Balance,
|
||||
bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||
) -> bp_millau::Balance {
|
||||
let conversion_rate = bridged_to_this_conversion_rate_override
|
||||
.unwrap_or_else(RialtoToMillauConversionRate::get);
|
||||
bp_millau::Balance::try_from(conversion_rate.saturating_mul_int(bridged_balance))
|
||||
.unwrap_or(bp_millau::Balance::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
/// Millau chain from message lane point of view.
|
||||
@@ -123,12 +97,6 @@ impl messages::UnderlyingChainProvider for Millau {
|
||||
impl messages::ThisChainWithMessages for Millau {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type ConfirmationTransactionEstimation = BasicConfirmationTransactionEstimation<
|
||||
bp_millau::AccountId,
|
||||
{ bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() },
|
||||
{ bp_rialto::EXTRA_STORAGE_PROOF_SIZE },
|
||||
{ bp_millau::TX_EXTRA_BYTES },
|
||||
>;
|
||||
|
||||
fn is_message_accepted(send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
|
||||
let here_location =
|
||||
@@ -153,21 +121,6 @@ impl messages::ThisChainWithMessages for Millau {
|
||||
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
||||
MessageNonce::MAX
|
||||
}
|
||||
|
||||
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
|
||||
messages::transaction_payment(
|
||||
bp_millau::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||
1,
|
||||
multiplier,
|
||||
|weight| weight.ref_time() as _,
|
||||
transaction,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Rialto chain from message lane point of view.
|
||||
@@ -182,45 +135,6 @@ impl messages::BridgedChainWithMessages for Rialto {
|
||||
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn estimate_delivery_transaction(
|
||||
message_payload: &[u8],
|
||||
include_pay_dispatch_fee_cost: bool,
|
||||
message_dispatch_weight: Weight,
|
||||
) -> MessageTransaction<Weight> {
|
||||
let message_payload_len = u32::try_from(message_payload.len()).unwrap_or(u32::MAX);
|
||||
let extra_bytes_in_payload = message_payload_len
|
||||
.saturating_sub(pallet_bridge_messages::EXPECTED_DEFAULT_MESSAGE_LENGTH);
|
||||
|
||||
MessageTransaction {
|
||||
dispatch_weight: bp_rialto::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT
|
||||
.saturating_mul(extra_bytes_in_payload as u64)
|
||||
.saturating_add(bp_rialto::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT)
|
||||
.saturating_sub(if include_pay_dispatch_fee_cost {
|
||||
Weight::from_ref_time(0)
|
||||
} else {
|
||||
bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT
|
||||
})
|
||||
.saturating_add(message_dispatch_weight),
|
||||
size: message_payload_len
|
||||
.saturating_add(bp_millau::EXTRA_STORAGE_PROOF_SIZE)
|
||||
.saturating_add(bp_rialto::TX_EXTRA_BYTES),
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
messages::transaction_payment(
|
||||
bp_rialto::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||
1,
|
||||
multiplier,
|
||||
|weight| weight.ref_time() as _,
|
||||
transaction,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetHeaderChain<ToRialtoMessagePayload, bp_millau::AccountId> for Rialto {
|
||||
@@ -242,7 +156,7 @@ impl TargetHeaderChain<ToRialtoMessagePayload, bp_millau::AccountId> for Rialto
|
||||
}
|
||||
}
|
||||
|
||||
impl SourceHeaderChain<bp_rialto::Balance> for Rialto {
|
||||
impl SourceHeaderChain for Rialto {
|
||||
type Error = &'static str;
|
||||
// The proof is:
|
||||
// - hash of the header this proof has been created with;
|
||||
@@ -254,28 +168,12 @@ impl SourceHeaderChain<bp_rialto::Balance> for Rialto {
|
||||
fn verify_messages_proof(
|
||||
proof: Self::MessagesProof,
|
||||
messages_count: u32,
|
||||
) -> Result<ProvedMessages<Message<bp_rialto::Balance>>, Self::Error> {
|
||||
) -> Result<ProvedMessages<Message>, Self::Error> {
|
||||
messages::target::verify_messages_proof::<WithRialtoMessageBridge>(proof, messages_count)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
/// Millau -> Rialto message lane pallet parameters.
|
||||
#[derive(RuntimeDebug, Clone, Encode, Decode, PartialEq, Eq, TypeInfo)]
|
||||
pub enum MillauToRialtoMessagesParameter {
|
||||
/// The conversion formula we use is: `MillauTokens = RialtoTokens * conversion_rate`.
|
||||
RialtoToMillauConversionRate(FixedU128),
|
||||
}
|
||||
|
||||
impl MessagesParameter for MillauToRialtoMessagesParameter {
|
||||
fn save(&self) {
|
||||
match *self {
|
||||
MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(ref conversion_rate) =>
|
||||
RialtoToMillauConversionRate::set(conversion_rate),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -295,13 +193,7 @@ mod tests {
|
||||
fn ensure_millau_message_lane_weights_are_correct() {
|
||||
type Weights = pallet_bridge_messages::weights::BridgeWeight<Runtime>;
|
||||
|
||||
pallet_bridge_messages::ensure_weights_are_correct::<Weights>(
|
||||
bp_millau::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT,
|
||||
bp_millau::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT,
|
||||
bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT,
|
||||
bp_millau::PAY_INBOUND_DISPATCH_FEE_WEIGHT,
|
||||
DbWeight::get(),
|
||||
);
|
||||
pallet_bridge_messages::ensure_weights_are_correct::<Weights>();
|
||||
|
||||
let max_incoming_message_proof_size = bp_rialto::EXTRA_STORAGE_PROOF_SIZE.saturating_add(
|
||||
messages::target::maximal_incoming_message_size(bp_millau::Millau::max_extrinsic_size()),
|
||||
@@ -366,13 +258,5 @@ mod tests {
|
||||
bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME,
|
||||
},
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
RialtoToMillauConversionRate::key().to_vec(),
|
||||
bp_runtime::storage_parameter_key(
|
||||
bp_millau::RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME
|
||||
)
|
||||
.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,11 @@ use crate::{Runtime, RuntimeCall, RuntimeOrigin, WithRialtoParachainsInstance};
|
||||
use bp_messages::{
|
||||
source_chain::TargetHeaderChain,
|
||||
target_chain::{ProvedMessages, SourceHeaderChain},
|
||||
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
|
||||
InboundLaneData, LaneId, Message, MessageNonce,
|
||||
};
|
||||
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
|
||||
use bridge_runtime_common::messages::{
|
||||
self, BasicConfirmationTransactionEstimation, MessageBridge, MessageTransaction,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{dispatch::DispatchClass, parameter_types, weights::Weight, RuntimeDebug};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
|
||||
use sp_std::convert::TryFrom;
|
||||
use bridge_runtime_common::messages::{self, MessageBridge};
|
||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||
|
||||
/// Default lane that is used to send messages to Rialto parachain.
|
||||
pub const DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN: LaneId = [0, 0, 0, 0];
|
||||
@@ -40,18 +34,7 @@ pub const DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN: LaneId = [0, 0, 0, 0];
|
||||
/// tests, confirming that we don't break encoding somewhere between.
|
||||
pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT;
|
||||
|
||||
/// Initial value of `RialtoParachainToMillauConversionRate` parameter.
|
||||
pub const INITIAL_RIALTO_PARACHAIN_TO_MILLAU_CONVERSION_RATE: FixedU128 =
|
||||
FixedU128::from_inner(FixedU128::DIV);
|
||||
/// Initial value of `RialtoParachainFeeMultiplier` parameter.
|
||||
pub const INITIAL_RIALTO_PARACHAIN_FEE_MULTIPLIER: FixedU128 =
|
||||
FixedU128::from_inner(FixedU128::DIV);
|
||||
|
||||
parameter_types! {
|
||||
/// RialtoParachain to Millau conversion rate. Initially we treat both tokens as equal.
|
||||
pub storage RialtoParachainToMillauConversionRate: FixedU128 = INITIAL_RIALTO_PARACHAIN_TO_MILLAU_CONVERSION_RATE;
|
||||
/// Fee multiplier value at RialtoParachain chain.
|
||||
pub storage RialtoParachainFeeMultiplier: FixedU128 = INITIAL_RIALTO_PARACHAIN_FEE_MULTIPLIER;
|
||||
/// Weight credit for our test messages.
|
||||
///
|
||||
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
|
||||
@@ -95,7 +78,6 @@ pub type ToRialtoParachainMaximalOutboundPayloadSize =
|
||||
pub struct WithRialtoParachainMessageBridge;
|
||||
|
||||
impl MessageBridge for WithRialtoParachainMessageBridge {
|
||||
const RELAYER_FEE_PERCENT: u32 = 10;
|
||||
const THIS_CHAIN_ID: ChainId = MILLAU_CHAIN_ID;
|
||||
const BRIDGED_CHAIN_ID: ChainId = RIALTO_PARACHAIN_CHAIN_ID;
|
||||
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;
|
||||
@@ -107,16 +89,6 @@ impl MessageBridge for WithRialtoParachainMessageBridge {
|
||||
WithRialtoParachainsInstance,
|
||||
bp_rialto_parachain::RialtoParachain,
|
||||
>;
|
||||
|
||||
fn bridged_balance_to_this_balance(
|
||||
bridged_balance: bp_rialto_parachain::Balance,
|
||||
bridged_to_this_conversion_rate_override: Option<FixedU128>,
|
||||
) -> bp_millau::Balance {
|
||||
let conversion_rate = bridged_to_this_conversion_rate_override
|
||||
.unwrap_or_else(RialtoParachainToMillauConversionRate::get);
|
||||
bp_millau::Balance::try_from(conversion_rate.saturating_mul_int(bridged_balance))
|
||||
.unwrap_or(bp_millau::Balance::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
/// Millau chain from message lane point of view.
|
||||
@@ -130,12 +102,6 @@ impl messages::UnderlyingChainProvider for Millau {
|
||||
impl messages::ThisChainWithMessages for Millau {
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type ConfirmationTransactionEstimation = BasicConfirmationTransactionEstimation<
|
||||
bp_rialto_parachain::AccountId,
|
||||
{ bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() },
|
||||
{ bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE },
|
||||
{ bp_millau::TX_EXTRA_BYTES },
|
||||
>;
|
||||
|
||||
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
|
||||
*lane == DEFAULT_XCM_LANE_TO_RIALTO_PARACHAIN || *lane == [0, 0, 0, 1]
|
||||
@@ -144,21 +110,6 @@ impl messages::ThisChainWithMessages for Millau {
|
||||
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
||||
MessageNonce::MAX
|
||||
}
|
||||
|
||||
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
|
||||
messages::transaction_payment(
|
||||
bp_millau::BlockWeights::get().get(DispatchClass::Normal).base_extrinsic,
|
||||
1,
|
||||
multiplier,
|
||||
|weight| weight.ref_time() as _,
|
||||
transaction,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// RialtoParachain chain from message lane point of view.
|
||||
@@ -173,49 +124,6 @@ impl messages::BridgedChainWithMessages for RialtoParachain {
|
||||
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn estimate_delivery_transaction(
|
||||
message_payload: &[u8],
|
||||
include_pay_dispatch_fee_cost: bool,
|
||||
message_dispatch_weight: Weight,
|
||||
) -> MessageTransaction<Weight> {
|
||||
let message_payload_len = u32::try_from(message_payload.len()).unwrap_or(u32::MAX);
|
||||
let extra_bytes_in_payload = message_payload_len
|
||||
.saturating_sub(pallet_bridge_messages::EXPECTED_DEFAULT_MESSAGE_LENGTH);
|
||||
|
||||
MessageTransaction {
|
||||
dispatch_weight: bp_rialto_parachain::ADDITIONAL_MESSAGE_BYTE_DELIVERY_WEIGHT
|
||||
.saturating_mul(extra_bytes_in_payload as _)
|
||||
.saturating_add(bp_rialto_parachain::DEFAULT_MESSAGE_DELIVERY_TX_WEIGHT)
|
||||
.saturating_sub(if include_pay_dispatch_fee_cost {
|
||||
Weight::from_ref_time(0)
|
||||
} else {
|
||||
bp_rialto_parachain::PAY_INBOUND_DISPATCH_FEE_WEIGHT
|
||||
})
|
||||
.saturating_add(message_dispatch_weight),
|
||||
size: message_payload_len
|
||||
.saturating_add(bp_millau::EXTRA_STORAGE_PROOF_SIZE)
|
||||
.saturating_add(bp_rialto_parachain::TX_EXTRA_BYTES),
|
||||
}
|
||||
}
|
||||
|
||||
fn transaction_payment(
|
||||
transaction: MessageTransaction<Weight>,
|
||||
) -> bp_rialto_parachain::Balance {
|
||||
// we don't have a direct access to the value of multiplier at RialtoParachain chain
|
||||
// => it is a messages module parameter
|
||||
let multiplier = RialtoParachainFeeMultiplier::get();
|
||||
// in our testnets, both per-byte fee and weight-to-fee are 1:1
|
||||
messages::transaction_payment(
|
||||
bp_rialto_parachain::BlockWeights::get()
|
||||
.get(DispatchClass::Normal)
|
||||
.base_extrinsic,
|
||||
1,
|
||||
multiplier,
|
||||
|weight| weight.ref_time() as _,
|
||||
transaction,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetHeaderChain<ToRialtoParachainMessagePayload, bp_millau::AccountId> for RialtoParachain {
|
||||
@@ -237,7 +145,7 @@ impl TargetHeaderChain<ToRialtoParachainMessagePayload, bp_millau::AccountId> fo
|
||||
}
|
||||
}
|
||||
|
||||
impl SourceHeaderChain<bp_rialto_parachain::Balance> for RialtoParachain {
|
||||
impl SourceHeaderChain for RialtoParachain {
|
||||
type Error = &'static str;
|
||||
// The proof is:
|
||||
// - hash of the header this proof has been created with;
|
||||
@@ -249,7 +157,7 @@ impl SourceHeaderChain<bp_rialto_parachain::Balance> for RialtoParachain {
|
||||
fn verify_messages_proof(
|
||||
proof: Self::MessagesProof,
|
||||
messages_count: u32,
|
||||
) -> Result<ProvedMessages<Message<bp_rialto_parachain::Balance>>, Self::Error> {
|
||||
) -> Result<ProvedMessages<Message>, Self::Error> {
|
||||
messages::target::verify_messages_proof::<WithRialtoParachainMessageBridge>(
|
||||
proof,
|
||||
messages_count,
|
||||
@@ -257,20 +165,3 @@ impl SourceHeaderChain<bp_rialto_parachain::Balance> for RialtoParachain {
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
/// Millau -> RialtoParachain message lane pallet parameters.
|
||||
#[derive(RuntimeDebug, Clone, Encode, Decode, PartialEq, Eq, TypeInfo)]
|
||||
pub enum MillauToRialtoParachainMessagesParameter {
|
||||
/// The conversion formula we use is: `MillauTokens = RialtoParachainTokens * conversion_rate`.
|
||||
RialtoParachainToMillauConversionRate(FixedU128),
|
||||
}
|
||||
|
||||
impl MessagesParameter for MillauToRialtoParachainMessagesParameter {
|
||||
fn save(&self) {
|
||||
match *self {
|
||||
MillauToRialtoParachainMessagesParameter::RialtoParachainToMillauConversionRate(
|
||||
ref conversion_rate,
|
||||
) => RialtoParachainToMillauConversionRate::set(conversion_rate),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ mod tests {
|
||||
fn xcm_messages_are_sent_using_bridge_router() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let xcm: Xcm<()> = vec![Instruction::Trap(42)].into();
|
||||
let expected_fee = MultiAssets::from((Here, 4_259_858_152_u64));
|
||||
let expected_fee = MultiAssets::from((Here, 1_000_000_u128));
|
||||
let expected_hash =
|
||||
([0u8, 0u8, 0u8, 0u8], 1u64).using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
@@ -305,7 +305,7 @@ mod tests {
|
||||
|
||||
let mut incoming_message = DispatchMessage {
|
||||
key: MessageKey { lane_id: [0, 0, 0, 0], nonce: 1 },
|
||||
data: DispatchMessageData { payload: Ok((location, xcm).into()), fee: 0 },
|
||||
data: DispatchMessageData { payload: Ok((location, xcm).into()) },
|
||||
};
|
||||
|
||||
let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message);
|
||||
|
||||
Reference in New Issue
Block a user