Skip to content

Commit 599c74c

Browse files
committed
Update ChannelMonitor::best_block before calling block_confirmed
No matter the context, if we're told about a block which is guaranteed by our API semantics to be on the best chain, and it has a higher height than our current understanding of the best chain, we should update our understanding. This avoids complexity in `block_confirmed` by never having a height set which is *higher* than our current best chain, potentially avoiding some bugs in the rather-complicated code. It also requires a minor test tweak as we in some cases now no longer broadcast a conflicting transaction after the original has reached the ANTI_REORG_DELAY.
1 parent 6970333 commit 599c74c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,10 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20042004
self.is_paying_spendable_output(&tx, height, &logger);
20052005
}
20062006

2007+
if height > self.best_block.height() {
2008+
self.best_block = BestBlock::new(block_hash, height);
2009+
}
2010+
20072011
self.block_confirmed(height, txn_matched, watch_outputs, claimable_outpoints, broadcaster, fee_estimator, logger)
20082012
}
20092013

lightning/src/ln/functional_tests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,10 +3001,16 @@ fn do_test_htlc_on_chain_timeout(connect_style: ConnectStyle) {
30013001

30023002
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
30033003
{
3004-
// B will rebroadcast its own holder commitment transaction here...just because
3004+
// B may rebroadcast its own holder commitment transaction here, as a safeguard against
3005+
// some incredibly unlikely partial-eclipse-attack scenarios. That said, because the
3006+
// original commitment_tx[0] (also spending chan_2.3) has reached ANTI_REORG_DELAY B really
3007+
// shouldn't broadcast anything here, and in some connect style scenarios we do not.
30053008
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
3006-
assert_eq!(node_txn.len(), 1);
3007-
check_spends!(node_txn[0], chan_2.3);
3009+
if node_txn.len() == 1 {
3010+
check_spends!(node_txn[0], chan_2.3);
3011+
} else {
3012+
assert_eq!(node_txn.len(), 0);
3013+
}
30083014
}
30093015

30103016
expect_pending_htlcs_forwardable!(nodes[1]);

0 commit comments

Comments
 (0)