mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
Remove chain-specific dependencies from crates that will be used in Cumulus (#1783)
* leave-modules.sh * remove bp-rialto dependency from bp-relayers * update leave-modules.sh * fix Cargo.toml of pallet-bridge-relayers * update leave-modules.sh * remove bp-rialto and millau-runtime frombridge-runtime-common Cargo.toml * update leave-modules.sh * remove chain dependencies from bridge-runtime-common crate * fix tests * cleanup script * rename script * kind of success message * remove leave-modules.sh * use TargetHeaderChainAdapter and SourceHeaderChainAdapter in our testnets * update script
This commit is contained in:
committed by
Bastian Köcher
parent
9465ef6071
commit
ec9cd8ddb0
@@ -473,7 +473,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
|
|||||||
type InboundRelayer = bp_rialto::AccountId;
|
type InboundRelayer = bp_rialto::AccountId;
|
||||||
type DeliveryPayments = ();
|
type DeliveryPayments = ();
|
||||||
|
|
||||||
type TargetHeaderChain = crate::rialto_messages::Rialto;
|
type TargetHeaderChain = crate::rialto_messages::RialtoAsTargetHeaderChain;
|
||||||
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
|
type LaneMessageVerifier = crate::rialto_messages::ToRialtoMessageVerifier;
|
||||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||||
Runtime,
|
Runtime,
|
||||||
@@ -481,7 +481,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
|
|||||||
frame_support::traits::ConstU64<10_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 MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch;
|
||||||
type BridgedChainId = RialtoChainId;
|
type BridgedChainId = RialtoChainId;
|
||||||
}
|
}
|
||||||
@@ -504,7 +504,7 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
|
|||||||
type InboundRelayer = bp_rialto_parachain::AccountId;
|
type InboundRelayer = bp_rialto_parachain::AccountId;
|
||||||
type DeliveryPayments = ();
|
type DeliveryPayments = ();
|
||||||
|
|
||||||
type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachain;
|
type TargetHeaderChain = crate::rialto_parachain_messages::RialtoParachainAsTargetHeaderChain;
|
||||||
type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier;
|
type LaneMessageVerifier = crate::rialto_parachain_messages::ToRialtoParachainMessageVerifier;
|
||||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||||
Runtime,
|
Runtime,
|
||||||
@@ -512,7 +512,7 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
|
|||||||
frame_support::traits::ConstU64<10_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 MessageDispatch = crate::rialto_parachain_messages::FromRialtoParachainMessageDispatch;
|
||||||
type BridgedChainId = RialtoParachainChainId;
|
type BridgedChainId = RialtoParachainChainId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,11 @@
|
|||||||
|
|
||||||
use crate::{RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
|
use crate::{RialtoGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
|
||||||
|
|
||||||
use bp_messages::{
|
use bp_messages::{LaneId, MessageNonce};
|
||||||
source_chain::TargetHeaderChain,
|
|
||||||
target_chain::{ProvedMessages, SourceHeaderChain},
|
|
||||||
InboundLaneData, LaneId, Message, MessageNonce,
|
|
||||||
};
|
|
||||||
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
|
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};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
|
|
||||||
/// Default lane that is used to send messages to Rialto.
|
/// Default lane that is used to send messages to Rialto.
|
||||||
@@ -110,6 +108,10 @@ impl messages::ThisChainWithMessages for Millau {
|
|||||||
/// Rialto chain from message lane point of view.
|
/// Rialto chain from message lane point of view.
|
||||||
#[derive(RuntimeDebug, Clone, Copy)]
|
#[derive(RuntimeDebug, Clone, Copy)]
|
||||||
pub struct Rialto;
|
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 {
|
impl messages::UnderlyingChainProvider for Rialto {
|
||||||
type Chain = bp_rialto::Rialto;
|
type Chain = bp_rialto::Rialto;
|
||||||
@@ -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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -18,13 +18,11 @@
|
|||||||
|
|
||||||
use crate::{Runtime, RuntimeCall, RuntimeOrigin, WithRialtoParachainsInstance};
|
use crate::{Runtime, RuntimeCall, RuntimeOrigin, WithRialtoParachainsInstance};
|
||||||
|
|
||||||
use bp_messages::{
|
use bp_messages::{LaneId, MessageNonce};
|
||||||
source_chain::TargetHeaderChain,
|
|
||||||
target_chain::{ProvedMessages, SourceHeaderChain},
|
|
||||||
InboundLaneData, LaneId, Message, MessageNonce,
|
|
||||||
};
|
|
||||||
use bp_runtime::{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, MessageBridge};
|
use bridge_runtime_common::messages::{
|
||||||
|
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
|
||||||
|
};
|
||||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
|
|
||||||
/// Default lane that is used to send messages to Rialto parachain.
|
/// Default lane that is used to send messages to Rialto parachain.
|
||||||
@@ -53,14 +51,6 @@ pub type ToRialtoParachainMessageVerifier =
|
|||||||
pub type FromRialtoParachainMessagePayload =
|
pub type FromRialtoParachainMessagePayload =
|
||||||
messages::target::FromBridgedChainMessagePayload<RuntimeCall>;
|
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.
|
/// Call-dispatch based message dispatch for RialtoParachain -> Millau messages.
|
||||||
pub type FromRialtoParachainMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
|
pub type FromRialtoParachainMessageDispatch = messages::target::FromBridgedChainMessageDispatch<
|
||||||
WithRialtoParachainMessageBridge,
|
WithRialtoParachainMessageBridge,
|
||||||
@@ -115,6 +105,12 @@ impl messages::ThisChainWithMessages for Millau {
|
|||||||
/// RialtoParachain chain from message lane point of view.
|
/// RialtoParachain chain from message lane point of view.
|
||||||
#[derive(RuntimeDebug, Clone, Copy)]
|
#[derive(RuntimeDebug, Clone, Copy)]
|
||||||
pub struct RialtoParachain;
|
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 {
|
impl messages::UnderlyingChainProvider for RialtoParachain {
|
||||||
type Chain = bp_rialto_parachain::RialtoParachain;
|
type Chain = bp_rialto_parachain::RialtoParachain;
|
||||||
@@ -125,43 +121,3 @@ impl messages::BridgedChainWithMessages for RialtoParachain {
|
|||||||
true
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -581,7 +581,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
|
|||||||
type InboundRelayer = bp_millau::AccountId;
|
type InboundRelayer = bp_millau::AccountId;
|
||||||
type DeliveryPayments = ();
|
type DeliveryPayments = ();
|
||||||
|
|
||||||
type TargetHeaderChain = crate::millau_messages::Millau;
|
type TargetHeaderChain = crate::millau_messages::MillauAsTargetHeaderChain;
|
||||||
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
||||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||||
Runtime,
|
Runtime,
|
||||||
@@ -589,7 +589,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for 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 MessageDispatch = crate::millau_messages::FromMillauMessageDispatch;
|
||||||
type BridgedChainId = BridgedChainId;
|
type BridgedChainId = BridgedChainId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,11 @@
|
|||||||
|
|
||||||
use crate::{MillauGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
|
use crate::{MillauGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
|
||||||
|
|
||||||
use bp_messages::{
|
use bp_messages::{LaneId, MessageNonce};
|
||||||
source_chain::TargetHeaderChain,
|
|
||||||
target_chain::{ProvedMessages, SourceHeaderChain},
|
|
||||||
InboundLaneData, LaneId, Message, MessageNonce,
|
|
||||||
};
|
|
||||||
use bp_runtime::{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, MessageBridge};
|
use bridge_runtime_common::messages::{
|
||||||
|
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
|
||||||
|
};
|
||||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
|
|
||||||
/// Default lane that is used to send messages to Millau.
|
/// Default lane that is used to send messages to Millau.
|
||||||
@@ -114,6 +112,10 @@ impl messages::ThisChainWithMessages for RialtoParachain {
|
|||||||
/// Millau chain from message lane point of view.
|
/// Millau chain from message lane point of view.
|
||||||
#[derive(RuntimeDebug, Clone, Copy)]
|
#[derive(RuntimeDebug, Clone, Copy)]
|
||||||
pub struct Millau;
|
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 {
|
impl messages::UnderlyingChainProvider for Millau {
|
||||||
type Chain = bp_millau::Millau;
|
type Chain = bp_millau::Millau;
|
||||||
@@ -124,40 +126,3 @@ impl messages::BridgedChainWithMessages for Millau {
|
|||||||
true
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for Runtime {
|
|||||||
type InboundRelayer = bp_millau::AccountId;
|
type InboundRelayer = bp_millau::AccountId;
|
||||||
type DeliveryPayments = ();
|
type DeliveryPayments = ();
|
||||||
|
|
||||||
type TargetHeaderChain = crate::millau_messages::Millau;
|
type TargetHeaderChain = crate::millau_messages::MillauAsTargetHeaderChain;
|
||||||
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
type LaneMessageVerifier = crate::millau_messages::ToMillauMessageVerifier;
|
||||||
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||||
Runtime,
|
Runtime,
|
||||||
@@ -456,7 +456,7 @@ impl pallet_bridge_messages::Config<WithMillauMessagesInstance> for 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 MessageDispatch = crate::millau_messages::FromMillauMessageDispatch;
|
||||||
type BridgedChainId = BridgedChainId;
|
type BridgedChainId = BridgedChainId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,11 @@
|
|||||||
|
|
||||||
use crate::{MillauGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
|
use crate::{MillauGrandpaInstance, Runtime, RuntimeCall, RuntimeOrigin};
|
||||||
|
|
||||||
use bp_messages::{
|
use bp_messages::{LaneId, MessageNonce};
|
||||||
source_chain::TargetHeaderChain,
|
|
||||||
target_chain::{ProvedMessages, SourceHeaderChain},
|
|
||||||
InboundLaneData, LaneId, Message, MessageNonce,
|
|
||||||
};
|
|
||||||
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
|
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};
|
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||||
|
|
||||||
/// Lane that is used for XCM messages exchange.
|
/// Lane that is used for XCM messages exchange.
|
||||||
@@ -110,6 +108,10 @@ impl messages::ThisChainWithMessages for Rialto {
|
|||||||
/// Millau chain from message lane point of view.
|
/// Millau chain from message lane point of view.
|
||||||
#[derive(RuntimeDebug, Clone, Copy)]
|
#[derive(RuntimeDebug, Clone, Copy)]
|
||||||
pub struct Millau;
|
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 {
|
impl messages::UnderlyingChainProvider for Millau {
|
||||||
type Chain = bp_millau::Millau;
|
type Chain = bp_millau::Millau;
|
||||||
@@ -121,43 +123,6 @@ impl messages::BridgedChainWithMessages for Millau {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TargetHeaderChain<ToMillauMessagePayload, bp_rialto::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::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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ pallet-bridge-relayers = { path = "../../modules/relayers", default-features = f
|
|||||||
|
|
||||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
|
|
||||||
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
@@ -46,9 +45,8 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master
|
|||||||
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
|
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bp-rialto = { path = "../../primitives/chain-rialto" }
|
|
||||||
bp-test-utils = { path = "../../primitives/test-utils" }
|
bp-test-utils = { path = "../../primitives/test-utils" }
|
||||||
millau-runtime = { path = "../millau/runtime" }
|
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
@@ -82,7 +80,6 @@ std = [
|
|||||||
"xcm-executor/std",
|
"xcm-executor/std",
|
||||||
]
|
]
|
||||||
runtime-benchmarks = [
|
runtime-benchmarks = [
|
||||||
"pallet-balances",
|
|
||||||
"pallet-bridge-grandpa/runtime-benchmarks",
|
"pallet-bridge-grandpa/runtime-benchmarks",
|
||||||
"pallet-bridge-messages/runtime-benchmarks",
|
"pallet-bridge-messages/runtime-benchmarks",
|
||||||
"xcm-builder/runtime-benchmarks",
|
"xcm-builder/runtime-benchmarks",
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ macro_rules! assert_bridge_messages_pallet_types(
|
|||||||
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
|
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
|
||||||
// and relays will stop functioning)
|
// and relays will stop functioning)
|
||||||
use $crate::messages::{
|
use $crate::messages::{
|
||||||
source::FromThisChainMessagePayload,
|
source::{FromThisChainMessagePayload, TargetHeaderChainAdapter},
|
||||||
target::FromBridgedChainMessagePayload,
|
target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter},
|
||||||
AccountIdOf, BalanceOf, BridgedChain, CallOf, ThisChain,
|
AccountIdOf, BalanceOf, BridgedChain, CallOf, ThisChain,
|
||||||
};
|
};
|
||||||
use pallet_bridge_messages::Config as MessagesConfig;
|
use pallet_bridge_messages::Config as MessagesConfig;
|
||||||
@@ -93,8 +93,8 @@ macro_rules! assert_bridge_messages_pallet_types(
|
|||||||
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundPayload, FromBridgedChainMessagePayload<CallOf<ThisChain<$bridge>>>);
|
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundPayload, FromBridgedChainMessagePayload<CallOf<ThisChain<$bridge>>>);
|
||||||
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundRelayer, AccountIdOf<BridgedChain<$bridge>>);
|
assert_type_eq_all!(<$r as MessagesConfig<$i>>::InboundRelayer, AccountIdOf<BridgedChain<$bridge>>);
|
||||||
|
|
||||||
assert_type_eq_all!(<$r as MessagesConfig<$i>>::TargetHeaderChain, BridgedChain<$bridge>);
|
assert_type_eq_all!(<$r as MessagesConfig<$i>>::TargetHeaderChain, TargetHeaderChainAdapter<$bridge>);
|
||||||
assert_type_eq_all!(<$r as MessagesConfig<$i>>::SourceHeaderChain, BridgedChain<$bridge>);
|
assert_type_eq_all!(<$r as MessagesConfig<$i>>::SourceHeaderChain, SourceHeaderChainAdapter<$bridge>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ pub mod parachains_benchmarking;
|
|||||||
pub mod refund_relayer_extension;
|
pub mod refund_relayer_extension;
|
||||||
|
|
||||||
mod messages_generation;
|
mod messages_generation;
|
||||||
|
mod mock;
|
||||||
|
|
||||||
#[cfg(feature = "integrity-test")]
|
#[cfg(feature = "integrity-test")]
|
||||||
pub mod integrity;
|
pub mod integrity;
|
||||||
|
|||||||
@@ -22,8 +22,10 @@
|
|||||||
|
|
||||||
use bp_header_chain::{HeaderChain, HeaderChainError};
|
use bp_header_chain::{HeaderChain, HeaderChainError};
|
||||||
use bp_messages::{
|
use bp_messages::{
|
||||||
source_chain::LaneMessageVerifier,
|
source_chain::{LaneMessageVerifier, TargetHeaderChain},
|
||||||
target_chain::{DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages},
|
target_chain::{
|
||||||
|
DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
|
||||||
|
},
|
||||||
InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData,
|
InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData,
|
||||||
};
|
};
|
||||||
use bp_runtime::{messages::MessageDispatchResult, Chain, ChainId, Size, StorageProofChecker};
|
use bp_runtime::{messages::MessageDispatchResult, Chain, ChainId, Size, StorageProofChecker};
|
||||||
@@ -212,6 +214,26 @@ pub mod source {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `TargetHeaderChain` implementation that is using default types and perform default checks.
|
||||||
|
pub struct TargetHeaderChainAdapter<B>(PhantomData<B>);
|
||||||
|
|
||||||
|
impl<B: MessageBridge> TargetHeaderChain<FromThisChainMessagePayload, AccountIdOf<ThisChain<B>>>
|
||||||
|
for TargetHeaderChainAdapter<B>
|
||||||
|
{
|
||||||
|
type Error = &'static str;
|
||||||
|
type MessagesDeliveryProof = FromBridgedChainMessagesDeliveryProof<HashOf<BridgedChain<B>>>;
|
||||||
|
|
||||||
|
fn verify_message(payload: &FromThisChainMessagePayload) -> Result<(), Self::Error> {
|
||||||
|
verify_chain_message::<B>(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_messages_delivery_proof(
|
||||||
|
proof: Self::MessagesDeliveryProof,
|
||||||
|
) -> Result<(LaneId, InboundLaneData<AccountIdOf<ThisChain<B>>>), Self::Error> {
|
||||||
|
verify_messages_delivery_proof::<B>(proof)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Do basic Bridged-chain specific verification of This -> Bridged chain message.
|
/// Do basic Bridged-chain specific verification of This -> Bridged chain message.
|
||||||
///
|
///
|
||||||
/// Ok result from this function means that the delivery transaction with this message
|
/// Ok result from this function means that the delivery transaction with this message
|
||||||
@@ -549,6 +571,21 @@ pub mod target {
|
|||||||
maximal_extrinsic_size / 3 * 2
|
maximal_extrinsic_size / 3 * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `SourceHeaderChain` implementation that is using default types and perform default checks.
|
||||||
|
pub struct SourceHeaderChainAdapter<B>(PhantomData<B>);
|
||||||
|
|
||||||
|
impl<B: MessageBridge> SourceHeaderChain for SourceHeaderChainAdapter<B> {
|
||||||
|
type Error = &'static str;
|
||||||
|
type MessagesProof = FromBridgedChainMessagesProof<HashOf<BridgedChain<B>>>;
|
||||||
|
|
||||||
|
fn verify_messages_proof(
|
||||||
|
proof: Self::MessagesProof,
|
||||||
|
messages_count: u32,
|
||||||
|
) -> Result<ProvedMessages<Message>, Self::Error> {
|
||||||
|
verify_messages_proof::<B>(proof, messages_count).map_err(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Verify proof of Bridged -> This chain messages.
|
/// Verify proof of Bridged -> This chain messages.
|
||||||
///
|
///
|
||||||
/// This function is used when Bridged chain is directly using GRANDPA finality. For Bridged
|
/// This function is used when Bridged chain is directly using GRANDPA finality. For Bridged
|
||||||
@@ -702,206 +739,22 @@ pub type BridgeMessagesCallOf<C> = bp_messages::BridgeMessagesCall<
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::messages_generation::{
|
use crate::{
|
||||||
|
messages_generation::{
|
||||||
encode_all_messages, encode_lane_data, prepare_messages_storage_proof,
|
encode_all_messages, encode_lane_data, prepare_messages_storage_proof,
|
||||||
|
},
|
||||||
|
mock::*,
|
||||||
};
|
};
|
||||||
use codec::{Decode, Encode};
|
use bp_header_chain::StoredHeaderDataBuilder;
|
||||||
use frame_support::weights::Weight;
|
use bp_runtime::HeaderId;
|
||||||
|
use codec::Encode;
|
||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
use sp_runtime::traits::{BlakeTwo256, Header as _};
|
use sp_runtime::traits::Header as _;
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
const BRIDGED_CHAIN_MIN_EXTRINSIC_WEIGHT: usize = 5;
|
|
||||||
const BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT: usize = 2048;
|
|
||||||
const BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE: u32 = 1024;
|
|
||||||
|
|
||||||
/// Bridge that is deployed on ThisChain and allows sending/receiving messages to/from
|
|
||||||
/// BridgedChain.
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
|
||||||
struct OnThisChainBridge;
|
|
||||||
|
|
||||||
impl MessageBridge for OnThisChainBridge {
|
|
||||||
const THIS_CHAIN_ID: ChainId = *b"this";
|
|
||||||
const BRIDGED_CHAIN_ID: ChainId = *b"brdg";
|
|
||||||
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
|
|
||||||
|
|
||||||
type ThisChain = ThisChain;
|
|
||||||
type BridgedChain = BridgedChain;
|
|
||||||
type BridgedHeaderChain = BridgedHeaderChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bridge that is deployed on BridgedChain and allows sending/receiving messages to/from
|
|
||||||
/// ThisChain;
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
|
||||||
struct OnBridgedChainBridge;
|
|
||||||
|
|
||||||
impl MessageBridge for OnBridgedChainBridge {
|
|
||||||
const THIS_CHAIN_ID: ChainId = *b"brdg";
|
|
||||||
const BRIDGED_CHAIN_ID: ChainId = *b"this";
|
|
||||||
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
|
|
||||||
|
|
||||||
type ThisChain = BridgedChain;
|
|
||||||
type BridgedChain = ThisChain;
|
|
||||||
type BridgedHeaderChain = ThisHeaderChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct ThisChainOrigin(Result<frame_system::RawOrigin<ThisChainAccountId>, ()>);
|
|
||||||
|
|
||||||
impl From<ThisChainOrigin>
|
|
||||||
for Result<frame_system::RawOrigin<ThisChainAccountId>, ThisChainOrigin>
|
|
||||||
{
|
|
||||||
fn from(
|
|
||||||
origin: ThisChainOrigin,
|
|
||||||
) -> Result<frame_system::RawOrigin<ThisChainAccountId>, ThisChainOrigin> {
|
|
||||||
origin.clone().0.map_err(|_| origin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
struct BridgedChainOrigin;
|
|
||||||
|
|
||||||
impl From<BridgedChainOrigin>
|
|
||||||
for Result<frame_system::RawOrigin<BridgedChainAccountId>, BridgedChainOrigin>
|
|
||||||
{
|
|
||||||
fn from(
|
|
||||||
_origin: BridgedChainOrigin,
|
|
||||||
) -> Result<frame_system::RawOrigin<BridgedChainAccountId>, BridgedChainOrigin> {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ThisUnderlyingChain;
|
|
||||||
type ThisChainHeader = sp_runtime::generic::Header<u64, BlakeTwo256>;
|
|
||||||
type ThisChainAccountId = u32;
|
|
||||||
type ThisChainBalance = u32;
|
|
||||||
#[derive(Decode, Encode)]
|
|
||||||
struct ThisChainCall;
|
|
||||||
|
|
||||||
impl Chain for ThisUnderlyingChain {
|
|
||||||
type BlockNumber = u64;
|
|
||||||
type Hash = H256;
|
|
||||||
type Hasher = BlakeTwo256;
|
|
||||||
type Header = ThisChainHeader;
|
|
||||||
type AccountId = ThisChainAccountId;
|
|
||||||
type Balance = ThisChainBalance;
|
|
||||||
type Index = u32;
|
|
||||||
type Signature = sp_runtime::MultiSignature;
|
|
||||||
|
|
||||||
fn max_extrinsic_size() -> u32 {
|
|
||||||
BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE
|
|
||||||
}
|
|
||||||
|
|
||||||
fn max_extrinsic_weight() -> Weight {
|
|
||||||
Weight::zero()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ThisChain;
|
|
||||||
|
|
||||||
impl UnderlyingChainProvider for ThisChain {
|
|
||||||
type Chain = ThisUnderlyingChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ThisChainWithMessages for ThisChain {
|
|
||||||
type RuntimeOrigin = ThisChainOrigin;
|
|
||||||
type RuntimeCall = ThisChainCall;
|
|
||||||
|
|
||||||
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
|
|
||||||
lane == TEST_LANE_ID
|
|
||||||
}
|
|
||||||
|
|
||||||
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
|
||||||
MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BridgedChainWithMessages for ThisChain {
|
|
||||||
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BridgedUnderlyingChain;
|
|
||||||
type BridgedChainHeader = sp_runtime::generic::Header<u64, BlakeTwo256>;
|
|
||||||
type BridgedChainAccountId = u128;
|
|
||||||
type BridgedChainBalance = u128;
|
|
||||||
#[derive(Decode, Encode)]
|
|
||||||
struct BridgedChainCall;
|
|
||||||
|
|
||||||
impl Chain for BridgedUnderlyingChain {
|
|
||||||
type BlockNumber = u64;
|
|
||||||
type Hash = H256;
|
|
||||||
type Hasher = BlakeTwo256;
|
|
||||||
type Header = BridgedChainHeader;
|
|
||||||
type AccountId = BridgedChainAccountId;
|
|
||||||
type Balance = BridgedChainBalance;
|
|
||||||
type Index = u32;
|
|
||||||
type Signature = sp_runtime::MultiSignature;
|
|
||||||
|
|
||||||
fn max_extrinsic_size() -> u32 {
|
|
||||||
BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE
|
|
||||||
}
|
|
||||||
fn max_extrinsic_weight() -> Weight {
|
|
||||||
Weight::zero()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BridgedChain;
|
|
||||||
|
|
||||||
impl UnderlyingChainProvider for BridgedChain {
|
|
||||||
type Chain = BridgedUnderlyingChain;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ThisChainWithMessages for BridgedChain {
|
|
||||||
type RuntimeOrigin = BridgedChainOrigin;
|
|
||||||
type RuntimeCall = BridgedChainCall;
|
|
||||||
|
|
||||||
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BridgedChainWithMessages for BridgedChain {
|
|
||||||
fn verify_dispatch_weight(message_payload: &[u8]) -> bool {
|
|
||||||
message_payload.len() >= BRIDGED_CHAIN_MIN_EXTRINSIC_WEIGHT &&
|
|
||||||
message_payload.len() <= BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_local! {
|
|
||||||
static TEST_BRIDGED_HEADER: RefCell<Option<BridgedChainHeader>> = RefCell::new(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BridgedHeaderChain;
|
|
||||||
|
|
||||||
impl HeaderChain<BridgedUnderlyingChain> for BridgedHeaderChain {
|
|
||||||
fn finalized_header_state_root(
|
|
||||||
_hash: HashOf<BridgedChain>,
|
|
||||||
) -> Option<HashOf<BridgedChain>> {
|
|
||||||
TEST_BRIDGED_HEADER.with(|h| h.borrow().clone()).map(|h| *h.state_root())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ThisHeaderChain;
|
|
||||||
|
|
||||||
impl HeaderChain<ThisUnderlyingChain> for ThisHeaderChain {
|
|
||||||
fn finalized_header_state_root(_hash: HashOf<ThisChain>) -> Option<HashOf<ThisChain>> {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_lane_outbound_data() -> OutboundLaneData {
|
fn test_lane_outbound_data() -> OutboundLaneData {
|
||||||
OutboundLaneData::default()
|
OutboundLaneData::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
const TEST_LANE_ID: &LaneId = &LaneId(*b"test");
|
|
||||||
const MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE: MessageNonce = 32;
|
|
||||||
|
|
||||||
fn regular_outbound_message_payload() -> source::FromThisChainMessagePayload {
|
fn regular_outbound_message_payload() -> source::FromThisChainMessagePayload {
|
||||||
vec![42]
|
vec![42]
|
||||||
}
|
}
|
||||||
@@ -910,7 +763,7 @@ mod tests {
|
|||||||
fn message_is_rejected_when_sent_using_disabled_lane() {
|
fn message_is_rejected_when_sent_using_disabled_lane() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
source::FromThisChainMessageVerifier::<OnThisChainBridge>::verify_message(
|
source::FromThisChainMessageVerifier::<OnThisChainBridge>::verify_message(
|
||||||
&ThisChainOrigin(Ok(frame_system::RawOrigin::Root)),
|
&frame_system::RawOrigin::Root.into(),
|
||||||
&LaneId(*b"dsbl"),
|
&LaneId(*b"dsbl"),
|
||||||
&test_lane_outbound_data(),
|
&test_lane_outbound_data(),
|
||||||
®ular_outbound_message_payload(),
|
®ular_outbound_message_payload(),
|
||||||
@@ -923,8 +776,8 @@ mod tests {
|
|||||||
fn message_is_rejected_when_there_are_too_many_pending_messages_at_outbound_lane() {
|
fn message_is_rejected_when_there_are_too_many_pending_messages_at_outbound_lane() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
source::FromThisChainMessageVerifier::<OnThisChainBridge>::verify_message(
|
source::FromThisChainMessageVerifier::<OnThisChainBridge>::verify_message(
|
||||||
&ThisChainOrigin(Ok(frame_system::RawOrigin::Root)),
|
&frame_system::RawOrigin::Root.into(),
|
||||||
TEST_LANE_ID,
|
&TEST_LANE_ID,
|
||||||
&OutboundLaneData {
|
&OutboundLaneData {
|
||||||
latest_received_nonce: 100,
|
latest_received_nonce: 100,
|
||||||
latest_generated_nonce: 100 + MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE + 1,
|
latest_generated_nonce: 100 + MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE + 1,
|
||||||
@@ -986,7 +839,7 @@ mod tests {
|
|||||||
test: impl Fn(target::FromBridgedChainMessagesProof<H256>) -> R,
|
test: impl Fn(target::FromBridgedChainMessagesProof<H256>) -> R,
|
||||||
) -> R {
|
) -> R {
|
||||||
let (state_root, storage_proof) = prepare_messages_storage_proof::<OnThisChainBridge>(
|
let (state_root, storage_proof) = prepare_messages_storage_proof::<OnThisChainBridge>(
|
||||||
*TEST_LANE_ID,
|
TEST_LANE_ID,
|
||||||
1..=nonces_end,
|
1..=nonces_end,
|
||||||
outbound_lane_data,
|
outbound_lane_data,
|
||||||
bp_runtime::StorageProofSize::Minimal(0),
|
bp_runtime::StorageProofSize::Minimal(0),
|
||||||
@@ -995,23 +848,32 @@ mod tests {
|
|||||||
encode_outbound_lane_data,
|
encode_outbound_lane_data,
|
||||||
);
|
);
|
||||||
|
|
||||||
TEST_BRIDGED_HEADER.with(|h| {
|
sp_io::TestExternalities::new(Default::default()).execute_with(move || {
|
||||||
*h.borrow_mut() = Some(BridgedChainHeader::new(
|
let bridged_header = BridgedChainHeader::new(
|
||||||
0,
|
0,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
state_root,
|
state_root,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
))
|
);
|
||||||
});
|
let bridged_header_hash = bridged_header.hash();
|
||||||
|
|
||||||
|
pallet_bridge_grandpa::BestFinalized::<TestRuntime>::put(HeaderId(
|
||||||
|
0,
|
||||||
|
bridged_header_hash,
|
||||||
|
));
|
||||||
|
pallet_bridge_grandpa::ImportedHeaders::<TestRuntime>::insert(
|
||||||
|
bridged_header_hash,
|
||||||
|
bridged_header.build(),
|
||||||
|
);
|
||||||
test(target::FromBridgedChainMessagesProof {
|
test(target::FromBridgedChainMessagesProof {
|
||||||
bridged_header_hash: Default::default(),
|
bridged_header_hash,
|
||||||
storage_proof,
|
storage_proof,
|
||||||
lane: *TEST_LANE_ID,
|
lane: TEST_LANE_ID,
|
||||||
nonces_start: 1,
|
nonces_start: 1,
|
||||||
nonces_end,
|
nonces_end,
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1038,7 +900,9 @@ mod tests {
|
|||||||
fn message_proof_is_rejected_if_header_is_missing_from_the_chain() {
|
fn message_proof_is_rejected_if_header_is_missing_from_the_chain() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
using_messages_proof(10, None, encode_all_messages, encode_lane_data, |proof| {
|
using_messages_proof(10, None, encode_all_messages, encode_lane_data, |proof| {
|
||||||
TEST_BRIDGED_HEADER.with(|h| *h.borrow_mut() = None);
|
let bridged_header_hash =
|
||||||
|
pallet_bridge_grandpa::BestFinalized::<TestRuntime>::get().unwrap().1;
|
||||||
|
pallet_bridge_grandpa::ImportedHeaders::<TestRuntime>::remove(bridged_header_hash);
|
||||||
target::verify_messages_proof::<OnThisChainBridge>(proof, 10)
|
target::verify_messages_proof::<OnThisChainBridge>(proof, 10)
|
||||||
}),
|
}),
|
||||||
Err(target::MessageProofError::HeaderChain(HeaderChainError::UnknownHeader)),
|
Err(target::MessageProofError::HeaderChain(HeaderChainError::UnknownHeader)),
|
||||||
@@ -1049,8 +913,19 @@ mod tests {
|
|||||||
fn message_proof_is_rejected_if_header_state_root_mismatches() {
|
fn message_proof_is_rejected_if_header_state_root_mismatches() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
using_messages_proof(10, None, encode_all_messages, encode_lane_data, |proof| {
|
using_messages_proof(10, None, encode_all_messages, encode_lane_data, |proof| {
|
||||||
TEST_BRIDGED_HEADER
|
let bridged_header_hash =
|
||||||
.with(|h| h.borrow_mut().as_mut().unwrap().state_root = Default::default());
|
pallet_bridge_grandpa::BestFinalized::<TestRuntime>::get().unwrap().1;
|
||||||
|
pallet_bridge_grandpa::ImportedHeaders::<TestRuntime>::insert(
|
||||||
|
bridged_header_hash,
|
||||||
|
BridgedChainHeader::new(
|
||||||
|
0,
|
||||||
|
Default::default(),
|
||||||
|
Default::default(),
|
||||||
|
Default::default(),
|
||||||
|
Default::default(),
|
||||||
|
)
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
target::verify_messages_proof::<OnThisChainBridge>(proof, 10)
|
target::verify_messages_proof::<OnThisChainBridge>(proof, 10)
|
||||||
}),
|
}),
|
||||||
Err(target::MessageProofError::HeaderChain(HeaderChainError::StorageRootMismatch)),
|
Err(target::MessageProofError::HeaderChain(HeaderChainError::StorageRootMismatch)),
|
||||||
@@ -1138,7 +1013,7 @@ mod tests {
|
|||||||
|proof| target::verify_messages_proof::<OnThisChainBridge>(proof, 0),
|
|proof| target::verify_messages_proof::<OnThisChainBridge>(proof, 0),
|
||||||
),
|
),
|
||||||
Ok(vec![(
|
Ok(vec![(
|
||||||
*TEST_LANE_ID,
|
TEST_LANE_ID,
|
||||||
ProvedLaneMessages {
|
ProvedLaneMessages {
|
||||||
lane_state: Some(OutboundLaneData {
|
lane_state: Some(OutboundLaneData {
|
||||||
oldest_unpruned_nonce: 1,
|
oldest_unpruned_nonce: 1,
|
||||||
@@ -1168,7 +1043,7 @@ mod tests {
|
|||||||
|proof| target::verify_messages_proof::<OnThisChainBridge>(proof, 1),
|
|proof| target::verify_messages_proof::<OnThisChainBridge>(proof, 1),
|
||||||
),
|
),
|
||||||
Ok(vec![(
|
Ok(vec![(
|
||||||
*TEST_LANE_ID,
|
TEST_LANE_ID,
|
||||||
ProvedLaneMessages {
|
ProvedLaneMessages {
|
||||||
lane_state: Some(OutboundLaneData {
|
lane_state: Some(OutboundLaneData {
|
||||||
oldest_unpruned_nonce: 1,
|
oldest_unpruned_nonce: 1,
|
||||||
@@ -1176,7 +1051,7 @@ mod tests {
|
|||||||
latest_generated_nonce: 1,
|
latest_generated_nonce: 1,
|
||||||
}),
|
}),
|
||||||
messages: vec![Message {
|
messages: vec![Message {
|
||||||
key: MessageKey { lane_id: *TEST_LANE_ID, nonce: 1 },
|
key: MessageKey { lane_id: TEST_LANE_ID, nonce: 1 },
|
||||||
payload: vec![42],
|
payload: vec![42],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ pub fn prepare_message_proof<R, BI, FI, B, BH, BHH>(
|
|||||||
) -> (FromBridgedChainMessagesProof<HashOf<BridgedChain<B>>>, Weight)
|
) -> (FromBridgedChainMessagesProof<HashOf<BridgedChain<B>>>, Weight)
|
||||||
where
|
where
|
||||||
R: frame_system::Config<AccountId = AccountIdOf<ThisChain<B>>>
|
R: frame_system::Config<AccountId = AccountIdOf<ThisChain<B>>>
|
||||||
+ pallet_balances::Config<BI, Balance = BalanceOf<ThisChain<B>>>
|
|
||||||
+ pallet_bridge_grandpa::Config<FI>,
|
+ pallet_bridge_grandpa::Config<FI>,
|
||||||
R::BridgedChain: bp_runtime::Chain<Hash = HashOf<BridgedChain<B>>, Header = BH>,
|
R::BridgedChain: bp_runtime::Chain<Hash = HashOf<BridgedChain<B>>, Header = BH>,
|
||||||
B: MessageBridge,
|
B: MessageBridge,
|
||||||
|
|||||||
@@ -96,20 +96,17 @@ impl<
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bp_messages::UnrewardedRelayersState;
|
use crate::{
|
||||||
use millau_runtime::{
|
|
||||||
bridge_runtime_common::{
|
|
||||||
messages::{
|
messages::{
|
||||||
source::FromBridgedChainMessagesDeliveryProof,
|
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
||||||
target::FromBridgedChainMessagesProof,
|
|
||||||
},
|
},
|
||||||
|
mock::{TestRuntime, ThisChainRuntimeCall},
|
||||||
BridgeRuntimeFilterCall,
|
BridgeRuntimeFilterCall,
|
||||||
},
|
|
||||||
Runtime, RuntimeCall, WithRialtoMessagesInstance,
|
|
||||||
};
|
};
|
||||||
|
use bp_messages::UnrewardedRelayersState;
|
||||||
|
|
||||||
fn deliver_message_10() {
|
fn deliver_message_10() {
|
||||||
pallet_bridge_messages::InboundLanes::<Runtime, WithRialtoMessagesInstance>::insert(
|
pallet_bridge_messages::InboundLanes::<TestRuntime>::insert(
|
||||||
bp_messages::LaneId([0, 0, 0, 0]),
|
bp_messages::LaneId([0, 0, 0, 0]),
|
||||||
bp_messages::InboundLaneData { relayers: Default::default(), last_confirmed_nonce: 10 },
|
bp_messages::InboundLaneData { relayers: Default::default(), last_confirmed_nonce: 10 },
|
||||||
);
|
);
|
||||||
@@ -119,10 +116,10 @@ mod tests {
|
|||||||
nonces_start: bp_messages::MessageNonce,
|
nonces_start: bp_messages::MessageNonce,
|
||||||
nonces_end: bp_messages::MessageNonce,
|
nonces_end: bp_messages::MessageNonce,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
pallet_bridge_messages::Pallet::<Runtime, WithRialtoMessagesInstance>::validate(
|
pallet_bridge_messages::Pallet::<TestRuntime>::validate(
|
||||||
&RuntimeCall::BridgeRialtoMessages(
|
&ThisChainRuntimeCall::BridgeMessages(
|
||||||
pallet_bridge_messages::Call::<Runtime, ()>::receive_messages_proof {
|
pallet_bridge_messages::Call::<TestRuntime, ()>::receive_messages_proof {
|
||||||
relayer_id_at_bridged_chain: [0u8; 32].into(),
|
relayer_id_at_bridged_chain: 42,
|
||||||
messages_count: (nonces_end - nonces_start + 1) as u32,
|
messages_count: (nonces_end - nonces_start + 1) as u32,
|
||||||
dispatch_weight: frame_support::weights::Weight::zero(),
|
dispatch_weight: frame_support::weights::Weight::zero(),
|
||||||
proof: FromBridgedChainMessagesProof {
|
proof: FromBridgedChainMessagesProof {
|
||||||
@@ -169,7 +166,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_message_10() {
|
fn confirm_message_10() {
|
||||||
pallet_bridge_messages::OutboundLanes::<Runtime, WithRialtoMessagesInstance>::insert(
|
pallet_bridge_messages::OutboundLanes::<TestRuntime>::insert(
|
||||||
bp_messages::LaneId([0, 0, 0, 0]),
|
bp_messages::LaneId([0, 0, 0, 0]),
|
||||||
bp_messages::OutboundLaneData {
|
bp_messages::OutboundLaneData {
|
||||||
oldest_unpruned_nonce: 0,
|
oldest_unpruned_nonce: 0,
|
||||||
@@ -180,11 +177,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validate_message_confirmation(last_delivered_nonce: bp_messages::MessageNonce) -> bool {
|
fn validate_message_confirmation(last_delivered_nonce: bp_messages::MessageNonce) -> bool {
|
||||||
pallet_bridge_messages::Pallet::<Runtime, WithRialtoMessagesInstance>::validate(
|
pallet_bridge_messages::Pallet::<TestRuntime>::validate(
|
||||||
&RuntimeCall::BridgeRialtoMessages(pallet_bridge_messages::Call::<
|
&ThisChainRuntimeCall::BridgeMessages(
|
||||||
Runtime,
|
pallet_bridge_messages::Call::<TestRuntime>::receive_messages_delivery_proof {
|
||||||
WithRialtoMessagesInstance,
|
|
||||||
>::receive_messages_delivery_proof {
|
|
||||||
proof: FromBridgedChainMessagesDeliveryProof {
|
proof: FromBridgedChainMessagesDeliveryProof {
|
||||||
bridged_header_hash: Default::default(),
|
bridged_header_hash: Default::default(),
|
||||||
storage_proof: Vec::new(),
|
storage_proof: Vec::new(),
|
||||||
@@ -194,7 +189,8 @@ mod tests {
|
|||||||
last_delivered_nonce,
|
last_delivered_nonce,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,422 @@
|
|||||||
|
// Copyright 2019-2021 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/>.
|
||||||
|
|
||||||
|
//! A mock runtime for testing different stuff in the crate. We've been using Millau
|
||||||
|
//! runtime for that before, but it has two drawbacks:
|
||||||
|
//!
|
||||||
|
//! - circular dependencies between this crate and Millau runtime;
|
||||||
|
//!
|
||||||
|
//! - we can't use (e.g. as git subtree or by copying) this crate in repo without Millau.
|
||||||
|
|
||||||
|
#![cfg(test)]
|
||||||
|
|
||||||
|
use crate::messages::{
|
||||||
|
source::{
|
||||||
|
FromThisChainMaximalOutboundPayloadSize, FromThisChainMessagePayload,
|
||||||
|
FromThisChainMessageVerifier, TargetHeaderChainAdapter,
|
||||||
|
},
|
||||||
|
target::{FromBridgedChainMessagePayload, SourceHeaderChainAdapter},
|
||||||
|
BridgedChainWithMessages, HashOf, MessageBridge, ThisChainWithMessages,
|
||||||
|
};
|
||||||
|
|
||||||
|
use bp_header_chain::HeaderChain;
|
||||||
|
use bp_messages::{target_chain::ForbidInboundMessages, LaneId, MessageNonce};
|
||||||
|
use bp_parachains::SingleParaStoredHeaderDataBuilder;
|
||||||
|
use bp_runtime::{Chain, ChainId, Parachain, UnderlyingChainProvider};
|
||||||
|
use codec::{Decode, Encode};
|
||||||
|
use frame_support::{
|
||||||
|
parameter_types,
|
||||||
|
weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight},
|
||||||
|
};
|
||||||
|
use pallet_transaction_payment::Multiplier;
|
||||||
|
use sp_runtime::{
|
||||||
|
testing::H256,
|
||||||
|
traits::{BlakeTwo256, ConstU32, ConstU64, ConstU8, IdentityLookup},
|
||||||
|
FixedPointNumber, Perquintill,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Account identifier at `ThisChain`.
|
||||||
|
pub type ThisChainAccountId = u64;
|
||||||
|
/// Balance at `ThisChain`.
|
||||||
|
pub type ThisChainBalance = u64;
|
||||||
|
/// Block number at `ThisChain`.
|
||||||
|
pub type ThisChainBlockNumber = u32;
|
||||||
|
/// Hash at `ThisChain`.
|
||||||
|
pub type ThisChainHash = H256;
|
||||||
|
/// Hasher at `ThisChain`.
|
||||||
|
pub type ThisChainHasher = BlakeTwo256;
|
||||||
|
/// Runtime call at `ThisChain`.
|
||||||
|
pub type ThisChainRuntimeCall = RuntimeCall;
|
||||||
|
/// Runtime call origin at `ThisChain`.
|
||||||
|
pub type ThisChainCallOrigin = RuntimeOrigin;
|
||||||
|
/// Header of `ThisChain`.
|
||||||
|
pub type ThisChainHeader = sp_runtime::generic::Header<ThisChainBlockNumber, ThisChainHasher>;
|
||||||
|
/// Block of `ThisChain`.
|
||||||
|
pub type ThisChainBlock = frame_system::mocking::MockBlock<TestRuntime>;
|
||||||
|
/// Unchecked extrinsic of `ThisChain`.
|
||||||
|
pub type ThisChainUncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;
|
||||||
|
|
||||||
|
/// Account identifier at the `BridgedChain`.
|
||||||
|
pub type BridgedChainAccountId = u128;
|
||||||
|
/// Balance at the `BridgedChain`.
|
||||||
|
pub type BridgedChainBalance = u128;
|
||||||
|
/// Block number at the `BridgedChain`.
|
||||||
|
pub type BridgedChainBlockNumber = u32;
|
||||||
|
/// Hash at the `BridgedChain`.
|
||||||
|
pub type BridgedChainHash = H256;
|
||||||
|
/// Hasher at the `BridgedChain`.
|
||||||
|
pub type BridgedChainHasher = BlakeTwo256;
|
||||||
|
/// Header of the `BridgedChain`.
|
||||||
|
pub type BridgedChainHeader =
|
||||||
|
sp_runtime::generic::Header<BridgedChainBlockNumber, BridgedChainHasher>;
|
||||||
|
|
||||||
|
/// Message lane used in tests.
|
||||||
|
pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 0]);
|
||||||
|
/// Maximal number of queued messages at the test lane.
|
||||||
|
pub const MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE: MessageNonce = 32;
|
||||||
|
/// Minimal extrinsic weight at the `BridgedChain`.
|
||||||
|
pub const BRIDGED_CHAIN_MIN_EXTRINSIC_WEIGHT: usize = 5;
|
||||||
|
/// Maximal extrinsic weight at the `BridgedChain`.
|
||||||
|
pub const BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT: usize = 2048;
|
||||||
|
/// Maximal extrinsic size at the `BridgedChain`.
|
||||||
|
pub const BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE: u32 = 1024;
|
||||||
|
|
||||||
|
frame_support::construct_runtime! {
|
||||||
|
pub enum TestRuntime where
|
||||||
|
Block = ThisChainBlock,
|
||||||
|
NodeBlock = ThisChainBlock,
|
||||||
|
UncheckedExtrinsic = ThisChainUncheckedExtrinsic,
|
||||||
|
{
|
||||||
|
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||||
|
Utility: pallet_utility,
|
||||||
|
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||||
|
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||||
|
BridgeRelayers: pallet_bridge_relayers::{Pallet, Call, Storage, Event<T>},
|
||||||
|
BridgeGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage},
|
||||||
|
BridgeParachains: pallet_bridge_parachains::{Pallet, Call, Storage, Event<T>},
|
||||||
|
BridgeMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event<T>, Config<T>},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
crate::generate_bridge_reject_obsolete_headers_and_messages! {
|
||||||
|
ThisChainRuntimeCall, ThisChainAccountId,
|
||||||
|
BridgeGrandpa, BridgeParachains, BridgeMessages
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const ActiveOutboundLanes: &'static [LaneId] = &[TEST_LANE_ID];
|
||||||
|
pub const BridgedChainId: ChainId = *b"brdg";
|
||||||
|
pub const BridgedParasPalletName: &'static str = "Paras";
|
||||||
|
pub const ExistentialDeposit: ThisChainBalance = 500;
|
||||||
|
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 };
|
||||||
|
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
|
||||||
|
pub const TransactionBaseFee: ThisChainBalance = 0;
|
||||||
|
pub const TransactionByteFee: ThisChainBalance = 1;
|
||||||
|
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
|
||||||
|
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
|
||||||
|
pub MaximumMultiplier: Multiplier = sp_runtime::traits::Bounded::max_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl frame_system::Config for TestRuntime {
|
||||||
|
type RuntimeOrigin = RuntimeOrigin;
|
||||||
|
type Index = u64;
|
||||||
|
type RuntimeCall = RuntimeCall;
|
||||||
|
type BlockNumber = ThisChainBlockNumber;
|
||||||
|
type Hash = ThisChainHash;
|
||||||
|
type Hashing = ThisChainHasher;
|
||||||
|
type AccountId = ThisChainAccountId;
|
||||||
|
type Lookup = IdentityLookup<Self::AccountId>;
|
||||||
|
type Header = ThisChainHeader;
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type BlockHashCount = ConstU32<250>;
|
||||||
|
type Version = ();
|
||||||
|
type PalletInfo = PalletInfo;
|
||||||
|
type AccountData = pallet_balances::AccountData<ThisChainBalance>;
|
||||||
|
type OnNewAccount = ();
|
||||||
|
type OnKilledAccount = ();
|
||||||
|
type BaseCallFilter = frame_support::traits::Everything;
|
||||||
|
type SystemWeightInfo = ();
|
||||||
|
type BlockWeights = ();
|
||||||
|
type BlockLength = ();
|
||||||
|
type DbWeight = DbWeight;
|
||||||
|
type SS58Prefix = ();
|
||||||
|
type OnSetCode = ();
|
||||||
|
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_utility::Config for TestRuntime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type RuntimeCall = RuntimeCall;
|
||||||
|
type PalletsOrigin = OriginCaller;
|
||||||
|
type WeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_balances::Config for TestRuntime {
|
||||||
|
type Balance = ThisChainBalance;
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type DustRemoval = ();
|
||||||
|
type ExistentialDeposit = ExistentialDeposit;
|
||||||
|
type AccountStore = System;
|
||||||
|
type WeightInfo = ();
|
||||||
|
type MaxLocks = ConstU32<50>;
|
||||||
|
type MaxReserves = ConstU32<50>;
|
||||||
|
type ReserveIdentifier = [u8; 8];
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_transaction_payment::Config for TestRuntime {
|
||||||
|
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
|
||||||
|
type OperationalFeeMultiplier = ConstU8<5>;
|
||||||
|
type WeightToFee = IdentityFee<ThisChainBalance>;
|
||||||
|
type LengthToFee = ConstantMultiplier<ThisChainBalance, TransactionByteFee>;
|
||||||
|
type FeeMultiplierUpdate = pallet_transaction_payment::TargetedFeeAdjustment<
|
||||||
|
TestRuntime,
|
||||||
|
TargetBlockFullness,
|
||||||
|
AdjustmentVariable,
|
||||||
|
MinimumMultiplier,
|
||||||
|
MaximumMultiplier,
|
||||||
|
>;
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_bridge_grandpa::Config for TestRuntime {
|
||||||
|
type BridgedChain = BridgedUnderlyingChain;
|
||||||
|
type MaxRequests = ConstU32<50>;
|
||||||
|
type HeadersToKeep = ConstU32<8>;
|
||||||
|
type MaxBridgedAuthorities = ConstU32<1024>;
|
||||||
|
type WeightInfo = pallet_bridge_grandpa::weights::BridgeWeight<TestRuntime>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_bridge_parachains::Config for TestRuntime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type BridgesGrandpaPalletInstance = ();
|
||||||
|
type ParasPalletName = BridgedParasPalletName;
|
||||||
|
type ParaStoredHeaderDataBuilder =
|
||||||
|
SingleParaStoredHeaderDataBuilder<BridgedUnderlyingParachain>;
|
||||||
|
type HeadsToKeep = ConstU32<8>;
|
||||||
|
type MaxParaHeadDataSize = ConstU32<1024>;
|
||||||
|
type WeightInfo = pallet_bridge_parachains::weights::BridgeWeight<TestRuntime>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_bridge_messages::Config for TestRuntime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<TestRuntime>;
|
||||||
|
type ActiveOutboundLanes = ActiveOutboundLanes;
|
||||||
|
type MaxUnrewardedRelayerEntriesAtInboundLane = ConstU64<16>;
|
||||||
|
type MaxUnconfirmedMessagesAtInboundLane = ConstU64<16>;
|
||||||
|
|
||||||
|
type MaximalOutboundPayloadSize = FromThisChainMaximalOutboundPayloadSize<OnThisChainBridge>;
|
||||||
|
type OutboundPayload = FromThisChainMessagePayload;
|
||||||
|
|
||||||
|
type InboundPayload = FromBridgedChainMessagePayload<ThisChainRuntimeCall>;
|
||||||
|
type InboundRelayer = BridgedChainAccountId;
|
||||||
|
type DeliveryPayments = ();
|
||||||
|
|
||||||
|
type TargetHeaderChain = TargetHeaderChainAdapter<OnThisChainBridge>;
|
||||||
|
type LaneMessageVerifier = FromThisChainMessageVerifier<OnThisChainBridge>;
|
||||||
|
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
|
||||||
|
TestRuntime,
|
||||||
|
frame_support::traits::ConstU64<100_000>,
|
||||||
|
frame_support::traits::ConstU64<10_000>,
|
||||||
|
>;
|
||||||
|
|
||||||
|
type SourceHeaderChain = SourceHeaderChainAdapter<OnThisChainBridge>;
|
||||||
|
type MessageDispatch =
|
||||||
|
ForbidInboundMessages<(), FromBridgedChainMessagePayload<ThisChainRuntimeCall>>;
|
||||||
|
type BridgedChainId = BridgedChainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl pallet_bridge_relayers::Config for TestRuntime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type Reward = ThisChainBalance;
|
||||||
|
type PaymentProcedure = ();
|
||||||
|
type WeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bridge that is deployed on ThisChain and allows sending/receiving messages to/from
|
||||||
|
/// BridgedChain.
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct OnThisChainBridge;
|
||||||
|
|
||||||
|
impl MessageBridge for OnThisChainBridge {
|
||||||
|
const THIS_CHAIN_ID: ChainId = *b"this";
|
||||||
|
const BRIDGED_CHAIN_ID: ChainId = *b"brdg";
|
||||||
|
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
|
||||||
|
|
||||||
|
type ThisChain = ThisChain;
|
||||||
|
type BridgedChain = BridgedChain;
|
||||||
|
type BridgedHeaderChain = pallet_bridge_grandpa::GrandpaChainHeaders<TestRuntime, ()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bridge that is deployed on BridgedChain and allows sending/receiving messages to/from
|
||||||
|
/// ThisChain;
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct OnBridgedChainBridge;
|
||||||
|
|
||||||
|
impl MessageBridge for OnBridgedChainBridge {
|
||||||
|
const THIS_CHAIN_ID: ChainId = *b"brdg";
|
||||||
|
const BRIDGED_CHAIN_ID: ChainId = *b"this";
|
||||||
|
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = "";
|
||||||
|
|
||||||
|
type ThisChain = BridgedChain;
|
||||||
|
type BridgedChain = ThisChain;
|
||||||
|
type BridgedHeaderChain = ThisHeaderChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dummy implementation of `HeaderChain` for `ThisChain` at the `BridgedChain`.
|
||||||
|
pub struct ThisHeaderChain;
|
||||||
|
|
||||||
|
impl HeaderChain<ThisUnderlyingChain> for ThisHeaderChain {
|
||||||
|
fn finalized_header_state_root(_hash: HashOf<ThisChain>) -> Option<HashOf<ThisChain>> {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call origin at `BridgedChain`.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct BridgedChainOrigin;
|
||||||
|
|
||||||
|
impl From<BridgedChainOrigin>
|
||||||
|
for Result<frame_system::RawOrigin<BridgedChainAccountId>, BridgedChainOrigin>
|
||||||
|
{
|
||||||
|
fn from(
|
||||||
|
_origin: BridgedChainOrigin,
|
||||||
|
) -> Result<frame_system::RawOrigin<BridgedChainAccountId>, BridgedChainOrigin> {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Underlying chain of `ThisChain`.
|
||||||
|
pub struct ThisUnderlyingChain;
|
||||||
|
|
||||||
|
impl Chain for ThisUnderlyingChain {
|
||||||
|
type BlockNumber = ThisChainBlockNumber;
|
||||||
|
type Hash = ThisChainHash;
|
||||||
|
type Hasher = ThisChainHasher;
|
||||||
|
type Header = ThisChainHeader;
|
||||||
|
type AccountId = ThisChainAccountId;
|
||||||
|
type Balance = ThisChainBalance;
|
||||||
|
type Index = u32;
|
||||||
|
type Signature = sp_runtime::MultiSignature;
|
||||||
|
|
||||||
|
fn max_extrinsic_size() -> u32 {
|
||||||
|
BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
fn max_extrinsic_weight() -> Weight {
|
||||||
|
Weight::zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The chain where we are in tests.
|
||||||
|
pub struct ThisChain;
|
||||||
|
|
||||||
|
impl UnderlyingChainProvider for ThisChain {
|
||||||
|
type Chain = ThisUnderlyingChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThisChainWithMessages for ThisChain {
|
||||||
|
type RuntimeOrigin = ThisChainCallOrigin;
|
||||||
|
type RuntimeCall = ThisChainRuntimeCall;
|
||||||
|
|
||||||
|
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, lane: &LaneId) -> bool {
|
||||||
|
*lane == TEST_LANE_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
||||||
|
MAXIMAL_PENDING_MESSAGES_AT_TEST_LANE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BridgedChainWithMessages for ThisChain {
|
||||||
|
fn verify_dispatch_weight(_message_payload: &[u8]) -> bool {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Underlying chain of `BridgedChain`.
|
||||||
|
pub struct BridgedUnderlyingChain;
|
||||||
|
/// Some parachain under `BridgedChain` consensus.
|
||||||
|
pub struct BridgedUnderlyingParachain;
|
||||||
|
/// Runtime call of the `BridgedChain`.
|
||||||
|
#[derive(Decode, Encode)]
|
||||||
|
pub struct BridgedChainCall;
|
||||||
|
|
||||||
|
impl Chain for BridgedUnderlyingChain {
|
||||||
|
type BlockNumber = BridgedChainBlockNumber;
|
||||||
|
type Hash = BridgedChainHash;
|
||||||
|
type Hasher = BridgedChainHasher;
|
||||||
|
type Header = BridgedChainHeader;
|
||||||
|
type AccountId = BridgedChainAccountId;
|
||||||
|
type Balance = BridgedChainBalance;
|
||||||
|
type Index = u32;
|
||||||
|
type Signature = sp_runtime::MultiSignature;
|
||||||
|
|
||||||
|
fn max_extrinsic_size() -> u32 {
|
||||||
|
BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE
|
||||||
|
}
|
||||||
|
fn max_extrinsic_weight() -> Weight {
|
||||||
|
Weight::zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Chain for BridgedUnderlyingParachain {
|
||||||
|
type BlockNumber = BridgedChainBlockNumber;
|
||||||
|
type Hash = BridgedChainHash;
|
||||||
|
type Hasher = BridgedChainHasher;
|
||||||
|
type Header = BridgedChainHeader;
|
||||||
|
type AccountId = BridgedChainAccountId;
|
||||||
|
type Balance = BridgedChainBalance;
|
||||||
|
type Index = u32;
|
||||||
|
type Signature = sp_runtime::MultiSignature;
|
||||||
|
|
||||||
|
fn max_extrinsic_size() -> u32 {
|
||||||
|
BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE
|
||||||
|
}
|
||||||
|
fn max_extrinsic_weight() -> Weight {
|
||||||
|
Weight::zero()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parachain for BridgedUnderlyingParachain {
|
||||||
|
const PARACHAIN_ID: u32 = 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The other, bridged chain, used in tests.
|
||||||
|
pub struct BridgedChain;
|
||||||
|
|
||||||
|
impl UnderlyingChainProvider for BridgedChain {
|
||||||
|
type Chain = BridgedUnderlyingChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThisChainWithMessages for BridgedChain {
|
||||||
|
type RuntimeOrigin = BridgedChainOrigin;
|
||||||
|
type RuntimeCall = BridgedChainCall;
|
||||||
|
|
||||||
|
fn is_message_accepted(_send_origin: &Self::RuntimeOrigin, _lane: &LaneId) -> bool {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maximal_pending_messages_at_outbound_lane() -> MessageNonce {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BridgedChainWithMessages for BridgedChain {
|
||||||
|
fn verify_dispatch_weight(message_payload: &[u8]) -> bool {
|
||||||
|
message_payload.len() >= BRIDGED_CHAIN_MIN_EXTRINSIC_WEIGHT &&
|
||||||
|
message_payload.len() <= BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,12 +19,7 @@
|
|||||||
//! with calls that are: delivering new messsage and all necessary underlying headers
|
//! with calls that are: delivering new messsage and all necessary underlying headers
|
||||||
//! (parachain or relay chain).
|
//! (parachain or relay chain).
|
||||||
|
|
||||||
// hack because we have circular (test-level) dependency between `millau-runtime`
|
|
||||||
// and `bridge-runtime-common` crates
|
|
||||||
#[cfg(not(test))]
|
|
||||||
use crate::messages::target::FromBridgedChainMessagesProof;
|
use crate::messages::target::FromBridgedChainMessagesProof;
|
||||||
#[cfg(test)]
|
|
||||||
use millau_runtime::bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
|
||||||
|
|
||||||
use bp_messages::{target_chain::SourceHeaderChain, LaneId, MessageNonce};
|
use bp_messages::{target_chain::SourceHeaderChain, LaneId, MessageNonce};
|
||||||
use bp_polkadot_core::parachains::ParaId;
|
use bp_polkadot_core::parachains::ParaId;
|
||||||
@@ -475,36 +470,37 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::{messages::target::FromBridgedChainMessagesProof, mock::*};
|
||||||
use bp_messages::InboundLaneData;
|
use bp_messages::InboundLaneData;
|
||||||
use bp_parachains::{BestParaHeadHash, ParaInfo};
|
use bp_parachains::{BestParaHeadHash, ParaInfo};
|
||||||
use bp_polkadot_core::parachains::ParaHeadsProof;
|
use bp_polkadot_core::parachains::ParaHeadsProof;
|
||||||
use bp_runtime::HeaderId;
|
use bp_runtime::HeaderId;
|
||||||
use bp_test_utils::make_default_justification;
|
use bp_test_utils::make_default_justification;
|
||||||
use frame_support::{assert_storage_noop, parameter_types, weights::Weight};
|
use frame_support::{assert_storage_noop, parameter_types, weights::Weight};
|
||||||
use millau_runtime::{
|
|
||||||
RialtoGrandpaInstance, Runtime, RuntimeCall, WithRialtoParachainMessagesInstance,
|
|
||||||
WithRialtoParachainsInstance,
|
|
||||||
};
|
|
||||||
use sp_runtime::{transaction_validity::InvalidTransaction, DispatchError};
|
use sp_runtime::{transaction_validity::InvalidTransaction, DispatchError};
|
||||||
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub TestParachain: u32 = 1000;
|
pub TestParachain: u32 = 1000;
|
||||||
pub TestLaneId: LaneId = LaneId([0, 0, 0, 0]);
|
pub TestLaneId: LaneId = TEST_LANE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestExtension = RefundRelayerForMessagesFromParachain<
|
type TestExtension = RefundRelayerForMessagesFromParachain<
|
||||||
millau_runtime::Runtime,
|
TestRuntime,
|
||||||
RialtoGrandpaInstance,
|
(),
|
||||||
WithRialtoParachainsInstance,
|
(),
|
||||||
WithRialtoParachainMessagesInstance,
|
(),
|
||||||
millau_runtime::BridgeRejectObsoleteHeadersAndMessages,
|
BridgeRejectObsoleteHeadersAndMessages,
|
||||||
TestParachain,
|
TestParachain,
|
||||||
TestLaneId,
|
TestLaneId,
|
||||||
millau_runtime::Runtime,
|
TestRuntime,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn relayer_account() -> millau_runtime::AccountId {
|
fn relayer_account_at_this_chain() -> ThisChainAccountId {
|
||||||
[0u8; 32].into()
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn relayer_account_at_bridged_chain() -> BridgedChainAccountId {
|
||||||
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize_environment(
|
fn initialize_environment(
|
||||||
@@ -513,9 +509,7 @@ mod tests {
|
|||||||
best_delivered_message: MessageNonce,
|
best_delivered_message: MessageNonce,
|
||||||
) {
|
) {
|
||||||
let best_relay_header = HeaderId(best_relay_header_number, RelayBlockHash::default());
|
let best_relay_header = HeaderId(best_relay_header_number, RelayBlockHash::default());
|
||||||
pallet_bridge_grandpa::BestFinalized::<Runtime, RialtoGrandpaInstance>::put(
|
pallet_bridge_grandpa::BestFinalized::<TestRuntime>::put(best_relay_header);
|
||||||
best_relay_header,
|
|
||||||
);
|
|
||||||
|
|
||||||
let para_id = ParaId(TestParachain::get());
|
let para_id = ParaId(TestParachain::get());
|
||||||
let para_info = ParaInfo {
|
let para_info = ParaInfo {
|
||||||
@@ -525,18 +519,16 @@ mod tests {
|
|||||||
},
|
},
|
||||||
next_imported_hash_position: 0,
|
next_imported_hash_position: 0,
|
||||||
};
|
};
|
||||||
pallet_bridge_parachains::ParasInfo::<Runtime, WithRialtoParachainsInstance>::insert(
|
pallet_bridge_parachains::ParasInfo::<TestRuntime>::insert(para_id, para_info);
|
||||||
para_id, para_info,
|
|
||||||
);
|
|
||||||
|
|
||||||
let lane_id = TestLaneId::get();
|
let lane_id = TestLaneId::get();
|
||||||
let lane_data =
|
let lane_data =
|
||||||
InboundLaneData { last_confirmed_nonce: best_delivered_message, ..Default::default() };
|
InboundLaneData { last_confirmed_nonce: best_delivered_message, ..Default::default() };
|
||||||
pallet_bridge_messages::InboundLanes::<Runtime, WithRialtoParachainMessagesInstance>::insert(lane_id, lane_data);
|
pallet_bridge_messages::InboundLanes::<TestRuntime>::insert(lane_id, lane_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_relay_header_call(relay_header_number: RelayBlockNumber) -> RuntimeCall {
|
fn submit_relay_header_call(relay_header_number: RelayBlockNumber) -> RuntimeCall {
|
||||||
let relay_header = bp_rialto::Header::new(
|
let relay_header = BridgedChainHeader::new(
|
||||||
relay_header_number,
|
relay_header_number,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -545,7 +537,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
let relay_justification = make_default_justification(&relay_header);
|
let relay_justification = make_default_justification(&relay_header);
|
||||||
|
|
||||||
RuntimeCall::BridgeRialtoGrandpa(GrandpaCall::submit_finality_proof {
|
RuntimeCall::BridgeGrandpa(GrandpaCall::submit_finality_proof {
|
||||||
finality_target: Box::new(relay_header),
|
finality_target: Box::new(relay_header),
|
||||||
justification: relay_justification,
|
justification: relay_justification,
|
||||||
})
|
})
|
||||||
@@ -554,7 +546,7 @@ mod tests {
|
|||||||
fn submit_parachain_head_call(
|
fn submit_parachain_head_call(
|
||||||
parachain_head_at_relay_header_number: RelayBlockNumber,
|
parachain_head_at_relay_header_number: RelayBlockNumber,
|
||||||
) -> RuntimeCall {
|
) -> RuntimeCall {
|
||||||
RuntimeCall::BridgeRialtoParachains(ParachainsCall::submit_parachain_heads {
|
RuntimeCall::BridgeParachains(ParachainsCall::submit_parachain_heads {
|
||||||
at_relay_block: (parachain_head_at_relay_header_number, RelayBlockHash::default()),
|
at_relay_block: (parachain_head_at_relay_header_number, RelayBlockHash::default()),
|
||||||
parachains: vec![(ParaId(TestParachain::get()), [1u8; 32].into())],
|
parachains: vec![(ParaId(TestParachain::get()), [1u8; 32].into())],
|
||||||
parachain_heads_proof: ParaHeadsProof(vec![]),
|
parachain_heads_proof: ParaHeadsProof(vec![]),
|
||||||
@@ -562,9 +554,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn message_delivery_call(best_message: MessageNonce) -> RuntimeCall {
|
fn message_delivery_call(best_message: MessageNonce) -> RuntimeCall {
|
||||||
RuntimeCall::BridgeRialtoParachainMessages(MessagesCall::receive_messages_proof {
|
RuntimeCall::BridgeMessages(MessagesCall::receive_messages_proof {
|
||||||
relayer_id_at_bridged_chain: relayer_account(),
|
relayer_id_at_bridged_chain: relayer_account_at_bridged_chain(),
|
||||||
proof: millau_runtime::bridge_runtime_common::messages::target::FromBridgedChainMessagesProof {
|
proof: FromBridgedChainMessagesProof {
|
||||||
bridged_header_hash: Default::default(),
|
bridged_header_hash: Default::default(),
|
||||||
storage_proof: vec![],
|
storage_proof: vec![],
|
||||||
lane: TestLaneId::get(),
|
lane: TestLaneId::get(),
|
||||||
@@ -602,9 +594,9 @@ mod tests {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_finality_pre_dispatch_data() -> PreDispatchData<millau_runtime::AccountId> {
|
fn all_finality_pre_dispatch_data() -> PreDispatchData<ThisChainAccountId> {
|
||||||
PreDispatchData {
|
PreDispatchData {
|
||||||
relayer: relayer_account(),
|
relayer: relayer_account_at_this_chain(),
|
||||||
call_type: CallType::AllFinalityAndDelivery(
|
call_type: CallType::AllFinalityAndDelivery(
|
||||||
ExpectedRelayChainState { best_block_number: 200 },
|
ExpectedRelayChainState { best_block_number: 200 },
|
||||||
ExpectedParachainState { at_relay_block_number: 200 },
|
ExpectedParachainState { at_relay_block_number: 200 },
|
||||||
@@ -613,9 +605,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parachain_finality_pre_dispatch_data() -> PreDispatchData<millau_runtime::AccountId> {
|
fn parachain_finality_pre_dispatch_data() -> PreDispatchData<ThisChainAccountId> {
|
||||||
PreDispatchData {
|
PreDispatchData {
|
||||||
relayer: relayer_account(),
|
relayer: relayer_account_at_this_chain(),
|
||||||
call_type: CallType::ParachainFinalityAndDelivery(
|
call_type: CallType::ParachainFinalityAndDelivery(
|
||||||
ExpectedParachainState { at_relay_block_number: 200 },
|
ExpectedParachainState { at_relay_block_number: 200 },
|
||||||
MessagesState { best_nonce: 100 },
|
MessagesState { best_nonce: 100 },
|
||||||
@@ -623,9 +615,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delivery_pre_dispatch_data() -> PreDispatchData<millau_runtime::AccountId> {
|
fn delivery_pre_dispatch_data() -> PreDispatchData<ThisChainAccountId> {
|
||||||
PreDispatchData {
|
PreDispatchData {
|
||||||
relayer: relayer_account(),
|
relayer: relayer_account_at_this_chain(),
|
||||||
call_type: CallType::Delivery(MessagesState { best_nonce: 100 }),
|
call_type: CallType::Delivery(MessagesState { best_nonce: 100 }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,14 +628,14 @@ mod tests {
|
|||||||
|
|
||||||
fn run_validate(call: RuntimeCall) -> TransactionValidity {
|
fn run_validate(call: RuntimeCall) -> TransactionValidity {
|
||||||
let extension: TestExtension = RefundRelayerForMessagesFromParachain(PhantomData);
|
let extension: TestExtension = RefundRelayerForMessagesFromParachain(PhantomData);
|
||||||
extension.validate(&relayer_account(), &call, &DispatchInfo::default(), 0)
|
extension.validate(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_pre_dispatch(
|
fn run_pre_dispatch(
|
||||||
call: RuntimeCall,
|
call: RuntimeCall,
|
||||||
) -> Result<Option<PreDispatchData<millau_runtime::AccountId>>, TransactionValidityError> {
|
) -> Result<Option<PreDispatchData<ThisChainAccountId>>, TransactionValidityError> {
|
||||||
let extension: TestExtension = RefundRelayerForMessagesFromParachain(PhantomData);
|
let extension: TestExtension = RefundRelayerForMessagesFromParachain(PhantomData);
|
||||||
extension.pre_dispatch(&relayer_account(), &call, &DispatchInfo::default(), 0)
|
extension.pre_dispatch(&relayer_account_at_this_chain(), &call, &DispatchInfo::default(), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_info() -> DispatchInfo {
|
fn dispatch_info() -> DispatchInfo {
|
||||||
@@ -661,7 +653,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_post_dispatch(
|
fn run_post_dispatch(
|
||||||
pre_dispatch_data: Option<PreDispatchData<millau_runtime::AccountId>>,
|
pre_dispatch_data: Option<PreDispatchData<ThisChainAccountId>>,
|
||||||
dispatch_result: DispatchResult,
|
dispatch_result: DispatchResult,
|
||||||
) {
|
) {
|
||||||
let post_dispatch_result = TestExtension::post_dispatch(
|
let post_dispatch_result = TestExtension::post_dispatch(
|
||||||
@@ -674,8 +666,8 @@ mod tests {
|
|||||||
assert_eq!(post_dispatch_result, Ok(()));
|
assert_eq!(post_dispatch_result, Ok(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_reward() -> millau_runtime::Balance {
|
fn expected_reward() -> ThisChainBalance {
|
||||||
pallet_transaction_payment::Pallet::<Runtime>::compute_actual_fee(
|
pallet_transaction_payment::Pallet::<TestRuntime>::compute_actual_fee(
|
||||||
1024,
|
1024,
|
||||||
&dispatch_info(),
|
&dispatch_info(),
|
||||||
&post_dispatch_info(),
|
&post_dispatch_info(),
|
||||||
@@ -804,7 +796,7 @@ mod tests {
|
|||||||
|
|
||||||
let call = RuntimeCall::Utility(UtilityCall::batch_all {
|
let call = RuntimeCall::Utility(UtilityCall::batch_all {
|
||||||
calls: vec![
|
calls: vec![
|
||||||
RuntimeCall::BridgeRialtoParachains(ParachainsCall::submit_parachain_heads {
|
RuntimeCall::BridgeParachains(ParachainsCall::submit_parachain_heads {
|
||||||
at_relay_block: (100, RelayBlockHash::default()),
|
at_relay_block: (100, RelayBlockHash::default()),
|
||||||
parachains: vec![
|
parachains: vec![
|
||||||
(ParaId(TestParachain::get()), [1u8; 32].into()),
|
(ParaId(TestParachain::get()), [1u8; 32].into()),
|
||||||
@@ -892,7 +884,10 @@ mod tests {
|
|||||||
|
|
||||||
run_post_dispatch(Some(all_finality_pre_dispatch_data()), Ok(()));
|
run_post_dispatch(Some(all_finality_pre_dispatch_data()), Ok(()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
RelayersPallet::<Runtime>::relayer_reward(relayer_account(), TestLaneId::get()),
|
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||||
|
relayer_account_at_this_chain(),
|
||||||
|
TestLaneId::get()
|
||||||
|
),
|
||||||
Some(expected_reward()),
|
Some(expected_reward()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -905,7 +900,10 @@ mod tests {
|
|||||||
|
|
||||||
run_post_dispatch(Some(parachain_finality_pre_dispatch_data()), Ok(()));
|
run_post_dispatch(Some(parachain_finality_pre_dispatch_data()), Ok(()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
RelayersPallet::<Runtime>::relayer_reward(relayer_account(), TestLaneId::get()),
|
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||||
|
relayer_account_at_this_chain(),
|
||||||
|
TestLaneId::get()
|
||||||
|
),
|
||||||
Some(expected_reward()),
|
Some(expected_reward()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -918,7 +916,10 @@ mod tests {
|
|||||||
|
|
||||||
run_post_dispatch(Some(delivery_pre_dispatch_data()), Ok(()));
|
run_post_dispatch(Some(delivery_pre_dispatch_data()), Ok(()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
RelayersPallet::<Runtime>::relayer_reward(relayer_account(), TestLaneId::get()),
|
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||||
|
relayer_account_at_this_chain(),
|
||||||
|
TestLaneId::get()
|
||||||
|
),
|
||||||
Some(expected_reward()),
|
Some(expected_reward()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ std = [
|
|||||||
"bp-relayers/std",
|
"bp-relayers/std",
|
||||||
"bp-runtime/std",
|
"bp-runtime/std",
|
||||||
"codec/std",
|
"codec/std",
|
||||||
|
"frame-benchmarking/std",
|
||||||
"frame-support/std",
|
"frame-support/std",
|
||||||
"frame-system/std",
|
"frame-system/std",
|
||||||
"log/std",
|
"log/std",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use bp_runtime::{messages::MessageDispatchResult, Size};
|
|||||||
use codec::{Decode, Encode, Error as CodecError};
|
use codec::{Decode, Encode, Error as CodecError};
|
||||||
use frame_support::{weights::Weight, Parameter, RuntimeDebug};
|
use frame_support::{weights::Weight, Parameter, RuntimeDebug};
|
||||||
use scale_info::TypeInfo;
|
use scale_info::TypeInfo;
|
||||||
use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, prelude::*};
|
use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, marker::PhantomData, prelude::*};
|
||||||
|
|
||||||
/// Proved messages from the source chain.
|
/// Proved messages from the source chain.
|
||||||
pub type ProvedMessages<Message> = BTreeMap<LaneId, ProvedLaneMessages<Message>>;
|
pub type ProvedMessages<Message> = BTreeMap<LaneId, ProvedLaneMessages<Message>>;
|
||||||
@@ -164,15 +164,19 @@ impl<AccountId> DeliveryPayments<AccountId> for () {
|
|||||||
|
|
||||||
/// Structure that may be used in place of `SourceHeaderChain` and `MessageDispatch` on chains,
|
/// Structure that may be used in place of `SourceHeaderChain` and `MessageDispatch` on chains,
|
||||||
/// where inbound messages are forbidden.
|
/// where inbound messages are forbidden.
|
||||||
pub struct ForbidInboundMessages;
|
pub struct ForbidInboundMessages<MessagesProof, DispatchPayload>(
|
||||||
|
PhantomData<(MessagesProof, DispatchPayload)>,
|
||||||
|
);
|
||||||
|
|
||||||
/// Error message that is used in `ForbidOutboundMessages` implementation.
|
/// Error message that is used in `ForbidOutboundMessages` implementation.
|
||||||
const ALL_INBOUND_MESSAGES_REJECTED: &str =
|
const ALL_INBOUND_MESSAGES_REJECTED: &str =
|
||||||
"This chain is configured to reject all inbound messages";
|
"This chain is configured to reject all inbound messages";
|
||||||
|
|
||||||
impl SourceHeaderChain for ForbidInboundMessages {
|
impl<MessagesProof: Parameter + Size, DispatchPayload> SourceHeaderChain
|
||||||
|
for ForbidInboundMessages<MessagesProof, DispatchPayload>
|
||||||
|
{
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
type MessagesProof = ();
|
type MessagesProof = MessagesProof;
|
||||||
|
|
||||||
fn verify_messages_proof(
|
fn verify_messages_proof(
|
||||||
_proof: Self::MessagesProof,
|
_proof: Self::MessagesProof,
|
||||||
@@ -182,8 +186,10 @@ impl SourceHeaderChain for ForbidInboundMessages {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<AccountId> MessageDispatch<AccountId> for ForbidInboundMessages {
|
impl<MessagesProof, DispatchPayload: Decode, AccountId> MessageDispatch<AccountId>
|
||||||
type DispatchPayload = ();
|
for ForbidInboundMessages<MessagesProof, DispatchPayload>
|
||||||
|
{
|
||||||
|
type DispatchPayload = DispatchPayload;
|
||||||
type DispatchLevelResult = ();
|
type DispatchLevelResult = ();
|
||||||
|
|
||||||
fn dispatch_weight(_message: &mut DispatchMessage<Self::DispatchPayload>) -> Weight {
|
fn dispatch_weight(_message: &mut DispatchMessage<Self::DispatchPayload>) -> Weight {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
|
|||||||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bp-rialto = { path = "../chain-rialto" }
|
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
hex-literal = "0.3"
|
hex-literal = "0.3"
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,14 @@ pub trait PaymentProcedure<Relayer, Reward> {
|
|||||||
fn pay_reward(relayer: &Relayer, lane_id: LaneId, reward: Reward) -> Result<(), Self::Error>;
|
fn pay_reward(relayer: &Relayer, lane_id: LaneId, reward: Reward) -> Result<(), Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Relayer, Reward> PaymentProcedure<Relayer, Reward> for () {
|
||||||
|
type Error = &'static str;
|
||||||
|
|
||||||
|
fn pay_reward(_: &Relayer, _: LaneId, _: Reward) -> Result<(), Self::Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Reward payment procedure that does `balances::transfer` call from the account, derived from
|
/// Reward payment procedure that does `balances::transfer` call from the account, derived from
|
||||||
/// given lane.
|
/// given lane.
|
||||||
pub struct PayLaneRewardFromAccount<T, Relayer>(PhantomData<(T, Relayer)>);
|
pub struct PayLaneRewardFromAccount<T, Relayer>(PhantomData<(T, Relayer)>);
|
||||||
@@ -88,21 +96,18 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use sp_runtime::testing::H256;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lanes_are_using_different_accounts() {
|
fn lanes_are_using_different_accounts() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
PayLaneRewardFromAccount::<(), bp_rialto::AccountId>::lane_rewards_account(LaneId([
|
PayLaneRewardFromAccount::<(), H256>::lane_rewards_account(LaneId([0, 0, 0, 0])),
|
||||||
0, 0, 0, 0
|
|
||||||
])),
|
|
||||||
hex_literal::hex!("626c616e000000006272696467652d6c616e6500000000000000000000000000")
|
hex_literal::hex!("626c616e000000006272696467652d6c616e6500000000000000000000000000")
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
PayLaneRewardFromAccount::<(), bp_rialto::AccountId>::lane_rewards_account(LaneId([
|
PayLaneRewardFromAccount::<(), H256>::lane_rewards_account(LaneId([0, 0, 0, 1])),
|
||||||
0, 0, 0, 1
|
|
||||||
])),
|
|
||||||
hex_literal::hex!("626c616e000000016272696467652d6c616e6500000000000000000000000000")
|
hex_literal::hex!("626c616e000000016272696467652d6c616e6500000000000000000000000000")
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn maximal_rialto_to_millau_message_size_is_computed_correctly() {
|
fn maximal_rialto_to_millau_message_size_is_computed_correctly() {
|
||||||
use rialto_runtime::millau_messages::Millau;
|
use rialto_runtime::millau_messages::MillauAsTargetHeaderChain;
|
||||||
|
|
||||||
let maximal_message_size = encode_message::compute_maximal_message_size(
|
let maximal_message_size = encode_message::compute_maximal_message_size(
|
||||||
bp_rialto::Rialto::max_extrinsic_size(),
|
bp_rialto::Rialto::max_extrinsic_size(),
|
||||||
@@ -60,10 +60,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let message = vec![42; maximal_message_size as _];
|
let message = vec![42; maximal_message_size as _];
|
||||||
assert_eq!(Millau::verify_message(&message), Ok(()));
|
assert_eq!(MillauAsTargetHeaderChain::verify_message(&message), Ok(()));
|
||||||
|
|
||||||
let message = vec![42; (maximal_message_size + 1) as _];
|
let message = vec![42; (maximal_message_size + 1) as _];
|
||||||
assert!(Millau::verify_message(&message).is_err());
|
assert!(MillauAsTargetHeaderChain::verify_message(&message).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user