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
+6
View File
@@ -17,6 +17,8 @@ serde = { version = "1.0.117", optional = true, features = ["derive"] }
bp-message-lane = { path = "../../../primitives/message-lane", default-features = false }
bp-millau = { path = "../../../primitives/millau", default-features = false }
bp-rialto = { path = "../../../primitives/rialto", default-features = false }
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
bridge-runtime-common = { path = "../../runtime-common", default-features = false }
pallet-bridge-call-dispatch = { path = "../../../modules/call-dispatch", default-features = false }
pallet-message-lane = { path = "../../../modules/message-lane", default-features = false }
pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false }
@@ -47,6 +49,7 @@ sp-runtime = { version = "2.0", default-features = false }
sp-session = { version = "2.0", default-features = false }
sp-std = { version = "2.0", default-features = false }
sp-transaction-pool = { version = "2.0", default-features = false }
sp-trie = { version = "2.0", default-features = false }
sp-version = { version = "2.0", default-features = false }
[build-dependencies]
@@ -58,6 +61,8 @@ std = [
"bp-message-lane/std",
"bp-millau/std",
"bp-rialto/std",
"bp-runtime/std",
"bridge-runtime-common/std",
"codec/std",
"frame-executive/std",
"frame-support/std",
@@ -87,5 +92,6 @@ std = [
"sp-session/std",
"sp-std/std",
"sp-transaction-pool/std",
"sp-trie/std",
"sp-version/std",
]
+35 -9
View File
@@ -29,12 +29,13 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub mod rialto;
pub mod rialto_messages;
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::traits::{Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, OpaqueKeys, Saturating, Verify};
use sp_runtime::traits::{Block as BlockT, IdentityLookup, NumberFor, OpaqueKeys};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
transaction_validity::{TransactionSource, TransactionValidity},
@@ -65,18 +66,18 @@ pub use sp_runtime::{Perbill, Permill};
pub type BlockNumber = bp_millau::BlockNumber;
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
pub type Signature = MultiSignature;
pub type Signature = bp_millau::Signature;
/// Some way of identifying an account on the chain. We intentionally make it equivalent
/// to the public key of our transaction signing scheme.
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
pub type AccountId = bp_millau::AccountId;
/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
/// never know...
pub type AccountIndex = u32;
/// Balance of an account.
pub type Balance = u128;
pub type Balance = bp_millau::Balance;
/// Index of a transaction in the chain.
pub type Index = u32;
@@ -145,12 +146,10 @@ pub fn native_version() -> NativeVersion {
parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 2_000_000_000_000;
pub const MaximumBlockWeight: Weight = bp_millau::MAXIMUM_BLOCK_WEIGHT;
pub const ExtrinsicBaseWeight: Weight = 10_000_000;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
/// Assume 10% of weight for average on_initialize calls.
pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()
.saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(bp_millau::AVAILABLE_BLOCK_RATIO);
pub MaximumExtrinsicWeight: Weight = bp_millau::MAXIMUM_EXTRINSIC_WEIGHT;
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight {
@@ -317,6 +316,32 @@ impl pallet_substrate_bridge::Trait for Runtime {
impl pallet_shift_session_manager::Trait for Runtime {}
parameter_types! {
pub const MaxMessagesToPruneAtOnce: bp_message_lane::MessageNonce = 8;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = 128;
}
impl pallet_message_lane::Trait for Runtime {
type Event = Event;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
type OutboundPayload = crate::rialto_messages::ToRialtoMessagePayload;
type OutboundMessageFee = Balance;
type InboundPayload = crate::rialto_messages::FromRialtoMessagePayload;
type InboundMessageFee = bp_rialto::Balance;
type InboundRelayer = bp_rialto::AccountId;
type TargetHeaderChain = crate::rialto_messages::Rialto;
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
type MessageDeliveryAndDispatchPayment =
pallet_message_lane::instant_payments::InstantCurrencyPayments<AccountId, pallet_balances::Module<Runtime>>;
type SourceHeaderChain = crate::rialto_messages::Rialto;
type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch;
}
construct_runtime!(
pub enum Runtime where
Block = Block,
@@ -324,6 +349,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
BridgeRialto: pallet_substrate_bridge::{Module, Call, Storage, Config<T>},
BridgeRialtoMessageLane: pallet_message_lane::{Module, Call, Event<T>},
BridgeCallDispatch: pallet_bridge_call_dispatch::{Module, Event<T>},
System: frame_system::{Module, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
@@ -0,0 +1,157 @@
// 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/>.
//! Everything required to serve Millau <-> Rialto message lanes.
use bridge_runtime_common::messages;
use bp_message_lane::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
};
use bp_runtime::InstanceId;
use bridge_runtime_common::messages::MessageBridge;
use frame_support::{
weights::{Weight, WeightToFeePolynomial},
RuntimeDebug,
};
use sp_trie::StorageProof;
/// Message payload for Millau -> Rialto messages.
pub type ToRialtoMessagePayload = messages::source::FromThisChainMessagePayload<WithRialtoMessageBridge>;
/// Message verifier for Millau -> Rialto messages.
pub type ToRialtoMessageVerifier = messages::source::FromThisChainMessageVerifier<WithRialtoMessageBridge>;
/// Message payload for Rialto -> Millau messages.
pub type FromRialtoMessagePayload = messages::target::FromBridgedChainMessagePayload<WithRialtoMessageBridge>;
/// Call-dispatch based message dispatch for Rialto -> Millau messages.
pub type FromRialtoMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
WithRialtoMessageBridge,
crate::Runtime,
pallet_bridge_call_dispatch::DefaultInstance,
>;
/// Millau <-> Rialto message bridge.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct WithRialtoMessageBridge;
impl MessageBridge for WithRialtoMessageBridge {
const INSTANCE: InstanceId = *b"rlto";
const RELAYER_FEE_PERCENT: u32 = 10;
type ThisChain = Millau;
type BridgedChain = Rialto;
fn maximal_dispatch_weight_of_message_on_bridged_chain() -> Weight {
// we don't want to relay too large messages + keep reserve for future upgrades
bp_rialto::MAXIMUM_EXTRINSIC_WEIGHT / 2
}
fn weight_of_delivery_transaction() -> Weight {
0 // TODO: https://github.com/paritytech/parity-bridges-common/issues/391
}
fn weight_of_delivery_confirmation_transaction_on_this_chain() -> Weight {
0 // TODO: https://github.com/paritytech/parity-bridges-common/issues/391
}
fn weight_of_reward_confirmation_transaction_on_target_chain() -> Weight {
0 // TODO: https://github.com/paritytech/parity-bridges-common/issues/391
}
fn this_weight_to_balance(weight: Weight) -> bp_rialto::Balance {
<crate::Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight)
}
fn bridged_weight_to_balance(weight: Weight) -> bp_millau::Balance {
// we're using the same weights in both chains now
<crate::Runtime as pallet_transaction_payment::Trait>::WeightToFee::calc(&weight)
}
fn this_chain_balance_to_bridged_chain_balance(this_balance: bp_rialto::Balance) -> bp_millau::Balance {
// 1:1 conversion that will probably change in the future
this_balance
}
}
/// Millau chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct Millau;
impl messages::ChainWithMessageLanes for Millau {
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
type Signature = bp_millau::Signature;
type Call = crate::Call;
type Weight = Weight;
type Balance = bp_millau::Balance;
}
/// Rialto chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct Rialto;
impl messages::ChainWithMessageLanes for Rialto {
type AccountId = bp_rialto::AccountId;
type Signer = bp_rialto::AccountSigner;
type Signature = bp_rialto::Signature;
type Call = (); // unknown to us
type Weight = Weight;
type Balance = bp_rialto::Balance;
}
impl TargetHeaderChain<ToRialtoMessagePayload, bp_rialto::AccountId> for Rialto {
type Error = &'static str;
// The proof is:
// - hash of the header this proof has been created with;
// - the storage proof or one or several keys;
// - id of the lane we prove state of.
type MessagesDeliveryProof = (bp_rialto::Hash, StorageProof, LaneId);
fn verify_message(payload: &ToRialtoMessagePayload) -> Result<(), Self::Error> {
if payload.weight > WithRialtoMessageBridge::maximal_dispatch_weight_of_message_on_bridged_chain() {
return Err("Too large weight declared");
}
Ok(())
}
fn verify_messages_delivery_proof(
_proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_rialto::AccountId>), Self::Error> {
unimplemented!("https://github.com/paritytech/parity-bridges-common/issues/397")
}
}
impl SourceHeaderChain<bp_rialto::Balance> for Rialto {
type Error = &'static str;
// The proof is:
// - hash of the header this proof has been created with;
// - the storage proof or one or several keys;
// - id of the lane we prove messages for;
// - inclusive range of messages nonces that are proved.
type MessagesProof = (bp_rialto::Hash, StorageProof, LaneId, MessageNonce, MessageNonce);
fn verify_messages_proof(
_proof: Self::MessagesProof,
) -> Result<ProvedMessages<Message<bp_rialto::Balance>>, Self::Error> {
unimplemented!("https://github.com/paritytech/parity-bridges-common/issues/397")
}
}