Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove chain-specific dependencies from crates that will be used in Cumulus #1783

Merged
merged 15 commits into from
Jan 20, 2023
Merged
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,15 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type InboundRelayer = bp_rialto::AccountId;
type DeliveryPayments = ();

type TargetHeaderChain = crate::rialto_messages::Rialto;
type TargetHeaderChain = crate::rialto_messages::RialtoAsTargetHeaderChain;
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
frame_support::traits::ConstU64<100_000>,
frame_support::traits::ConstU64<10_000>,
>;

type SourceHeaderChain = crate::rialto_messages::Rialto;
type SourceHeaderChain = crate::rialto_messages::RialtoAsSourceHeaderChain;
type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch;
type BridgedChainId = RialtoChainId;
}
Expand All @@ -504,15 +504,15 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
type InboundRelayer = bp_rialto_parachain::AccountId;
type DeliveryPayments = ();

type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachain;
type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachainAsTargetHeaderChain;
type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
frame_support::traits::ConstU64<100_000>,
frame_support::traits::ConstU64<10_000>,
>;

type SourceHeaderChain = crate::rialto_parachain_messages::RialtoParachain;
type SourceHeaderChain = crate::rialto_parachain_messages::RialtoParachainAsSourceHeaderChain;
type MessageDispatch = crate::rialto_parachain_messages::FromRialtoParachainMessageDispatch;
type BridgedChainId = RialtoParachainChainId;
}
Expand Down
51 changes: 8 additions & 43 deletions bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

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

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
};
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
use bridge_runtime_common::messages::{self, MessageBridge};
use bridge_runtime_common::messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Default lane that is used to send messages to Rialto.
Expand Down Expand Up @@ -110,6 +108,10 @@ impl messages::ThisChainWithMessages for Millau {
/// Rialto chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct Rialto;
/// Rialto as source header chain.
pub type RialtoAsSourceHeaderChain = SourceHeaderChainAdapter<WithRialtoMessageBridge>;
/// Rialto as target header chain.
pub type RialtoAsTargetHeaderChain = TargetHeaderChainAdapter<WithRialtoMessageBridge>;

impl messages::UnderlyingChainProvider for Rialto {
type Chain = bp_rialto::Rialto;
Expand All @@ -121,43 +123,6 @@ impl messages::BridgedChainWithMessages for Rialto {
}
}

impl TargetHeaderChain<ToRialtoMessagePayload, bp_millau::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 = ToRialtoMessagesDeliveryProof;

fn verify_message(payload: &ToRialtoMessagePayload) -> Result<(), Self::Error> {
messages::source::verify_chain_message::<WithRialtoMessageBridge>(payload)
}

fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_millau::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<WithRialtoMessageBridge>(proof)
}
}

impl SourceHeaderChain 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 = FromRialtoMessagesProof;

fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message>, Self::Error> {
messages::target::verify_messages_proof::<WithRialtoMessageBridge>(proof, messages_count)
.map_err(Into::into)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
64 changes: 10 additions & 54 deletions bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

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

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
};
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bridge_runtime_common::messages::{self, MessageBridge};
use bridge_runtime_common::messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Default lane that is used to send messages to Rialto parachain.
Expand Down Expand Up @@ -53,14 +51,6 @@ pub type ToRialtoParachainMessageVerifier =
pub type FromRialtoParachainMessagePayload =
messages::target::FromBridgedChainMessagePayload<RuntimeCall>;

/// Messages proof for RialtoParachain -> Millau messages.
type FromRialtoParachainMessagesProof =
messages::target::FromBridgedChainMessagesProof<bp_rialto_parachain::Hash>;

/// Messages delivery proof for Millau -> RialtoParachain messages.
type ToRialtoParachainMessagesDeliveryProof =
messages::source::FromBridgedChainMessagesDeliveryProof<bp_rialto_parachain::Hash>;

/// Call-dispatch based message dispatch for RialtoParachain -> Millau messages.
pub type FromRialtoParachainMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
WithRialtoParachainMessageBridge,
Expand Down Expand Up @@ -115,6 +105,12 @@ impl messages::ThisChainWithMessages for Millau {
/// RialtoParachain chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct RialtoParachain;
/// RialtoParachain as source header chain.
pub type RialtoParachainAsSourceHeaderChain =
SourceHeaderChainAdapter<WithRialtoParachainMessageBridge>;
/// RialtoParachain as target header chain.
pub type RialtoParachainAsTargetHeaderChain =
TargetHeaderChainAdapter<WithRialtoParachainMessageBridge>;

impl messages::UnderlyingChainProvider for RialtoParachain {
type Chain = bp_rialto_parachain::RialtoParachain;
Expand All @@ -125,43 +121,3 @@ impl messages::BridgedChainWithMessages for RialtoParachain {
true
}
}

impl TargetHeaderChain<ToRialtoParachainMessagePayload, bp_millau::AccountId> for RialtoParachain {
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 = ToRialtoParachainMessagesDeliveryProof;

fn verify_message(payload: &ToRialtoParachainMessagePayload) -> Result<(), Self::Error> {
messages::source::verify_chain_message::<WithRialtoParachainMessageBridge>(payload)
}

fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_millau::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<WithRialtoParachainMessageBridge>(proof)
}
}

