Struct lightning_block_sync::SpvClient
source · pub struct SpvClient<'a, P: Poll, C: Cache, L: Deref>where
L::Target: Listen,{ /* private fields */ }
Expand description
A lightweight client for keeping a listener in sync with the chain, allowing for Simplified Payment Verification (SPV).
The client is parameterized by a chain poller which is responsible for polling one or more block sources for the best chain tip. During this process it detects any chain forks, determines which constitutes the best chain, and updates the listener accordingly with any blocks that were connected or disconnected since the last poll.
Block headers for the best chain are maintained in the parameterized cache, allowing for a custom cache eviction policy. This offers flexibility to those sensitive to resource usage. Hence, there is a trade-off between a lower memory footprint and potentially increased network I/O as headers are re-fetched during fork detection.
Implementations§
source§impl<'a, P: Poll, C: Cache, L: Deref> SpvClient<'a, P, C, L>where
L::Target: Listen,
impl<'a, P: Poll, C: Cache, L: Deref> SpvClient<'a, P, C, L>where L::Target: Listen,
sourcepub fn new(
chain_tip: ValidatedBlockHeader,
chain_poller: P,
header_cache: &'a mut C,
chain_listener: L
) -> Self
pub fn new( chain_tip: ValidatedBlockHeader, chain_poller: P, header_cache: &'a mut C, chain_listener: L ) -> Self
Creates a new SPV client using chain_tip
as the best known chain tip.
Subsequent calls to poll_best_tip
will poll for the best chain tip using the given chain
poller, which may be configured with one or more block sources to query. At least one block
source must provide headers back from the best chain tip to its common ancestor with
chain_tip
.
header_cache
is used to look up and store headers on the best chainchain_listener
is notified of any blocks connected or disconnected
sourcepub async fn poll_best_tip(&mut self) -> BlockSourceResult<(ChainTip, bool)>
pub async fn poll_best_tip(&mut self) -> BlockSourceResult<(ChainTip, bool)>
Polls for the best tip and updates the chain listener with any connected or disconnected blocks accordingly.
Returns the best polled chain tip relative to the previous best known tip and whether any blocks were indeed connected or disconnected.