Skip to content

Add .to_best_block() method to ValidatedBlockHeader #1777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lightning-block-sync/src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down