X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;fp=lightning%2Fsrc%2Fln%2Fchannelmanager.rs;h=21d13eaefc2d350c81c32ad3c246c4f3823e4c15;hb=da298e498fc8bdf6af2b2becf82b0123118f46b4;hp=c147ed1c4f137cd0519defe457327b3ce753a240;hpb=0882655680040a0226b1790b6558150324a288f4;p=rust-lightning diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index c147ed1c..21d13eae 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -36,8 +36,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1; use chain; -use chain::Confirm; -use chain::Watch; +use chain::{Confirm, Watch, BestBlock}; use chain::chaininterface::{BroadcasterInterface, FeeEstimator}; use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent, CLOSED_CHANNEL_UPDATE_ID}; use chain::transaction::{OutPoint, TransactionData}; @@ -508,34 +507,6 @@ pub struct ChainParameters { pub best_block: BestBlock, } -/// The best known block as identified by its hash and height. -#[derive(Clone, Copy, PartialEq)] -pub struct BestBlock { - block_hash: BlockHash, - height: u32, -} - -impl BestBlock { - /// Returns the best block from the genesis of the given network. - pub fn from_genesis(network: Network) -> Self { - BestBlock { - block_hash: genesis_block(network).header.block_hash(), - height: 0, - } - } - - /// Returns the best block as identified by the given block hash and height. - pub fn new(block_hash: BlockHash, height: u32) -> Self { - BestBlock { block_hash, height } - } - - /// Returns the best block hash. - pub fn block_hash(&self) -> BlockHash { self.block_hash } - - /// Returns the best block height. - pub fn height(&self) -> u32 { self.height } -} - #[derive(Copy, Clone, PartialEq)] enum NotifyOption { DoPersist, @@ -4085,6 +4056,12 @@ where let guard = mtx.lock().unwrap(); *guard } + + /// Gets the latest best block which was connected either via the [`chain::Listen`] or + /// [`chain::Confirm`] interfaces. + pub fn current_best_block(&self) -> BestBlock { + self.best_block.read().unwrap().clone() + } } impl