Remove ChainListener
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 29 Jul 2020 20:02:29 +0000 (13:02 -0700)
committerJeffrey Czyz <jkczyz@gmail.com>
Fri, 7 Aug 2020 00:15:11 +0000 (17:15 -0700)
BlockNotifier was removed in the previous commit, thus ChainListener is
no longer needed. Instead, anything needing chain events should be
notified directly.

fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
lightning/src/chain/chaininterface.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/channelmonitor.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs

index 2face646a216c8f9822c9e87cd192b3a2a3f49cc..43a4fb2aaf747996c04ac6b1db7c90c01431e807 100644 (file)
@@ -22,7 +22,7 @@ use bitcoin::hash_types::{BlockHash, WPubkeyHash};
 
 use lightning::chain;
 use lightning::chain::transaction::OutPoint;
-use lightning::chain::chaininterface::{BroadcasterInterface, ChainListener, ConfirmationTarget, FeeEstimator};
+use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
 use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
 use lightning::ln::channelmonitor;
 use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};
index 251c965991953b8b4c70138d27a74c4cfac0192e..a869078f6d9a0f754910dc7de3d514a79154625d 100644 (file)
@@ -18,7 +18,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
 use lightning::chain;
-use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator};
+use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
 use lightning::chain::transaction::OutPoint;
 use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
 use lightning::ln::channelmonitor;
index 2b56853df74a265d79e51488898547e39c939ae0..f9f7254218e70d29197cfb4fc68a10e3744c3643 100644 (file)
@@ -4,7 +4,6 @@
 //! Includes traits for monitoring and receiving notifications of new blocks and block
 //! disconnections, transaction broadcasting, and feerate information requests.
 
-use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::script::Script;
 use bitcoin::hash_types::Txid;
@@ -17,18 +16,6 @@ pub trait BroadcasterInterface: Sync + Send {
        fn broadcast_transaction(&self, tx: &Transaction);
 }
 
