Skip to content

Commit 390ff52

Browse files
committed
Correctly update the last block hash on disconnect
When a block is disconnected, the hash of the disconnected block was used to update the last connected block. However, this amounts to a no-op because these hashes should be equal. Successive disconnections would update the hash but leave it one block off. Normally, this not a problem because the last block_disconnected should be followed by block_connected since the former is triggered by a chain re-org. However, this assumes the user calls the API correctly and that no failure occurs that would prevent block_connected from being called (e.g., if fetching the connected block fails). Instead, update the last block hash with the disconnected block's previous block hash.
1 parent 1c948a5 commit 390ff52

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20902090
F::Target: FeeEstimator,
20912091
L::Target: Logger,
20922092
{
2093-
let block_hash = header.block_hash();
2094-
log_trace!(logger, "Block {} at height {} disconnected", block_hash, height);
2093+
log_trace!(logger, "Block {} at height {} disconnected", header.block_hash(), height);
20952094

20962095
if let Some(_) = self.onchain_events_waiting_threshold_conf.remove(&(height + ANTI_REORG_DELAY - 1)) {
20972096
//We may discard:
@@ -2101,7 +2100,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
21012100

21022101
self.onchain_tx_handler.block_disconnected(height, broadcaster, fee_estimator, logger);
21032102

2104-
self.last_block_hash = block_hash;
2103+
self.last_block_hash = header.prev_blockhash;
21052104
}
21062105

21072106
/// Filters a block's `txdata` for transactions spending watched outputs or for any child

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3327,7 +3327,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
33273327
}
33283328
});
33293329

3330-
*self.last_block_hash.lock().unwrap() = header.block_hash();
3330+
*self.last_block_hash.lock().unwrap() = header.prev_blockhash;
33313331
self.latest_block_height.fetch_sub(1, Ordering::AcqRel);
33323332
}
33333333

0 commit comments

Comments
 (0)