impl SourceHeaderChain for RialtoParachain {
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 = FromRialtoParachainMessagesProof;

fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message>, Self::Error> {
messages::target::verify_messages_proof::<WithRialtoParachainMessageBridge>(
proof,
messages_count,
)
.map_err(Into::into)
}
}
4 changes: 2 additions & 2 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type InboundRelayer = bp_millau::AccountId;
type DeliveryPayments = ();

type TargetHeaderChain = crate::millau_messages::Millau;
type TargetHeaderChain = crate::millau_messages::MillauAsTargetHeaderChain;
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
frame_support::traits::ConstU128<100_000>,
frame_support::traits::ConstU128<100_000>,
>;

type SourceHeaderChain = crate::millau_messages::Millau;
type SourceHeaderChain = crate::millau_messages::MillauAsSourceHeaderChain;
type MessageDispatch = crate::millau_messages::FromMillauMessageDispatch;
type BridgedChainId = BridgedChainId;
}
Expand Down
51 changes: 8 additions & 43 deletions bin/rialto-parachain/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

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

use bp_messages::{
source_chain::TargetHeaderChain,
target_chain::{ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, MessageNonce,
};
use bp_messages::{LaneId, MessageNonce};
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_PARACHAIN_CHAIN_ID};
use bridge_runtime_common::messages::{self, MessageBridge};
use bridge_runtime_common::messages::{
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
};
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};

/// Default lane that is used to send messages to Millau.
Expand Down Expand Up @@ -114,6 +112,10 @@ impl messages::ThisChainWithMessages for RialtoParachain {
/// Millau chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct Millau;
/// Millau as source header chain.
pub type MillauAsSourceHeaderChain = SourceHeaderChainAdapter<WithMillauMessageBridge>;
/// Millau as target header chain.
pub type MillauAsTargetHeaderChain = TargetHeaderChainAdapter<WithMillauMessageBridge>;

impl messages::UnderlyingChainProvider for Millau {
type Chain = bp_millau::Millau;
Expand All @@ -124,40 +126,3 @@ impl messages::BridgedChainWithMessages for Millau {
true
}
}

impl TargetHeaderChain<ToMillauMessagePayload, bp_rialto_parachain::AccountId> for Millau {
type Error = &'static str;
// The proof is:
// - hash of the header this proof has been created with;
// - the storage proof of one or several keys;
// - id of the lane we prove state of.
type MessagesDeliveryProof = ToMillauMessagesDeliveryProof;

fn verify_message(payload: &ToMillauMessagePayload) -> Result<(), Self::Error> {
messages::source::verify_chain_message::<WithMillauMessageBridge>(payload)
}

fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<(LaneId, InboundLaneData<bp_rialto_parachain::AccountId>), Self::Error> {
messages::source::verify_messages_delivery_proof::<WithMillauMessageBridge>(proof)
}
}

impl SourceHeaderChain for Millau {
type Error = &'static str;
// The proof is:
// - hash of the header this proof has been created with;
// - the storage proof of one or several keys;
// - id of the lane we prove messages for;
// - inclusive range of messages nonces that are proved.
type MessagesProof = FromMillauMessagesProof;

fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message>, Self::Error> {
messages::target::verify_messages_proof::<WithMillauMessageBridge>(proof, messages_count)
.map_err(Into::into)
}
}
4 changes: 2 additions & 2 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
type InboundRelayer = bp_millau::AccountId;
type DeliveryPayments = ();

type TargetHeaderChain = crate::millau_messages::Millau;
type TargetHeaderChain = crate::millau_messages::MillauAsTargetHeaderChain;
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
frame_support::traits::ConstU128<100_000>,
frame_support::traits::ConstU128<100_000>,
>;

type SourceHeaderChain = crate::millau_messages::Millau;
type SourceHeaderChain = crate::millau_messages::MillauAsSourceHeaderChain;
type MessageDispatch = crate::millau_messages::FromMillauMessageDispatch;
type BridgedChainId = BridgedChainId;
}
Expand Down
Loading