pay dispatch fee at target chain (#911)

* pay dispatch fee at target chain

* refund unspent dispatch weight to messages relayer

* test that transfer actually happens

* pay-at-target-cchain benchmarks + fix previous benchmarks (invalid signature)

* include/exclude pay-dispatch-fee weight from delivery_and_dispatch_fee/delivery tx cost

* remvoe some redundant traces

* enum DispatchFeePayment {}

* typo

* update docs

* (revert removal of valid check)

* Update modules/messages/src/benchmarking.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update modules/messages/src/benchmarking.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update modules/messages/src/benchmarking.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* Update modules/messages/src/benchmarking.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2021-06-18 12:35:15 +03:00
committed by Bastian Köcher
parent 613803a15d
commit 20b7f341e1
27 changed files with 1052 additions and 278 deletions
@@ -18,7 +18,7 @@
use crate::{LaneId, Message, MessageData, MessageKey, OutboundLaneData};
use bp_runtime::Size;
use bp_runtime::{messages::MessageDispatchResult, Size};
use codec::{Decode, Encode, Error as CodecError};
use frame_support::{weights::Weight, Parameter, RuntimeDebug};
use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, prelude::*};
@@ -84,7 +84,7 @@ pub trait SourceHeaderChain<Fee> {
}
/// Called when inbound message is received.
pub trait MessageDispatch<Fee> {
pub trait MessageDispatch<AccountId, Fee> {
/// 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).
@@ -100,7 +100,13 @@ pub trait MessageDispatch<Fee> {
///
/// It is up to the implementers of this trait to determine whether the message
/// is invalid (i.e. improperly encoded, has too large weight, ...) or not.
fn dispatch(message: DispatchMessage<Self::DispatchPayload, Fee>);
///
/// If your configuration allows paying dispatch fee at the target chain, then
/// it must be paid inside this method to the `relayer_account`.
fn dispatch(
relayer_account: &AccountId,
message: DispatchMessage<Self::DispatchPayload, Fee>,
) -> MessageDispatchResult;
}
impl<Message> Default for ProvedLaneMessages<Message> {
@@ -149,12 +155,17 @@ impl<Fee> SourceHeaderChain<Fee> for ForbidInboundMessages {
}
}
impl<Fee> MessageDispatch<Fee> for ForbidInboundMessages {
impl<AccountId, Fee> MessageDispatch<AccountId, Fee> for ForbidInboundMessages {
type DispatchPayload = ();
fn dispatch_weight(_message: &DispatchMessage<Self::DispatchPayload, Fee>) -> Weight {
Weight::MAX
}
fn dispatch(_message: DispatchMessage<Self::DispatchPayload, Fee>) {}
fn dispatch(_: &AccountId, _: DispatchMessage<Self::DispatchPayload, Fee>) -> MessageDispatchResult {
MessageDispatchResult {
unspent_weight: 0,
dispatch_fee_paid_during_dispatch: false,
}
}
}