Skip to content

Commit 99e2283

Browse files
committed
Drop pub functions for ChainMonitor's Listen impl
1 parent 93d20ff commit 99e2283

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

fuzz/src/full_stack.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ impl<'a> MoneyLossDetector<'a> {
209209
self.height += 1;
210210
self.manager.transactions_confirmed(&header, &txdata, self.height as u32);
211211
self.manager.best_block_updated(&header, self.height as u32);
212-
(*self.monitor).block_connected(&header, &txdata, self.height as u32);
212+
(*self.monitor).transactions_confirmed(&header, &txdata, self.height as u32);
213+
(*self.monitor).best_block_updated(&header, self.height as u32);
213214
if self.header_hashes.len() > self.height {
214215
self.header_hashes[self.height] = (header.block_hash(), self.blocks_connected);
215216
} else {

lightning/src/chain/chainmonitor.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,14 @@ where C::Target: chain::Filter,
7474
P::Target: channelmonitor::Persist<ChannelSigner>,
7575
{
7676
/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
77-
/// of a channel and reacting accordingly based on transactions in the connected block. See
77+
/// of a channel and reacting accordingly based on transactions in the given chain data. See
7878
/// [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will
7979
/// be returned by [`chain::Watch::release_pending_monitor_events`].
8080
///
8181
/// Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent
8282
/// calls must not exclude any transactions matching the new outputs nor any in-block
8383
/// descendants of such transactions. It is not necessary to re-fetch the block to obtain
8484
/// updated `txdata`.
85-
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
86-
self.process_chain_data(header, txdata, |monitor, txdata| {
87-
monitor.block_connected(
88-
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
89-
});
90-
}
91-
9285
fn process_chain_data<FN>(&self, header: &BlockHeader, txdata: &TransactionData, process: FN)
9386
where
9487
FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs>
@@ -129,16 +122,6 @@ where C::Target: chain::Filter,
129122
}
130123
}
131124

132-
/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
133-
/// of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for
134-
/// details.
135-
pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
136-
let monitors = self.monitors.read().unwrap();
137-
for monitor in monitors.values() {
138-
monitor.block_disconnected(header, disconnected_height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
139-
}
140-
}
141-
142125
/// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
143126
///
144127
/// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
@@ -158,7 +141,7 @@ where C::Target: chain::Filter,
158141
}
159142
}
160143

161-
impl<ChannelSigner: Sign, C: Deref + Send + Sync, T: Deref + Send + Sync, F: Deref + Send + Sync, L: Deref + Send + Sync, P: Deref + Send + Sync>
144+
impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
162145
chain::Listen for ChainMonitor<ChannelSigner, C, T, F, L, P>
163146
where
164147
ChannelSigner: Sign,
@@ -169,12 +152,20 @@ where
169152
P::Target: channelmonitor::Persist<ChannelSigner>,
170153
{
171154
fn block_connected(&self, block: &Block, height: u32) {
155+
let header = &block.header;
172156
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
173-
ChainMonitor::block_connected(self, &block.header, &txdata, height);
157+
self.process_chain_data(header, &txdata, |monitor, txdata| {
158+
monitor.block_connected(
159+
header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
160+
});
174161
}
175162

176163
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
177-
ChainMonitor::block_disconnected(self, header, height);
164+
let monitors = self.monitors.read().unwrap();
165+
for monitor in monitors.values() {
166+
monitor.block_disconnected(
167+
header, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
168+
}
178169
}
179170
}
180171

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
//! There are a bunch of these as their handling is relatively error-prone so they are split out
1313
//! here. See also the chanmon_fail_consistency fuzz test.
1414
15-
use bitcoin::blockdata::block::BlockHeader;
15+
use bitcoin::blockdata::block::{Block, BlockHeader};
1616
use bitcoin::hash_types::BlockHash;
1717
use bitcoin::network::constants::Network;
1818
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr};
1919
use chain::transaction::OutPoint;
20+
use chain::Listen;
2021
use chain::Watch;
2122
use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
2223
use ln::features::InitFeatures;
@@ -114,7 +115,7 @@ fn test_monitor_and_persister_update_fail() {
114115
chain_mon
115116
};
116117
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
117-
chain_mon.chain_monitor.block_connected(&header, &[], 200);
118+
chain_mon.chain_monitor.block_connected(&Block { header, txdata: vec![] }, 200);
118119

119120
// Set the persister's return value to be a TemporaryFailure.
120121
persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, s
140140
node.node.best_block_updated(&block.header, height);
141141
},
142142
ConnectStyle::FullBlockViaListen => {
143-
node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
144-
Listen::block_connected(node.node, &block, height);
143+
node.chain_monitor.chain_monitor.block_connected(&block, height);
144+
node.node.block_connected(&block, height);
145145
}
146146
}
147147
}

lightning/src/ln/functional_tests.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! claim outputs on-chain.
1313
1414
use chain;
15+
use chain::Listen;
1516
use chain::Watch;
1617
use chain::channelmonitor;
1718
use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
@@ -8225,7 +8226,7 @@ fn test_update_err_monitor_lockdown() {
82258226
watchtower
82268227
};
82278228
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
8228-
watchtower.chain_monitor.block_connected(&header, &[], 200);
8229+
watchtower.chain_monitor.block_connected(&Block { header, txdata: vec![] }, 200);
82298230

82308231
// Try to update ChannelMonitor
82318232
assert!(nodes[1].node.claim_funds(preimage, &None, 9_000_000));
@@ -8284,7 +8285,7 @@ fn test_concurrent_monitor_claim() {
82848285
watchtower
82858286
};
82868287
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
8287-
watchtower_alice.chain_monitor.block_connected(&header, &vec![], CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8288+
watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
82888289

82898290
// Watchtower Alice should have broadcast a commitment/HTLC-timeout
82908291
{
@@ -8310,7 +8311,7 @@ fn test_concurrent_monitor_claim() {
83108311
watchtower
83118312
};
83128313
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
8313-
watchtower_bob.chain_monitor.block_connected(&header, &vec![], CHAN_CONFIRM_DEPTH + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8314+
watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
83148315

83158316
// Route another payment to generate another update with still previous HTLC pending
83168317
let (_, payment_hash) = get_payment_preimage_hash!(nodes[0]);
@@ -8336,7 +8337,8 @@ fn test_concurrent_monitor_claim() {
83368337
check_added_monitors!(nodes[0], 1);
83378338

83388339
//// Provide one more block to watchtower Bob, expect broadcast of commitment and HTLC-Timeout
8339-
watchtower_bob.chain_monitor.block_connected(&header, &vec![], CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8340+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
8341+
watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
83408342

83418343
// Watchtower Bob should have broadcast a commitment/HTLC-timeout
83428344
let bob_state_y;
@@ -8348,7 +8350,8 @@ fn test_concurrent_monitor_claim() {
83488350
};
83498351

83508352
// We confirm Bob's state Y on Alice, she should broadcast a HTLC-timeout
8351-
watchtower_alice.chain_monitor.block_connected(&header, &vec![(0, &bob_state_y)], CHAN_CONFIRM_DEPTH + 2 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
8353+
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
8354+
watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![bob_state_y.clone()] }, CHAN_CONFIRM_DEPTH + 2 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
83528355
{
83538356
let htlc_txn = chanmon_cfgs[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
83548357
// We broadcast twice the transaction, once due to the HTLC-timeout, once due

0 commit comments

Comments
 (0)