mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
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:
committed by
Bastian Köcher
parent
78a43c561a
commit
f0d05de080
@@ -56,9 +56,10 @@ use bp_messages::{
|
||||
target_chain::{
|
||||
DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
|
||||
},
|
||||
total_unrewarded_messages, DeliveredMessages, InboundLaneData, LaneId, MessageData, MessageKey,
|
||||
MessageNonce, OperatingMode, OutboundLaneData, Parameter as MessagesParameter,
|
||||
UnrewardedRelayer, UnrewardedRelayersState,
|
||||
total_unrewarded_messages, DeliveredMessages, InboundLaneData, InboundMessageDetails, LaneId,
|
||||
MessageData, MessageKey, MessageNonce, MessagePayload, OperatingMode, OutboundLaneData,
|
||||
OutboundMessageDetails, Parameter as MessagesParameter, UnrewardedRelayer,
|
||||
UnrewardedRelayersState,
|
||||
};
|
||||
use bp_runtime::{ChainId, Size};
|
||||
use codec::{Decode, Encode};
|
||||
@@ -156,7 +157,7 @@ pub mod pallet {
|
||||
/// Payload type of inbound messages. This payload is dispatched on this chain.
|
||||
type InboundPayload: Decode;
|
||||
/// 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
|
||||
/// bridged chain.
|
||||
type InboundRelayer: Parameter;
|
||||
@@ -762,6 +763,22 @@ pub mod pallet {
|
||||
) -> Option<MessageData<T::OutboundMessageFee>> {
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
#[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 },
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user