Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub mod pallet {
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type of relayer reward.
type Reward: AtLeast32BitUnsigned + Copy + Parameter + MaxEncodedLen;
type Reward: AtLeast32BitUnsigned + Copy + Member + Parameter + MaxEncodedLen;
/// Pay rewards scheme.
type PaymentProcedure: PaymentProcedure<Self::AccountId, Self::Reward>;
/// Stake and slash scheme.
Expand Down
4 changes: 2 additions & 2 deletions primitives/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ pub struct RelayerRewardsKeyProvider<AccountId, Reward>(PhantomData<(AccountId,

impl<AccountId, Reward> StorageDoubleMapKeyProvider for RelayerRewardsKeyProvider<AccountId, Reward>
where
AccountId: Codec + EncodeLike,
Reward: Codec + EncodeLike,
AccountId: 'static + Codec + EncodeLike + Send + Sync,
Reward: 'static + Codec + EncodeLike + Send + Sync,
{
const MAP_NAME: &'static str = "RelayerRewards";

Expand Down
10 changes: 5 additions & 5 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ pub trait StorageMapKeyProvider {
/// The same as `StorageMap::Hasher1`.
type Hasher: StorageHasher;
/// The same as `StorageMap::Key1`.
type Key: FullCodec;
type Key: FullCodec + Send + Sync;
/// The same as `StorageMap::Value`.
type Value: FullCodec;
type Value: 'static + FullCodec;

/// This is a copy of the
/// `frame_support::storage::generator::StorageMap::storage_map_final_key`.
Expand All @@ -326,13 +326,13 @@ pub trait StorageDoubleMapKeyProvider {
/// The same as `StorageDoubleMap::Hasher1`.
type Hasher1: StorageHasher;
/// The same as `StorageDoubleMap::Key1`.
type Key1: FullCodec;
type Key1: FullCodec + Send + Sync;
/// The same as `StorageDoubleMap::Hasher2`.
type Hasher2: StorageHasher;
/// The same as `StorageDoubleMap::Key2`.
type Key2: FullCodec;
type Key2: FullCodec + Send + Sync;
/// The same as `StorageDoubleMap::Value`.
type Value: FullCodec;
type Value: 'static + FullCodec;

/// This is a copy of the
/// `frame_support::storage::generator::StorageDoubleMap::storage_double_map_final_key`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SubstrateFinalitySyncPipeline for KusamaFinalityToBridgeHubPolkadot {
type SubmitFinalityProofCallBuilder = KusamaFinalityToBridgeHubPolkadotCallBuilder;

async fn start_relay_guards(
target_client: &Client<Self::TargetChain>,
target_client: &impl Client<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
enable_version_guard: bool,
) -> relay_substrate_client::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SubstrateFinalitySyncPipeline for PolkadotFinalityToBridgeHubKusama {
type SubmitFinalityProofCallBuilder = PolkadotFinalityToBridgeHubKusamaCallBuilder;

async fn start_relay_guards(
target_client: &Client<Self::TargetChain>,
target_client: &impl Client<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
enable_version_guard: bool,
) -> relay_substrate_client::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SubstrateFinalitySyncPipeline for RococoFinalityToBridgeHubWococo {
type SubmitFinalityProofCallBuilder = RococoFinalityToBridgeHubWococoCallBuilder;

async fn start_relay_guards(
target_client: &Client<Self::TargetChain>,
target_client: &impl Client<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
enable_version_guard: bool,
) -> relay_substrate_client::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl SubstrateFinalitySyncPipeline for WococoFinalityToBridgeHubRococo {
type SubmitFinalityProofCallBuilder = WococoFinalityToBridgeHubRococoCallBuilder;

async fn start_relay_guards(
target_client: &Client<Self::TargetChain>,
target_client: &impl Client<Self::TargetChain>,
_transaction_params: &TransactionParams<AccountKeyPairOf<Self::TargetChain>>,
enable_version_guard: bool,
) -> relay_substrate_client::Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions relays/bin-substrate/src/cli/chain_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ macro_rules! declare_chain_connection_params_cli_schema {
#[allow(dead_code)]
pub async fn into_client<Chain: CliChain>(
self,
) -> anyhow::Result<relay_substrate_client::Client<Chain>> {
) -> anyhow::Result<$crate::cli::DefaultClient<Chain>> {
let chain_runtime_version = self
.[<$chain_prefix _runtime_version>]
.into_runtime_version(Chain::RUNTIME_VERSION)?;
Ok(relay_substrate_client::Client::new(relay_substrate_client::ConnectionParams {
Ok(relay_substrate_client::new(relay_substrate_client::ConnectionParams {
host: self.[<$chain_prefix _host>],
port: self.[<$chain_prefix _port>],
secure: self.[<$chain_prefix _secure>],
Expand Down
5 changes: 5 additions & 0 deletions relays/bin-substrate/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ mod resubmit_transactions;
/// The target that will be used when publishing logs related to this pallet.
pub const LOG_TARGET: &str = "bridge";

/// Default Substrate client type that we are using. We'll use it all over the glue CLI code
/// to avoid multiple level generic arguments and constraints. We still allow usage of other
/// clients in the **core logic code**.
pub type DefaultClient<C> = relay_substrate_client::RpcWithCachingClient<C>;

/// Parse relay CLI args.
pub fn parse_args() -> Command {
Command::from_args()
Expand Down
10 changes: 6 additions & 4 deletions relays/bin-substrate/src/cli/register_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ impl RegisterParachain {

// hopefully we're the only actor that is registering parachain right now
// => read next parachain id
let best_relay_header_hash = relay_client.best_header_hash().await?;
let para_id_key = bp_runtime::storage_value_final_key(
PARAS_REGISTRAR_PALLET_NAME.as_bytes(),
NEXT_FREE_PARA_ID_STORAGE_NAME.as_bytes(),
);
let para_id: ParaId = relay_client
.storage_value(StorageKey(para_id_key.to_vec()), None)
.storage_value(best_relay_header_hash, StorageKey(para_id_key.to_vec()))
.await?
.unwrap_or(polkadot_primitives::v4::LOWEST_PUBLIC_ID)
.max(polkadot_primitives::v4::LOWEST_PUBLIC_ID);
Expand Down Expand Up @@ -131,7 +132,7 @@ impl RegisterParachain {
// step 2: register parathread
let para_genesis_header = para_client.header_by_number(Zero::zero()).await?;
let para_code = para_client
.raw_storage_value(StorageKey(CODE.to_vec()), Some(para_genesis_header.hash()))
.raw_storage_value(para_genesis_header.hash(), StorageKey(CODE.to_vec()))
.await?
.ok_or_else(|| {
anyhow::format_err!("Cannot fetch validation code of {}", Parachain::NAME)
Expand Down Expand Up @@ -229,14 +230,15 @@ impl RegisterParachain {

/// Wait until parachain state is changed.
async fn wait_para_state<Relaychain: Chain>(
relay_client: &Client<Relaychain>,
relay_client: &impl Client<Relaychain>,
para_state_key: &[u8],
from_states: &[ParaLifecycle],
to_state: ParaLifecycle,
) -> anyhow::Result<()> {
loop {
let best_relay_header_hash = relay_client.best_header_hash().await?;
let para_state: ParaLifecycle = relay_client
.storage_value(StorageKey(para_state_key.to_vec()), None)
.storage_value(best_relay_header_hash, StorageKey(para_state_key.to_vec()))
.await?
.ok_or_else(|| {
anyhow::format_err!(
Expand Down
1 change: 1 addition & 0 deletions relays/bin-substrate/src/cli/relay_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::bridges::{
},
westend_millau::westend_headers_to_millau::WestendToMillauCliBridge,
};
use relay_substrate_client::Client;
use relay_utils::metrics::{GlobalMetrics, StandaloneMetric};
use substrate_relay_helper::finality::SubstrateFinalitySyncPipeline;

Expand Down
12 changes: 8 additions & 4 deletions relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ use crate::{
},
chain_schema::*,
relay_headers_and_messages::parachain_to_parachain::ParachainToParachainBridge,
CliChain, HexLaneId, PrometheusParams,
CliChain, DefaultClient, HexLaneId, PrometheusParams,
},
declare_chain_cli_schema,
};
use bp_messages::LaneId;
use bp_runtime::BalanceOf;
use relay_substrate_client::{
AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, ChainWithMessages,
ChainWithTransactions, Client, Parachain,
ChainWithTransactions, Parachain,
};
use relay_utils::metrics::MetricsParams;
use sp_core::Pair;
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<Left: ChainWithTransactions + CliChain, Right: ChainWithTransactions + CliC
/// Parameters that are associated with one side of the bridge.
pub struct BridgeEndCommonParams<Chain: ChainWithTransactions + CliChain> {
/// Chain client.
pub client: Client<Chain>,
pub client: DefaultClient<Chain>,
/// Transactions signer.
pub sign: AccountKeyPairOf<Chain>,
/// Transactions mortality.
Expand Down Expand Up @@ -178,7 +178,7 @@ where
source_to_target_headers_relay: Arc<dyn OnDemandRelay<Source, Target>>,
target_to_source_headers_relay: Arc<dyn OnDemandRelay<Target, Source>>,
lane_id: LaneId,
) -> MessagesRelayParams<Bridge::MessagesLane> {
) -> MessagesRelayParams<Bridge::MessagesLane, DefaultClient<Source>, DefaultClient<Target>> {
MessagesRelayParams {
source_client: self.source.client.clone(),
source_transaction_params: TransactionParams {
Expand Down Expand Up @@ -374,6 +374,8 @@ where
for lane in lanes {
let left_to_right_messages = substrate_relay_helper::messages_lane::run::<
<Self::L2R as MessagesCliBridge>::MessagesLane,
_,
_,
>(self.left_to_right().messages_relay_params(
left_to_right_on_demand_headers.clone(),
right_to_left_on_demand_headers.clone(),
Expand All @@ -385,6 +387,8 @@ where

let right_to_left_messages = substrate_relay_helper::messages_lane::run::<
<Self::R2L as MessagesCliBridge>::MessagesLane,
_,
_,
>(self.right_to_left().messages_relay_params(
right_to_left_on_demand_headers.clone(),
left_to_right_on_demand_headers.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use crate::cli::{
bridge::{CliBridgeBase, MessagesCliBridge, ParachainToRelayHeadersCliBridge},
relay_headers_and_messages::{Full2WayBridgeBase, Full2WayBridgeCommonParams},
CliChain,
CliChain, DefaultClient,
};
use bp_polkadot_core::parachains::ParaHash;
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
Expand Down Expand Up @@ -51,9 +51,9 @@ pub struct ParachainToParachainBridge<
pub common:
Full2WayBridgeCommonParams<<R2L as CliBridgeBase>::Target, <L2R as CliBridgeBase>::Target>,
/// Client of the left relay chain.
pub left_relay: Client<<L2R as ParachainToRelayHeadersCliBridge>::SourceRelay>,
pub left_relay: DefaultClient<<L2R as ParachainToRelayHeadersCliBridge>::SourceRelay>,
/// Client of the right relay chain.
pub right_relay: Client<<R2L as ParachainToRelayHeadersCliBridge>::SourceRelay>,
pub right_relay: DefaultClient<<R2L as ParachainToRelayHeadersCliBridge>::SourceRelay>,

/// Override for right_relay->left headers signer.
pub right_headers_to_left_transaction_params:
Expand Down Expand Up @@ -233,25 +233,33 @@ where
)
.await?;

let left_relay_to_right_on_demand_headers =
OnDemandHeadersRelay::<<L2R as ParachainToRelayHeadersCliBridge>::RelayFinality>::new(
self.left_relay.clone(),
self.common.right.client.clone(),
self.left_headers_to_right_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
Some(self.common.metrics_params.clone()),
);
let right_relay_to_left_on_demand_headers =
OnDemandHeadersRelay::<<R2L as ParachainToRelayHeadersCliBridge>::RelayFinality>::new(
self.right_relay.clone(),
self.common.left.client.clone(),
self.right_headers_to_left_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
Some(self.common.metrics_params.clone()),
);
let left_relay_to_right_on_demand_headers = OnDemandHeadersRelay::<
<L2R as ParachainToRelayHeadersCliBridge>::RelayFinality,
_,
_,
>::new(
self.left_relay.clone(),
self.common.right.client.clone(),
self.left_headers_to_right_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
Some(self.common.metrics_params.clone()),
);
let right_relay_to_left_on_demand_headers = OnDemandHeadersRelay::<
<R2L as ParachainToRelayHeadersCliBridge>::RelayFinality,
_,
_,
>::new(
self.right_relay.clone(),
self.common.left.client.clone(),
self.right_headers_to_left_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
Some(self.common.metrics_params.clone()),
);

let left_to_right_on_demand_parachains = OnDemandParachainsRelay::<
<L2R as ParachainToRelayHeadersCliBridge>::ParachainFinality,
_,
_,
>::new(
self.left_relay.clone(),
self.common.right.client.clone(),
Expand All @@ -260,6 +268,8 @@ where
);
let right_to_left_on_demand_parachains = OnDemandParachainsRelay::<
<R2L as ParachainToRelayHeadersCliBridge>::ParachainFinality,
_,
_,
>::new(
self.right_relay.clone(),
self.common.left.client.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::cli::{
RelayToRelayHeadersCliBridge,
},
relay_headers_and_messages::{Full2WayBridgeBase, Full2WayBridgeCommonParams},
CliChain,
CliChain, DefaultClient,
};
use bp_polkadot_core::parachains::ParaHash;
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct RelayToParachainBridge<
pub common:
Full2WayBridgeCommonParams<<R2L as CliBridgeBase>::Target, <L2R as CliBridgeBase>::Target>,
/// Client of the right relay chain.
pub right_relay: Client<<R2L as ParachainToRelayHeadersCliBridge>::SourceRelay>,
pub right_relay: DefaultClient<<R2L as ParachainToRelayHeadersCliBridge>::SourceRelay>,

/// Override for right_relay->left headers signer.
pub right_headers_to_left_transaction_params:
Expand Down Expand Up @@ -216,23 +216,28 @@ where
.await?;

let left_to_right_on_demand_headers =
OnDemandHeadersRelay::<<L2R as RelayToRelayHeadersCliBridge>::Finality>::new(
OnDemandHeadersRelay::<<L2R as RelayToRelayHeadersCliBridge>::Finality, _, _>::new(
self.common.left.client.clone(),
self.common.right.client.clone(),
self.left_headers_to_right_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
None,
);
let right_relay_to_left_on_demand_headers =
OnDemandHeadersRelay::<<R2L as ParachainToRelayHeadersCliBridge>::RelayFinality>::new(
self.right_relay.clone(),
self.common.left.client.clone(),
self.right_headers_to_left_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
Some(self.common.metrics_params.clone()),
);
let right_relay_to_left_on_demand_headers = OnDemandHeadersRelay::<
<R2L as ParachainToRelayHeadersCliBridge>::RelayFinality,
_,
_,
>::new(
self.right_relay.clone(),
self.common.left.client.clone(),
self.right_headers_to_left_transaction_params.clone(),
self.common.shared.only_mandatory_headers,
Some(self.common.metrics_params.clone()),
);
let right_to_left_on_demand_parachains = OnDemandParachainsRelay::<
<R2L as ParachainToRelayHeadersCliBridge>::ParachainFinality,
_,
_,
>::new(
self.right_relay.clone(),
self.common.left.client.clone(),
Expand Down
Loading