diff --git a/zebrad/src/components/inbound.rs b/zebrad/src/components/inbound.rs index 8646ce0b..d682e076 100644 --- a/zebrad/src/components/inbound.rs +++ b/zebrad/src/components/inbound.rs @@ -53,17 +53,37 @@ pub type SetupData = (Outbound, Arc>); /// responding to block gossip by attempting to download and validate advertised /// blocks. pub struct Inbound { - // invariant: outbound, address_book are Some if network_setup is None + // invariant: address_book, outbound, downloads are Some if network_setup is None // // why not use an enum for the inbound state? because it would mean // match-wrapping the body of Service::call rather than just expect()ing // some Options. + + // Setup + /// A oneshot channel used to receive the address_book and outbound services + /// after the network is set up. network_setup: Option>, - outbound: Option, + + // Services + /// A list of peer addresses. address_book: Option>>, - state: State, - verifier: Verifier, + + /// A service that downloads and verifies gossipped blocks. downloads: Option, Timeout, State>>>>, + + /// A service that forwards requests to connected peers, and returns their + /// responses. + /// + /// Only used for readiness checks, and via `downloads`. + outbound: Option, + + /// A service that manages cached blockchain state. + state: State, + + /// A service that verifies downloaded blocks. + /// + /// Only used for readiness checks, and via `downloads`. + verifier: Verifier, } impl Inbound { @@ -74,11 +94,11 @@ impl Inbound { ) -> Self { Self { network_setup: Some(network_setup), - outbound: None, address_book: None, + downloads: None, + outbound: None, state, verifier, - downloads: None, } } } diff --git a/zebrad/src/components/inbound/downloads.rs b/zebrad/src/components/inbound/downloads.rs index d1ce7a57..d138a1e9 100644 --- a/zebrad/src/components/inbound/downloads.rs +++ b/zebrad/src/components/inbound/downloads.rs @@ -33,11 +33,24 @@ where ZS: Service + Send + Clone + 'static, ZS::Future: Send, { + // Services + /// A service that forwards requests to connected peers, and returns their + /// responses. network: ZN, + + /// A service that verifies downloaded blocks. verifier: ZV, + + /// A service that manages cached blockchain state. state: ZS, + + // Internal downloads state + /// A list of pending block download and verify tasks. #[pin] pending: FuturesUnordered>>, + + /// A list of channels that can be used to cancel pending block download and + /// verify tasks. cancel_handles: HashMap>, } diff --git a/zebrad/src/components/sync/downloads.rs b/zebrad/src/components/sync/downloads.rs index bc1e5b7d..0751f42a 100644 --- a/zebrad/src/components/sync/downloads.rs +++ b/zebrad/src/components/sync/downloads.rs @@ -43,10 +43,21 @@ where ZV: Service, Response = block::Hash, Error = BoxError> + Send + Clone + 'static, ZV::Future: Send, { + // Services + /// A service that forwards requests to connected peers, and returns their + /// responses. network: ZN, + + /// A service that verifies downloaded blocks. verifier: ZV, + + // Internal downloads state + /// A list of pending block download and verify tasks. #[pin] pending: FuturesUnordered>>, + + /// A list of channels that can be used to cancel pending block download and + /// verify tasks. cancel_handles: HashMap>, }