Skip to content

Commit 6c09eb7

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 4bf6747 commit 6c09eb7

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
@@ -31,7 +31,7 @@ use bitcoin::hash_types::{BlockHash, WPubkeyHash};
3131

3232
use lightning::chain;
3333
use lightning::chain::transaction::OutPoint;
34-
use lightning::chain::chaininterface::{BroadcasterInterface, ChainListener, ConfirmationTarget, FeeEstimator};
34+
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3535
use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys};
3636
use lightning::ln::channelmonitor;
3737
use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};

fuzz/src/full_stack.rs

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

2929
use lightning::chain;
30-
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator};
30+
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3131
use lightning::chain::transaction::OutPoint;
3232
use lightning::chain::keysinterface::{InMemoryChannelKeys, KeysInterface};
3333
use lightning::ln::channelmonitor;

lightning/src/chain/chaininterface.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! Includes traits for monitoring and receiving notifications of new blocks and block
1414
//! disconnections, transaction broadcasting, and feerate information requests.
1515
16-
use bitcoin::blockdata::block::BlockHeader;
1716
use bitcoin::blockdata::transaction::Transaction;
1817
use bitcoin::blockdata::script::Script;
1918
use bitcoin::hash_types::Txid;
@@ -26,18 +25,6 @@ pub trait BroadcasterInterface: Sync + Send {
2625
fn broadcast_transaction(&self, tx: &Transaction);
2726
}
2827

29-
/// A trait indicating a desire to listen for events from the chain
30-
pub trait ChainListener: Sync + Send {
31-
/// Notifies a listener that a block was connected. Transactions may be filtered and are given
32-
/// paired with their position within the block.
33-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32);
34-
35-
/// Notifies a listener that a block was disconnected.
36-
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
37-
/// Height must be the one of the block which was disconnected (not new height of the best chain)
38-
fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32);
39-
}
40-
4128
/// An enum that represents the speed at which we want a transaction to confirm used for feerate
4229
/// estimation.
4330
pub enum ConfirmationTarget {
@@ -53,8 +40,7 @@ pub enum ConfirmationTarget {
5340
/// horizons.
5441
///
5542
/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
56-
/// called from inside the library in response to ChainListener events, P2P events, or timer
57-
/// events).
43+
/// called from inside the library in response to chain events, P2P events, or timer events).
5844
pub trait FeeEstimator: Sync + Send {
5945
/// Gets estimated satoshis of fee required per 1000 Weight-Units.
6046
///

lightning/src/ln/channelmanager.rs

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

3838
use chain;
3939
use chain::Watch;
40-
use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
40+
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
4141
use chain::transaction::OutPoint;
4242
use ln::channel::{Channel, ChannelError};
4343
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent};
@@ -3049,15 +3049,15 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
30493049
}
30503050
}
30513051

3052-
impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
3053-
ChainListener for ChannelManager<ChanSigner, M, T, K, F, L>
3052+
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<ChanSigner, M, T, K, F, L>
30543053
where M::Target: chain::Watch<Keys=ChanSigner>,
30553054
T::Target: BroadcasterInterface,
30563055
K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
30573056
F::Target: FeeEstimator,
3058-
L::Target: Logger,
3057+
L::Target: Logger,
30593058
{
3060-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
3059+
///
3060+
pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
30613061
let header_hash = header.bitcoin_hash();
30623062
log_trace!(self.logger, "Block {} at height {} connected", header_hash, height);
30633063
let _ = self.total_consistency_lock.read().unwrap();
@@ -3169,7 +3169,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
31693169
}
31703170

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

lightning/src/ln/channelmonitor.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, Loca
4444
use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
4545
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
4646
use chain;
47-
use chain::chaininterface::{ChainListener, ChainWatchedUtil, BroadcasterInterface, FeeEstimator};
47+
use chain::chaininterface::{ChainWatchedUtil, BroadcasterInterface, FeeEstimator};
4848
use chain::transaction::OutPoint;
4949
use chain::keysinterface::{SpendableOutputDescriptor, ChannelKeys};
5050
use util::logger::Logger;
@@ -175,7 +175,7 @@ pub struct HTLCUpdate {
175175
}
176176
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
177177

178-
/// An implementation of a [`chain::Watch`] and ChainListener.
178+
/// An implementation of [`chain::Watch`].
179179
///
180180
/// May be used in conjunction with [`ChannelManager`] to monitor channels locally or used
181181
/// independently to monitor channels remotely.
@@ -237,13 +237,17 @@ impl WatchEventQueue {
237237
}
238238
}
239239

240-
impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
241-
ChainListener for ChainMonitor<ChanSigner, T, F, L>
240+
impl<ChanSigner: ChannelKeys, T: Deref, F: Deref, L: Deref> ChainMonitor<Key, ChanSigner, T, F, L>
242241
where T::Target: BroadcasterInterface,
243242
F::Target: FeeEstimator,
244243
L::Target: Logger,
245244
{
246-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
245+
/// Delegates to [`ChannelMonitor::block_connected`] for each watched channel. Any HTLCs that
246+
/// were resolved on chain will be retuned by [`chain::Watch::release_pending_htlc_updates`].
247+
///
248+
/// [`ChannelMonitor::block_connected`]: struct.ChannelMonitor.html#method.block_connected
249+
/// [`chain::Watch::release_pending_htlc_updates`]: ../../chain/trait.Watch.html#tymethod.release_pending_htlc_updates
250+
pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
247251
let mut watch_events = self.watch_events.lock().unwrap();
248252
let matched_txn: Vec<_> = txdata.iter().filter(|&&(_, tx)| watch_events.watched.does_match_tx(tx)).map(|e| *e).collect();
249253
{
@@ -260,7 +264,10 @@ impl<ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L:
260264
}
261265
}
262266

263-
fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
267+
/// Delegates to [`ChannelMonitor::block_disconnected`] for each watched channel.
268+
///
269+
/// [`ChannelMonitor::block_disconnected`]: struct.ChannelMonitor.html#method.block_disconnected
270+
pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
264271
let mut monitors = self.monitors.lock().unwrap();
265272
for monitor in monitors.values_mut() {
266273
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
@@ -12,7 +12,6 @@
1212
1313
use chain;
1414
use chain::Watch;
15-
use chain::chaininterface::ChainListener;
1615
use chain::transaction::OutPoint;
1716
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
1817
use ln::channelmonitor::ChannelMonitor;

lightning/src/ln/functional_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use chain::Watch;
1515
use chain::transaction::OutPoint;
1616
use chain::keysinterface::{ChannelKeys, KeysInterface, SpendableOutputDescriptor};
17-
use chain::chaininterface::ChainListener;
1817
use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
1918
use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,HTLCForwardInfo,RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure, BREAKDOWN_TIMEOUT};
2019
use ln::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};

0 commit comments

Comments
 (0)