Skip to content

Commit

Permalink
Avoid send broadcast message when shutdown private channel
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 2, 2025
1 parent a6e8625 commit 4867c1c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,16 +1760,18 @@ where
}
ChannelEvent::ClosingTransactionConfirmed => {
// Broadcast the channel update message which disables the channel.
let update = state.generate_disabled_channel_update(&self.network).await;

self.network
.send_message(NetworkActorMessage::new_command(
NetworkActorCommand::BroadcastMessages(vec![
BroadcastMessage::ChannelUpdate(update),
]),
))
.expect(ASSUME_NETWORK_ACTOR_ALIVE);
if state.is_public() {
let update = state.generate_disabled_channel_update(&self.network).await;

self.network
.send_message(NetworkActorMessage::new_command(
NetworkActorCommand::BroadcastMessages(vec![
BroadcastMessage::ChannelUpdate(update),
]),
))
.expect(ASSUME_NETWORK_ACTOR_ALIVE);
}
debug_event!(self.network, "ChannelClosed");
myself.stop(Some("ChannelClosed".to_string()));
}
}
Expand Down Expand Up @@ -3407,6 +3409,7 @@ impl ChannelActorState {
// The function that would change the channel update parameters.
f: impl FnOnce(&mut ChannelUpdate),
) -> ChannelUpdate {
assert!(self.is_public());
let mut channel_update = self
.get_unsigned_channel_update_message()
.expect("public channel can generate channel update message");
Expand Down
10 changes: 10 additions & 0 deletions src/fiber/tests/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4293,6 +4293,8 @@ async fn test_shutdown_channel_with_different_size_shutdown_script() {
let node_a_funding_amount = 100000000000;
let node_b_funding_amount = 6200000000;

// create a private channel for testing shutdown,
// https://github.com/nervosnetwork/fiber/issues/431
let (mut node_a, mut node_b, new_channel_id) =
create_nodes_with_established_channel(node_a_funding_amount, node_b_funding_amount, false)
.await;
Expand Down Expand Up @@ -4347,6 +4349,14 @@ async fn test_shutdown_channel_with_different_size_shutdown_script() {
})
.await;

node_a
.expect_event(|event| matches!(event, NetworkServiceEvent::DebugEvent(DebugEvent::Common(message)) if message == "ChannelClosed"))
.await;

node_b
.expect_event(|event| matches!(event, NetworkServiceEvent::DebugEvent(DebugEvent::Common(message)) if message == "ChannelClosed"))
.await;

assert_eq!(node_a_shutdown_tx_hash, node_b_shutdown_tx_hash);

assert_eq!(
Expand Down

0 comments on commit 4867c1c

Please sign in to comment.