Refactor inbound members into a consistent order

And add download comments
This commit is contained in:
teor 2021-01-13 20:26:50 +10:00 committed by Deirdre Connolly
parent fb76eb2e6b
commit 92d95d4be5
3 changed files with 50 additions and 6 deletions

View File

@ -53,17 +53,37 @@ pub type SetupData = (Outbound, Arc<Mutex<AddressBook>>);
/// responding to block gossip by attempting to download and validate advertised /// responding to block gossip by attempting to download and validate advertised
/// blocks. /// blocks.
pub struct Inbound { 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 // 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 // match-wrapping the body of Service::call rather than just expect()ing
// some Options. // some Options.
// Setup
/// A oneshot channel used to receive the address_book and outbound services
/// after the network is set up.
network_setup: Option<oneshot::Receiver<SetupData>>, network_setup: Option<oneshot::Receiver<SetupData>>,
outbound: Option<Outbound>,
// Services
/// A list of peer addresses.
address_book: Option<Arc<Mutex<zn::AddressBook>>>, address_book: Option<Arc<Mutex<zn::AddressBook>>>,
state: State,
verifier: Verifier, /// A service that downloads and verifies gossipped blocks.
downloads: Option<Pin<Box<Downloads<Timeout<Outbound>, Timeout<Verifier>, State>>>>, downloads: Option<Pin<Box<Downloads<Timeout<Outbound>, Timeout<Verifier>, State>>>>,
/// A service that forwards requests to connected peers, and returns their
/// responses.
///
/// Only used for readiness checks, and via `downloads`.
outbound: Option<Outbound>,
/// 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 { impl Inbound {
@ -74,11 +94,11 @@ impl Inbound {
) -> Self { ) -> Self {
Self { Self {
network_setup: Some(network_setup), network_setup: Some(network_setup),
outbound: None,
address_book: None, address_book: None,
downloads: None,
outbound: None,
state, state,
verifier, verifier,
downloads: None,
} }
} }
} }

View File

@ -33,11 +33,24 @@ where
ZS: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static, ZS: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static,
ZS::Future: Send, ZS::Future: Send,
{ {
// Services
/// A service that forwards requests to connected peers, and returns their
/// responses.
network: ZN, network: ZN,
/// A service that verifies downloaded blocks.
verifier: ZV, verifier: ZV,
/// A service that manages cached blockchain state.
state: ZS, state: ZS,
// Internal downloads state
/// A list of pending block download and verify tasks.
#[pin] #[pin]
pending: FuturesUnordered<JoinHandle<Result<block::Hash, (BoxError, block::Hash)>>>, pending: FuturesUnordered<JoinHandle<Result<block::Hash, (BoxError, block::Hash)>>>,
/// A list of channels that can be used to cancel pending block download and
/// verify tasks.
cancel_handles: HashMap<block::Hash, oneshot::Sender<()>>, cancel_handles: HashMap<block::Hash, oneshot::Sender<()>>,
} }

View File

@ -43,10 +43,21 @@ where
ZV: Service<Arc<Block>, Response = block::Hash, Error = BoxError> + Send + Clone + 'static, ZV: Service<Arc<Block>, Response = block::Hash, Error = BoxError> + Send + Clone + 'static,
ZV::Future: Send, ZV::Future: Send,
{ {
// Services
/// A service that forwards requests to connected peers, and returns their
/// responses.
network: ZN, network: ZN,
/// A service that verifies downloaded blocks.
verifier: ZV, verifier: ZV,
// Internal downloads state
/// A list of pending block download and verify tasks.
#[pin] #[pin]
pending: FuturesUnordered<JoinHandle<Result<block::Hash, (BoxError, block::Hash)>>>, pending: FuturesUnordered<JoinHandle<Result<block::Hash, (BoxError, block::Hash)>>>,
/// A list of channels that can be used to cancel pending block download and
/// verify tasks.
cancel_handles: HashMap<block::Hash, oneshot::Sender<()>>, cancel_handles: HashMap<block::Hash, oneshot::Sender<()>>,
} }