From ec8412b6d0e356fcd39d21bbd7e4c73869673d21 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Mon, 14 Jun 2021 16:55:05 +0300 Subject: [PATCH] rename messages_dispatch_weight -> message_details (#996) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomasz Drwięga --- bridges/bin/millau/runtime/src/lib.rs | 16 +++-- bridges/bin/rialto/runtime/src/lib.rs | 16 +++-- bridges/modules/messages/src/lib.rs | 10 +-- bridges/primitives/chain-kusama/src/lib.rs | 13 ++-- bridges/primitives/chain-millau/src/lib.rs | 13 ++-- bridges/primitives/chain-polkadot/src/lib.rs | 13 ++-- bridges/primitives/chain-rialto/src/lib.rs | 13 ++-- bridges/primitives/chain-rococo/src/lib.rs | 13 ++-- bridges/primitives/chain-westend/src/lib.rs | 13 ++-- bridges/primitives/chain-wococo/src/lib.rs | 13 ++-- bridges/primitives/messages/src/lib.rs | 13 ++++ .../src/chains/millau_messages_to_rialto.rs | 3 +- .../src/chains/rialto_messages_to_millau.rs | 3 +- .../relays/bin-substrate/src/messages_lane.rs | 2 +- .../bin-substrate/src/messages_source.rs | 61 ++++++++++++------- 15 files changed, 130 insertions(+), 85 deletions(-) diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index d793c74a27..da2db79b55 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -601,17 +601,23 @@ impl_runtime_apis! { ).ok() } - fn messages_dispatch_weight( + fn message_details( lane: bp_messages::LaneId, begin: bp_messages::MessageNonce, end: bp_messages::MessageNonce, - ) -> Vec<(bp_messages::MessageNonce, Weight, u32)> { + ) -> Vec> { (begin..=end).filter_map(|nonce| { - let encoded_payload = BridgeRialtoMessages::outbound_message_payload(lane, nonce)?; + let message_data = BridgeRialtoMessages::outbound_message_data(lane, nonce)?; let decoded_payload = rialto_messages::ToRialtoMessagePayload::decode( - &mut &encoded_payload[..] + &mut &message_data.payload[..] ).ok()?; - Some((nonce, decoded_payload.weight, encoded_payload.len() as _)) + Some(bp_messages::MessageDetails { + nonce, + dispatch_weight: decoded_payload.weight, + size: message_data.payload.len() as _, + delivery_and_dispatch_fee: message_data.fee, + // TODO: include dispatch fee type (https://github.com/paritytech/parity-bridges-common/pull/911) + }) }) .collect() } diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index 6c2a1f7418..854acdbe1d 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -752,17 +752,23 @@ impl_runtime_apis! { ).ok() } - fn messages_dispatch_weight( + fn message_details( lane: bp_messages::LaneId, begin: bp_messages::MessageNonce, end: bp_messages::MessageNonce, - ) -> Vec<(bp_messages::MessageNonce, Weight, u32)> { + ) -> Vec> { (begin..=end).filter_map(|nonce| { - let encoded_payload = BridgeMillauMessages::outbound_message_payload(lane, nonce)?; + let message_data = BridgeMillauMessages::outbound_message_data(lane, nonce)?; let decoded_payload = millau_messages::ToMillauMessagePayload::decode( - &mut &encoded_payload[..] + &mut &message_data.payload[..] ).ok()?; - Some((nonce, decoded_payload.weight, encoded_payload.len() as _)) + Some(bp_messages::MessageDetails { + nonce, + dispatch_weight: decoded_payload.weight, + size: message_data.payload.len() as _, + delivery_and_dispatch_fee: message_data.fee, + // TODO: include dispatch fee type (https://github.com/paritytech/parity-bridges-common/pull/911) + }) }) .collect() } diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 4e9800e0c7..0d9b5788d2 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -49,8 +49,8 @@ use crate::weights::WeightInfo; use bp_messages::{ source_chain::{LaneMessageVerifier, MessageDeliveryAndDispatchPayment, RelayersRewards, TargetHeaderChain}, target_chain::{DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain}, - total_unrewarded_messages, InboundLaneData, LaneId, MessageData, MessageKey, MessageNonce, MessagePayload, - OperatingMode, OutboundLaneData, Parameter as MessagesParameter, UnrewardedRelayersState, + total_unrewarded_messages, InboundLaneData, LaneId, MessageData, MessageKey, MessageNonce, OperatingMode, + OutboundLaneData, Parameter as MessagesParameter, UnrewardedRelayersState, }; use bp_runtime::Size; use codec::{Decode, Encode}; @@ -607,9 +607,9 @@ decl_module! { } impl, I: Instance> Pallet { - /// Get payload of given outbound message. - pub fn outbound_message_payload(lane: LaneId, nonce: MessageNonce) -> Option { - OutboundMessages::::get(MessageKey { lane_id: lane, nonce }).map(|message_data| message_data.payload) + /// Get stored data of the outbound message with given nonce. + pub fn outbound_message_data(lane: LaneId, nonce: MessageNonce) -> Option> { + OutboundMessages::::get(MessageKey { lane_id: lane, nonce }) } /// Get nonce of latest generated message at given outbound lane. diff --git a/bridges/primitives/chain-kusama/src/lib.rs b/bridges/primitives/chain-kusama/src/lib.rs index 758bba5a71..d0e9e3acd5 100644 --- a/bridges/primitives/chain-kusama/src/lib.rs +++ b/bridges/primitives/chain-kusama/src/lib.rs @@ -20,7 +20,7 @@ // Runtime-generated DecodeLimit::decode_all_with_depth_limit #![allow(clippy::unnecessary_mut_passed)] -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use sp_std::prelude::*; pub use bp_polkadot_core::*; @@ -43,8 +43,8 @@ pub const IS_KNOWN_KUSAMA_HEADER_METHOD: &str = "KusamaFinalityApi_is_known_head /// Name of the `ToKusamaOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_KUSAMA_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToKusamaOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToKusamaOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_KUSAMA_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToKusamaOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToKusamaOutboundLaneApi::message_details` runtime method. +pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details"; /// Name of the `ToKusamaOutboundLaneApi::latest_generated_nonce` runtime method. pub const TO_KUSAMA_LATEST_GENERATED_NONCE_METHOD: &str = "ToKusamaOutboundLaneApi_latest_generated_nonce"; /// Name of the `ToKusamaOutboundLaneApi::latest_received_nonce` runtime method. @@ -87,15 +87,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/chain-millau/src/lib.rs b/bridges/primitives/chain-millau/src/lib.rs index 7b88b7c49a..36c179ca5f 100644 --- a/bridges/primitives/chain-millau/src/lib.rs +++ b/bridges/primitives/chain-millau/src/lib.rs @@ -22,7 +22,7 @@ mod millau_hash; -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use bp_runtime::Chain; use frame_support::{ weights::{constants::WEIGHT_PER_SECOND, DispatchClass, Weight}, @@ -244,8 +244,8 @@ pub const BEST_FINALIZED_MILLAU_HEADER_METHOD: &str = "MillauFinalityApi_best_fi /// Name of the `ToMillauOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_MILLAU_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToMillauOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToMillauOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_MILLAU_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToMillauOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToMillauOutboundLaneApi::message_details` runtime method. +pub const TO_MILLAU_MESSAGE_DETAILS_METHOD: &str = "ToMillauOutboundLaneApi_message_details"; /// Name of the `ToMillauOutboundLaneApi::latest_received_nonce` runtime method. pub const TO_MILLAU_LATEST_RECEIVED_NONCE_METHOD: &str = "ToMillauOutboundLaneApi_latest_received_nonce"; /// Name of the `ToMillauOutboundLaneApi::latest_generated_nonce` runtime method. @@ -288,15 +288,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/chain-polkadot/src/lib.rs b/bridges/primitives/chain-polkadot/src/lib.rs index 7cd155d64a..7ab1c7f439 100644 --- a/bridges/primitives/chain-polkadot/src/lib.rs +++ b/bridges/primitives/chain-polkadot/src/lib.rs @@ -20,7 +20,7 @@ // Runtime-generated DecodeLimit::decode_all_with_depth_limit #![allow(clippy::unnecessary_mut_passed)] -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use sp_std::prelude::*; pub use bp_polkadot_core::*; @@ -43,8 +43,8 @@ pub const IS_KNOWN_POLKADOT_HEADER_METHOD: &str = "PolkadotFinalityApi_is_known_ /// Name of the `ToPolkadotOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_POLKADOT_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToPolkadotOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToPolkadotOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_POLKADOT_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToPolkadotOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToPolkadotOutboundLaneApi::message_details` runtime method. +pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details"; /// Name of the `ToPolkadotOutboundLaneApi::latest_generated_nonce` runtime method. pub const TO_POLKADOT_LATEST_GENERATED_NONCE_METHOD: &str = "ToPolkadotOutboundLaneApi_latest_generated_nonce"; /// Name of the `ToPolkadotOutboundLaneApi::latest_received_nonce` runtime method. @@ -87,15 +87,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/chain-rialto/src/lib.rs b/bridges/primitives/chain-rialto/src/lib.rs index 3cd19739d4..cc7c8e8c08 100644 --- a/bridges/primitives/chain-rialto/src/lib.rs +++ b/bridges/primitives/chain-rialto/src/lib.rs @@ -20,7 +20,7 @@ // Runtime-generated DecodeLimit::decode_all_With_depth_limit #![allow(clippy::unnecessary_mut_passed)] -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use bp_runtime::Chain; use frame_support::{ weights::{constants::WEIGHT_PER_SECOND, DispatchClass, Weight}, @@ -205,8 +205,8 @@ pub const BEST_FINALIZED_RIALTO_HEADER_METHOD: &str = "RialtoFinalityApi_best_fi /// Name of the `ToRialtoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_RIALTO_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToRialtoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToRialtoOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_RIALTO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToRialtoOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToRialtoOutboundLaneApi::message_details` runtime method. +pub const TO_RIALTO_MESSAGE_DETAILS_METHOD: &str = "ToRialtoOutboundLaneApi_message_details"; /// Name of the `ToRialtoOutboundLaneApi::latest_generated_nonce` runtime method. pub const TO_RIALTO_LATEST_GENERATED_NONCE_METHOD: &str = "ToRialtoOutboundLaneApi_latest_generated_nonce"; /// Name of the `ToRialtoOutboundLaneApi::latest_received_nonce` runtime method. @@ -249,15 +249,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/chain-rococo/src/lib.rs b/bridges/primitives/chain-rococo/src/lib.rs index 246e797567..20a5cd6658 100644 --- a/bridges/primitives/chain-rococo/src/lib.rs +++ b/bridges/primitives/chain-rococo/src/lib.rs @@ -20,7 +20,7 @@ // Runtime-generated DecodeLimit::decode_all_with_depth_limit #![allow(clippy::unnecessary_mut_passed)] -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use bp_runtime::Chain; use sp_std::prelude::*; use sp_version::RuntimeVersion; @@ -91,8 +91,8 @@ pub const IS_KNOWN_ROCOCO_HEADER_METHOD: &str = "RococoFinalityApi_is_known_head /// Name of the `ToRococoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_ROCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToRococoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToRococoOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_ROCOCO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToRococoOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToRococoOutboundLaneApi::message_details` runtime method. +pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details"; /// Name of the `ToRococoOutboundLaneApi::latest_generated_nonce` runtime method. pub const TO_ROCOCO_LATEST_GENERATED_NONCE_METHOD: &str = "ToRococoOutboundLaneApi_latest_generated_nonce"; /// Name of the `ToRococoOutboundLaneApi::latest_received_nonce` runtime method. @@ -135,15 +135,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/chain-westend/src/lib.rs b/bridges/primitives/chain-westend/src/lib.rs index 42298100f6..a0895da259 100644 --- a/bridges/primitives/chain-westend/src/lib.rs +++ b/bridges/primitives/chain-westend/src/lib.rs @@ -20,7 +20,7 @@ // Runtime-generated DecodeLimit::decode_all_with_depth_limit #![allow(clippy::unnecessary_mut_passed)] -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use bp_runtime::Chain; use sp_std::prelude::*; use sp_version::RuntimeVersion; @@ -98,8 +98,8 @@ pub const IS_KNOWN_WESTEND_HEADER_METHOD: &str = "WestendFinalityApi_is_known_he /// Name of the `ToWestendOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_WESTEND_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToWestendOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToWestendOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_WESTEND_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToWestendOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToWestendOutboundLaneApi::message_details` runtime method. +pub const TO_WESTEND_MESSAGE_DETAILS_METHOD: &str = "ToWestendOutboundLaneApi_message_details"; /// Name of the `ToWestendOutboundLaneApi::latest_generated_nonce` runtime method. pub const TO_WESTEND_LATEST_GENERATED_NONCE_METHOD: &str = "ToWestendOutboundLaneApi_latest_generated_nonce"; /// Name of the `ToWestendOutboundLaneApi::latest_received_nonce` runtime method. @@ -149,15 +149,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/chain-wococo/src/lib.rs b/bridges/primitives/chain-wococo/src/lib.rs index 81dbaff186..94e3ecbf2e 100644 --- a/bridges/primitives/chain-wococo/src/lib.rs +++ b/bridges/primitives/chain-wococo/src/lib.rs @@ -20,7 +20,7 @@ // Runtime-generated DecodeLimit::decode_all_with_depth_limit #![allow(clippy::unnecessary_mut_passed)] -use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; +use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState}; use bp_runtime::Chain; use sp_std::prelude::*; use sp_version::RuntimeVersion; @@ -98,8 +98,8 @@ pub const IS_KNOWN_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_is_known_head /// Name of the `ToWococoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str = "ToWococoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; -/// Name of the `ToWococoOutboundLaneApi::messages_dispatch_weight` runtime method. -pub const TO_WOCOCO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToWococoOutboundLaneApi_messages_dispatch_weight"; +/// Name of the `ToWococoOutboundLaneApi::message_details` runtime method. +pub const TO_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "ToWococoOutboundLaneApi_message_details"; /// Name of the `ToWococoOutboundLaneApi::latest_generated_nonce` runtime method. pub const TO_WOCOCO_LATEST_GENERATED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_generated_nonce"; /// Name of the `ToWococoOutboundLaneApi::latest_received_nonce` runtime method. @@ -142,15 +142,16 @@ sp_api::decl_runtime_apis! { lane_id: LaneId, payload: OutboundPayload, ) -> Option; - /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. + /// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all + /// messages in given inclusive range. /// /// If some (or all) messages are missing from the storage, they'll also will /// be missing from the resulting vector. The vector is ordered by the nonce. - fn messages_dispatch_weight( + fn message_details( lane: LaneId, begin: MessageNonce, end: MessageNonce, - ) -> Vec<(MessageNonce, Weight, u32)>; + ) -> Vec>; /// Returns nonce of the latest message, received by bridged chain. fn latest_received_nonce(lane: LaneId) -> MessageNonce; /// Returns nonce of the latest message, generated by given lane. diff --git a/bridges/primitives/messages/src/lib.rs b/bridges/primitives/messages/src/lib.rs index 2bc3372329..211f4e7175 100644 --- a/bridges/primitives/messages/src/lib.rs +++ b/bridges/primitives/messages/src/lib.rs @@ -163,6 +163,19 @@ impl InboundLaneData { } } +/// Message details, returned by runtime APIs. +#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq)] +pub struct MessageDetails { + /// Nonce assigned to the message. + pub nonce: MessageNonce, + /// Message dispatch weight, declared by the submitter. + pub dispatch_weight: Weight, + /// Size of the encoded message. + pub size: u32, + /// Delivery+dispatch fee paid by the message submitter at the source chain. + pub delivery_and_dispatch_fee: OutboundMessageFee, +} + /// Gist of `InboundLaneData::relayers` field used by runtime APIs. #[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq)] pub struct UnrewardedRelayersState { diff --git a/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs b/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs index de2246a923..2bca68c37e 100644 --- a/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs +++ b/bridges/relays/bin-substrate/src/chains/millau_messages_to_rialto.rs @@ -42,8 +42,7 @@ pub type MillauMessagesToRialto = SubstrateMessageLaneToSubstrate; impl SubstrateMessageLane for MillauMessagesToRialto { - const OUTBOUND_LANE_MESSAGES_DISPATCH_WEIGHT_METHOD: &'static str = - bp_rialto::TO_RIALTO_MESSAGES_DISPATCH_WEIGHT_METHOD; + const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD; const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str = bp_rialto::TO_RIALTO_LATEST_GENERATED_NONCE_METHOD; const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_rialto::TO_RIALTO_LATEST_RECEIVED_NONCE_METHOD; diff --git a/bridges/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs b/bridges/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs index 981bc76db6..c85cf9d367 100644 --- a/bridges/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs +++ b/bridges/relays/bin-substrate/src/chains/rialto_messages_to_millau.rs @@ -42,8 +42,7 @@ pub type RialtoMessagesToMillau = SubstrateMessageLaneToSubstrate; impl SubstrateMessageLane for RialtoMessagesToMillau { - const OUTBOUND_LANE_MESSAGES_DISPATCH_WEIGHT_METHOD: &'static str = - bp_millau::TO_MILLAU_MESSAGES_DISPATCH_WEIGHT_METHOD; + const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str = bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD; const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str = bp_millau::TO_MILLAU_LATEST_GENERATED_NONCE_METHOD; const OUTBOUND_LANE_LATEST_RECEIVED_NONCE_METHOD: &'static str = bp_millau::TO_MILLAU_LATEST_RECEIVED_NONCE_METHOD; diff --git a/bridges/relays/bin-substrate/src/messages_lane.rs b/bridges/relays/bin-substrate/src/messages_lane.rs index bfca980a07..40de424a78 100644 --- a/bridges/relays/bin-substrate/src/messages_lane.rs +++ b/bridges/relays/bin-substrate/src/messages_lane.rs @@ -49,7 +49,7 @@ pub struct MessagesRelayParams { /// Message sync pipeline for Substrate <-> Substrate relays. pub trait SubstrateMessageLane: MessageLane { /// Name of the runtime method that returns dispatch weight of outbound messages at the source chain. - const OUTBOUND_LANE_MESSAGES_DISPATCH_WEIGHT_METHOD: &'static str; + const OUTBOUND_LANE_MESSAGE_DETAILS_METHOD: &'static str; /// Name of the runtime method that returns latest generated nonce at the source chain. const OUTBOUND_LANE_LATEST_GENERATED_NONCE_METHOD: &'static str; /// Name of the runtime method that returns latest received (confirmed) nonce at the the source chain. diff --git a/bridges/relays/bin-substrate/src/messages_source.rs b/bridges/relays/bin-substrate/src/messages_source.rs index 49e2c7efee..68329a2dbc 100644 --- a/bridges/relays/bin-substrate/src/messages_source.rs +++ b/bridges/relays/bin-substrate/src/messages_source.rs @@ -176,13 +176,13 @@ where let encoded_response = self .client .state_call( - P::OUTBOUND_LANE_MESSAGES_DISPATCH_WEIGHT_METHOD.into(), + P::OUTBOUND_LANE_MESSAGE_DETAILS_METHOD.into(), Bytes((self.lane_id, nonces.start(), nonces.end()).encode()), Some(id.1), ) .await?; - make_message_weights_map::( + make_message_details_map::( Decode::decode(&mut &encoded_response.0[..]).map_err(SubstrateError::ResponseParseFailed)?, nonces, ) @@ -287,8 +287,8 @@ where }) } -fn make_message_weights_map( - weights: Vec<(MessageNonce, Weight, u32)>, +fn make_message_details_map( + weights: Vec>, nonces: RangeInclusive, ) -> Result { let make_missing_nonce_error = |expected_nonce| { @@ -308,7 +308,7 @@ fn make_message_weights_map( // check if last nonce is missing - loop below is not checking this let last_nonce_is_missing = weights .last() - .map(|(last_nonce, _, _)| last_nonce != nonces.end()) + .map(|details| details.nonce != *nonces.end()) .unwrap_or(true); if last_nonce_is_missing { return make_missing_nonce_error(*nonces.end()); @@ -317,8 +317,8 @@ fn make_message_weights_map( let mut expected_nonce = *nonces.start(); let mut is_at_head = true; - for (nonce, weight, size) in weights { - match (nonce == expected_nonce, is_at_head) { + for details in weights { + match (details.nonce == expected_nonce, is_at_head) { (true, _) => (), (false, true) => { // this may happen if some messages were already pruned from the source node @@ -328,7 +328,7 @@ fn make_message_weights_map( target: "bridge", "Some messages are missing from the {} node: {:?}. Target node may be out of sync?", C::NAME, - expected_nonce..nonce, + expected_nonce..details.nonce, ); } (false, false) => { @@ -340,13 +340,13 @@ fn make_message_weights_map( } weights_map.insert( - nonce, + details.nonce, MessageWeights { - weight, - size: size as _, + weight: details.dispatch_weight, + size: details.size as _, }, ); - expected_nonce = nonce + 1; + expected_nonce = details.nonce + 1; is_at_head = false; } @@ -357,11 +357,24 @@ fn make_message_weights_map( mod tests { use super::*; + fn message_details_from_rpc( + nonces: RangeInclusive, + ) -> Vec> { + nonces + .into_iter() + .map(|nonce| bp_messages::MessageDetails { + nonce, + dispatch_weight: 0, + size: 0, + delivery_and_dispatch_fee: 0, + }) + .collect() + } + #[test] - fn make_message_weights_map_succeeds_if_no_messages_are_missing() { + fn make_message_details_map_succeeds_if_no_messages_are_missing() { assert_eq!( - make_message_weights_map::(vec![(1, 0, 0), (2, 0, 0), (3, 0, 0)], 1..=3,) - .unwrap(), + make_message_details_map::(message_details_from_rpc(1..=3), 1..=3,).unwrap(), vec![ (1, MessageWeights { weight: 0, size: 0 }), (2, MessageWeights { weight: 0, size: 0 }), @@ -373,9 +386,9 @@ mod tests { } #[test] - fn make_message_weights_map_succeeds_if_head_messages_are_missing() { + fn make_message_details_map_succeeds_if_head_messages_are_missing() { assert_eq!( - make_message_weights_map::(vec![(2, 0, 0), (3, 0, 0)], 1..=3,).unwrap(), + make_message_details_map::(message_details_from_rpc(2..=3), 1..=3,).unwrap(), vec![ (2, MessageWeights { weight: 0, size: 0 }), (3, MessageWeights { weight: 0, size: 0 }), @@ -386,25 +399,27 @@ mod tests { } #[test] - fn make_message_weights_map_fails_if_mid_messages_are_missing() { + fn make_message_details_map_fails_if_mid_messages_are_missing() { + let mut message_details_from_rpc = message_details_from_rpc(1..=3); + message_details_from_rpc.remove(1); assert!(matches!( - make_message_weights_map::(vec![(1, 0, 0), (3, 0, 0)], 1..=3,), + make_message_details_map::(message_details_from_rpc, 1..=3,), Err(SubstrateError::Custom(_)) )); } #[test] - fn make_message_weights_map_fails_if_tail_messages_are_missing() { + fn make_message_details_map_fails_if_tail_messages_are_missing() { assert!(matches!( - make_message_weights_map::(vec![(1, 0, 0), (2, 0, 0)], 1..=3,), + make_message_details_map::(message_details_from_rpc(1..=2), 1..=3,), Err(SubstrateError::Custom(_)) )); } #[test] - fn make_message_weights_map_fails_if_all_messages_are_missing() { + fn make_message_details_map_fails_if_all_messages_are_missing() { assert!(matches!( - make_message_weights_map::(vec![], 1..=3), + make_message_details_map::(vec![], 1..=3), Err(SubstrateError::Custom(_)) )); }