Skip to content

Commit 7e286e1

Browse files
committed
Drop ChannelManager::block_connected() entirely
1 parent 465fbff commit 7e286e1

File tree

2 files changed

+12
-49
lines changed

2 files changed

+12
-49
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3302,8 +3302,17 @@ where
33023302
self.update_best_block(&block.header, height);
33033303
}
33043304

3305-
fn block_disconnected(&self, header: &BlockHeader, _height: u32) {
3306-
ChannelManager::block_disconnected(self, header);
3305+
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
3306+
assert_eq!(*self.last_block_hash.read().unwrap(), header.block_hash(),
3307+
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
3308+
3309+
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
3310+
let new_height = self.latest_block_height.fetch_sub(1, Ordering::AcqRel) as u32 - 1;
3311+
assert_eq!(new_height, height - 1,
3312+
"Blocks must be disconnected in chain-order - the disconnected block must have the correct height");
3313+
*self.last_block_hash.write().unwrap() = header.prev_blockhash;
3314+
3315+
self.do_chain_event(new_height, |channel| channel.update_best_block(new_height, header.time));
33073316
}
33083317
}
33093318

@@ -3453,52 +3462,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34533462
}
34543463
}
34553464

3456-
/// Updates channel state based on a disconnected block.
3457-
///
3458-
/// If necessary, the channel may be force-closed without letting the counterparty participate
3459-
/// in the shutdown.
3460-
pub fn block_disconnected(&self, header: &BlockHeader) {
3461-
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
3462-
// during initialization prior to the chain_monitor being fully configured in some cases.
3463-
// See the docs for `ChannelManagerReadArgs` for more.
3464-
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
3465-
3466-
assert_eq!(*self.last_block_hash.read().unwrap(), header.block_hash(),
3467-
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
3468-
let new_height = self.latest_block_height.fetch_sub(1, Ordering::AcqRel) as u32 - 1;
3469-
*self.last_block_hash.write().unwrap() = header.prev_blockhash;
3470-
3471-
let mut failed_channels = Vec::new();
3472-
{
3473-
let mut channel_lock = self.channel_state.lock().unwrap();
3474-
let channel_state = &mut *channel_lock;
3475-
let short_to_id = &mut channel_state.short_to_id;
3476-
let pending_msg_events = &mut channel_state.pending_msg_events;
3477-
channel_state.by_id.retain(|_, v| {
3478-
if let Err(err_msg) = v.update_best_block(new_height, header.time) {
3479-
if let Some(short_id) = v.get_short_channel_id() {
3480-
short_to_id.remove(&short_id);
3481-
}
3482-
failed_channels.push(v.force_shutdown(true));
3483-
if let Ok(update) = self.get_channel_update(&v) {
3484-
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
3485-
msg: update
3486-
});
3487-
}
3488-
pending_msg_events.push(events::MessageSendEvent::HandleError {
3489-
node_id: v.get_counterparty_node_id(),
3490-
action: msgs::ErrorAction::SendErrorMessage { msg: err_msg },
3491-
});
3492-
false
3493-
} else {
3494-
true
3495-
}
3496-
});
3497-
}
3498-
3499-
self.handle_init_event_channel_failures(failed_channels);
3500-
}
3501-
35023465
/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
35033466
/// indicating whether persistence is necessary. Only one listener on
35043467
/// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
112112
let orig_header = node.blocks.borrow_mut().pop().unwrap();
113113
assert!(orig_header.1 > 0); // Cannot disconnect genesis
114114
node.chain_monitor.chain_monitor.block_disconnected(&orig_header.0, orig_header.1);
115-
node.node.block_disconnected(&orig_header.0);
115+
node.node.block_disconnected(&orig_header.0, orig_header.1);
116116
}
117117
}
118118

0 commit comments

Comments
 (0)