substrate_relay_helper/on_demand/mod.rs
1// Copyright 2019-2021 Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Bridges Common is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
16
17//! Types and functions intended to ease adding of new Substrate -> Substrate
18//! on-demand pipelines.
19
20use async_trait::async_trait;
21use relay_substrate_client::{BlockNumberOf, CallOf, Chain, Error as SubstrateError, HeaderIdOf};
22
23pub mod headers;
24pub mod parachains;
25
26/// On-demand headers relay that is relaying finalizing headers only when requested.
27#[async_trait]
28pub trait OnDemandRelay<SourceChain: Chain, TargetChain: Chain>: Send + Sync {
29 /// Reconnect to source and target nodes.
30 async fn reconnect(&self) -> Result<(), SubstrateError>;
31
32 /// Ask relay to relay source header with given number to the target chain.
33 ///
34 /// Depending on implementation, on-demand relay may also relay `required_header` ancestors
35 /// (e.g. if they're mandatory), or its descendants. The request is considered complete if
36 /// the best avbailable header at the target chain has number that is larger than or equal
37 /// to the `required_header`.
38 async fn require_more_headers(&self, required_header: BlockNumberOf<SourceChain>);
39
40 /// Ask relay to prove source `required_header` to the `TargetChain`.
41 ///
42 /// Returns number of header that is proved (it may be the `required_header` or one of its
43 /// descendants) and calls for delivering the proof.
44 async fn prove_header(
45 &self,
46 required_header: BlockNumberOf<SourceChain>,
47 ) -> Result<(HeaderIdOf<SourceChain>, Vec<CallOf<TargetChain>>), SubstrateError>;
48}