Skip to content

Commit b1c66fa

Browse files
committed
Drop ChannelManager::block_connected() entirely
It is now entirely redundant with ChannelManager::update_best_block and has always been redundant with Listen::block_connected.
1 parent 18b3c27 commit b1c66fa

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

@@ -3469,52 +3478,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34693478
}
34703479
}
34713480

3472-
/// Updates channel state based on a disconnected block.
3473-
///
3474-
/// If necessary, the channel may be force-closed without letting the counterparty participate
3475-
/// in the shutdown.
3476-
pub fn block_disconnected(&self, header: &BlockHeader) {
3477-
// Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
3478-
// during initialization prior to the chain_monitor being fully configured in some cases.
3479-
// See the docs for `ChannelManagerReadArgs` for more.
3480-
let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
3481-
3482-
assert_eq!(*self.last_block_hash.read().unwrap(), header.block_hash(),
3483-
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
3484-
let new_height = self.latest_block_height.fetch_sub(1, Ordering::AcqRel) as u32 - 1;
3485-
*self.last_block_hash.write().unwrap() = header.prev_blockhash;
3486-
3487-
let mut failed_channels = Vec::new();
3488-
{
3489-
let mut channel_lock = self.channel_state.lock().unwrap();
3490-
let channel_state = &mut *channel_lock;
3491-
let short_to_id = &mut channel_state.short_to_id;
3492-
let pending_msg_events = &mut channel_state.pending_msg_events;
3493-
channel_state.by_id.retain(|_, v| {
3494-
if let Err(err_msg) = v.update_best_block(new_height, header.time) {
3495-
if let Some(short_id) = v.get_short_channel_id() {
3496-
short_to_id.remove(&short_id);
3497-
}
3498-
failed_channels.push(v.force_shutdown(true));
3499-
if let Ok(update) = self.get_channel_update(&v) {
3500-
pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
3501-
msg: update
3502-
});
3503-
}
3504-
pending_msg_events.push(events::MessageSendEvent::HandleError {
3505-
node_id: v.get_counterparty_node_id(),
3506-
action: msgs::ErrorAction::SendErrorMessage { msg: err_msg },
3507-
});
3508-
false
3509-
} else {
3510-
true
3511-
}
3512-
});
3513-
}
3514-
3515-
self.handle_init_event_channel_failures(failed_channels);
3516-
}
3517-
35183481
/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
35193482
/// indicating whether persistence is necessary. Only one listener on
35203483
/// `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)