Remove unnecessary spaces
[rust-lightning] / lightning-block-sync / src / poll.rs
index 3ff7606b8d9cfdd8db1f9a936c14d4624c9e8945..c59652ea51716db9c7d24c3d9015c2e73f13833b 100644 (file)
@@ -1,3 +1,5 @@
+//! Adapters that make one or more [`BlockSource`]s simpler to poll for new chain tip transitions.
+
 use crate::{AsyncBlockSourceResult, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceResult};
 
 use bitcoin::blockdata::block::Block;
@@ -42,7 +44,9 @@ pub enum ChainTip {
 }
 
 /// The `Validate` trait defines behavior for validating chain data.
-pub(crate) trait Validate {
+///
+/// This trait is sealed and not meant to be implemented outside of this crate.
+pub trait Validate: sealed::Validate {
        /// The validated data wrapper which can be dereferenced to obtain the validated data.
        type T: std::ops::Deref<Target = Self>;
 
@@ -96,7 +100,7 @@ impl Validate for Block {
 /// A block header with validated proof of work and corresponding block hash.
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub struct ValidatedBlockHeader {
-       block_hash: BlockHash,
+       pub(crate) block_hash: BlockHash,
        inner: BlockHeaderData,
 }
 
@@ -142,7 +146,7 @@ impl ValidatedBlockHeader {
 
 /// A block with validated data against its transaction list and corresponding block hash.
 pub struct ValidatedBlock {
-       block_hash: BlockHash,
+       pub(crate) block_hash: BlockHash,
        inner: Block,
 }
 
@@ -154,16 +158,24 @@ impl std::ops::Deref for ValidatedBlock {
        }
 }
 
+mod sealed {
+       /// Used to prevent implementing [`super::Validate`] outside the crate but still allow its use.
+       pub trait Validate {}
+
+       impl Validate for crate::BlockHeaderData {}
+       impl Validate for bitcoin::blockdata::block::Block {}
+}
+
 /// The canonical `Poll` implementation used for a single `BlockSource`.
 ///
-/// Other `Poll` implementations must be built using `ChainPoller` as it provides the only means of
-/// validating chain data.
-pub struct ChainPoller<B: DerefMut<Target=T> + Sized + Sync + Send, T: BlockSource> {
+/// Other `Poll` implementations should be built using `ChainPoller` as it provides the simplest way
+/// of validating chain data and checking consistency.
+pub struct ChainPoller<B: DerefMut<Target=T> + Sized, T: BlockSource> {
        block_source: B,
        network: Network,
 }
 
-impl<B: DerefMut<Target=T> + Sized + Sync + Send, T: BlockSource> ChainPoller<B, T> {
+impl<B: DerefMut<Target=T> + Sized, T: BlockSource> ChainPoller<B, T> {
        /// Creates a new poller for the given block source.
        ///
        /// If the `network` parameter is mainnet, then the difficulty between blocks is checked for
@@ -173,7 +185,7 @@ impl<B: DerefMut<Target=T> + Sized + Sync + Send, T: BlockSource> ChainPoller<B,
        }
 }
 
-impl<B: DerefMut<Target=T> + Sized + Sync + Send, T: BlockSource> Poll for ChainPoller<B, T> {
+impl<B: DerefMut<Target=T> + Sized + Send + Sync, T: BlockSource> Poll for ChainPoller<B, T> {
        fn poll_chain_tip<'a>(&'a mut self, best_known_chain_tip: ValidatedBlockHeader) ->
                AsyncBlockSourceResult<'a, ChainTip>
        {