Get dispatch weight from the target chain (when DispatchFeePayment::AtTargetChain is used) (#1430)

* reintroduce From<SourceChain>InboundLaneApi

* impl From<Chain>InboundLaneApi for testnet runtimes

* use inboundlaneapi in relay

* remove unused OutboundXcmWeigher

* spelling

* added the only test to messages pallet

* fmt
This commit is contained in:
Svyatoslav Nikolsky
2022-06-01 13:00:59 +03:00
committed by Bastian Köcher
parent 78a43c561a
commit f0d05de080
25 changed files with 411 additions and 89 deletions
+26 -6
View File
@@ -833,16 +833,26 @@ impl_runtime_apis! {
lane: bp_messages::LaneId, lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce, begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce, end: bp_messages::MessageNonce,
) -> Vec<bp_messages::MessageDetails<Balance>> { ) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
bridge_runtime_common::messages_api::outbound_message_details::< bridge_runtime_common::messages_api::outbound_message_details::<
Runtime, Runtime,
WithRialtoMessagesInstance, WithRialtoMessagesInstance,
WithRialtoMessageBridge,
xcm_config::OutboundXcmWeigher,
>(lane, begin, end) >(lane, begin, end)
} }
} }
impl bp_rialto::FromRialtoInboundLaneApi<Block, bp_rialto::Balance> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_rialto::Balance>)>,
) -> Vec<bp_messages::InboundMessageDetails> {
bridge_runtime_common::messages_api::inbound_message_details::<
Runtime,
WithRialtoMessagesInstance,
>(lane, messages)
}
}
impl bp_rialto_parachain::ToRialtoParachainOutboundLaneApi<Block, Balance, ToRialtoParachainMessagePayload> for Runtime { impl bp_rialto_parachain::ToRialtoParachainOutboundLaneApi<Block, Balance, ToRialtoParachainMessagePayload> for Runtime {
fn estimate_message_delivery_and_dispatch_fee( fn estimate_message_delivery_and_dispatch_fee(
_lane_id: bp_messages::LaneId, _lane_id: bp_messages::LaneId,
@@ -860,16 +870,26 @@ impl_runtime_apis! {
lane: bp_messages::LaneId, lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce, begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce, end: bp_messages::MessageNonce,
) -> Vec<bp_messages::MessageDetails<Balance>> { ) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
bridge_runtime_common::messages_api::outbound_message_details::< bridge_runtime_common::messages_api::outbound_message_details::<
Runtime, Runtime,
WithRialtoParachainMessagesInstance, WithRialtoParachainMessagesInstance,
WithRialtoParachainMessageBridge,
xcm_config::OutboundXcmWeigher,
>(lane, begin, end) >(lane, begin, end)
} }
} }
impl bp_rialto_parachain::FromRialtoParachainInboundLaneApi<Block, bp_rialto_parachain::Balance> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_rialto_parachain::Balance>)>,
) -> Vec<bp_messages::InboundMessageDetails> {
bridge_runtime_common::messages_api::inbound_message_details::<
Runtime,
WithRialtoParachainMessagesInstance,
>(lane, messages)
}
}
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime { impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> ( fn benchmark_metadata(extra: bool) -> (
@@ -122,8 +122,6 @@ pub type Barrier = (
AllowKnownQueryResponses<XcmPallet>, AllowKnownQueryResponses<XcmPallet>,
); );
/// Outbound XCM weigher type.
pub type OutboundXcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, (), MaxInstructions>;
/// XCM weigher type. /// XCM weigher type.
pub type XcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>; pub type XcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
@@ -383,8 +383,6 @@ pub type Barrier = (
// ^^^ Parent & its unit plurality gets free execution // ^^^ Parent & its unit plurality gets free execution
); );
/// Outbound XCM weigher type.
pub type OutboundXcmWeigher = FixedWeightBounds<UnitWeightCost, (), MaxInstructions>;
/// XCM weigher type. /// XCM weigher type.
pub type XcmWeigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>; pub type XcmWeigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
@@ -708,16 +706,26 @@ impl_runtime_apis! {
lane: bp_messages::LaneId, lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce, begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce, end: bp_messages::MessageNonce,
) -> Vec<bp_messages::MessageDetails<Balance>> { ) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
bridge_runtime_common::messages_api::outbound_message_details::< bridge_runtime_common::messages_api::outbound_message_details::<
Runtime, Runtime,
WithMillauMessagesInstance, WithMillauMessagesInstance,
WithMillauMessageBridge,
OutboundXcmWeigher,
>(lane, begin, end) >(lane, begin, end)
} }
} }
impl bp_millau::FromMillauInboundLaneApi<Block, bp_millau::Balance> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_millau::Balance>)>,
) -> Vec<bp_messages::InboundMessageDetails> {
bridge_runtime_common::messages_api::inbound_message_details::<
Runtime,
WithMillauMessagesInstance,
>(lane, messages)
}
}
#[cfg(feature = "runtime-benchmarks")] #[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime { impl frame_benchmarking::Benchmark<Block> for Runtime {
fn dispatch_benchmark( fn dispatch_benchmark(
+13 -3
View File
@@ -893,15 +893,25 @@ impl_runtime_apis! {
lane: bp_messages::LaneId, lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce, begin: bp_messages::MessageNonce,
end: bp_messages::MessageNonce, end: bp_messages::MessageNonce,
) -> Vec<bp_messages::MessageDetails<Balance>> { ) -> Vec<bp_messages::OutboundMessageDetails<Balance>> {
bridge_runtime_common::messages_api::outbound_message_details::< bridge_runtime_common::messages_api::outbound_message_details::<
Runtime, Runtime,
WithMillauMessagesInstance, WithMillauMessagesInstance,
WithMillauMessageBridge,
xcm_config::OutboundXcmWeigher,
>(lane, begin, end) >(lane, begin, end)
} }
} }
impl bp_millau::FromMillauInboundLaneApi<Block, bp_millau::Balance> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails<bp_millau::Balance>)>,
) -> Vec<bp_messages::InboundMessageDetails> {
bridge_runtime_common::messages_api::inbound_message_details::<
Runtime,
WithMillauMessagesInstance,
>(lane, messages)
}
}
} }
#[cfg(test)] #[cfg(test)]
@@ -122,8 +122,6 @@ pub type Barrier = (
AllowKnownQueryResponses<XcmPallet>, AllowKnownQueryResponses<XcmPallet>,
); );
/// Outbound XCM weigher type.
pub type OutboundXcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, (), MaxInstructions>;
/// Incoming XCM weigher type. /// Incoming XCM weigher type.
pub type XcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>; pub type XcmWeigher = xcm_builder::FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
+27 -41
View File
@@ -16,68 +16,54 @@
//! Helpers for implementing various message-related runtime API mthods. //! Helpers for implementing various message-related runtime API mthods.
use crate::messages::{target::FromBridgedChainMessagePayload, MessageBridge}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
use bp_messages::{LaneId, MessageDetails, MessageKey, MessageNonce}; };
use codec::Decode;
use frame_support::weights::Weight;
use sp_std::vec::Vec; use sp_std::vec::Vec;
/// Implementation of the `To*OutboundLaneApi::message_details`. /// Implementation of the `To*OutboundLaneApi::message_details`.
pub fn outbound_message_details<Runtime, MessagesPalletInstance, BridgeConfig, XcmWeigher>( pub fn outbound_message_details<Runtime, MessagesPalletInstance>(
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<Runtime::OutboundMessageFee>> ) -> Vec<OutboundMessageDetails<Runtime::OutboundMessageFee>>
where where
Runtime: pallet_bridge_messages::Config<MessagesPalletInstance>, Runtime: pallet_bridge_messages::Config<MessagesPalletInstance>,
MessagesPalletInstance: 'static, MessagesPalletInstance: 'static,
BridgeConfig: MessageBridge,
XcmWeigher: xcm_executor::traits::WeightBounds<()>,
{ {
(begin..=end) (begin..=end)
.filter_map(|nonce| { .filter_map(|nonce| {
let message_data = let message_data =
pallet_bridge_messages::Pallet::<Runtime, MessagesPalletInstance>::outbound_message_data(lane, nonce)?; pallet_bridge_messages::Pallet::<Runtime, MessagesPalletInstance>::outbound_message_data(lane, nonce)?;
Some(MessageDetails { Some(OutboundMessageDetails {
nonce, nonce,
// this shall match the similar code in the `FromBridgedChainMessageDispatch` - if we have failed // dispatch message weight is always zero at the source chain, since we're paying for
// to decode or estimate dispatch weight, we'll just return 0 to disable actual execution // dispatch at the target chain
dispatch_weight: compute_message_weight::<XcmWeigher>( dispatch_weight: 0,
MessageKey { lane_id: lane, nonce },
&message_data.payload,
).unwrap_or(0),
size: message_data.payload.len() as _, size: message_data.payload.len() as _,
delivery_and_dispatch_fee: message_data.fee, delivery_and_dispatch_fee: message_data.fee,
// we're delivering XCM messages here, so fee is always paid at the target chain
dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtTargetChain, dispatch_fee_payment: bp_runtime::messages::DispatchFeePayment::AtTargetChain,
}) })
}) })
.collect() .collect()
} }
// at the source chain we don't know the type of target chain `Call` => `()` is used (it is /// Implementation of the `To*InboundLaneApi::message_details`.
// similarly currently used in Polkadot codebase) pub fn inbound_message_details<Runtime, MessagesPalletInstance>(
fn compute_message_weight<XcmWeigher: xcm_executor::traits::WeightBounds<()>>( lane: LaneId,
message_key: MessageKey, messages: Vec<(MessagePayload, OutboundMessageDetails<Runtime::InboundMessageFee>)>,
encoded_payload: &[u8], ) -> Vec<InboundMessageDetails>
) -> Result<Weight, ()> { where
let mut payload = FromBridgedChainMessagePayload::<()>::decode(&mut &encoded_payload[..]) Runtime: pallet_bridge_messages::Config<MessagesPalletInstance>,
.map_err(|e| { MessagesPalletInstance: 'static,
log::debug!( {
target: "runtime::bridge-dispatch", messages
"Failed to decode outbound XCM message {:?}: {:?}", .into_iter()
message_key, .map(|(payload, details)| {
e, pallet_bridge_messages::Pallet::<Runtime, MessagesPalletInstance>::inbound_message_data(
); lane, payload, details,
})?; )
let weight = XcmWeigher::weight(&mut payload.xcm.1); })
let weight = weight.map_err(|e| { .collect()
log::debug!(
target: "runtime::bridge-dispatch",
"Failed to compute dispatch weight of outbound XCM message {:?}: {:?}",
message_key,
e,
);
})?;
Ok(weight)
} }
+42 -4
View File
@@ -56,9 +56,10 @@ use bp_messages::{
target_chain::{ target_chain::{
DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
}, },
total_unrewarded_messages, DeliveredMessages, InboundLaneData, LaneId, MessageData, MessageKey, total_unrewarded_messages, DeliveredMessages, InboundLaneData, InboundMessageDetails, LaneId,
MessageNonce, OperatingMode, OutboundLaneData, Parameter as MessagesParameter, MessageData, MessageKey, MessageNonce, MessagePayload, OperatingMode, OutboundLaneData,
UnrewardedRelayer, UnrewardedRelayersState, OutboundMessageDetails, Parameter as MessagesParameter, UnrewardedRelayer,
UnrewardedRelayersState,
}; };
use bp_runtime::{ChainId, Size}; use bp_runtime::{ChainId, Size};
use codec::{Decode, Encode}; use codec::{Decode, Encode};
@@ -156,7 +157,7 @@ pub mod pallet {
/// Payload type of inbound messages. This payload is dispatched on this chain. /// Payload type of inbound messages. This payload is dispatched on this chain.
type InboundPayload: Decode; type InboundPayload: Decode;
/// Message fee type of inbound messages. This fee is paid on the bridged chain. /// Message fee type of inbound messages. This fee is paid on the bridged chain.
type InboundMessageFee: Decode; type InboundMessageFee: Decode + Zero;
/// Identifier of relayer that deliver messages to this chain. Relayer reward is paid on the /// Identifier of relayer that deliver messages to this chain. Relayer reward is paid on the
/// bridged chain. /// bridged chain.
type InboundRelayer: Parameter; type InboundRelayer: Parameter;
@@ -762,6 +763,22 @@ pub mod pallet {
) -> Option<MessageData<T::OutboundMessageFee>> { ) -> Option<MessageData<T::OutboundMessageFee>> {
OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce }) OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce })
} }
/// Prepare data, related to given inbound message.
pub fn inbound_message_data(
lane: LaneId,
payload: MessagePayload,
outbound_details: OutboundMessageDetails<T::InboundMessageFee>,
) -> InboundMessageDetails {
let mut dispatch_message = DispatchMessage {
key: MessageKey { lane_id: lane, nonce: outbound_details.nonce },
data: MessageData { payload, fee: outbound_details.delivery_and_dispatch_fee }
.into(),
};
InboundMessageDetails {
dispatch_weight: T::MessageDispatch::dispatch_weight(&mut dispatch_message),
}
}
} }
} }
@@ -2332,4 +2349,25 @@ mod tests {
bp_messages::storage_keys::inbound_lane_data_key("Messages", &TEST_LANE_ID).0, bp_messages::storage_keys::inbound_lane_data_key("Messages", &TEST_LANE_ID).0,
); );
} }
#[test]
fn inbound_message_details_works() {
run_test(|| {
assert_eq!(
Pallet::<TestRuntime>::inbound_message_data(
TEST_LANE_ID,
REGULAR_PAYLOAD.encode(),
OutboundMessageDetails {
nonce: 0,
dispatch_weight: 0,
size: 0,
delivery_and_dispatch_fee: 0,
dispatch_fee_payment:
bp_runtime::messages::DispatchFeePayment::AtTargetChain,
},
),
InboundMessageDetails { dispatch_weight: REGULAR_PAYLOAD.declared_weight },
);
});
}
} }
+22 -2
View File
@@ -18,7 +18,9 @@
// RuntimeApi generated functions // RuntimeApi generated functions
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use frame_support::weights::{ use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
}; };
@@ -105,6 +107,9 @@ pub const TO_KUSAMA_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToKusamaOutboundLaneApi::message_details` runtime method. /// Name of the `ToKusamaOutboundLaneApi::message_details` runtime method.
pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details"; pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details";
/// Name of the `FromKusamaInboundLaneApi::message_details` runtime method.
pub const FROM_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "FromKusamaInboundLaneApi_message_details";
sp_api::decl_runtime_apis! { sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Kusama headers. /// API for querying information about the finalized Kusama headers.
/// ///
@@ -143,6 +148,21 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by Kusama chain.
///
/// This API is implemented by runtimes that are receiving messages from Kusama chain, not the
/// Kusama runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromKusamaInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
+22 -2
View File
@@ -20,7 +20,9 @@
mod millau_hash; mod millau_hash;
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use bp_runtime::Chain; use bp_runtime::Chain;
use frame_support::{ use frame_support::{
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight}, weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight},
@@ -294,6 +296,9 @@ pub const TO_MILLAU_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToMillauOutboundLaneApi::message_details` runtime method. /// Name of the `ToMillauOutboundLaneApi::message_details` runtime method.
pub const TO_MILLAU_MESSAGE_DETAILS_METHOD: &str = "ToMillauOutboundLaneApi_message_details"; pub const TO_MILLAU_MESSAGE_DETAILS_METHOD: &str = "ToMillauOutboundLaneApi_message_details";
/// Name of the `FromMillauInboundLaneApi::message_details` runtime method.
pub const FROM_MILLAU_MESSAGE_DETAILS_METHOD: &str = "FromMillauInboundLaneApi_message_details";
sp_api::decl_runtime_apis! { sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Millau headers. /// API for querying information about the finalized Millau headers.
/// ///
@@ -332,7 +337,22 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by Millau chain.
///
/// This API is implemented by runtimes that are receiving messages from Millau chain, not the
/// Millau runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromMillauInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
+23 -2
View File
@@ -18,7 +18,9 @@
// RuntimeApi generated functions // RuntimeApi generated functions
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use frame_support::weights::{ use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
}; };
@@ -105,6 +107,10 @@ pub const TO_POLKADOT_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToPolkadotOutboundLaneApi::message_details` runtime method. /// Name of the `ToPolkadotOutboundLaneApi::message_details` runtime method.
pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details"; pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details";
/// Name of the `FromPolkadotInboundLaneApi::message_details` runtime method.
pub const FROM_POLKADOT_MESSAGE_DETAILS_METHOD: &str =
"FromPolkadotOutboundLaneApi_message_details";
sp_api::decl_runtime_apis! { sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Polkadot headers. /// API for querying information about the finalized Polkadot headers.
/// ///
@@ -143,6 +149,21 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by Polkadot chain.
///
/// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the
/// Polkadot runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromPolkadotInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
@@ -18,7 +18,9 @@
// RuntimeApi generated functions // RuntimeApi generated functions
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use bp_runtime::Chain; use bp_runtime::Chain;
use frame_support::{ use frame_support::{
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight}, weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight},
@@ -210,6 +212,10 @@ pub const TO_RIALTO_PARACHAIN_ESTIMATE_MESSAGE_FEE_METHOD: &str =
pub const TO_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD: &str = pub const TO_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD: &str =
"ToRialtoParachainOutboundLaneApi_message_details"; "ToRialtoParachainOutboundLaneApi_message_details";
/// Name of the `FromRialtoParachainInboundLaneApi::message_details` runtime method.
pub const FROM_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD: &str =
"FromRialtoParachainInboundLaneApi_message_details";
// We use this to get the account on RialtoParachain (target) which is derived from Millau's // We use this to get the account on RialtoParachain (target) which is derived from Millau's
// (source) account. We do this so we can fund the derived account on RialtoParachain at Genesis to // (source) account. We do this so we can fund the derived account on RialtoParachain at Genesis to
// it can pay transaction fees. // it can pay transaction fees.
@@ -261,7 +267,22 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by RialtoParachain chain.
///
/// This API is implemented by runtimes that are receiving messages from RialtoParachain chain, not the
/// RialtoParachain runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromRialtoParachainInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
+22 -2
View File
@@ -18,7 +18,9 @@
// RuntimeApi generated functions // RuntimeApi generated functions
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use bp_runtime::Chain; use bp_runtime::Chain;
use frame_support::{ use frame_support::{
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight}, weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight},
@@ -250,6 +252,9 @@ pub const TO_RIALTO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToRialtoOutboundLaneApi::message_details` runtime method. /// Name of the `ToRialtoOutboundLaneApi::message_details` runtime method.
pub const TO_RIALTO_MESSAGE_DETAILS_METHOD: &str = "ToRialtoOutboundLaneApi_message_details"; pub const TO_RIALTO_MESSAGE_DETAILS_METHOD: &str = "ToRialtoOutboundLaneApi_message_details";
/// Name of the `FromRialtoInboundLaneApi::message_details` runtime method.
pub const FROM_RIALTO_MESSAGE_DETAILS_METHOD: &str = "FromRialtoInboundLaneApi_message_details";
sp_api::decl_runtime_apis! { sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Rialto headers. /// API for querying information about the finalized Rialto headers.
/// ///
@@ -288,7 +293,22 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by Rialto chain.
///
/// This API is implemented by runtimes that are receiving messages from Rialto chain, not the
/// Rialto runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromRialtoInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
+22 -2
View File
@@ -18,7 +18,9 @@
// RuntimeApi generated functions // RuntimeApi generated functions
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use frame_support::weights::{ use frame_support::weights::{
Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
}; };
@@ -89,6 +91,9 @@ pub const TO_ROCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToRococoOutboundLaneApi::message_details` runtime method. /// Name of the `ToRococoOutboundLaneApi::message_details` runtime method.
pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details"; pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details";
/// Name of the `FromRococoInboundLaneApi::message_details` runtime method.
pub const FROM_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "FromRococoInboundLaneApi_message_details";
/// Existential deposit on Rococo. /// Existential deposit on Rococo.
pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100; pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100;
@@ -139,6 +144,21 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by Rococo chain.
///
/// This API is implemented by runtimes that are receiving messages from Rococo chain, not the
/// Rococo runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromRococoInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
+22 -2
View File
@@ -18,7 +18,9 @@
// RuntimeApi generated functions // RuntimeApi generated functions
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
use bp_messages::{LaneId, MessageDetails, MessageNonce}; use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use sp_runtime::FixedU128; use sp_runtime::FixedU128;
use sp_std::prelude::*; use sp_std::prelude::*;
@@ -58,6 +60,9 @@ pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToWococoOutboundLaneApi::message_details` runtime method. /// Name of the `ToWococoOutboundLaneApi::message_details` runtime method.
pub const TO_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "ToWococoOutboundLaneApi_message_details"; pub const TO_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "ToWococoOutboundLaneApi_message_details";
/// Name of the `FromWococoInboundLaneApi::message_details` runtime method.
pub const FROM_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "FromWococoInboundLaneApi_message_details";
sp_api::decl_runtime_apis! { sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Wococo headers. /// API for querying information about the finalized Wococo headers.
/// ///
@@ -96,6 +101,21 @@ sp_api::decl_runtime_apis! {
lane: LaneId, lane: LaneId,
begin: MessageNonce, begin: MessageNonce,
end: MessageNonce, end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>; ) -> Vec<OutboundMessageDetails<OutboundMessageFee>>;
}
/// Inbound message lane API for messages sent by Wococo chain.
///
/// This API is implemented by runtimes that are receiving messages from Wococo chain, not the
/// Wococo runtime itself.
///
/// Entries of the resulting vector are matching entries of the `messages` vector. Entries of the
/// `messages` vector may (and need to) be read using `To<ThisChain>OutboundLaneApi::message_details`.
pub trait FromWococoInboundLaneApi<InboundMessageFee: Parameter> {
/// Return details of given inbound messages.
fn message_details(
lane: LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails<InboundMessageFee>)>,
) -> Vec<InboundMessageDetails>;
} }
} }
+18 -3
View File
@@ -176,12 +176,15 @@ impl<RelayerId> InboundLaneData<RelayerId> {
} }
} }
/// Message details, returned by runtime APIs. /// Outbound message details, returned by runtime APIs.
#[derive(Clone, Encode, Decode, RuntimeDebug, PartialEq, Eq)] #[derive(Clone, Encode, Decode, RuntimeDebug, PartialEq, Eq)]
pub struct MessageDetails<OutboundMessageFee> { pub struct OutboundMessageDetails<OutboundMessageFee> {
/// Nonce assigned to the message. /// Nonce assigned to the message.
pub nonce: MessageNonce, pub nonce: MessageNonce,
/// Message dispatch weight, declared by the submitter. /// Message dispatch weight.
///
/// Depending on messages pallet configuration, it may be declared by the message submitter,
/// computed automatically or just be zero if dispatch fee is paid at the target chain.
pub dispatch_weight: Weight, pub dispatch_weight: Weight,
/// Size of the encoded message. /// Size of the encoded message.
pub size: u32, pub size: u32,
@@ -191,6 +194,18 @@ pub struct MessageDetails<OutboundMessageFee> {
pub dispatch_fee_payment: DispatchFeePayment, pub dispatch_fee_payment: DispatchFeePayment,
} }
/// Inbound message details, returned by runtime APIs.
#[derive(Clone, Encode, Decode, RuntimeDebug, PartialEq, Eq)]
pub struct InboundMessageDetails {
/// Computed message dispatch weight.
///
/// Runtime API guarantees that it will match the value, returned by
/// `target_chain::MessageDispatch::dispatch_weight`. This means that if the runtime
/// has failed to decode the message, it will be zero - that's because `undecodable`
/// message cannot be dispatched.
pub dispatch_weight: Weight,
}
/// Bit vector of message dispatch results. /// Bit vector of message dispatch results.
pub type DispatchResultsBitVec = BitVec<u8, Msb0>; pub type DispatchResultsBitVec = BitVec<u8, Msb0>;
@@ -93,8 +93,9 @@ pub trait MessageDispatch<AccountId, Fee> {
/// Estimate dispatch weight. /// Estimate dispatch weight.
/// ///
/// This function must: (1) be instant and (2) return correct upper bound /// This function must return correct upper bound of dispatch weight. The return value
/// of dispatch weight. /// of this function is expected to match return value of the corresponding
/// `From<Chain>InboundLaneApi::message_details().dispatch_weight` call.
fn dispatch_weight(message: &mut DispatchMessage<Self::DispatchPayload, Fee>) -> Weight; fn dispatch_weight(message: &mut DispatchMessage<Self::DispatchPayload, Fee>) -> Weight;
/// Called when inbound message is received. /// Called when inbound message is received.
+2
View File
@@ -79,6 +79,8 @@ impl ChainWithMessages for Kusama {
bp_kusama::WITH_KUSAMA_MESSAGES_PALLET_NAME; bp_kusama::WITH_KUSAMA_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD; bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_kusama::FROM_KUSAMA_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_kusama::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_kusama::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
+2
View File
@@ -63,6 +63,8 @@ impl ChainWithMessages for Millau {
bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME; bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD; bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_millau::FROM_MILLAU_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_millau::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_millau::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
@@ -80,6 +80,8 @@ impl ChainWithMessages for Polkadot {
bp_polkadot::WITH_POLKADOT_MESSAGES_PALLET_NAME; bp_polkadot::WITH_POLKADOT_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_METHOD; bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_polkadot::FROM_POLKADOT_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_polkadot::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_polkadot::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
@@ -88,6 +88,8 @@ impl ChainWithMessages for RialtoParachain {
bp_rialto_parachain::WITH_RIALTO_PARACHAIN_MESSAGES_PALLET_NAME; bp_rialto_parachain::WITH_RIALTO_PARACHAIN_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rialto_parachain::TO_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD; bp_rialto_parachain::TO_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rialto_parachain::FROM_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_rialto_parachain::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_rialto_parachain::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
+2
View File
@@ -85,6 +85,8 @@ impl ChainWithMessages for Rialto {
bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME; bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD; bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rialto::FROM_RIALTO_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
+2
View File
@@ -82,6 +82,8 @@ impl ChainWithMessages for Rococo {
bp_rococo::WITH_ROCOCO_MESSAGES_PALLET_NAME; bp_rococo::WITH_ROCOCO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_METHOD; bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rococo::FROM_ROCOCO_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_rococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_rococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
@@ -105,6 +105,10 @@ pub trait ChainWithMessages: Chain {
/// The method is provided by the runtime that is bridged with this `ChainWithMessages`. /// The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str; const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str;
/// Name of the `From<ChainWithMessages>InboundLaneApi::message_details` runtime API method.
/// The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str;
/// Additional weight of the dispatch fee payment if dispatch is paid at the target chain /// Additional weight of the dispatch fee payment if dispatch is paid at the target chain
/// and this `ChainWithMessages` is the target chain. /// and this `ChainWithMessages` is the target chain.
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight; const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight;
+2
View File
@@ -82,6 +82,8 @@ impl ChainWithMessages for Wococo {
bp_wococo::WITH_WOCOCO_MESSAGES_PALLET_NAME; bp_wococo::WITH_WOCOCO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_METHOD; bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_wococo::FROM_WOCOCO_MESSAGE_DETAILS_METHOD;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_wococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT; bp_wococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
@@ -31,8 +31,10 @@ use async_std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use bp_messages::{ use bp_messages::{
storage_keys::{operating_mode_key, outbound_lane_data_key}, storage_keys::{operating_mode_key, outbound_lane_data_key},
LaneId, MessageNonce, OperatingMode, OutboundLaneData, UnrewardedRelayersState, InboundMessageDetails, LaneId, MessageData, MessageNonce, OperatingMode, OutboundLaneData,
OutboundMessageDetails, UnrewardedRelayersState,
}; };
use bp_runtime::messages::DispatchFeePayment;
use bridge_runtime_common::messages::{ use bridge_runtime_common::messages::{
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof, source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
}; };
@@ -54,7 +56,7 @@ use relay_substrate_client::{
use relay_utils::{relay_loop::Client as RelayClient, HeaderId}; use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
use sp_core::{Bytes, Pair}; use sp_core::{Bytes, Pair};
use sp_runtime::{traits::Header as HeaderT, DeserializeOwned}; use sp_runtime::{traits::Header as HeaderT, DeserializeOwned};
use std::ops::RangeInclusive; use std::{collections::HashMap, ops::RangeInclusive};
/// Intermediate message proof returned by the source Substrate node. Includes everything /// Intermediate message proof returned by the source Substrate node. Includes everything
/// required to submit to the target node: cumulative dispatch weight of bundled messages and /// required to submit to the target node: cumulative dispatch weight of bundled messages and
@@ -199,11 +201,97 @@ where
) )
.await?; .await?;
make_message_details_map::<P::SourceChain>( let mut messages = make_message_details_map::<P::SourceChain>(
Decode::decode(&mut &encoded_response.0[..]) Decode::decode(&mut &encoded_response.0[..])
.map_err(SubstrateError::ResponseParseFailed)?, .map_err(SubstrateError::ResponseParseFailed)?,
nonces, nonces,
) )?;
// prepare arguments of the inbound message details call (if we need it)
let mut messages_to_refine = HashMap::new();
for (message_nonce, message) in &messages {
if message.dispatch_fee_payment != DispatchFeePayment::AtTargetChain {
continue
}
// for pay-at-target messages we may want to ask target chain for
// refined dispatch weight
let message_key = bp_messages::storage_keys::message_key(
P::TargetChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
*message_nonce,
);
let message_data: MessageData<BalanceOf<P::SourceChain>> =
self.source_client.storage_value(message_key, Some(id.1)).await?.ok_or_else(
|| {
SubstrateError::Custom(format!(
"Message to {} {:?}/{} is missing from runtime the storage of {} at {:?}",
P::TargetChain::NAME,
self.lane_id,
message_nonce,
P::SourceChain::NAME,
id,
))
},
)?;
let message_payload = message_data.payload;
messages_to_refine.insert(
*message_nonce,
(
message_payload,
OutboundMessageDetails {
nonce: *message_nonce,
dispatch_weight: message.dispatch_weight,
size: message.size,
delivery_and_dispatch_fee: message.reward,
dispatch_fee_payment: DispatchFeePayment::AtTargetChain,
},
),
);
}
// request inbound message details from the target client
if !messages_to_refine.is_empty() {
let refined_messages_encoded = self
.target_client
.state_call(
P::SourceChain::FROM_CHAIN_MESSAGE_DETAILS_METHOD.into(),
Bytes((self.lane_id, messages_to_refine.values().collect::<Vec<_>>()).encode()),
None,
)
.await?;
let refined_messages =
Vec::<InboundMessageDetails>::decode(&mut &refined_messages_encoded.0[..])
.map_err(SubstrateError::ResponseParseFailed)?;
if refined_messages.len() != messages_to_refine.len() {
return Err(SubstrateError::Custom(format!(
"Call of {} at {} has returned {} entries instead of expected {}",
P::SourceChain::FROM_CHAIN_MESSAGE_DETAILS_METHOD,
P::TargetChain::NAME,
refined_messages.len(),
messages_to_refine.len(),
)))
}
for (nonce, refined_message) in messages_to_refine.keys().zip(refined_messages) {
let message = messages
.get_mut(nonce)
.expect("`messages_to_refine` is a subset of `messages`; qed");
log::trace!(
target: "bridge",
"Refined weight of {}->{} message {:?}/{}: at-source: {}, at-target: {}",
P::SourceChain::NAME,
P::TargetChain::NAME,
self.lane_id,
nonce,
message.dispatch_weight,
refined_message.dispatch_weight,
);
message.dispatch_weight = refined_message.dispatch_weight;
}
}
Ok(messages)
} }
async fn prove_messages( async fn prove_messages(
@@ -483,7 +571,7 @@ where
} }
fn make_message_details_map<C: Chain>( fn make_message_details_map<C: Chain>(
weights: Vec<bp_messages::MessageDetails<C::Balance>>, weights: Vec<bp_messages::OutboundMessageDetails<C::Balance>>,
nonces: RangeInclusive<MessageNonce>, nonces: RangeInclusive<MessageNonce>,
) -> Result<MessageDetailsMap<C::Balance>, SubstrateError> { ) -> Result<MessageDetailsMap<C::Balance>, SubstrateError> {
let make_missing_nonce_error = |expected_nonce| { let make_missing_nonce_error = |expected_nonce| {
@@ -558,10 +646,10 @@ mod tests {
fn message_details_from_rpc( fn message_details_from_rpc(
nonces: RangeInclusive<MessageNonce>, nonces: RangeInclusive<MessageNonce>,
) -> Vec<bp_messages::MessageDetails<bp_wococo::Balance>> { ) -> Vec<bp_messages::OutboundMessageDetails<bp_wococo::Balance>> {
nonces nonces
.into_iter() .into_iter()
.map(|nonce| bp_messages::MessageDetails { .map(|nonce| bp_messages::OutboundMessageDetails {
nonce, nonce,
dispatch_weight: 0, dispatch_weight: 0,
size: 0, size: 0,