Skip to content

Commit

Permalink
headers(part 3) feat: implement Linear downloader (#119)
Browse files Browse the repository at this point in the history
* feat: add headers downloaders crate

* feat: more scaffolding

* interfaces: generalize retryable erros

* feat: implement linear downloader

* fix linear downloader tests & add builder

* extend & reverse

* feat: linear downloader generics behind arc and reversed return order (#120)

* put client & consensus behind arc and return headers in rev

* cleanup

Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
  • Loading branch information
gakonst and rkrasiuk authored Oct 24, 2022
1 parent c19a425 commit fcb81f1
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 5 deletions.
60 changes: 60 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"crates/net/rpc",
"crates/net/rpc-api",
"crates/net/rpc-types",
"crates/net/headers-downloaders",
"crates/primitives",
"crates/stages",
"crates/transaction-pool",
Expand Down
3 changes: 2 additions & 1 deletion crates/interfaces/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use tokio::sync::watch::Receiver;
/// Consensus is a protocol that chooses canonical chain.
/// We are checking validity of block header here.
#[async_trait]
pub trait Consensus {
#[auto_impl::auto_impl(&, Arc)]
pub trait Consensus: Send + Sync {
/// Get a receiver for the fork choice state
fn fork_choice_state(&self) -> Receiver<ForkchoiceState>;

Expand Down
7 changes: 4 additions & 3 deletions crates/interfaces/src/p2p/headers/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ pub enum DownloadError {
}

impl DownloadError {
/// Returns bool indicating whether this error is retryable or fatal
/// Returns bool indicating whether this error is retryable or fatal, in the cases
/// where the peer responds with no headers, or times out.
pub fn is_retryable(&self) -> bool {
matches!(self, DownloadError::NoHeaderResponse { .. })
matches!(self, DownloadError::NoHeaderResponse { .. } | DownloadError::Timeout { .. })
}
}

/// The header downloading strategy
#[async_trait]
pub trait Downloader: Sync + Send + Debug {
pub trait Downloader: Sync + Send {
/// The Consensus used to verify block validity when
/// downloading
type Consensus: Consensus;
Expand Down
22 changes: 22 additions & 0 deletions crates/net/headers-downloaders/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "reth-headers-downloaders"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/foundry-rs/reth"
readme = "README.md"
description = "Implementations of various header downloader"

[dependencies]
async-trait = "0.1.58"
reth-interfaces = { path = "../../interfaces" }
reth-primitives = { path = "../../primitives" }
reth-rpc-types = { path = "../rpc-types" }

[dev-dependencies]
assert_matches = "1.5.0"
once_cell = "1.15.0"
rand = "0.8.5"
reth-interfaces = { path = "../../interfaces", features = ["test-helpers"] }
tokio = { version = "1.21.2", features = ["full"] }
serial_test = "0.9.0"
11 changes: 11 additions & 0 deletions crates/net/headers-downloaders/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![warn(missing_docs, unreachable_pub)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]

//! Implements Header Downloader algorithms
/// A Linear downloader implementation.
pub mod linear;
Loading

0 comments on commit fcb81f1

Please sign in to comment.