, Self::Error>;
/// Get nonce of instance of latest generated message.
async fn latest_generated_nonce(
&self,
id: SourceHeaderIdOf,
) -> Result<(SourceHeaderIdOf
, P::MessageNonce), Self::Error>;
/// Get nonce of the latest message, which receiving has been confirmed by the target chain.
async fn latest_confirmed_received_nonce(
&self,
id: SourceHeaderIdOf
,
) -> Result<(SourceHeaderIdOf
, P::MessageNonce), Self::Error>;
/// Prove messages in inclusive range [begin; end].
async fn prove_messages(
&self,
id: SourceHeaderIdOf
,
nonces: RangeInclusive,
) -> Result<(SourceHeaderIdOf, RangeInclusive, P::MessagesProof), Self::Error>;
/// Submit messages receiving proof.
async fn submit_messages_receiving_proof(
&self,
generated_at_block: TargetHeaderIdOf,
proof: P::MessagesReceivingProof,
) -> Result, Self::Error>;
}
/// Target client trait.
#[async_trait(?Send)]
pub trait TargetClient: Clone {
/// Type of error this clients returns.
type Error: std::fmt::Debug + MaybeConnectionError;
/// Try to reconnect to source node.
fn reconnect(self) -> Self;
/// Returns state of the client.
async fn state(&self) -> Result, Self::Error>;
/// Get nonce of latest received message.
async fn latest_received_nonce(
&self,
id: TargetHeaderIdOf,
) -> Result<(TargetHeaderIdOf
, P::MessageNonce), Self::Error>;
/// Prove messages receiving at given block.
async fn prove_messages_receiving(
&self,
id: TargetHeaderIdOf
,
) -> Result<(TargetHeaderIdOf
, P::MessagesReceivingProof), Self::Error>;
/// Submit messages proof.
async fn submit_messages_proof(
&self,
generated_at_header: SourceHeaderIdOf
,
nonces: RangeInclusive,
proof: P::MessagesProof,
) -> Result, Self::Error>;
}
/// State of the client.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ClientState {
/// Best header id of this chain.
pub best_self: SelfHeaderId,
/// Best header id of the peer chain.
pub best_peer: PeerHeaderId,
}
/// State of source client in one-way message lane.
pub type SourceClientState = ClientState, TargetHeaderIdOf>;
/// State of target client in one-way message lane.
pub type TargetClientState
= ClientState, SourceHeaderIdOf>;
/// Both clients state.
#[derive(Debug, Default)]
pub struct ClientsState {
/// Source client state.
pub source: Option>,
/// Target client state.
pub target: Option>,
}
/// Run message lane service loop.
pub fn run(
mut source_client: impl SourceClient,
source_tick: Duration,
mut target_client: impl TargetClient
,
target_tick: Duration,
reconnect_delay: Duration,
stall_timeout: Duration,
exit_signal: impl Future