mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 11:25:42 +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
@@ -21,7 +21,7 @@
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
use bitvec::prelude::*;
|
||||
use bp_runtime::{messages::DispatchFeePayment, BasicOperatingMode, OperatingMode};
|
||||
use bp_runtime::{BasicOperatingMode, OperatingMode};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::RuntimeDebug;
|
||||
use scale_info::TypeInfo;
|
||||
@@ -65,16 +65,6 @@ impl OperatingMode for MessagesOperatingMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Messages pallet parameter.
|
||||
pub trait Parameter: frame_support::Parameter {
|
||||
/// Save parameter value in the runtime storage.
|
||||
fn save(&self);
|
||||
}
|
||||
|
||||
impl Parameter for () {
|
||||
fn save(&self) {}
|
||||
}
|
||||
|
||||
/// Lane identifier.
|
||||
pub type LaneId = [u8; 4];
|
||||
|
||||
@@ -96,22 +86,13 @@ pub struct MessageKey {
|
||||
pub nonce: MessageNonce,
|
||||
}
|
||||
|
||||
/// Message data as it is stored in the storage.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
|
||||
pub struct MessageData<Fee> {
|
||||
/// Message payload.
|
||||
pub payload: MessagePayload,
|
||||
/// Message delivery and dispatch fee, paid by the submitter.
|
||||
pub fee: Fee,
|
||||
}
|
||||
|
||||
/// Message as it is stored in the storage.
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
|
||||
pub struct Message<Fee> {
|
||||
pub struct Message {
|
||||
/// Message key.
|
||||
pub key: MessageKey,
|
||||
/// Message data.
|
||||
pub data: MessageData<Fee>,
|
||||
/// Message payload.
|
||||
pub payload: MessagePayload,
|
||||
}
|
||||
|
||||
/// Inbound lane data.
|
||||
@@ -198,7 +179,7 @@ impl<RelayerId> InboundLaneData<RelayerId> {
|
||||
|
||||
/// Outbound message details, returned by runtime APIs.
|
||||
#[derive(Clone, Encode, Decode, RuntimeDebug, PartialEq, Eq)]
|
||||
pub struct OutboundMessageDetails<OutboundMessageFee> {
|
||||
pub struct OutboundMessageDetails {
|
||||
/// Nonce assigned to the message.
|
||||
pub nonce: MessageNonce,
|
||||
/// Message dispatch weight.
|
||||
@@ -208,10 +189,6 @@ pub struct OutboundMessageDetails<OutboundMessageFee> {
|
||||
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,
|
||||
/// Where the fee for dispatching message is paid?
|
||||
pub dispatch_fee_payment: DispatchFeePayment,
|
||||
}
|
||||
|
||||
/// Inbound message details, returned by runtime APIs.
|
||||
|
||||
@@ -27,17 +27,8 @@ use sp_std::{
|
||||
ops::RangeInclusive,
|
||||
};
|
||||
|
||||
/// Relayers rewards, grouped by relayer account id.
|
||||
pub type RelayersRewards<AccountId, Balance> = BTreeMap<AccountId, RelayerRewards<Balance>>;
|
||||
|
||||
/// Single relayer rewards.
|
||||
#[derive(RuntimeDebug, Default)]
|
||||
pub struct RelayerRewards<Balance> {
|
||||
/// Total rewards that are to be paid to the relayer.
|
||||
pub reward: Balance,
|
||||
/// Total number of messages relayed by this relayer.
|
||||
pub messages: MessageNonce,
|
||||
}
|
||||
/// Number of messages, delivered by relayers.
|
||||
pub type RelayersRewards<AccountId> = BTreeMap<AccountId, MessageNonce>;
|
||||
|
||||
/// Target chain API. Used by source chain to verify target chain proofs.
|
||||
///
|
||||
@@ -83,7 +74,7 @@ pub trait TargetHeaderChain<Payload, AccountId> {
|
||||
/// Lane3 until some block, ...), then it may be built using this verifier.
|
||||
///
|
||||
/// Any fee requirements should also be enforced here.
|
||||
pub trait LaneMessageVerifier<SenderOrigin, Payload, Fee> {
|
||||
pub trait LaneMessageVerifier<SenderOrigin, Payload> {
|
||||
/// Error type.
|
||||
type Error: Debug + Into<&'static str>;
|
||||
|
||||
@@ -91,7 +82,6 @@ pub trait LaneMessageVerifier<SenderOrigin, Payload, Fee> {
|
||||
/// lane.
|
||||
fn verify_message(
|
||||
submitter: &SenderOrigin,
|
||||
delivery_and_dispatch_fee: &Fee,
|
||||
lane: &LaneId,
|
||||
outbound_data: &OutboundLaneData,
|
||||
payload: &Payload,
|
||||
@@ -107,21 +97,10 @@ pub trait LaneMessageVerifier<SenderOrigin, Payload, Fee> {
|
||||
/// 3) message-dispatch fee. It is paid by relayer for processing message by target chain;
|
||||
/// 4) message-receiving-delivery-transaction-fee. It is submitted to the source node
|
||||
/// by relayer.
|
||||
///
|
||||
/// So to be sure that any non-altruist relayer would agree to deliver message, submitter
|
||||
/// should set `delivery_and_dispatch_fee` to at least (equivalent of): sum of fees from (2)
|
||||
/// to (4) above, plus some interest for the relayer.
|
||||
pub trait MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId, Balance> {
|
||||
pub trait MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId> {
|
||||
/// Error type.
|
||||
type Error: Debug + Into<&'static str>;
|
||||
|
||||
/// Withhold/write-off delivery_and_dispatch_fee from submitter account to
|
||||
/// some relayers-fund account.
|
||||
fn pay_delivery_and_dispatch_fee(
|
||||
submitter: &SenderOrigin,
|
||||
fee: &Balance,
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Pay rewards for delivering messages to the given relayers.
|
||||
///
|
||||
/// The implementation may also choose to pay reward to the `confirmation_relayer`, which is
|
||||
@@ -134,18 +113,9 @@ pub trait MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId, Balance> {
|
||||
);
|
||||
}
|
||||
|
||||
impl<SenderOrigin, AccountId, Balance>
|
||||
MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId, Balance> for ()
|
||||
{
|
||||
impl<SenderOrigin, AccountId> MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId> for () {
|
||||
type Error = &'static str;
|
||||
|
||||
fn pay_delivery_and_dispatch_fee(
|
||||
_submitter: &SenderOrigin,
|
||||
_fee: &Balance,
|
||||
) -> Result<(), Self::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pay_relayers_rewards(
|
||||
_lane_id: LaneId,
|
||||
_messages_relayers: VecDeque<UnrewardedRelayer<AccountId>>,
|
||||
@@ -165,7 +135,7 @@ pub struct SendMessageArtifacts {
|
||||
}
|
||||
|
||||
/// Messages bridge API to be used from other pallets.
|
||||
pub trait MessagesBridge<SenderOrigin, Balance, Payload> {
|
||||
pub trait MessagesBridge<SenderOrigin, Payload> {
|
||||
/// Error type.
|
||||
type Error: Debug;
|
||||
|
||||
@@ -176,7 +146,6 @@ pub trait MessagesBridge<SenderOrigin, Balance, Payload> {
|
||||
sender: SenderOrigin,
|
||||
lane: LaneId,
|
||||
message: Payload,
|
||||
delivery_and_dispatch_fee: Balance,
|
||||
) -> Result<SendMessageArtifacts, Self::Error>;
|
||||
}
|
||||
|
||||
@@ -184,16 +153,13 @@ pub trait MessagesBridge<SenderOrigin, Balance, Payload> {
|
||||
#[derive(Eq, RuntimeDebug, PartialEq)]
|
||||
pub struct NoopMessagesBridge;
|
||||
|
||||
impl<SenderOrigin, Balance, Payload> MessagesBridge<SenderOrigin, Balance, Payload>
|
||||
for NoopMessagesBridge
|
||||
{
|
||||
impl<SenderOrigin, Payload> MessagesBridge<SenderOrigin, Payload> for NoopMessagesBridge {
|
||||
type Error = &'static str;
|
||||
|
||||
fn send_message(
|
||||
_sender: SenderOrigin,
|
||||
_lane: LaneId,
|
||||
_message: Payload,
|
||||
_delivery_and_dispatch_fee: Balance,
|
||||
) -> Result<SendMessageArtifacts, Self::Error> {
|
||||
Ok(SendMessageArtifacts { nonce: 0, weight: Weight::zero() })
|
||||
}
|
||||
@@ -266,14 +232,11 @@ impl<Payload, AccountId> TargetHeaderChain<Payload, AccountId> for ForbidOutboun
|
||||
}
|
||||
}
|
||||
|
||||
impl<SenderOrigin, Payload, Fee> LaneMessageVerifier<SenderOrigin, Payload, Fee>
|
||||
for ForbidOutboundMessages
|
||||
{
|
||||
impl<SenderOrigin, Payload> LaneMessageVerifier<SenderOrigin, Payload> for ForbidOutboundMessages {
|
||||
type Error = &'static str;
|
||||
|
||||
fn verify_message(
|
||||
_submitter: &SenderOrigin,
|
||||
_delivery_and_dispatch_fee: &Fee,
|
||||
_lane: &LaneId,
|
||||
_outbound_data: &OutboundLaneData,
|
||||
_payload: &Payload,
|
||||
@@ -282,18 +245,11 @@ impl<SenderOrigin, Payload, Fee> LaneMessageVerifier<SenderOrigin, Payload, Fee>
|
||||
}
|
||||
}
|
||||
|
||||
impl<SenderOrigin, AccountId, Balance>
|
||||
MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId, Balance> for ForbidOutboundMessages
|
||||
impl<SenderOrigin, AccountId> MessageDeliveryAndDispatchPayment<SenderOrigin, AccountId>
|
||||
for ForbidOutboundMessages
|
||||
{
|
||||
type Error = &'static str;
|
||||
|
||||
fn pay_delivery_and_dispatch_fee(
|
||||
_submitter: &SenderOrigin,
|
||||
_fee: &Balance,
|
||||
) -> Result<(), Self::Error> {
|
||||
Err(ALL_OUTBOUND_MESSAGES_REJECTED)
|
||||
}
|
||||
|
||||
fn pay_relayers_rewards(
|
||||
_lane_id: LaneId,
|
||||
_messages_relayers: VecDeque<UnrewardedRelayer<AccountId>>,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Primitives of messages module, that are used on the target chain.
|
||||
|
||||
use crate::{LaneId, Message, MessageData, MessageKey, OutboundLaneData};
|
||||
use crate::{LaneId, Message, MessageKey, MessagePayload, OutboundLaneData};
|
||||
|
||||
use bp_runtime::{messages::MessageDispatchResult, Size};
|
||||
use codec::{Decode, Encode, Error as CodecError};
|
||||
@@ -38,20 +38,18 @@ pub struct ProvedLaneMessages<Message> {
|
||||
|
||||
/// Message data with decoded dispatch payload.
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct DispatchMessageData<DispatchPayload, Fee> {
|
||||
pub struct DispatchMessageData<DispatchPayload> {
|
||||
/// Result of dispatch payload decoding.
|
||||
pub payload: Result<DispatchPayload, CodecError>,
|
||||
/// Message delivery and dispatch fee, paid by the submitter.
|
||||
pub fee: Fee,
|
||||
}
|
||||
|
||||
/// Message with decoded dispatch payload.
|
||||
#[derive(RuntimeDebug)]
|
||||
pub struct DispatchMessage<DispatchPayload, Fee> {
|
||||
pub struct DispatchMessage<DispatchPayload> {
|
||||
/// Message key.
|
||||
pub key: MessageKey,
|
||||
/// Message data with decoded dispatch payload.
|
||||
pub data: DispatchMessageData<DispatchPayload, Fee>,
|
||||
pub data: DispatchMessageData<DispatchPayload>,
|
||||
}
|
||||
|
||||
/// Source chain API. Used by target chain, to verify source chain proofs.
|
||||
@@ -59,7 +57,7 @@ pub struct DispatchMessage<DispatchPayload, Fee> {
|
||||
/// All implementations of this trait should only work with finalized data that
|
||||
/// can't change. Wrong implementation may lead to invalid lane states (i.e. lane
|
||||
/// that's stuck) and/or processing messages without paying fees.
|
||||
pub trait SourceHeaderChain<Fee> {
|
||||
pub trait SourceHeaderChain {
|
||||
/// Error type.
|
||||
type Error: Debug + Into<&'static str>;
|
||||
|
||||
@@ -81,11 +79,11 @@ pub trait SourceHeaderChain<Fee> {
|
||||
fn verify_messages_proof(
|
||||
proof: Self::MessagesProof,
|
||||
messages_count: u32,
|
||||
) -> Result<ProvedMessages<Message<Fee>>, Self::Error>;
|
||||
) -> Result<ProvedMessages<Message>, Self::Error>;
|
||||
}
|
||||
|
||||
/// Called when inbound message is received.
|
||||
pub trait MessageDispatch<AccountId, Fee> {
|
||||
pub trait MessageDispatch<AccountId> {
|
||||
/// Decoded message payload type. Valid message may contain invalid payload. In this case
|
||||
/// message is delivered, but dispatch fails. Therefore, two separate types of payload
|
||||
/// (opaque `MessagePayload` used in delivery and this `DispatchPayload` used in dispatch).
|
||||
@@ -96,7 +94,7 @@ pub trait MessageDispatch<AccountId, Fee> {
|
||||
/// This function must return correct upper bound of dispatch weight. The return value
|
||||
/// 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>) -> Weight;
|
||||
|
||||
/// Called when inbound message is received.
|
||||
///
|
||||
@@ -107,7 +105,7 @@ pub trait MessageDispatch<AccountId, Fee> {
|
||||
/// it must be paid inside this method to the `relayer_account`.
|
||||
fn dispatch(
|
||||
relayer_account: &AccountId,
|
||||
message: DispatchMessage<Self::DispatchPayload, Fee>,
|
||||
message: DispatchMessage<Self::DispatchPayload>,
|
||||
) -> MessageDispatchResult;
|
||||
}
|
||||
|
||||
@@ -117,20 +115,15 @@ impl<Message> Default for ProvedLaneMessages<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DispatchPayload: Decode, Fee> From<Message<Fee>> for DispatchMessage<DispatchPayload, Fee> {
|
||||
fn from(message: Message<Fee>) -> Self {
|
||||
DispatchMessage { key: message.key, data: message.data.into() }
|
||||
impl<DispatchPayload: Decode> From<Message> for DispatchMessage<DispatchPayload> {
|
||||
fn from(message: Message) -> Self {
|
||||
DispatchMessage { key: message.key, data: message.payload.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<DispatchPayload: Decode, Fee> From<MessageData<Fee>>
|
||||
for DispatchMessageData<DispatchPayload, Fee>
|
||||
{
|
||||
fn from(data: MessageData<Fee>) -> Self {
|
||||
DispatchMessageData {
|
||||
payload: DispatchPayload::decode(&mut &data.payload[..]),
|
||||
fee: data.fee,
|
||||
}
|
||||
impl<DispatchPayload: Decode> From<MessagePayload> for DispatchMessageData<DispatchPayload> {
|
||||
fn from(payload: MessagePayload) -> Self {
|
||||
DispatchMessageData { payload: DispatchPayload::decode(&mut &payload[..]) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,29 +135,26 @@ pub struct ForbidInboundMessages;
|
||||
const ALL_INBOUND_MESSAGES_REJECTED: &str =
|
||||
"This chain is configured to reject all inbound messages";
|
||||
|
||||
impl<Fee> SourceHeaderChain<Fee> for ForbidInboundMessages {
|
||||
impl SourceHeaderChain for ForbidInboundMessages {
|
||||
type Error = &'static str;
|
||||
type MessagesProof = ();
|
||||
|
||||
fn verify_messages_proof(
|
||||
_proof: Self::MessagesProof,
|
||||
_messages_count: u32,
|
||||
) -> Result<ProvedMessages<Message<Fee>>, Self::Error> {
|
||||
) -> Result<ProvedMessages<Message>, Self::Error> {
|
||||
Err(ALL_INBOUND_MESSAGES_REJECTED)
|
||||
}
|
||||
}
|
||||
|
||||
impl<AccountId, Fee> MessageDispatch<AccountId, Fee> for ForbidInboundMessages {
|
||||
impl<AccountId> MessageDispatch<AccountId> for ForbidInboundMessages {
|
||||
type DispatchPayload = ();
|
||||
|
||||
fn dispatch_weight(_message: &mut DispatchMessage<Self::DispatchPayload, Fee>) -> Weight {
|
||||
fn dispatch_weight(_message: &mut DispatchMessage<Self::DispatchPayload>) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
|
||||
fn dispatch(
|
||||
_: &AccountId,
|
||||
_: DispatchMessage<Self::DispatchPayload, Fee>,
|
||||
) -> MessageDispatchResult {
|
||||
fn dispatch(_: &AccountId, _: DispatchMessage<Self::DispatchPayload>) -> MessageDispatchResult {
|
||||
MessageDispatchResult {
|
||||
dispatch_result: false,
|
||||
unspent_weight: Weight::zero(),
|
||||
|
||||
Reference in New Issue
Block a user