Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid send broadcast message when shutdown private channel #433

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading