Skip to content

Commit a9f8b6e

Browse files
committed
Add ValidatedBlockHeader::to_best_block
1 parent 4ae65e8 commit a9f8b6e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lightning-block-sync/src/poll.rs

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{AsyncBlockSourceResult, BlockHeaderData, BlockSource, BlockSourceErr
55
use bitcoin::blockdata::block::Block;
66
use bitcoin::hash_types::BlockHash;
77
use bitcoin::network::constants::Network;
8+
use lightning::chain::BestBlock;
89

910
use std::ops::Deref;
1011

@@ -140,6 +141,19 @@ impl ValidatedBlockHeader {
140141

141142
Ok(())
142143
}
144+
145+
/// Returns the [`BestBlock`] corresponding to this validated block header, which can be passed
146+
/// into [`ChannelManager::new`] as part of its [`ChainParameters`]. Useful for ensuring that
147+
/// the [`SpvClient`] and [`ChannelManager`] are initialized to the same block during a fresh
148+
/// start.
149+
///
150+
/// [`SpvClient`]: crate::SpvClient
151+
/// [`ChainParameters`]: lightning::ln::channelmanager::ChainParameters
152+
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
153+
/// [`ChannelManager::new`]: lightning::ln::channelmanager::ChannelManager::new
154+
pub fn to_best_block(&self) -> BestBlock {
155+
BestBlock::new(self.block_hash, self.inner.height)
156+
}
143157
}
144158

145159
/// A block with validated data against its transaction list and corresponding block hash.

0 commit comments

Comments
 (0)