Skip to content

Commit

Permalink
refactor transaction sign scheme (paritytech#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent 8d0dd03 commit 4a1c5c7
Show file tree
Hide file tree
Showing 36 changed files with 188 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto {
rialto_runtime::Runtime,
rialto_runtime::MillauGrandpaInstance,
>;
type TransactionSignScheme = relay_rialto_client::Rialto;
}

//// `Millau` to `Rialto` bridge definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
rialto_parachain_runtime::Runtime,
rialto_parachain_runtime::MillauGrandpaInstance,
>;
type TransactionSignScheme = relay_rialto_parachain_client::RialtoParachain;
}

//// `Millau` to `RialtoParachain` bridge definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
type SourceChain = Millau;
type TargetChain = Rialto;

type SourceTransactionSignScheme = Millau;
type TargetTransactionSignScheme = Rialto;

type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
Self,
rialto_runtime::Runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
type SourceChain = Millau;
type TargetChain = RialtoParachain;

type SourceTransactionSignScheme = Millau;
type TargetTransactionSignScheme = RialtoParachain;

type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
Self,
rialto_parachain_runtime::Runtime,
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/bin-substrate/src/chains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod tests {
use codec::Encode;
use relay_millau_client::Millau;
use relay_rialto_client::Rialto;
use relay_substrate_client::{SignParam, TransactionSignScheme, UnsignedTransaction};
use relay_substrate_client::{ChainWithTransactions, SignParam, UnsignedTransaction};

#[test]
fn maximal_rialto_to_millau_message_size_is_computed_correctly() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau {
millau_runtime::Runtime,
millau_runtime::RialtoGrandpaInstance,
>;
type TransactionSignScheme = relay_millau_client::Millau;
}

//// `Rialto` to `Millau` bridge definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
type SourceChain = Rialto;
type TargetChain = Millau;

type SourceTransactionSignScheme = Rialto;
type TargetTransactionSignScheme = Millau;

type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
Self,
millau_runtime::Runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ impl SubstrateMessageLane for RialtoParachainMessagesToMillau {
type SourceChain = RialtoParachain;
type TargetChain = Millau;

type SourceTransactionSignScheme = RialtoParachain;
type TargetTransactionSignScheme = Millau;

type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
Self,
millau_runtime::Runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ impl SubstrateParachainsPipeline for RialtoParachainsToMillau {
type TargetChain = Millau;

type SubmitParachainHeadsCallBuilder = RialtoParachainsToMillauSubmitParachainHeadsCallBuilder;
type TransactionSignScheme = Millau;

const SOURCE_PARACHAIN_PARA_ID: u32 = bp_rialto_parachain::RIALTO_PARACHAIN_ID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau {
millau_runtime::Runtime,
millau_runtime::WestendGrandpaInstance,
>;
type TransactionSignScheme = relay_millau_client::Millau;
}

//// `Westend` to `Millau` bridge definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl SubstrateParachainsPipeline for WestendParachainsToMillau {
type TargetChain = Millau;

type SubmitParachainHeadsCallBuilder = WestendParachainsToMillauSubmitParachainHeadsCallBuilder;
type TransactionSignScheme = Millau;

const SOURCE_PARACHAIN_PARA_ID: u32 = bp_westend::WESTMINT_PARACHAIN_ID;
}
Expand Down
11 changes: 2 additions & 9 deletions bridges/relays/bin-substrate/src/cli/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::cli::CliChain;
use messages_relay::relay_strategy::MixStrategy;
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
use parachains_relay::ParachainsPipeline;
use relay_substrate_client::{AccountKeyPairOf, Chain, RelayChain, TransactionSignScheme};
use relay_substrate_client::{AccountKeyPairOf, Chain, ChainWithTransactions, RelayChain};
use strum::{EnumString, EnumVariantNames};
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline, messages_lane::SubstrateMessageLane,
Expand Down Expand Up @@ -58,9 +58,7 @@ pub trait CliBridgeBase: Sized {
/// The source chain.
type Source: Chain + CliChain;
/// The target chain.
type Target: Chain
+ TransactionSignScheme<Chain = Self::Target>
+ CliChain<KeyPair = AccountKeyPairOf<Self::Target>>;
type Target: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Target>>;
}

/// Bridge representation that can be used from the CLI for relaying headers
Expand All @@ -70,7 +68,6 @@ pub trait RelayToRelayHeadersCliBridge: CliBridgeBase {
type Finality: SubstrateFinalitySyncPipeline<
SourceChain = Self::Source,
TargetChain = Self::Target,
TransactionSignScheme = Self::Target,
>;
}

Expand All @@ -87,13 +84,11 @@ pub trait ParachainToRelayHeadersCliBridge: CliBridgeBase {
SourceRelayChain = Self::SourceRelay,
SourceParachain = Self::Source,
TargetChain = Self::Target,
TransactionSignScheme = Self::Target,
> + ParachainsPipeline<SourceChain = Self::SourceRelay, TargetChain = Self::Target>;
/// Finality proofs synchronization pipeline (source relay chain -> target).
type RelayFinality: SubstrateFinalitySyncPipeline<
SourceChain = Self::SourceRelay,
TargetChain = Self::Target,
TransactionSignScheme = Self::Target,
>;
}

Expand All @@ -106,8 +101,6 @@ pub trait MessagesCliBridge: CliBridgeBase {
type MessagesLane: SubstrateMessageLane<
SourceChain = Self::Source,
TargetChain = Self::Target,
SourceTransactionSignScheme = Self::Source,
TargetTransactionSignScheme = Self::Target,
RelayStrategy = MixStrategy,
>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use bp_messages::LaneId;
use bp_runtime::{BalanceOf, BlockNumberOf};
use messages_relay::relay_strategy::MixStrategy;
use relay_substrate_client::{
AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, Client, TransactionSignScheme,
AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, ChainWithTransactions, Client,
};
use relay_utils::metrics::MetricsParams;
use sp_core::Pair;
Expand Down Expand Up @@ -93,8 +93,8 @@ pub struct HeadersAndMessagesSharedParams {
}

pub struct Full2WayBridgeCommonParams<
Left: TransactionSignScheme + CliChain,
Right: TransactionSignScheme + CliChain,
Left: ChainWithTransactions + CliChain,
Right: ChainWithTransactions + CliChain,
> {
pub shared: HeadersAndMessagesSharedParams,
pub left: BridgeEndCommonParams<Left>,
Expand All @@ -105,7 +105,7 @@ pub struct Full2WayBridgeCommonParams<
pub right_to_left_metrics: StandaloneMessagesMetrics<Right, Left>,
}

impl<Left: TransactionSignScheme + CliChain, Right: TransactionSignScheme + CliChain>
impl<Left: ChainWithTransactions + CliChain, Right: ChainWithTransactions + CliChain>
Full2WayBridgeCommonParams<Left, Right>
{
pub fn new<L2R: MessagesCliBridge<Source = Left, Target = Right>>(
Expand All @@ -132,7 +132,7 @@ impl<Left: TransactionSignScheme + CliChain, Right: TransactionSignScheme + CliC
}
}

pub struct BridgeEndCommonParams<Chain: TransactionSignScheme + CliChain> {
pub struct BridgeEndCommonParams<Chain: ChainWithTransactions + CliChain> {
pub client: Client<Chain>,
pub sign: AccountKeyPairOf<Chain>,
pub transactions_mortality: Option<u32>,
Expand All @@ -142,8 +142,8 @@ pub struct BridgeEndCommonParams<Chain: TransactionSignScheme + CliChain> {

struct FullBridge<
'a,
Source: TransactionSignScheme + CliChain,
Target: TransactionSignScheme + CliChain,
Source: ChainWithTransactions + CliChain,
Target: ChainWithTransactions + CliChain,
Bridge: MessagesCliBridge<Source = Source, Target = Target>,
> {
shared: &'a HeadersAndMessagesSharedParams,
Expand All @@ -156,8 +156,8 @@ struct FullBridge<

impl<
'a,
Source: TransactionSignScheme<Chain = Source> + CliChain,
Target: TransactionSignScheme<Chain = Target> + CliChain,
Source: ChainWithTransactions + CliChain,
Target: ChainWithTransactions + CliChain,
Bridge: MessagesCliBridge<Source = Source, Target = Target>,
> FullBridge<'a, Source, Target, Bridge>
where
Expand Down Expand Up @@ -186,7 +186,6 @@ where
};
substrate_relay_helper::conversion_rate_update::run_conversion_rate_update_loop::<
Bridge::MessagesLane,
Source,
>(
self.source.client.clone(),
TransactionParams {
Expand Down Expand Up @@ -266,11 +265,9 @@ trait Full2WayBridgeBase: Sized + Send + Sync {
/// The CLI params for the bridge.
type Params;
/// The left relay chain.
type Left: TransactionSignScheme<Chain = Self::Left>
+ CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
type Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
/// The right destination chain (it can be a relay or a parachain).
type Right: TransactionSignScheme<Chain = Self::Right>
+ CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;
type Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;

fn common(&self) -> &Full2WayBridgeCommonParams<Self::Left, Self::Right>;

Expand All @@ -295,14 +292,12 @@ where
type Base: Full2WayBridgeBase<Left = Self::Left, Right = Self::Right>;

/// The left relay chain.
type Left: Chain
type Left: ChainWithTransactions
+ ChainWithBalances
+ TransactionSignScheme<Chain = Self::Left>
+ CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
/// The right relay chain.
type Right: Chain
type Right: ChainWithTransactions
+ ChainWithBalances
+ TransactionSignScheme<Chain = Self::Right>
+ CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;

// Left to Right bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::cli::{
use bp_polkadot_core::parachains::ParaHash;
use bp_runtime::BlockNumberOf;
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, Chain, Client, TransactionSignScheme};
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, Chain, ChainWithTransactions, Client};
use sp_core::Pair;
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
Expand Down Expand Up @@ -95,9 +95,9 @@ macro_rules! declare_relay_to_parachain_bridge_schema {

impl [<$left_chain $right_parachain HeadersAndMessages>] {
async fn into_bridge<
Left: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Right>>,
RightRelay: TransactionSignScheme + CliChain,
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
RightRelay: ChainWithTransactions + CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
R2L: CliBridgeBase<Source = Right, Target = Left>
+ MessagesCliBridge
Expand Down Expand Up @@ -146,12 +146,12 @@ macro_rules! declare_relay_to_parachain_bridge_schema {

#[async_trait]
impl<
Left: Chain + TransactionSignScheme<Chain = Left> + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: Chain<Hash = ParaHash>
+ TransactionSignScheme<Chain = Right>
+ ChainWithTransactions
+ CliChain<KeyPair = AccountKeyPairOf<Right>>,
RightRelay: Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash, Hasher = RelayBlockHasher>
+ TransactionSignScheme
+ ChainWithTransactions
+ CliChain,
L2R: CliBridgeBase<Source = Left, Target = Right>
+ MessagesCliBridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::cli::{
CliChain,
};
use bp_runtime::BlockNumberOf;
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, Chain, TransactionSignScheme};
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, ChainWithTransactions};
use sp_core::Pair;
use substrate_relay_helper::{
finality::SubstrateFinalitySyncPipeline,
Expand Down Expand Up @@ -77,8 +77,8 @@ macro_rules! declare_relay_to_relay_bridge_schema {

impl [<$left_chain $right_chain HeadersAndMessages>] {
async fn into_bridge<
Left: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Right>>,
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
L2R: CliBridgeBase<Source = Left, Target = Right> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
R2L: CliBridgeBase<Source = Right, Target = Left> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
>(
Expand Down Expand Up @@ -117,8 +117,8 @@ macro_rules! declare_relay_to_relay_bridge_schema {

#[async_trait]
impl<
Left: Chain + TransactionSignScheme<Chain = Left> + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: Chain + TransactionSignScheme<Chain = Right> + CliChain<KeyPair = AccountKeyPairOf<Right>>,
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
L2R: CliBridgeBase<Source = Left, Target = Right>
+ MessagesCliBridge
+ RelayToRelayHeadersCliBridge,
Expand Down
5 changes: 2 additions & 3 deletions bridges/relays/bin-substrate/src/cli/relay_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::chains::{
rialto_parachains_to_millau::RialtoParachainToMillauCliBridge,
};
use messages_relay::relay_strategy::MixStrategy;
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, BalanceOf, TransactionSignScheme};
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, BalanceOf, ChainWithTransactions};
use substrate_relay_helper::{messages_lane::MessagesRelayParams, TransactionParams};

use crate::cli::{bridge::*, chain_schema::*, CliChain, HexLaneId, PrometheusParams};
Expand Down Expand Up @@ -77,8 +77,7 @@ pub struct RelayMessages {
#[async_trait]
trait MessagesRelayer: MessagesCliBridge
where
Self::Source: TransactionSignScheme<Chain = Self::Source>
+ CliChain<KeyPair = AccountKeyPairOf<Self::Source>>,
Self::Source: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Source>>,
AccountIdOf<Self::Source>: From<<AccountKeyPairOf<Self::Source> as Pair>::Public>,
AccountIdOf<Self::Target>: From<<AccountKeyPairOf<Self::Target> as Pair>::Public>,
BalanceOf<Self::Source>: TryFrom<BalanceOf<Self::Target>>,
Expand Down
Loading

0 comments on commit 4a1c5c7

Please sign in to comment.