Skip to content

Commit

Permalink
Reintroduce header chain trait (paritytech#1622)
Browse files Browse the repository at this point in the history
* reintroduce header chain trait

* renive BridgedChainWithMessages::maximal_extrinsic_size
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent f04f540 commit 2e19b73
Show file tree
Hide file tree
Showing 19 changed files with 648 additions and 831 deletions.
39 changes: 11 additions & 28 deletions bridges/bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

//! Everything required to serve Millau <-> Rialto messages.

use crate::{OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};
use crate::{OriginCaller, RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
};
use bp_runtime::{Chain, ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{
self, BasicConfirmationTransactionEstimation, MessageBridge, MessageTransaction,
};
Expand Down Expand Up @@ -98,6 +98,8 @@ impl MessageBridge for WithRialtoMessageBridge {

type ThisChain = Millau;
type BridgedChain = Rialto;
type BridgedHeaderChain =
pallet_bridge_grandpa::GrandpaChainHeaders<Runtime, RialtoGrandpaInstance>;

fn bridged_balance_to_this_balance(
bridged_balance: bp_rialto::Balance,
Expand All @@ -115,18 +117,14 @@ impl MessageBridge for WithRialtoMessageBridge {
pub struct Millau;

impl messages::ChainWithMessages for Millau {
type Hash = bp_millau::Hash;
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
type Signature = bp_millau::Signature;
type Balance = bp_millau::Balance;
type Chain = bp_millau::Millau;
}

impl messages::ThisChainWithMessages for Millau {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type ConfirmationTransactionEstimation = BasicConfirmationTransactionEstimation<
Self::AccountId,
bp_millau::AccountId,
{ bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() },
{ bp_rialto::EXTRA_STORAGE_PROOF_SIZE },
{ bp_millau::TX_EXTRA_BYTES },
Expand Down Expand Up @@ -177,18 +175,10 @@ impl messages::ThisChainWithMessages for Millau {
pub struct Rialto;

impl messages::ChainWithMessages for Rialto {
type Hash = bp_rialto::Hash;
type AccountId = bp_rialto::AccountId;
type Signer = bp_rialto::AccountSigner;
type Signature = bp_rialto::Signature;
type Balance = bp_rialto::Balance;
type Chain = bp_rialto::Rialto;
}

impl messages::BridgedChainWithMessages for Rialto {
fn maximal_extrinsic_size() -> u32 {
bp_rialto::Rialto::max_extrinsic_size()
}

fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
}
Expand Down Expand Up @@ -248,11 +238,7 @@ impl TargetHeaderChain<ToRialtoMessagePayload, bp_millau::AccountId> for Rialto
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_millau::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<
WithRialtoMessageBridge,
Runtime,
crate::RialtoGrandpaInstance,
>(proof)
messages::source::verify_messages_delivery_proof::<WithRialtoMessageBridge>(proof)
}
}

Expand All @@ -269,11 +255,8 @@ impl SourceHeaderChain<bp_rialto::Balance> for Rialto {
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<bp_rialto::Balance>>, Self::Error> {
messages::target::verify_messages_proof::<
WithRialtoMessageBridge,
Runtime,
crate::RialtoGrandpaInstance,
>(proof, messages_count)
messages::target::verify_messages_proof::<WithRialtoMessageBridge>(proof, messages_count)
.map_err(Into::into)
}
}

Expand All @@ -296,7 +279,7 @@ impl MessagesParameter for MillauToRialtoMessagesParameter {
#[cfg(test)]
mod tests {
use super::*;
use crate::{DbWeight, RialtoGrandpaInstance, Runtime, WithRialtoMessagesInstance};
use crate::{DbWeight, Runtime, WithRialtoMessagesInstance};

use bp_runtime::Chain;
use bridge_runtime_common::{
Expand Down
46 changes: 16 additions & 30 deletions bridges/bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

//! Everything required to serve Millau <-> RialtoParachain messages.

use crate::{Runtime, RuntimeCall, RuntimeOrigin};
use crate::{Runtime, RuntimeCall, RuntimeOrigin, WithRialtoParachainsInstance};

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
};
use bp_polkadot_core::parachains::ParaId;
use bp_runtime::{Chain, ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bridge_runtime_common::messages::{
self, BasicConfirmationTransactionEstimation, MessageBridge, MessageTransaction,
};
Expand Down Expand Up @@ -103,6 +102,11 @@ impl MessageBridge for WithRialtoParachainMessageBridge {

type ThisChain = Millau;
type BridgedChain = RialtoParachain;
type BridgedHeaderChain = pallet_bridge_parachains::ParachainHeaders<
Runtime,
WithRialtoParachainsInstance,
bp_rialto_parachain::RialtoParachain,
>;

fn bridged_balance_to_this_balance(
bridged_balance: bp_rialto_parachain::Balance,
Expand All @@ -120,18 +124,14 @@ impl MessageBridge for WithRialtoParachainMessageBridge {
pub struct Millau;

impl messages::ChainWithMessages for Millau {
type Hash = bp_millau::Hash;
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
type Signature = bp_millau::Signature;
type Balance = bp_millau::Balance;
type Chain = bp_millau::Millau;
}

impl messages::ThisChainWithMessages for Millau {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;
type ConfirmationTransactionEstimation = BasicConfirmationTransactionEstimation<
Self::AccountId,
bp_rialto_parachain::AccountId,
{ bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() },
{ bp_rialto_parachain::EXTRA_STORAGE_PROOF_SIZE },
{ bp_millau::TX_EXTRA_BYTES },
Expand Down Expand Up @@ -166,18 +166,10 @@ impl messages::ThisChainWithMessages for Millau {
pub struct RialtoParachain;

impl messages::ChainWithMessages for RialtoParachain {
type Hash = bp_rialto_parachain::Hash;
type AccountId = bp_rialto_parachain::AccountId;
type Signer = bp_rialto_parachain::AccountSigner;
type Signature = bp_rialto_parachain::Signature;
type Balance = bp_rialto_parachain::Balance;
type Chain = bp_rialto_parachain::RialtoParachain;
}

impl messages::BridgedChainWithMessages for RialtoParachain {
fn maximal_extrinsic_size() -> u32 {
bp_rialto_parachain::RialtoParachain::max_extrinsic_size()
}

fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
}
Expand Down Expand Up @@ -241,12 +233,7 @@ impl TargetHeaderChain<ToRialtoParachainMessagePayload, bp_millau::AccountId> fo
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_millau::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof_from_parachain::<
WithRialtoParachainMessageBridge,
bp_rialto_parachain::Header,
Runtime,
crate::WithRialtoParachainsInstance,
>(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof)
messages::source::verify_messages_delivery_proof::<WithRialtoParachainMessageBridge>(proof)
}
}

Expand All @@ -263,12 +250,11 @@ impl SourceHeaderChain<bp_rialto_parachain::Balance> for RialtoParachain {
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<bp_rialto_parachain::Balance>>, Self::Error> {
messages::target::verify_messages_proof_from_parachain::<
WithRialtoParachainMessageBridge,
bp_rialto_parachain::Header,
Runtime,
crate::WithRialtoParachainsInstance,
>(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof, messages_count)
messages::target::verify_messages_proof::<WithRialtoParachainMessageBridge>(
proof,
messages_count,
)
.map_err(Into::into)
}
}

Expand Down
37 changes: 10 additions & 27 deletions bridges/bin/rialto-parachain/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
// TODO: this is almost exact copy of `millau_messages.rs` from Rialto runtime.
// Should be extracted to a separate crate and reused here.

use crate::{OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};
use crate::{MillauGrandpaInstance, OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
};
use bp_runtime::{Chain, ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bridge_runtime_common::messages::{
self, BasicConfirmationTransactionEstimation, MessageBridge, MessageTransaction,
};
Expand Down Expand Up @@ -102,6 +102,8 @@ impl MessageBridge for WithMillauMessageBridge {

type ThisChain = RialtoParachain;
type BridgedChain = Millau;
type BridgedHeaderChain =
pallet_bridge_grandpa::GrandpaChainHeaders<Runtime, MillauGrandpaInstance>;

fn bridged_balance_to_this_balance(
bridged_balance: bp_millau::Balance,
Expand All @@ -119,18 +121,14 @@ impl MessageBridge for WithMillauMessageBridge {
pub struct RialtoParachain;

impl messages::ChainWithMessages for RialtoParachain {
type Hash = bp_rialto_parachain::Hash;
type AccountId = bp_rialto_parachain::AccountId;
type Signer = bp_rialto_parachain::AccountSigner;
type Signature = bp_rialto_parachain::Signature;
type Balance = bp_rialto_parachain::Balance;
type Chain = bp_rialto_parachain::RialtoParachain;
}

impl messages::ThisChainWithMessages for RialtoParachain {
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;
type ConfirmationTransactionEstimation = BasicConfirmationTransactionEstimation<
Self::AccountId,
bp_rialto_parachain::AccountId,
{ bp_rialto_parachain::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() },
{ bp_millau::EXTRA_STORAGE_PROOF_SIZE },
{ bp_rialto_parachain::TX_EXTRA_BYTES },
Expand Down Expand Up @@ -184,18 +182,10 @@ impl messages::ThisChainWithMessages for RialtoParachain {
pub struct Millau;

impl messages::ChainWithMessages for Millau {
type Hash = bp_millau::Hash;
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
type Signature = bp_millau::Signature;
type Balance = bp_millau::Balance;
type Chain = bp_millau::Millau;
}

impl messages::BridgedChainWithMessages for Millau {
fn maximal_extrinsic_size() -> u32 {
bp_millau::Millau::max_extrinsic_size()
}

fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
}
Expand Down Expand Up @@ -255,11 +245,7 @@ impl TargetHeaderChain<ToMillauMessagePayload, bp_rialto_parachain::AccountId> f
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_rialto_parachain::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<
WithMillauMessageBridge,
Runtime,
crate::MillauGrandpaInstance,
>(proof)
messages::source::verify_messages_delivery_proof::<WithMillauMessageBridge>(proof)
}
}

Expand All @@ -276,11 +262,8 @@ impl SourceHeaderChain<bp_millau::Balance> for Millau {
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<bp_millau::Balance>>, Self::Error> {
messages::target::verify_messages_proof::<
WithMillauMessageBridge,
Runtime,
crate::MillauGrandpaInstance,
>(proof, messages_count)
messages::target::verify_messages_proof::<WithMillauMessageBridge>(proof, messages_count)
.map_err(Into::into)
}
}

Expand Down
37 changes: 10 additions & 27 deletions bridges/bin/rialto/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

//! Everything required to serve Millau <-> Rialto messages.

use crate::{OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};
use crate::{MillauGrandpaInstance, OriginCaller, Runtime, RuntimeCall, RuntimeOrigin};

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
};
use bp_runtime::{Chain, ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{
self, BasicConfirmationTransactionEstimation, MessageBridge, MessageTransaction,
};
Expand Down Expand Up @@ -96,6 +96,8 @@ impl MessageBridge for WithMillauMessageBridge {

type ThisChain = Rialto;
type BridgedChain = Millau;
type BridgedHeaderChain =
pallet_bridge_grandpa::GrandpaChainHeaders<Runtime, MillauGrandpaInstance>;

fn bridged_balance_to_this_balance(
bridged_balance: bp_millau::Balance,
Expand All @@ -113,18 +115,14 @@ impl MessageBridge for WithMillauMessageBridge {
pub struct Rialto;

impl messages::ChainWithMessages for Rialto {
type Hash = bp_rialto::Hash;
type AccountId = bp_rialto::AccountId;
type Signer = bp_rialto::AccountSigner;
type Signature = bp_rialto::Signature;
type Balance = bp_rialto::Balance;
type Chain = bp_rialto::Rialto;
}

impl messages::ThisChainWithMessages for Rialto {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type ConfirmationTransactionEstimation = BasicConfirmationTransactionEstimation<
Self::AccountId,
bp_rialto::AccountId,
{ bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT.ref_time() },
{ bp_millau::EXTRA_STORAGE_PROOF_SIZE },
{ bp_rialto::TX_EXTRA_BYTES },
Expand Down Expand Up @@ -175,18 +173,10 @@ impl messages::ThisChainWithMessages for Rialto {
pub struct Millau;

impl messages::ChainWithMessages for Millau {
type Hash = bp_millau::Hash;
type AccountId = bp_millau::AccountId;
type Signer = bp_millau::AccountSigner;
type Signature = bp_millau::Signature;
type Balance = bp_millau::Balance;
type Chain = bp_millau::Millau;
}

impl messages::BridgedChainWithMessages for Millau {
fn maximal_extrinsic_size() -> u32 {
bp_millau::Millau::max_extrinsic_size()
}

fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
true
}
Expand Down Expand Up @@ -246,11 +236,7 @@ impl TargetHeaderChain<ToMillauMessagePayload, bp_rialto::AccountId> for Millau
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_rialto::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<
WithMillauMessageBridge,
Runtime,
crate::MillauGrandpaInstance,
>(proof)
messages::source::verify_messages_delivery_proof::<WithMillauMessageBridge>(proof)
}
}

Expand All @@ -267,11 +253,8 @@ impl SourceHeaderChain<bp_millau::Balance> for Millau {
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<bp_millau::Balance>>, Self::Error> {
messages::target::verify_messages_proof::<
WithMillauMessageBridge,
Runtime,
crate::MillauGrandpaInstance,
>(proof, messages_count)
messages::target::verify_messages_proof::<WithMillauMessageBridge>(proof, messages_count)
.map_err(Into::into)
}
}

Expand Down
Loading

0 comments on commit 2e19b73

Please sign in to comment.