;
/// Get completion data by header hash.
async fn header_completion(
&self,
id: HeaderIdOf,
) -> Result<(HeaderIdOf
, Option), Self::Error>;
/// Get extra data by header hash.
async fn header_extra(
&self,
id: HeaderIdOf,
header: QueuedHeader
,
) -> Result<(HeaderIdOf
, P::Extra), Self::Error>;
}
/// Target client trait.
#[async_trait]
pub trait TargetClient: RelayClient {
/// Returns ID of the best header known to the target node.
async fn best_header_id(&self) -> Result, Self::Error>;
/// Returns true if header is known to the target node.
async fn is_known_header(
&self,
id: HeaderIdOf,
) -> Result<(HeaderIdOf
, bool), Self::Error>;
/// Submit headers.
async fn submit_headers(
&self,
headers: Vec>,
) -> SubmittedHeaders, Self::Error>;
/// Returns ID of headers that require to be 'completed' before children can be submitted.
async fn incomplete_headers_ids(&self) -> Result>, Self::Error>;
/// Submit completion data for header.
async fn complete_header(
&self,
id: HeaderIdOf,
completion: P::Completion,
) -> Result, Self::Error>;
/// Returns true if header requires extra data to be submitted.
async fn requires_extra(
&self,
header: QueuedHeader,
) -> Result<(HeaderIdOf
, bool), Self::Error>;
}
/// Synchronization maintain procedure.
#[async_trait]
pub trait SyncMaintain: 'static + Clone + Send + Sync {
/// Run custom maintain procedures. This is guaranteed to be called when both source and target
/// clients are unoccupied.
async fn maintain(&self, _sync: &mut HeadersSync) {}
}
impl SyncMaintain for () {}
/// Return prefix that will be used by default to expose Prometheus metrics of the finality proofs
/// sync loop.
pub fn metrics_prefix() -> String {
format!("{}_to_{}_Sync", P::SOURCE_NAME, P::TARGET_NAME)
}
/// Run headers synchronization.
#[allow(clippy::too_many_arguments)]
pub async fn run>(
source_client: impl SourceClient,
source_tick: Duration,
target_client: TC,
target_tick: Duration,
sync_maintain: impl SyncMaintain
,
sync_params: HeadersSyncParams,
metrics_params: MetricsParams,
exit_signal: impl Future