Skip to content

Commit 2bd571d

Browse files
committed
Drop last bits of rescan as its too complicated to be worth having
Previously, we had a concept of "rescaning" blocks when we detected a need to monitor for a new set of outputs in future blocks while connecting a block. In such cases, we'd need to possibly learn about these new spends later in the *same block*, requiring clients who filter blocks to get a newly-filtered copy of the same block. While redoing the chain access API, it became increasingly clear this was an overly complicated API feature, and it seems likely most clients will not use it anyway. Further, any client who *does* filter blocks can simply update their filtering algorithm to include any descendants of matched transactions in the filter results, avoiding the need for rescan support entirely. Thus, it was decided that we'd move forward without rescan support in #649, however to avoid significant further changes in the already-large 649, we decided to fully remove support in a follow-up. Here, we remove the API features that existed for rescan and fix the few tests to not rely on it. After this commit, we now only ever have one possible version of block connection transactions, making it possible to be significantly more confident in our test coverage actually capturing all realistic scenarios.
1 parent b627aa6 commit 2bd571d

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,27 @@ impl<ChanSigner: ChannelKeys, C: Deref, T: Deref, F: Deref, L: Deref> ChainMonit
8080
/// [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will
8181
/// be returned by [`chain::Watch::release_pending_monitor_events`].
8282
///
83-
/// Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch, returning
84-
/// `true` if so. Subsequent calls must not exclude any transactions matching the new outputs
85-
/// nor any in-block descendants of such transactions. It is not necessary to re-fetch the block
86-
/// to obtain updated `txdata`.
83+
/// Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent
84+
/// calls must not exclude any transactions matching the new outputs nor any in-block
85+
/// descendants of such transactions. It is not necessary to re-fetch the block to obtain
86+
/// updated `txdata`.
8787
///
8888
/// [`ChannelMonitor::block_connected`]: ../channelmonitor/struct.ChannelMonitor.html#method.block_connected
8989
/// [`chain::Watch::release_pending_monitor_events`]: ../trait.Watch.html#tymethod.release_pending_monitor_events
9090
/// [`chain::Filter`]: ../trait.Filter.html
91-
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) -> bool {
92-
let mut has_new_outputs_to_watch = false;
93-
{
94-
let mut monitors = self.monitors.lock().unwrap();
95-
for monitor in monitors.values_mut() {
96-
let mut txn_outputs = monitor.block_connected(header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
97-
has_new_outputs_to_watch |= !txn_outputs.is_empty();
98-
99-
if let Some(ref chain_source) = self.chain_source {
100-
for (txid, outputs) in txn_outputs.drain(..) {
101-
for (idx, output) in outputs.iter().enumerate() {
102-
chain_source.register_output(&OutPoint { txid, index: idx as u16 }, &output.script_pubkey);
103-
}
91+
pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
92+
let mut monitors = self.monitors.lock().unwrap();
93+
for monitor in monitors.values_mut() {
94+
let mut txn_outputs = monitor.block_connected(header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
95+
96+
if let Some(ref chain_source) = self.chain_source {
97+
for (txid, outputs) in txn_outputs.drain(..) {
98+
for (idx, output) in outputs.iter().enumerate() {
99+
chain_source.register_output(&OutPoint { txid, index: idx as u16 }, &output.script_pubkey);
104100
}
105101
}
106102
}
107103
}
108-
has_new_outputs_to_watch
109104
}
110105

111106
/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32, he
8181

8282
pub fn connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, height: u32) {
8383
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
84-
while node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height) {}
84+
node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
8585
node.node.block_connected(&block.header, &txdata, height);
8686
}
8787

lightning/src/ln/functional_tests.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4852,8 +4852,7 @@ fn test_claim_on_remote_sizeable_push_msat() {
48524852
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1, 1, true, header.block_hash());
48534853

48544854
let spend_txn = check_spendable_outputs!(nodes[1], 1, node_cfgs[1].keys_manager, 100000);
4855-
assert_eq!(spend_txn.len(), 2);
4856-
assert_eq!(spend_txn[0], spend_txn[1]);
4855+
assert_eq!(spend_txn.len(), 1);
48574856
check_spends!(spend_txn[0], node_txn[0]);
48584857
}
48594858

@@ -4885,10 +4884,9 @@ fn test_claim_on_remote_revoked_sizeable_push_msat() {
48854884
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1, 1, true, header.block_hash());
48864885

48874886
let spend_txn = check_spendable_outputs!(nodes[1], 1, node_cfgs[1].keys_manager, 100000);
4888-
assert_eq!(spend_txn.len(), 3);
4889-
assert_eq!(spend_txn[0], spend_txn[1]); // to_remote output on revoked remote commitment_tx
4890-
check_spends!(spend_txn[0], revoked_local_txn[0]);
4891-
check_spends!(spend_txn[2], node_txn[0]);
4887+
assert_eq!(spend_txn.len(), 2);
4888+
check_spends!(spend_txn[0], revoked_local_txn[0]); // to_remote output on revoked remote commitment_tx
4889+
check_spends!(spend_txn[1], node_txn[0]);
48924890
}
48934891

48944892
#[test]
@@ -4983,8 +4981,8 @@ fn test_static_spendable_outputs_timeout_tx() {
49834981
expect_payment_failed!(nodes[1], our_payment_hash, true);
49844982

49854983
let spend_txn = check_spendable_outputs!(nodes[1], 1, node_cfgs[1].keys_manager, 100000);
4986-
assert_eq!(spend_txn.len(), 3); // SpendableOutput: remote_commitment_tx.to_remote (*2), timeout_tx.output (*1)
4987-
check_spends!(spend_txn[2], node_txn[0].clone());
4984+
assert_eq!(spend_txn.len(), 2); // SpendableOutput: remote_commitment_tx.to_remote, timeout_tx.output
4985+
check_spends!(spend_txn[1], node_txn[0]);
49884986
}
49894987

49904988
#[test]
@@ -5159,12 +5157,11 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
51595157

51605158
// Check A's ChannelMonitor was able to generate the right spendable output descriptor
51615159
let spend_txn = check_spendable_outputs!(nodes[0], 1, node_cfgs[0].keys_manager, 100000);
5162-
assert_eq!(spend_txn.len(), 3); // Duplicated SpendableOutput due to block rescan after revoked htlc output tracking
5163-
assert_eq!(spend_txn[0], spend_txn[1]);
5160+
assert_eq!(spend_txn.len(), 2);
51645161
assert_eq!(spend_txn[0].input.len(), 1);
51655162
check_spends!(spend_txn[0], revoked_local_txn[0]); // spending to_remote output from revoked local tx
51665163
assert_ne!(spend_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
5167-
check_spends!(spend_txn[2], node_txn[1]); // spending justice tx output on the htlc success tx
5164+
check_spends!(spend_txn[1], node_txn[1]); // spending justice tx output on the htlc success tx
51685165
}
51695166

51705167
#[test]
@@ -5726,10 +5723,9 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
57265723

57275724
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
57285725
let spend_txn = check_spendable_outputs!(nodes[0], 1, node_cfgs[0].keys_manager, 100000);
5729-
assert_eq!(spend_txn.len(), 3);
5730-
assert_eq!(spend_txn[0], spend_txn[1]);
5726+
assert_eq!(spend_txn.len(), 2);
57315727
check_spends!(spend_txn[0], local_txn[0]);
5732-
check_spends!(spend_txn[2], htlc_timeout);
5728+
check_spends!(spend_txn[1], htlc_timeout);
57335729
}
57345730

57355731
#[test]
@@ -5797,10 +5793,9 @@ fn test_key_derivation_params() {
57975793
// Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
57985794
let new_keys_manager = test_utils::TestKeysInterface::new(&seed, Network::Testnet);
57995795
let spend_txn = check_spendable_outputs!(nodes[0], 1, new_keys_manager, 100000);
5800-
assert_eq!(spend_txn.len(), 3);
5801-
assert_eq!(spend_txn[0], spend_txn[1]);
5796+
assert_eq!(spend_txn.len(), 2);
58025797
check_spends!(spend_txn[0], local_txn_1[0]);
5803-
check_spends!(spend_txn[2], htlc_timeout);
5798+
check_spends!(spend_txn[1], htlc_timeout);
58045799
}
58055800

58065801
#[test]

0 commit comments

Comments
 (0)