Skip to content

Commit e887cd3

Browse files
committed
f - Handle height decreases in ChannelMonitor::update_best_block
1 parent 9842820 commit e887cd3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,9 +2084,16 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20842084
{
20852085
let block_hash = header.block_hash();
20862086
log_trace!(logger, "New best block {} at height {}", block_hash, height);
2087-
self.best_block = BestBlock::new(block_hash, height);
20882087

2089-
self.block_confirmed(height, vec![], vec![], vec![], broadcaster, fee_estimator, logger)
2088+
if height > self.best_block.height() {
2089+
self.best_block = BestBlock::new(block_hash, height);
2090+
self.block_confirmed(height, vec![], vec![], vec![], broadcaster, fee_estimator, logger)
2091+
} else {
2092+
self.best_block = BestBlock::new(block_hash, height);
2093+
self.onchain_events_waiting_threshold_conf.retain(|ref entry| entry.height <= height);
2094+
self.onchain_tx_handler.block_disconnected(height + 1, broadcaster, fee_estimator, logger);
2095+
Vec::new()
2096+
}
20902097
}
20912098

20922099
fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
@@ -2275,7 +2282,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
22752282
//We may discard:
22762283
//- htlc update there as failure-trigger tx (revoked commitment tx, non-revoked commitment tx, HTLC-timeout tx) has been disconnected
22772284
//- maturing spendable output has transaction paying us has been disconnected
2278-
self.onchain_events_waiting_threshold_conf.retain(|ref entry| entry.height != height);
2285+
self.onchain_events_waiting_threshold_conf.retain(|ref entry| entry.height < height);
22792286

22802287
self.onchain_tx_handler.block_disconnected(height, broadcaster, fee_estimator, logger);
22812288

lightning/src/ln/onchaintx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
848848

849849
// Check if any pending claim request must be rescheduled
850850
for (first_claim_txid, ref claim_data) in self.pending_claim_requests.iter() {
851-
if let Some(h) = claim_data.height_timer {
852-
if h == height {
851+
if let Some(height_timer) = claim_data.height_timer {
852+
if height >= height_timer {
853853
bump_candidates.insert(*first_claim_txid, (*claim_data).clone());
854854
}
855855
}
@@ -878,7 +878,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
878878
let onchain_events_waiting_threshold_conf =
879879
self.onchain_events_waiting_threshold_conf.drain(..).collect::<Vec<_>>();
880880
for entry in onchain_events_waiting_threshold_conf {
881-
if entry.height == height {
881+
if entry.height >= height {
882882
//- our claim tx on a commitment tx output
883883
//- resurect outpoint back in its claimable set and regenerate tx
884884
match entry.event {
@@ -912,7 +912,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
912912
// right now if one of the outpoint get disconnected, just erase whole pending claim request.
913913
let mut remove_request = Vec::new();
914914
self.claimable_outpoints.retain(|_, ref v|
915-
if v.1 == height {
915+
if v.1 >= height {
916916
remove_request.push(v.0.clone());
917917
false
918918
} else { true });

0 commit comments

Comments
 (0)