-/// A trait indicating a desire to listen for events from the chain
-pub trait ChainListener: Sync + Send {
-       /// Notifies a listener that a block was connected. Transactions may be filtered and are given
-       /// paired with their position within the block.
-       fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32);
-
-       /// Notifies a listener that a block was disconnected.
-       /// Unlike block_connected, this *must* never be called twice for the same disconnect event.
-       /// Height must be the one of the block which was disconnected (not new height of the best chain)
-       fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32);
-}
-
 /// An enum that represents the speed at which we want a transaction to confirm used for feerate
 /// estimation.
 pub enum ConfirmationTarget {
@@ -44,8 +31,7 @@ pub enum ConfirmationTarget {
 /// horizons.
 ///
 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
-/// called from inside the library in response to ChainListener events, P2P events, or timer
-/// events).
+/// called from inside the library in response to chain events, P2P events, or timer events).
 pub trait FeeEstimator: Sync + Send {
        /// Gets estimated satoshis of fee required per 1000 Weight-Units.
        ///
index 1dad51b1cd6019f7f2e6e6e50664298a5d3f77b9..c853150f62d216a9445a82ed0304ebfec79b1371 100644 (file)
@@ -28,7 +28,7 @@ use bitcoin::secp256k1;
 
 use chain;
 use chain::Watch;
-use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
+use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
 use chain::transaction::OutPoint;
 use ln::channel::{Channel, ChannelError};
 use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
@@ -2968,15 +2968,15 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
        }
 }
 
-impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
-       ChainListener for ChannelManager<ChanSigner, M, T, K, F, L>
+impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<ChanSigner, M, T, K, F, L>
        where M::Target: chain::Watch<Keys=ChanSigner>,
         T::Target: BroadcasterInterface,
         K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
         F::Target: FeeEstimator,
-                               L::Target: Logger,
+        L::Target: Logger,
 {
-       fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
+       ///
+       pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
                let header_hash = header.bitcoin_hash();
                log_trace!(self.logger, "Block {} at height {} connected", header_hash, height);
                let _ = self.total_consistency_lock.read().unwrap();
@@ -3103,7 +3103,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
        }
 
        /// We force-close the channel without letting our counterparty participate in the shutdown
-       fn block_disconnected(&self, header: &BlockHeader, _: u32) {
+       pub fn block_disconnected(&self, header: &BlockHeader, _: u32) {
                let _ = self.total_consistency_lock.read().unwrap();
                let mut failed_channels = Vec::new();
                {
index 1ed76954fee9c39dabce24054e9660e62caad9e8..2baf327251f7570979ffd570f70a57c035800ef0 100644 (file)
@@ -35,7 +35,7 @@ use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, Loca
 use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
 use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
 use chain;
-use chain::chaininterface::{ChainListener, ChainWatchedUtil, BroadcasterInterface, FeeEstimator};
+use chain::chaininterface::{ChainWatchedUtil, BroadcasterInterface, FeeEstimator};
 use chain::transaction::OutPoint;
 use chain::keysinterface::{SpendableOutputDescriptor, ChannelKeys};
 use util::logger::Logger;
@@ -154,7 +154,7 @@ pub struct HTLCUpdate {
 }
 impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
 
-/// An implementation of a [`chain::Watch`] and ChainListener.
+/// An implementation of [`chain::Watch`].
 ///
 /// May be used in conjunction with [`ChannelManager`] to monitor channels locally or used
 /// independently to monitor channels remotely.
@@ -218,13 +218,17 @@ impl WatchEventQueue {
        }
 }
 
-impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
-       ChainListener for ChainMonitor<ChanSigner, T, F, L>
+impl<ChanSigner: ChannelKeys, T: Deref, F: Deref, L: Deref> ChainMonitor<Key, ChanSigner, T, F, L>
        where T::Target: BroadcasterInterface,
              F::Target: FeeEstimator,
              L::Target: Logger,
 {
-       fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
+       /// Delegates to [`ChannelMonitor::block_connected`] for each watched channel. Any HTLCs that
+       /// were resolved on chain will be retuned by [`chain::Watch::release_pending_htlc_updates`].
+       ///
+       /// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
+       /// [`chain::Watch::release_pending_htlc_updates`]: ../../chain/trait.Watch.html#tymethod.release_pending_htlc_updates
+       pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
                let mut watch_events = self.watch_events.lock().unwrap();
                let matched_txn: Vec<_> = txdata.iter().filter(|&&(_, tx)| watch_events.watched.does_match_tx(tx)).map(|e| *e).collect();
                {
@@ -241,7 +245,10 @@ impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L:
                }
        }
 
-       fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
+       /// Delegates to [`ChannelMonitor::block_disconnected`] for each watched channel.
+       ///
+       /// [`ChannelMonitor::block_disconnected`]: struct.ChannelMonitor.html#method.block_disconnected
+       pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
                let mut monitors = self.monitors.lock().unwrap();
                for monitor in monitors.values_mut() {
                        monitor.block_disconnected(header, disconnected_height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
index 3284ba757c89ba69acf397ee528a09835b48f68b..8d60af476485bd961d44bdd542ed9b3cbfa8ef09 100644 (file)
@@ -3,7 +3,6 @@
 
 use chain;
 use chain::Watch;
-use chain::chaininterface::ChainListener;
 use chain::transaction::OutPoint;
 use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
 use ln::channelmonitor::ChannelMonitor;
index d106f0c7ddb4723aa802082fc0b5c1e24abef224..e257f55e92dc27a6469638adb588767c3a50405f 100644 (file)
@@ -5,7 +5,6 @@
 use chain::Watch;
 use chain::transaction::OutPoint;
 use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor};
-use chain::chaininterface::ChainListener;
 use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
 use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure, BREAKDOWN_TIMEOUT};
 use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};