mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 21:01:02 +00:00
Fix clippy suggestions. (#179)
* Fix clippy errors. * Cargo fmt. * Enable clippy checks. * Create if does not exist. * Fix warnings and enable sccache for clippy. * chmod +x * Revert and ignore errors. * Update cancel-workflow-action. * Fixes. * Clippy fixes. * Fix compilation. * Fix new clippy warnings. * fmt --all * Fix the rest. * fmt --all * Conditional. * Bump smallvec. * Use separate cache dir for clippy to prevent races. * Remove unused imports in tests * Remove "useless conversion" * Move clippy to main worfklow to avoid clashes. * Fix clippy error. * Fix remaning clippy errors. * cargo fmt --all Co-authored-by: Hernando Castano <castano.ha@gmail.com>
This commit is contained in:
committed by
Bastian Köcher
parent
65852944e3
commit
bdf6901ce2
@@ -100,7 +100,7 @@ impl SourceClient<EthereumToSubstrateExchange> for EthereumTransactionsSource {
|
||||
eth_header_id: &EthereumHeaderId,
|
||||
eth_tx: EthereumTransaction,
|
||||
) -> Result<EthereumTransactionInclusionProof, Self::Error> {
|
||||
const TRANSACTION_HAS_RAW_FIELD_PROOF: &'static str = "RPC level checks that transactions from Ethereum\
|
||||
const TRANSACTION_HAS_RAW_FIELD_PROOF: &str = "RPC level checks that transactions from Ethereum\
|
||||
node are having `raw` field; qed";
|
||||
|
||||
let eth_header = self.client.header_by_hash_with_transactions(eth_header_id.1).await?;
|
||||
|
||||
@@ -163,7 +163,7 @@ impl TargetClient<EthereumHeadersSyncPipeline> for SubstrateHeadersTarget {
|
||||
&self,
|
||||
headers: Vec<QueuedEthereumHeader>,
|
||||
) -> SubmittedHeaders<EthereumHeaderId, Self::Error> {
|
||||
let (sign_params, sign_transactions) = (self.sign_params.clone(), self.sign_transactions.clone());
|
||||
let (sign_params, sign_transactions) = (self.sign_params.clone(), self.sign_transactions);
|
||||
self.client
|
||||
.submit_ethereum_headers(sign_params, headers, sign_transactions)
|
||||
.await
|
||||
@@ -173,6 +173,7 @@ impl TargetClient<EthereumHeadersSyncPipeline> for SubstrateHeadersTarget {
|
||||
Ok(HashSet::new())
|
||||
}
|
||||
|
||||
#[allow(clippy::unit_arg)]
|
||||
async fn complete_header(&self, id: EthereumHeaderId, _completion: ()) -> Result<EthereumHeaderId, Self::Error> {
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ pub use web3::types::{Address, Bytes, CallRequest, H256, U128, U256, U64};
|
||||
|
||||
/// When header is just received from the Ethereum node, we check that it has
|
||||
/// both number and hash fields filled.
|
||||
pub const HEADER_ID_PROOF: &'static str = "checked on retrieval; qed";
|
||||
pub const HEADER_ID_PROOF: &str = "checked on retrieval; qed";
|
||||
|
||||
/// When receipt is just received from the Ethereum node, we check that it has
|
||||
/// gas_used field filled.
|
||||
pub const RECEIPT_GAS_USED_PROOF: &'static str = "checked on retrieval; qed";
|
||||
pub const RECEIPT_GAS_USED_PROOF: &str = "checked on retrieval; qed";
|
||||
|
||||
/// Ethereum transaction hash type.
|
||||
pub type TransactionHash = H256;
|
||||
|
||||
@@ -323,7 +323,7 @@ mod tests {
|
||||
&self,
|
||||
_: &TestTransactionHash,
|
||||
) -> Result<Option<(TestHeaderId, TestTransaction)>, TestError> {
|
||||
self.data.lock().transaction.clone()
|
||||
self.data.lock().transaction
|
||||
}
|
||||
|
||||
async fn transaction_proof(
|
||||
@@ -331,7 +331,7 @@ mod tests {
|
||||
_: &TestHeaderId,
|
||||
_: TestTransaction,
|
||||
) -> Result<TestTransactionProof, TestError> {
|
||||
self.data.lock().transaction_proof.clone()
|
||||
self.data.lock().transaction_proof
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,11 +368,11 @@ mod tests {
|
||||
}
|
||||
|
||||
async fn is_header_known(&self, _: &TestHeaderId) -> Result<bool, TestError> {
|
||||
self.data.lock().is_header_known.clone()
|
||||
self.data.lock().is_header_known
|
||||
}
|
||||
|
||||
async fn is_header_finalized(&self, _: &TestHeaderId) -> Result<bool, TestError> {
|
||||
self.data.lock().is_header_finalized.clone()
|
||||
self.data.lock().is_header_finalized
|
||||
}
|
||||
|
||||
async fn submit_transaction_proof(&self, proof: TestTransactionProof) -> Result<(), TestError> {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// 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/>.
|
||||
|
||||
use crate::sync_types::{HeaderId, HeaderStatus, HeadersSyncPipeline, QueuedHeader, SourceHeader};
|
||||
use crate::sync_types::{HeaderId, HeaderIdOf, HeaderStatus, HeadersSyncPipeline, QueuedHeader, SourceHeader};
|
||||
use linked_hash_map::LinkedHashMap;
|
||||
use num_traits::{One, Zero};
|
||||
use std::{
|
||||
@@ -59,9 +59,9 @@ pub struct QueuedHeaders<P: HeadersSyncPipeline> {
|
||||
known_headers: KnownHeaders<P>,
|
||||
/// Headers that are waiting for completion data from source node. Mapped (and auto-sorted
|
||||
/// by) to the last fetch time.
|
||||
incomplete_headers: LinkedHashMap<HeaderId<P::Hash, P::Number>, Option<Instant>>,
|
||||
incomplete_headers: LinkedHashMap<HeaderIdOf<P>, Option<Instant>>,
|
||||
/// Headers that are waiting to be completed at target node. Auto-sorted by insertion time.
|
||||
completion_data: LinkedHashMap<HeaderId<P::Hash, P::Number>, P::Completion>,
|
||||
completion_data: LinkedHashMap<HeaderIdOf<P>, P::Completion>,
|
||||
/// Best synced block number.
|
||||
best_synced_number: P::Number,
|
||||
/// Pruned blocks border. We do not store or accept any blocks with number less than
|
||||
@@ -106,7 +106,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
/// Returns number of headers that are currently in given queue.
|
||||
pub fn headers_in_status(&self, status: HeaderStatus) -> usize {
|
||||
match status {
|
||||
HeaderStatus::Unknown | HeaderStatus::Synced => return 0,
|
||||
HeaderStatus::Unknown | HeaderStatus::Synced => 0,
|
||||
HeaderStatus::MaybeOrphan => self
|
||||
.maybe_orphan
|
||||
.values()
|
||||
@@ -168,7 +168,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Returns synchronization status of the header.
|
||||
pub fn status(&self, id: &HeaderId<P::Hash, P::Number>) -> HeaderStatus {
|
||||
pub fn status(&self, id: &HeaderIdOf<P>) -> HeaderStatus {
|
||||
self.known_headers
|
||||
.get(&id.0)
|
||||
.and_then(|x| x.get(&id.1))
|
||||
@@ -179,7 +179,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
/// Get oldest header from given queue.
|
||||
pub fn header(&self, status: HeaderStatus) -> Option<&QueuedHeader<P>> {
|
||||
match status {
|
||||
HeaderStatus::Unknown | HeaderStatus::Synced => return None,
|
||||
HeaderStatus::Unknown | HeaderStatus::Synced => None,
|
||||
HeaderStatus::MaybeOrphan => oldest_header(&self.maybe_orphan),
|
||||
HeaderStatus::Orphan => oldest_header(&self.orphan),
|
||||
HeaderStatus::MaybeExtra => oldest_header(&self.maybe_extra),
|
||||
@@ -197,7 +197,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
f: impl FnMut(&QueuedHeader<P>) -> bool,
|
||||
) -> Option<Vec<&QueuedHeader<P>>> {
|
||||
match status {
|
||||
HeaderStatus::Unknown | HeaderStatus::Synced => return None,
|
||||
HeaderStatus::Unknown | HeaderStatus::Synced => None,
|
||||
HeaderStatus::MaybeOrphan => oldest_headers(&self.maybe_orphan, f),
|
||||
HeaderStatus::Orphan => oldest_headers(&self.orphan, f),
|
||||
HeaderStatus::MaybeExtra => oldest_headers(&self.maybe_extra, f),
|
||||
@@ -268,12 +268,12 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Receive best header from the target node.
|
||||
pub fn target_best_header_response(&mut self, id: &HeaderId<P::Hash, P::Number>) {
|
||||
pub fn target_best_header_response(&mut self, id: &HeaderIdOf<P>) {
|
||||
self.header_synced(id)
|
||||
}
|
||||
|
||||
/// Receive target node response for MaybeOrphan request.
|
||||
pub fn maybe_orphan_response(&mut self, id: &HeaderId<P::Hash, P::Number>, response: bool) {
|
||||
pub fn maybe_orphan_response(&mut self, id: &HeaderIdOf<P>, response: bool) {
|
||||
if !response {
|
||||
move_header_descendants::<P>(
|
||||
&mut [&mut self.maybe_orphan],
|
||||
@@ -295,7 +295,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Receive target node response for MaybeExtra request.
|
||||
pub fn maybe_extra_response(&mut self, id: &HeaderId<P::Hash, P::Number>, response: bool) {
|
||||
pub fn maybe_extra_response(&mut self, id: &HeaderIdOf<P>, response: bool) {
|
||||
let (destination_status, destination_queue) = if response {
|
||||
(HeaderStatus::Extra, &mut self.extra)
|
||||
} else if self.is_parent_incomplete(id) {
|
||||
@@ -315,7 +315,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Receive extra from source node.
|
||||
pub fn extra_response(&mut self, id: &HeaderId<P::Hash, P::Number>, extra: P::Extra) {
|
||||
pub fn extra_response(&mut self, id: &HeaderIdOf<P>, extra: P::Extra) {
|
||||
let (destination_status, destination_queue) = if self.is_parent_incomplete(id) {
|
||||
(HeaderStatus::Incomplete, &mut self.incomplete)
|
||||
} else {
|
||||
@@ -334,7 +334,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Receive completion response from source node.
|
||||
pub fn completion_response(&mut self, id: &HeaderId<P::Hash, P::Number>, completion: Option<P::Completion>) {
|
||||
pub fn completion_response(&mut self, id: &HeaderIdOf<P>, completion: Option<P::Completion>) {
|
||||
let completion = match completion {
|
||||
Some(completion) => completion,
|
||||
None => {
|
||||
@@ -361,12 +361,12 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
id,
|
||||
);
|
||||
|
||||
self.completion_data.insert(id.clone(), completion);
|
||||
self.completion_data.insert(*id, completion);
|
||||
}
|
||||
}
|
||||
|
||||
/// When header is submitted to target node.
|
||||
pub fn headers_submitted(&mut self, ids: Vec<HeaderId<P::Hash, P::Number>>) {
|
||||
pub fn headers_submitted(&mut self, ids: Vec<HeaderIdOf<P>>) {
|
||||
for id in ids {
|
||||
move_header(
|
||||
&mut self.ready,
|
||||
@@ -380,7 +380,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// When header completion data is sent to target node.
|
||||
pub fn header_completed(&mut self, id: &HeaderId<P::Hash, P::Number>) {
|
||||
pub fn header_completed(&mut self, id: &HeaderIdOf<P>) {
|
||||
if self.completion_data.remove(id).is_some() {
|
||||
log::debug!(
|
||||
target: "bridge",
|
||||
@@ -404,7 +404,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Marks given headers incomplete.
|
||||
pub fn add_incomplete_headers(&mut self, new_incomplete_headers: Vec<HeaderId<P::Hash, P::Number>>) {
|
||||
pub fn add_incomplete_headers(&mut self, new_incomplete_headers: Vec<HeaderIdOf<P>>) {
|
||||
for new_incomplete_header in new_incomplete_headers {
|
||||
self.header_synced(&new_incomplete_header);
|
||||
move_header_descendants::<P>(
|
||||
@@ -426,7 +426,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// When incomplete headers ids are receved from target node.
|
||||
pub fn incomplete_headers_response(&mut self, ids: HashSet<HeaderId<P::Hash, P::Number>>) {
|
||||
pub fn incomplete_headers_response(&mut self, ids: HashSet<HeaderIdOf<P>>) {
|
||||
// all new incomplete headers are marked Synced and all their descendants
|
||||
// are moved from Ready/Submitted to Incomplete queue
|
||||
let new_incomplete_headers = ids
|
||||
@@ -466,7 +466,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Returns id of the header for which we want to fetch completion data.
|
||||
pub fn incomplete_header(&mut self) -> Option<HeaderId<P::Hash, P::Number>> {
|
||||
pub fn incomplete_header(&mut self) -> Option<HeaderIdOf<P>> {
|
||||
queued_incomplete_header(&mut self.incomplete_headers, |last_fetch_time| {
|
||||
let retry = match *last_fetch_time {
|
||||
Some(last_fetch_time) => last_fetch_time.elapsed() > RETRY_FETCH_COMPLETION_INTERVAL,
|
||||
@@ -483,7 +483,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Returns header completion data to upload to target node.
|
||||
pub fn header_to_complete(&mut self) -> Option<(HeaderId<P::Hash, P::Number>, &P::Completion)> {
|
||||
pub fn header_to_complete(&mut self) -> Option<(HeaderIdOf<P>, &P::Completion)> {
|
||||
queued_incomplete_header(&mut self.completion_data, |_| true)
|
||||
}
|
||||
|
||||
@@ -520,7 +520,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
|
||||
/// Returns true if parent of this header is either incomplete or waiting for
|
||||
/// its own incomplete ancestor to be completed.
|
||||
fn is_parent_incomplete(&self, id: &HeaderId<P::Hash, P::Number>) -> bool {
|
||||
fn is_parent_incomplete(&self, id: &HeaderIdOf<P>) -> bool {
|
||||
let status = self.status(id);
|
||||
let header = match status {
|
||||
HeaderStatus::MaybeOrphan => header(&self.maybe_orphan, id),
|
||||
@@ -546,7 +546,7 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// When we receive new Synced header from target node.
|
||||
fn header_synced(&mut self, id: &HeaderId<P::Hash, P::Number>) {
|
||||
fn header_synced(&mut self, id: &HeaderIdOf<P>) {
|
||||
// update best synced block number
|
||||
self.best_synced_number = std::cmp::max(self.best_synced_number, id.0);
|
||||
|
||||
@@ -593,19 +593,12 @@ impl<P: HeadersSyncPipeline> QueuedHeaders<P> {
|
||||
}
|
||||
|
||||
/// Insert header to the queue.
|
||||
fn insert_header<P: HeadersSyncPipeline>(
|
||||
queue: &mut HeadersQueue<P>,
|
||||
id: HeaderId<P::Hash, P::Number>,
|
||||
header: QueuedHeader<P>,
|
||||
) {
|
||||
fn insert_header<P: HeadersSyncPipeline>(queue: &mut HeadersQueue<P>, id: HeaderIdOf<P>, header: QueuedHeader<P>) {
|
||||
queue.entry(id.0).or_default().insert(id.1, header);
|
||||
}
|
||||
|
||||
/// Remove header from the queue.
|
||||
fn remove_header<P: HeadersSyncPipeline>(
|
||||
queue: &mut HeadersQueue<P>,
|
||||
id: &HeaderId<P::Hash, P::Number>,
|
||||
) -> Option<QueuedHeader<P>> {
|
||||
fn remove_header<P: HeadersSyncPipeline>(queue: &mut HeadersQueue<P>, id: &HeaderIdOf<P>) -> Option<QueuedHeader<P>> {
|
||||
let mut headers_at = match queue.entry(id.0) {
|
||||
BTreeMapEntry::Occupied(headers_at) => headers_at,
|
||||
BTreeMapEntry::Vacant(_) => return None,
|
||||
@@ -619,10 +612,7 @@ fn remove_header<P: HeadersSyncPipeline>(
|
||||
}
|
||||
|
||||
/// Get header from the queue.
|
||||
fn header<'a, P: HeadersSyncPipeline>(
|
||||
queue: &'a HeadersQueue<P>,
|
||||
id: &HeaderId<P::Hash, P::Number>,
|
||||
) -> Option<&'a QueuedHeader<P>> {
|
||||
fn header<'a, P: HeadersSyncPipeline>(queue: &'a HeadersQueue<P>, id: &HeaderIdOf<P>) -> Option<&'a QueuedHeader<P>> {
|
||||
queue.get(&id.0).and_then(|by_hash| by_hash.get(&id.1))
|
||||
}
|
||||
|
||||
@@ -634,9 +624,9 @@ fn move_header<P: HeadersSyncPipeline>(
|
||||
destination_queue: &mut HeadersQueue<P>,
|
||||
known_headers: &mut KnownHeaders<P>,
|
||||
destination_status: HeaderStatus,
|
||||
id: &HeaderId<P::Hash, P::Number>,
|
||||
id: &HeaderIdOf<P>,
|
||||
prepare: impl FnOnce(QueuedHeader<P>) -> QueuedHeader<P>,
|
||||
) -> Option<HeaderId<P::Hash, P::Number>> {
|
||||
) -> Option<HeaderIdOf<P>> {
|
||||
let header = match remove_header(source_queue, id) {
|
||||
Some(header) => prepare(header),
|
||||
None => return None,
|
||||
@@ -655,7 +645,7 @@ fn move_header_descendants<P: HeadersSyncPipeline>(
|
||||
destination_queue: &mut HeadersQueue<P>,
|
||||
known_headers: &mut KnownHeaders<P>,
|
||||
destination_status: HeaderStatus,
|
||||
id: &HeaderId<P::Hash, P::Number>,
|
||||
id: &HeaderIdOf<P>,
|
||||
) {
|
||||
let mut current_number = id.0 + One::one();
|
||||
let mut current_parents = HashSet::new();
|
||||
@@ -743,7 +733,7 @@ fn prune_known_headers<P: HeadersSyncPipeline>(known_headers: &mut KnownHeaders<
|
||||
/// Change header status.
|
||||
fn set_header_status<P: HeadersSyncPipeline>(
|
||||
known_headers: &mut KnownHeaders<P>,
|
||||
id: &HeaderId<P::Hash, P::Number>,
|
||||
id: &HeaderIdOf<P>,
|
||||
status: HeaderStatus,
|
||||
) {
|
||||
log::debug!(
|
||||
|
||||
@@ -101,7 +101,6 @@ fn main() {
|
||||
}
|
||||
("", _) => {
|
||||
log::error!(target: "bridge", "No subcommand specified");
|
||||
return;
|
||||
}
|
||||
_ => unreachable!("all possible subcommands are checked above; qed"),
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ use crate::ethereum_types::{EthereumHeaderId, TransactionHash as EthereumTransac
|
||||
use crate::sync_types::MaybeConnectionError;
|
||||
|
||||
use jsonrpsee::client::RequestError;
|
||||
use serde_json;
|
||||
|
||||
/// Contains common errors that can occur when
|
||||
/// interacting with a Substrate or Ethereum node
|
||||
@@ -79,10 +78,7 @@ impl From<ethabi::Error> for RpcError {
|
||||
|
||||
impl MaybeConnectionError for RpcError {
|
||||
fn is_connection_error(&self) -> bool {
|
||||
match *self {
|
||||
RpcError::Request(RequestError::TransportError(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, RpcError::Request(RequestError::TransportError(_)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -400,5 +400,5 @@ fn create_signed_transaction(
|
||||
let signer: sp_runtime::MultiSigner = signer.public().into();
|
||||
let (function, extra, _) = raw_payload.deconstruct();
|
||||
|
||||
bridge_node_runtime::UncheckedExtrinsic::new_signed(function, signer.into_account().into(), signature.into(), extra)
|
||||
bridge_node_runtime::UncheckedExtrinsic::new_signed(function, signer.into_account(), signature.into(), extra)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::headers::QueuedHeaders;
|
||||
use crate::sync_types::{HeaderId, HeaderStatus, HeadersSyncPipeline, QueuedHeader};
|
||||
use crate::sync_types::{HeaderIdOf, HeaderStatus, HeadersSyncPipeline, QueuedHeader};
|
||||
use num_traits::{One, Saturating, Zero};
|
||||
|
||||
/// Common sync params.
|
||||
@@ -56,7 +56,7 @@ pub struct HeadersSync<P: HeadersSyncPipeline> {
|
||||
/// Best header number known to source node.
|
||||
source_best_number: Option<P::Number>,
|
||||
/// Best header known to target node.
|
||||
target_best_header: Option<HeaderId<P::Hash, P::Number>>,
|
||||
target_best_header: Option<HeaderIdOf<P>>,
|
||||
/// Headers queue.
|
||||
headers: QueuedHeaders<P>,
|
||||
}
|
||||
@@ -78,7 +78,7 @@ impl<P: HeadersSyncPipeline> HeadersSync<P> {
|
||||
}
|
||||
|
||||
/// Best header known to target node.
|
||||
pub fn target_best_header(&self) -> Option<HeaderId<P::Hash, P::Number>> {
|
||||
pub fn target_best_header(&self) -> Option<HeaderIdOf<P>> {
|
||||
self.target_best_header
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl<P: HeadersSyncPipeline> HeadersSync<P> {
|
||||
}
|
||||
|
||||
/// Returns synchronization status.
|
||||
pub fn status(&self) -> (&Option<HeaderId<P::Hash, P::Number>>, &Option<P::Number>) {
|
||||
pub fn status(&self) -> (&Option<HeaderIdOf<P>>, &Option<P::Number>) {
|
||||
(&self.target_best_header, &self.source_best_number)
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ impl<P: HeadersSyncPipeline> HeadersSync<P> {
|
||||
/// Select header that needs to be downloaded from the source node.
|
||||
pub fn select_new_header_to_download(&self) -> Option<P::Number> {
|
||||
// if we haven't received best header from source node yet, there's nothing we can download
|
||||
let source_best_number = self.source_best_number.clone()?;
|
||||
let source_best_number = self.source_best_number?;
|
||||
|
||||
// if we haven't received known best header from target node yet, there's nothing we can download
|
||||
let target_best_header = self.target_best_header.as_ref()?;
|
||||
@@ -205,7 +205,7 @@ impl<P: HeadersSyncPipeline> HeadersSync<P> {
|
||||
|
||||
/// Receive new best header from the target node.
|
||||
/// Returns true if it is different from the previous block known to us.
|
||||
pub fn target_best_header_response(&mut self, best_header: HeaderId<P::Hash, P::Number>) -> bool {
|
||||
pub fn target_best_header_response(&mut self, best_header: HeaderIdOf<P>) -> bool {
|
||||
log::debug!(
|
||||
target: "bridge",
|
||||
"Received best known header from {}: {:?}",
|
||||
@@ -244,7 +244,7 @@ pub mod tests {
|
||||
use super::*;
|
||||
use crate::ethereum_types::{EthereumHeadersSyncPipeline, H256};
|
||||
use crate::headers::tests::{header, id};
|
||||
use crate::sync_types::HeaderStatus;
|
||||
use crate::sync_types::{HeaderId, HeaderStatus};
|
||||
|
||||
fn side_hash(number: u64) -> H256 {
|
||||
H256::from_low_u64_le(1000 + number)
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::metrics::{start as metrics_start, GlobalMetrics, MetricsParams, Regis
|
||||
use crate::sync::HeadersSyncParams;
|
||||
use crate::sync_loop_metrics::SyncLoopMetrics;
|
||||
use crate::sync_types::{
|
||||
HeaderId, HeaderStatus, HeadersSyncPipeline, MaybeConnectionError, QueuedHeader, SubmittedHeaders,
|
||||
HeaderIdOf, HeaderStatus, HeadersSyncPipeline, MaybeConnectionError, QueuedHeader, SubmittedHeaders,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
@@ -68,17 +68,15 @@ pub trait SourceClient<P: HeadersSyncPipeline>: Sized {
|
||||
async fn header_by_number(&self, number: P::Number) -> Result<P::Header, Self::Error>;
|
||||
|
||||
/// Get completion data by header hash.
|
||||
async fn header_completion(
|
||||
&self,
|
||||
id: HeaderId<P::Hash, P::Number>,
|
||||
) -> Result<(HeaderId<P::Hash, P::Number>, Option<P::Completion>), Self::Error>;
|
||||
async fn header_completion(&self, id: HeaderIdOf<P>)
|
||||
-> Result<(HeaderIdOf<P>, Option<P::Completion>), Self::Error>;
|
||||
|
||||
/// Get extra data by header hash.
|
||||
async fn header_extra(
|
||||
&self,
|
||||
id: HeaderId<P::Hash, P::Number>,
|
||||
id: HeaderIdOf<P>,
|
||||
header: QueuedHeader<P>,
|
||||
) -> Result<(HeaderId<P::Hash, P::Number>, P::Extra), Self::Error>;
|
||||
) -> Result<(HeaderIdOf<P>, P::Extra), Self::Error>;
|
||||
}
|
||||
|
||||
/// Target client trait.
|
||||
@@ -88,35 +86,23 @@ pub trait TargetClient<P: HeadersSyncPipeline>: Sized {
|
||||
type Error: std::fmt::Debug + MaybeConnectionError;
|
||||
|
||||
/// Returns ID of best header known to the target node.
|
||||
async fn best_header_id(&self) -> Result<HeaderId<P::Hash, P::Number>, Self::Error>;
|
||||
async fn best_header_id(&self) -> Result<HeaderIdOf<P>, Self::Error>;
|
||||
|
||||
/// Returns true if header is known to the target node.
|
||||
async fn is_known_header(
|
||||
&self,
|
||||
id: HeaderId<P::Hash, P::Number>,
|
||||
) -> Result<(HeaderId<P::Hash, P::Number>, bool), Self::Error>;
|
||||
async fn is_known_header(&self, id: HeaderIdOf<P>) -> Result<(HeaderIdOf<P>, bool), Self::Error>;
|
||||
|
||||
/// Submit headers.
|
||||
async fn submit_headers(
|
||||
&self,
|
||||
headers: Vec<QueuedHeader<P>>,
|
||||
) -> SubmittedHeaders<HeaderId<P::Hash, P::Number>, Self::Error>;
|
||||
async fn submit_headers(&self, headers: Vec<QueuedHeader<P>>) -> SubmittedHeaders<HeaderIdOf<P>, Self::Error>;
|
||||
|
||||
/// Returns ID of headers that require to be 'completed' before children can be submitted.
|
||||
async fn incomplete_headers_ids(&self) -> Result<HashSet<HeaderId<P::Hash, P::Number>>, Self::Error>;
|
||||
async fn incomplete_headers_ids(&self) -> Result<HashSet<HeaderIdOf<P>>, Self::Error>;
|
||||
|
||||
/// Submit completion data for header.
|
||||
async fn complete_header(
|
||||
&self,
|
||||
id: HeaderId<P::Hash, P::Number>,
|
||||
completion: P::Completion,
|
||||
) -> Result<HeaderId<P::Hash, P::Number>, Self::Error>;
|
||||
async fn complete_header(&self, id: HeaderIdOf<P>, completion: P::Completion)
|
||||
-> Result<HeaderIdOf<P>, Self::Error>;
|
||||
|
||||
/// Returns true if header requires extra data to be submitted.
|
||||
async fn requires_extra(
|
||||
&self,
|
||||
header: QueuedHeader<P>,
|
||||
) -> Result<(HeaderId<P::Hash, P::Number>, bool), Self::Error>;
|
||||
async fn requires_extra(&self, header: QueuedHeader<P>) -> Result<(HeaderIdOf<P>, bool), Self::Error>;
|
||||
}
|
||||
|
||||
/// Run headers synchronization.
|
||||
@@ -327,7 +313,7 @@ pub fn run<P: HeadersSyncPipeline, TC: TargetClient<P>>(
|
||||
},
|
||||
submitted_headers = target_submit_header_future => {
|
||||
// following line helps Rust understand the type of `submitted_headers` :/
|
||||
let submitted_headers: SubmittedHeaders<HeaderId<P::Hash, P::Number>, TC::Error> = submitted_headers;
|
||||
let submitted_headers: SubmittedHeaders<HeaderIdOf<P>, TC::Error> = submitted_headers;
|
||||
let maybe_fatal_error = submitted_headers.fatal_error.map(Err).unwrap_or(Ok(()));
|
||||
|
||||
target_client_is_online = process_future_result(
|
||||
@@ -380,7 +366,7 @@ pub fn run<P: HeadersSyncPipeline, TC: TargetClient<P>>(
|
||||
// update metrics
|
||||
if metrics_enabled {
|
||||
metrics_global.update();
|
||||
metrics_sync.update(&mut sync);
|
||||
metrics_sync.update(&sync);
|
||||
}
|
||||
|
||||
// print progress
|
||||
|
||||
@@ -55,8 +55,8 @@ impl SyncLoopMetrics {
|
||||
/// Update metrics.
|
||||
pub fn update<P: HeadersSyncPipeline>(&mut self, sync: &HeadersSync<P>) {
|
||||
let headers = sync.headers();
|
||||
let source_best_number = sync.source_best_number().unwrap_or(Zero::zero());
|
||||
let target_best_number = sync.target_best_header().map(|id| id.0).unwrap_or(Zero::zero());
|
||||
let source_best_number = sync.source_best_number().unwrap_or_else(Zero::zero);
|
||||
let target_best_number = sync.target_best_header().map(|id| id.0).unwrap_or_else(Zero::zero);
|
||||
|
||||
self.best_block_numbers
|
||||
.with_label_values(&["source"])
|
||||
|
||||
@@ -408,7 +408,7 @@ fn run_backoff_test(result: Result<(), TestError>) -> (Duration, Duration) {
|
||||
&mut backoff,
|
||||
|_| {},
|
||||
&mut go_offline_future,
|
||||
|delay| async_std::task::sleep(delay),
|
||||
async_std::task::sleep,
|
||||
|| "Test error".into(),
|
||||
);
|
||||
|
||||
|
||||
@@ -95,6 +95,9 @@ pub trait HeadersSyncPipeline: Clone + Copy {
|
||||
fn estimate_size(source: &QueuedHeader<Self>) -> usize;
|
||||
}
|
||||
|
||||
/// A HeaderId for `HeaderSyncPipeline`.
|
||||
pub type HeaderIdOf<P> = HeaderId<<P as HeadersSyncPipeline>::Hash, <P as HeadersSyncPipeline>::Number>;
|
||||
|
||||
/// Header that we're receiving from source node.
|
||||
pub trait SourceHeader<Hash, Number> {
|
||||
/// Returns ID of header.
|
||||
|
||||
@@ -156,9 +156,10 @@ pub async fn run_async(params: Params, exit: Box<dyn Future<Output = ()> + Unpin
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn initial_next_events<'a>(
|
||||
chains: &'a HashMap<ChainId, RefCell<Chain>>,
|
||||
) -> Vec<Pin<Box<dyn Future<Output = Result<(ChainId, RawClientEvent), Error>> + 'a>>> {
|
||||
type EventsResult = Result<(ChainId, RawClientEvent), Error>;
|
||||
type EventsFuture<'a> = Pin<Box<dyn Future<Output = EventsResult> + 'a>>;
|
||||
|
||||
fn initial_next_events<'a>(chains: &'a HashMap<ChainId, RefCell<Chain>>) -> Vec<EventsFuture<'a>> {
|
||||
chains
|
||||
.values()
|
||||
.map(|chain_cell| async move {
|
||||
@@ -175,12 +176,9 @@ fn initial_next_events<'a>(
|
||||
}
|
||||
|
||||
async fn next_event<'a>(
|
||||
next_events: Vec<Pin<Box<dyn Future<Output = Result<(ChainId, RawClientEvent), Error>> + 'a>>>,
|
||||
next_events: Vec<EventsFuture<'a>>,
|
||||
chains: &'a HashMap<ChainId, RefCell<Chain>>,
|
||||
) -> (
|
||||
Result<(Hash, RawClientEvent), Error>,
|
||||
Vec<Pin<Box<dyn Future<Output = Result<(ChainId, RawClientEvent), Error>> + 'a>>>,
|
||||
) {
|
||||
) -> (Result<(Hash, RawClientEvent), Error>, Vec<EventsFuture<'a>>) {
|
||||
let (result, _, mut rest) = future::select_all(next_events).await;
|
||||
|
||||
match result {
|
||||
|
||||
Reference in New Issue
Block a user