New relayer rewards scheme integration (#1652)

* relayer rewards integration: initial commit

* added refund-relayer-extension to the millau runtime

* spelling

* spelling again

* new -> Default
This commit is contained in:
Svyatoslav Nikolsky
2022-12-09 17:19:02 +03:00
committed by Bastian Köcher
parent 161d861d9b
commit 2c5e2f09eb
11 changed files with 158 additions and 138 deletions
@@ -16,7 +16,7 @@
//! Primitives of messages module, that are used on the target chain.
use crate::{LaneId, Message, MessageKey, MessagePayload, OutboundLaneData};
use crate::{LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData};
use bp_runtime::{messages::MessageDispatchResult, Size};
use codec::{Decode, Encode, Error as CodecError};
@@ -112,6 +112,25 @@ pub trait MessageDispatch<AccountId> {
) -> MessageDispatchResult<Self::DispatchLevelResult>;
}
/// Manages payments that are happening at the target chain during message delivery transaction.
pub trait DeliveryPayments<AccountId> {
/// Error type.
type Error: Debug + Into<&'static str>;
/// Pay rewards for delivering messages to the given relayer.
///
/// This method is called during message delivery transaction which has been submitted
/// by the `relayer`. The transaction brings `total_messages` messages but only
/// `valid_messages` have been accepted. The post-dispatch transaction weight is the
/// `actual_weight`.
fn pay_reward(
relayer: AccountId,
total_messages: MessageNonce,
valid_messages: MessageNonce,
actual_weight: Weight,
);
}
impl<Message> Default for ProvedLaneMessages<Message> {
fn default() -> Self {
ProvedLaneMessages { lane_state: None, messages: Vec::new() }
@@ -130,6 +149,19 @@ impl<DispatchPayload: Decode> From<MessagePayload> for DispatchMessageData<Dispa
}
}
impl<AccountId> DeliveryPayments<AccountId> for () {
type Error = &'static str;
fn pay_reward(
_relayer: AccountId,
_total_messages: MessageNonce,
_valid_messages: MessageNonce,
_actual_weight: Weight,
) {
// this implementation is not rewarding relayer at all
}
}
/// Structure that may be used in place of `SourceHeaderChain` and `MessageDispatch` on chains,
/// where inbound messages are forbidden.
pub struct ForbidInboundMessages;