Integrate Rialto <-> Millau message lanes into Millau/Rialto runtimes (#386)

* millau -> rialto lanes integration

* extrace common message-lane integration types into bridge-runtime-common

* rialto_messages.rs in Millau runtime

* tests

* Update bin/rialto/runtime/src/millau_messages.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* RELAYER_INTEREST_PERCENT -> RELAYER_FEE_PERCENT

* Update bin/runtime-common/src/messages.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* estimate_message_dispatch_and_delivery_fee returns Result

* Update bin/rialto/runtime/src/millau_messages.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Update bin/rialto/runtime/src/millau_messages.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* Update bin/rialto/runtime/src/millau_messages.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* fmt

* mowed weight formula to primitives

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2020-10-26 10:03:47 +03:00
committed by Bastian Köcher
parent 3738bc4277
commit e2d9b6393d
17 changed files with 1138 additions and 25 deletions
+2 -2
View File
@@ -47,7 +47,7 @@ use sp_std::{marker::PhantomData, prelude::*};
pub type SpecVersion = u32;
/// Origin of the call on the target chain.
#[derive(RuntimeDebug, Encode, Decode, Clone)]
#[derive(RuntimeDebug, Encode, Decode, Clone, PartialEq, Eq)]
pub enum CallOrigin<SourceChainAccountPublic, TargetChainAccountPublic, TargetChainSignature> {
/// Call is originated from bridge account, which is (designed to be) specific to
/// the single deployed instance of the messages bridge (message-lane, ...) module.
@@ -67,7 +67,7 @@ pub enum CallOrigin<SourceChainAccountPublic, TargetChainAccountPublic, TargetCh
}
/// Message payload type used by call-dispatch module.
#[derive(RuntimeDebug, Encode, Decode, Clone)]
#[derive(RuntimeDebug, Encode, Decode, Clone, PartialEq, Eq)]
pub struct MessagePayload<SourceChainAccountPublic, TargetChainAccountPublic, TargetChainSignature, Call> {
/// Runtime specification version. We only dispatch messages that have the same
/// runtime version. Otherwise we risk to misinterpret encoded calls.
+2
View File
@@ -12,6 +12,7 @@ codec = { package = "parity-scale-codec", version = "1.3.1", default-features =
# Bridge dependencies
bp-message-lane = { path = "../../primitives/message-lane", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
# Substrate Dependencies
@@ -28,6 +29,7 @@ sp-io = "2.0"
default = ["std"]
std = [
"bp-message-lane/std",
"bp-runtime/std",
"codec/std",
"frame-support/std",
"frame-system/std",
@@ -0,0 +1,75 @@
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.
// Parity Bridges Common is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Bridges Common is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
//! Implementation of `MessageDeliveryAndDispatchPayment` trait on top of `Currency` trait.
//! All payments are instant.
use bp_message_lane::source_chain::MessageDeliveryAndDispatchPayment;
use bp_runtime::{bridge_account_id, MESSAGE_LANE_MODULE_PREFIX, NO_INSTANCE_ID};
use codec::Decode;
use frame_support::traits::{Currency as CurrencyT, ExistenceRequirement};
use sp_std::fmt::Debug;
/// Instant message payments made in given currency. Until claimed, fee is stored in special
/// 'relayers-fund' account.
pub struct InstantCurrencyPayments<AccountId, Currency> {
_phantom: sp_std::marker::PhantomData<(AccountId, Currency)>,
}
impl<AccountId, Currency> MessageDeliveryAndDispatchPayment<AccountId, Currency::Balance>
for InstantCurrencyPayments<AccountId, Currency>
where
Currency: CurrencyT<AccountId>,
AccountId: Debug + Default + Decode,
{
type Error = &'static str;
fn pay_delivery_and_dispatch_fee(submitter: &AccountId, fee: &Currency::Balance) -> Result<(), Self::Error> {
Currency::transfer(
submitter,
&relayers_fund_account(),
*fee,
ExistenceRequirement::AllowDeath,
)
.map_err(Into::into)
}
fn pay_relayer_reward(_confirmation_relayer: &AccountId, relayer: &AccountId, reward: &Currency::Balance) {
let pay_result = Currency::transfer(
&relayers_fund_account(),
relayer,
*reward,
ExistenceRequirement::AllowDeath,
);
// we can't actually do anything here, because rewards are paid as a part of unrelated transaction
if let Err(error) = pay_result {
frame_support::debug::trace!(
target: "runtime",
"Failed to pay relayer {:?} reward {:?}: {:?}",
relayer,
reward,
error,
);
}
}
}
/// Return account id of shared relayers-fund account that is storing all fees
/// paid by submitters, until they're claimed by relayers.
fn relayers_fund_account<AccountId: Default + Decode>() -> AccountId {
bridge_account_id(NO_INSTANCE_ID, MESSAGE_LANE_MODULE_PREFIX)
}
+2
View File
@@ -48,6 +48,8 @@ use sp_std::{cell::RefCell, marker::PhantomData, prelude::*};
mod inbound_lane;
mod outbound_lane;
pub mod instant_payments;
#[cfg(test)]
mod mock;