Skip to content
Closed
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
5 changes: 5 additions & 0 deletions relays/lib-substrate-relay/src/messages_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
messages_lane::SubstrateMessageLane, messages_target::SubstrateMessagesReceivingProof,
on_demand_headers::OnDemandHeadersRelay,
};
use std::any::Any;

use async_trait::async_trait;
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState};
Expand Down Expand Up @@ -122,6 +123,10 @@ where
<P::MessageLane as MessageLane>::TargetHeaderHash: Decode,
<P::MessageLane as MessageLane>::SourceChainBalance: AtLeast32BitUnsigned,
{
fn origin_client(&self) -> &dyn Any {
&self.client
}

async fn state(&self) -> Result<SourceClientState<P::MessageLane>, SubstrateError> {
// we can't continue to deliver confirmations if source node is out of sync, because
// it may have already received confirmations that we're going to deliver
Expand Down
6 changes: 5 additions & 1 deletion relays/lib-substrate-relay/src/messages_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use relay_substrate_client::{
use relay_utils::{relay_loop::Client as RelayClient, BlockNumberBase, HeaderId};
use sp_core::Bytes;
use sp_runtime::{traits::Saturating, DeserializeOwned, FixedPointNumber, FixedU128};
use std::{convert::TryFrom, ops::RangeInclusive};
use std::{any::Any, convert::TryFrom, ops::RangeInclusive};

/// Message receiving proof returned by the target Substrate node.
pub type SubstrateMessagesReceivingProof<C> =
Expand Down Expand Up @@ -125,6 +125,10 @@ where
<P::MessageLane as MessageLane>::SourceHeaderNumber: Decode,
<P::MessageLane as MessageLane>::SourceHeaderHash: Decode,
{
fn origin_client(&self) -> &dyn Any {
&self.client
}

async fn state(&self) -> Result<TargetClientState<P::MessageLane>, SubstrateError> {
// we can't continue to deliver messages if target node is out of sync, because
// it may have already received (some of) messages that we're going to deliver
Expand Down
21 changes: 20 additions & 1 deletion relays/messages/src/message_lane_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
//! finalized header. I.e. when talking about headers in lane context, we
//! only care about finalized headers.

use std::{collections::BTreeMap, fmt::Debug, future::Future, ops::RangeInclusive, time::Duration};
use std::{
any::Any, collections::BTreeMap, fmt::Debug, future::Future, ops::RangeInclusive,
time::Duration,
};

use async_trait::async_trait;
use futures::{channel::mpsc::unbounded, future::FutureExt, stream::StreamExt};
Expand Down Expand Up @@ -122,6 +125,9 @@ pub struct MessageProofParameters {
/// Source client trait.
#[async_trait]
pub trait SourceClient<P: MessageLane>: RelayClient {
/// Simplify to get origin client, But you need use `downcast_ref` to convert to you want types
fn origin_client(&self) -> &dyn Any;

/// Returns state of the client.
async fn state(&self) -> Result<SourceClientState<P>, Self::Error>;

Expand Down Expand Up @@ -172,6 +178,9 @@ pub trait SourceClient<P: MessageLane>: RelayClient {
/// Target client trait.
#[async_trait]
pub trait TargetClient<P: MessageLane>: RelayClient {
/// Simplify to get origin client, But you need use `downcast_ref` to convert to you want types
fn origin_client(&self) -> &dyn Any;

/// Returns state of the client.
async fn state(&self) -> Result<TargetClientState<P>, Self::Error>;

Expand Down Expand Up @@ -562,6 +571,11 @@ pub(crate) mod tests {

#[async_trait]
impl SourceClient<TestMessageLane> for TestSourceClient {
fn origin_client(&self) -> &dyn Any {
// todo: I'm not sure what to return there
&self.data
}

async fn state(&self) -> Result<SourceClientState<TestMessageLane>, TestError> {
let mut data = self.data.lock();
(self.tick)(&mut *data);
Expand Down Expand Up @@ -790,6 +804,11 @@ pub(crate) mod tests {
total_dispatch_weight +
total_size as TestSourceChainBalance)
}

fn origin_client(&self) -> &dyn Any {
// todo: I'm not sure what to return there
&self.data
}
}

fn run_loop_test(
Expand Down