Skip to content

Commit f011eed

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 2054e0f commit f011eed

File tree

7 files changed

+17
-32
lines changed

7 files changed

+17
-32
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};
@@ -2953,15 +2953,15 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
29532953
}
29542954
}
29552955

2956-
impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
2957-
ChainListener for ChannelManager<ChanSigner, M, T, K, F, L>
2956+
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<ChanSigner, M, T, K, F, L>
29582957
where M::Target: chain::Watch<Keys=ChanSigner>,
29592958
T::Target: BroadcasterInterface,
29602959
K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
29612960
F::Target: FeeEstimator,
2962-
L::Target: Logger,
2961+
L::Target: Logger,
29632962
{
2964-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
2963+
///
2964+
pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
29652965
let header_hash = header.bitcoin_hash();
29662966
log_trace!(self.logger, "Block {} at height {} connected", header_hash, height);
29672967
let _ = self.total_consistency_lock.read().unwrap();
@@ -3088,7 +3088,7 @@ impl<ChanSigner: ChannelKeys, M: Deref + Sync + Send, T: Deref + Sync + Send, K:
30883088
}
30893089

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

lightning/src/ln/channelmonitor.rs

Lines changed: 8 additions & 7 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,8 +154,8 @@ pub struct HTLCUpdate {
154154
}
155155
impl_writeable!(HTLCUpdate, 0, { payment_hash, payment_preimage, source });
156156

157-
/// A simple implementation of a [`chain::Watch`] and ChainListener. Can be used to create a
158-
/// watchtower or watch our own channels.
157+
/// A simple implementation of a [`chain::Watch`]. Can be used to create a watchtower or to watch
158+
/// channels locally.
159159
///
160160
/// Note that you must provide your own key by which to refer to channels.
161161
///
@@ -224,13 +224,13 @@ impl WatchEventQueue {
224224
}
225225
}
226226

227-
impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send>
228-
ChainListener for ChainMonitor<Key, ChanSigner, T, F, L>
227+
impl<Key : Send + cmp::Eq + hash::Hash + 'static, ChanSigner: ChannelKeys, T: Deref, F: Deref, L: Deref> ChainMonitor<Key, ChanSigner, T, F, L>
229228
where T::Target: BroadcasterInterface,
230229
F::Target: FeeEstimator,
231230
L::Target: Logger,
232231
{
233-
fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
232+
///
233+
pub fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
234234
let mut watch_events = self.watch_events.lock().unwrap();
235235
let matched_txn: Vec<_> = txdata.iter().filter(|&&(_, tx)| watch_events.watched.does_match_tx(tx)).map(|e| *e).collect();
236236
{
@@ -247,7 +247,8 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync
247247
}
248248
}
249249

250-
fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
250+
///
251+
pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
251252
let mut monitors = self.monitors.lock().unwrap();
252253
for monitor in monitors.values_mut() {
253254
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)