Skip to content

Commit cb7bada

Browse files
committed
Remove ChainListener
BlockNotifier was removed in the previous commit, thus ChainListener is no longer needed. Instead, anything needing chain events should be notified directly.
1 parent 382c71c commit cb7bada

File tree

7 files changed

+22
-31
lines changed

7 files changed

+22
-31
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use bitcoin::hash_types::{BlockHash, WPubkeyHash};
2222

2323
use lightning::chain;
2424
use lightning::chain::transaction::OutPoint;
25-
use lightning::chain::chaininterface::{BroadcasterInterface, ChainListener, ConfirmationTarget, FeeEstimator};
25+
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
2626
use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
2727
use lightning::ln::channelmonitor;
2828
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate};

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
1818
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
1919

2020
use lightning::chain;
21-
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator};
21+
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
2222
use lightning::chain::transaction::OutPoint;
2323
use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
2424
use lightning::ln::channelmonitor;

lightning/src/chain/chaininterface.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! Includes traits for monitoring and receiving notifications of new blocks and block
55
//! disconnections, transaction broadcasting, and feerate information requests.
66
7-
use bitcoin::blockdata::block::BlockHeader;
87
use bitcoin::blockdata::transaction::Transaction;
98
use bitcoin::blockdata::script::Script;
109
use bitcoin::hash_types::Txid;
@@ -17,18 +16,6 @@ pub trait BroadcasterInterface: Sync + Send {
1716
fn broadcast_transaction(&self, tx: &Transaction);
1817
}
1918

20-
/// A trait indicating a desire to listen for events from the chain
21-
pub trait ChainListener: Sync + Send {
22-
/// Notifies a listener that a block was connected. Transactions may be filtered and are given
23-
/// paired with their position within the block.
24-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32);
25-
26-
/// Notifies a listener that a block was disconnected.
27-
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
28-
/// Height must be the one of the block which was disconnected (not new height of the best chain)
29-
fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32);
30-
}
31-
3219
/// An enum that represents the speed at which we want a transaction to confirm used for feerate
3320
/// estimation.
3421
pub enum ConfirmationTarget {
@@ -44,8 +31,7 @@ pub enum ConfirmationTarget {
4431
/// horizons.
4532
///
4633
/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
47-
/// called from inside the library in response to ChainListener events, P2P events, or timer
48-
/// events).
34+
/// called from inside the library in response to chain events, P2P events, or timer events).
4935
pub trait FeeEstimator: Sync + Send {
5036
/// Gets estimated satoshis of fee required per 1000 Weight-Units.
5137
///

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use bitcoin::secp256k1;
2828

2929
use chain;
3030
use chain::Watch;
31-
use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
31+
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
3232
use chain::transaction::OutPoint;
3333
use ln::channel::{Channel, ChannelError};
3434
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>
29682968
}
29692969
}
29702970

2971-
impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
2972-
ChainListener for ChannelManager<ChanSigner, M, T, K, F, L>
2971+
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<ChanSigner, M, T, K, F, L>
29732972
where M::Target: chain::Watch<Keys=ChanSigner>,
29742973
T::Target: BroadcasterInterface,
29752974
K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
29762975
F::Target: FeeEstimator,
2977-
L::Target: Logger,
2976+
L::Target: Logger,
29782977
{
2979-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
2978+
///
2979+
pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
29802980
let header_hash = header.bitcoin_hash();
29812981
log_trace!(self.logger, "Block {} at height {} connected", header_hash, height);
29822982
let _ = self.total_consistency_lock.read().unwrap();
@@ -3103,7 +3103,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
31033103
}
31043104

31053105
/// We force-close the channel without letting our counterparty participate in the shutdown
3106-
fn block_disconnected(&self, header: &BlockHeader, _: u32) {
3106+
pub fn block_disconnected(&self, header: &BlockHeader, _: u32) {
31073107
let _ = self.total_consistency_lock.read().unwrap();
31083108
let mut failed_channels = Vec::new();
31093109
{

lightning/src/ln/channelmonitor.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, Loca
3535
use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
3636
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
3737
use chain;
38-
use chain::chaininterface::{ChainListener, ChainWatchedUtil, BroadcasterInterface, FeeEstimator};
38+
use chain::chaininterface::{ChainWatchedUtil, BroadcasterInterface, FeeEstimator};
3939
use chain::transaction::OutPoint;
4040
use chain::keysinterface::{SpendableOutputDescriptor, ChannelKeys};
4141
use util::logger::Logger;
@@ -154,7 +154,7 @@ pub struct HTLCUpdate {
154154
}
155155
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
156156

157-
/// An implementation of a [`chain::Watch`] and ChainListener.
157+
/// An implementation of [`chain::Watch`].
158158
///
159159
/// May be used in conjunction with [`ChannelManager`] to monitor channels locally or used
160160
/// independently to monitor channels remotely.
@@ -218,13 +218,17 @@ impl WatchEventQueue {
218218
}
219219
}
220220

221-
impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
222-
ChainListener for ChainMonitor<ChanSigner, T, F, L>
221+
impl<ChanSigner: ChannelKeys, T: Deref, F: Deref, L: Deref> ChainMonitor<Key, ChanSigner, T, F, L>
223222
where T::Target: BroadcasterInterface,
224223
F::Target: FeeEstimator,
225224
L::Target: Logger,
226225
{
227-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
226+
/// Delegates to [`ChannelMonitor::block_connected`] for each watched channel. Any HTLCs that
227+
/// were resolved on chain will be retuned by [`chain::Watch::release_pending_htlc_updates`].
228+
///
229+
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
230+
/// [`chain::Watch::release_pending_htlc_updates`]: ../../chain/trait.Watch.html#tymethod.release_pending_htlc_updates
231+
pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
228232
let mut watch_events = self.watch_events.lock().unwrap();
229233
let matched_txn: Vec<_> = txdata.iter().filter(|&&(_, tx)| watch_events.watched.does_match_tx(tx)).map(|e| *e).collect();
230234
{
@@ -241,7 +245,10 @@ impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L:
241245
}
242246
}
243247

244-
fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
248+
/// Delegates to [`ChannelMonitor::block_disconnected`] for each watched channel.
249+
///
250+
/// [`ChannelMonitor::block_disconnected`]: struct.ChannelMonitor.html#method.block_disconnected
251+
pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
245252
let mut monitors = self.monitors.lock().unwrap();
246253
for monitor in monitors.values_mut() {
247254
monitor.block_disconnected(header, disconnected_height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);

lightning/src/ln/functional_test_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
use chain;
55
use chain::Watch;
6-
use chain::chaininterface::ChainListener;
76
use chain::transaction::OutPoint;
87
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
98
use ln::channelmonitor::ChannelMonitor;

lightning/src/ln/functional_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use chain::Watch;
66
use chain::transaction::OutPoint;
77
use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor};
8-
use chain::chaininterface::ChainListener;
98
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
109
use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure, BREAKDOWN_TIMEOUT};
1110
use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};

0 commit comments

Comments
 (0)