mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
f87053c1cb
* finality proofs relay * SyncHeader::is_mandatory * empty ancestry proof * logs * fixed submit condition * fixed wrong split index * tick comment * recent_finality_proofs * basic finality loop tests * removed obsolete files * rename files in substrate relay * fmt * clippy * fixed TODOs * clippy * stop syncing if target node is out of sync * more clippy * more clippy * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * docs * moved doc * typo * Update relays/finality-relay/src/finality_loop_tests.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop_tests.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * header_and_finality_proof_by_number -> header_and_finality_proof * VecDeque isn't required (because of make_contiguous) * fixed wrong expect * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/substrate/src/rialto_headers_to_millau.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/substrate/src/rialto_headers_to_millau.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * RialtoSyncHeader * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * removed wrong comment * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * fix used runtime methods names * fix for new jsonrpsee * fix comment * initialize finality verifier pallet * fmt Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
92 lines
3.0 KiB
Rust
92 lines
3.0 KiB
Rust
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Bridges Common.
|
|
|
|
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Bridges Common is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Substrate client as Substrate finality proof target. The chain we connect to should have
|
|
//! runtime that implements `<BridgedChainName>FinalityApi` to allow bridging with
|
|
//! <BridgedName> chain.
|
|
|
|
use crate::finality_pipeline::SubstrateFinalitySyncPipeline;
|
|
|
|
use async_trait::async_trait;
|
|
use codec::{Decode, Encode};
|
|
use finality_relay::TargetClient;
|
|
use futures::TryFutureExt;
|
|
use relay_substrate_client::{Chain, Client, Error as SubstrateError};
|
|
use relay_utils::relay_loop::Client as RelayClient;
|
|
use sp_core::Bytes;
|
|
|
|
/// Substrate client as Substrate finality target.
|
|
pub struct SubstrateFinalityTarget<C: Chain, P> {
|
|
client: Client<C>,
|
|
pipeline: P,
|
|
}
|
|
|
|
impl<C: Chain, P> SubstrateFinalityTarget<C, P> {
|
|
/// Create new Substrate headers target.
|
|
pub fn new(client: Client<C>, pipeline: P) -> Self {
|
|
SubstrateFinalityTarget { client, pipeline }
|
|
}
|
|
}
|
|
|
|
impl<C: Chain, P: SubstrateFinalitySyncPipeline> Clone for SubstrateFinalityTarget<C, P> {
|
|
fn clone(&self) -> Self {
|
|
SubstrateFinalityTarget {
|
|
client: self.client.clone(),
|
|
pipeline: self.pipeline.clone(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<C: Chain, P: SubstrateFinalitySyncPipeline> RelayClient for SubstrateFinalityTarget<C, P> {
|
|
type Error = SubstrateError;
|
|
|
|
async fn reconnect(&mut self) -> Result<(), SubstrateError> {
|
|
self.client.reconnect().await
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<C, P> TargetClient<P> for SubstrateFinalityTarget<C, P>
|
|
where
|
|
C: Chain,
|
|
P::Number: Decode,
|
|
P::Hash: Decode,
|
|
P: SubstrateFinalitySyncPipeline,
|
|
{
|
|
async fn best_finalized_source_block_number(&self) -> Result<P::Number, SubstrateError> {
|
|
// we can't continue to relay finality if target node is out of sync, because
|
|
// it may have already received (some of) headers that we're going to relay
|
|
self.client.ensure_synced().await?;
|
|
|
|
Ok(crate::messages_source::read_client_state::<C, P::Hash, P::Number>(
|
|
&self.client,
|
|
P::BEST_FINALIZED_SOURCE_HEADER_ID_AT_TARGET,
|
|
)
|
|
.await?
|
|
.best_finalized_peer_at_best_self
|
|
.0)
|
|
}
|
|
|
|
async fn submit_finality_proof(&self, header: P::Header, proof: P::FinalityProof) -> Result<(), SubstrateError> {
|
|
self.pipeline
|
|
.make_submit_finality_proof_transaction(header, proof)
|
|
.and_then(|tx| self.client.submit_extrinsic(Bytes(tx.encode())))
|
|
.await
|
|
.map(drop)
|
|
}
|
|
}
|