if self.height > 0 && (self.max_height < 6 || self.height >= self.max_height - 6) {
self.height -= 1;
let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height], merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
- self.manager.block_disconnected(&header);
- self.monitor.block_disconnected(&header);
+ self.manager.block_disconnected(&header, self.height as u32);
+ self.monitor.block_disconnected(&header, self.height as u32);
let removal_height = self.height;
self.txids_confirmed.retain(|_, height| {
removal_height != *height
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]);
/// Notifies a listener that a block was disconnected.
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
- fn block_disconnected(&self, header: &BlockHeader);
+ /// Height must be the one of the block which was disconnected (not new height of the best chain)
+ fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32);
}
/// An enum that represents the speed at which we want a transaction to confirm used for feerate
}
/// Notify listeners that a block was disconnected.
- pub fn block_disconnected(&self, header: &BlockHeader) {
+ pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
let listeners = self.listeners.lock().unwrap().clone();
for listener in listeners.iter() {
match listener.upgrade() {
- Some(arc) => arc.block_disconnected(header),
+ Some(arc) => arc.block_disconnected(&header, disconnected_height),
None => ()
}
}
}
/// We force-close the channel without letting our counterparty participate in the shutdown
- fn block_disconnected(&self, header: &BlockHeader) {
+ fn block_disconnected(&self, header: &BlockHeader, _: u32) {
let _ = self.total_consistency_lock.read().unwrap();
let mut failed_channels = Vec::new();
{
pending_events.append(&mut new_events);
}
- fn block_disconnected(&self, _: &BlockHeader) { }
+ fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
+ let block_hash = header.bitcoin_hash();
+ let mut monitors = self.monitors.lock().unwrap();
+ for monitor in monitors.values_mut() {
+ monitor.block_disconnected(disconnected_height, &block_hash);
+ }
+ }
}
impl<Key : Send + cmp::Eq + hash::Hash + 'static> SimpleManyChannelMonitor<Key> {
(watch_outputs, spendable_outputs, htlc_updated)
}
+ fn block_disconnected(&mut self, height: u32, block_hash: &Sha256dHash) {
+ if let Some(_) = self.htlc_updated_waiting_threshold_conf.remove(&(height + HTLC_FAIL_ANTI_REORG_DELAY - 1)) {
+ //We discard htlc update there as failure-trigger tx (revoked commitment tx, non-revoked commitment tx, HTLC-timeout tx) has been disconnected
+ }
+ self.last_block_hash = block_hash.clone();
+ }
+
pub(super) fn would_broadcast_at_height(&self, height: u32) -> bool {
// We need to consider all HTLCs which are:
// * in any unrevoked remote commitment transaction, as they could broadcast said
header = BlockHeader { version: 0x20000000, prev_blockhash: header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
headers.push(header.clone());
}
+ let mut height = 99;
while !headers.is_empty() {
- nodes[0].node.block_disconnected(&headers.pop().unwrap());
+ nodes[0].node.block_disconnected(&headers.pop().unwrap(), height);
+ height -= 1;
}
check_closed_broadcast!(nodes[0]);
let channel_state = nodes[0].node.channel_state.lock().unwrap();