Skip to content

Commit ee17faf

Browse files
authored
Merge pull request #1777 from lexe-tech/max/best-block-header-best-block
Add `.to_best_block()` method to `ValidatedBlockHeader`
2 parents 95bb27a + a9f8b6e commit ee17faf

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
@@ -4,6 +4,7 @@ use crate::{AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, Blo
44

55
use bitcoin::hash_types::BlockHash;
66
use bitcoin::network::constants::Network;
7+
use lightning::chain::BestBlock;
78

89
use std::ops::Deref;
910

@@ -146,6 +147,19 @@ impl ValidatedBlockHeader {
146147

147148
Ok(())
148149
}
150+
151+
/// Returns the [`BestBlock`] corresponding to this validated block header, which can be passed
152+
/// into [`ChannelManager::new`] as part of its [`ChainParameters`]. Useful for ensuring that
153+
/// the [`SpvClient`] and [`ChannelManager`] are initialized to the same block during a fresh
154+
/// start.
155+
///
156+
/// [`SpvClient`]: crate::SpvClient
157+
/// [`ChainParameters`]: lightning::ln::channelmanager::ChainParameters
158+
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
159+
/// [`ChannelManager::new`]: lightning::ln::channelmanager::ChannelManager::new
160+
pub fn to_best_block(&self) -> BestBlock {
161+
BestBlock::new(self.block_hash, self.inner.height)
162+
}
149163
}
150164

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

0 commit comments

Comments
 (0)