]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add `ValidatedBlockHeader::to_best_block`
authorMax Fang <protonmail.com@maxfa.ng>
Tue, 18 Oct 2022 01:38:26 +0000 (18:38 -0700)
committerMax Fang <protonmail.com@maxfa.ng>
Tue, 18 Oct 2022 21:47:52 +0000 (14:47 -0700)
lightning-block-sync/src/poll.rs

index 4c6cb0c0600725e9cf3552045865e8b5be472199..1243d004aae7a2b56f8ac851624ab0c531f326eb 100644 (file)
@@ -5,6 +5,7 @@ use crate::{AsyncBlockSourceResult, BlockHeaderData, BlockSource, BlockSourceErr
 use bitcoin::blockdata::block::Block;
 use bitcoin::hash_types::BlockHash;
 use bitcoin::network::constants::Network;
+use lightning::chain::BestBlock;
 
 use std::ops::Deref;
 
@@ -140,6 +141,19 @@ impl ValidatedBlockHeader {
 
                Ok(())
        }
+
+    /// Returns the [`BestBlock`] corresponding to this validated block header, which can be passed
+    /// into [`ChannelManager::new`] as part of its [`ChainParameters`]. Useful for ensuring that
+    /// the [`SpvClient`] and [`ChannelManager`] are initialized to the same block during a fresh
+    /// start.
+    ///
+    /// [`SpvClient`]: crate::SpvClient
+    /// [`ChainParameters`]: lightning::ln::channelmanager::ChainParameters
+    /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
+    /// [`ChannelManager::new`]: lightning::ln::channelmanager::ChannelManager::new
+    pub fn to_best_block(&self) -> BestBlock {
+        BestBlock::new(self.block_hash, self.inner.height)
+    }
 }
 
 /// A block with validated data against its transaction list and corresponding block hash.