Skip to content

Commit c325279

Browse files
author
Antoine Riard
committed
Add ChannelClosed generation at cooperative/force-close/error processing
When we detect a channel `is_shutdown()` or call on it `force_shutdown()`, we notify the user with a Event::ChannelClosed informing about the id and closure reason in a best effort.
1 parent 4cbfa72 commit c325279

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ macro_rules! handle_error {
779779
});
780780
}
781781
}
782+
if let Some(channel_id) = chan_id {
783+
$self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id, err: format!("Channel processing error") });
784+
}
782785

783786
log_error!($self.logger, "{}", err.err);
784787
if let msgs::ErrorAction::IgnoreError = err.action {
@@ -1279,6 +1282,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
12791282
msg: update
12801283
});
12811284
}
1285+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: *channel_id, err: format!("") });
12821286

12831287
Ok(())
12841288
}
@@ -1325,6 +1329,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
13251329
msg: update
13261330
});
13271331
}
1332+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: *channel_id, err: format!("") });
13281333

13291334
Ok(chan.get_counterparty_node_id())
13301335
}
@@ -2220,6 +2225,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22202225
if let Some(short_id) = channel.get_short_channel_id() {
22212226
channel_state.short_to_id.remove(&short_id);
22222227
}
2228+
// ChannelClosed event is generated by handle_errors for us.
22232229
Err(MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, channel.force_shutdown(true), self.get_channel_update_for_broadcast(&channel).ok()))
22242230
},
22252231
ChannelError::CloseDelayBroadcast(_) => { panic!("Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here"); }
@@ -3091,6 +3097,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
30913097
msg: update
30923098
});
30933099
}
3100+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: msg.channel_id, err: format!("Counterparty-initiated cooper") });
30943101
}
30953102
Ok(())
30963103
}
@@ -3137,6 +3144,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31373144
msg: update
31383145
});
31393146
}
3147+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: msg.channel_id, err: format!("Successful cooperative-close") });
31403148
}
31413149
Ok(())
31423150
}
@@ -3615,6 +3623,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
36153623
msg: update
36163624
});
36173625
}
3626+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: chan.channel_id(), err: format!("Channel with commitment transaction broadcasted") });
36183627
pending_msg_events.push(events::MessageSendEvent::HandleError {
36193628
node_id: chan.get_counterparty_node_id(),
36203629
action: msgs::ErrorAction::SendErrorMessage {
@@ -3676,6 +3685,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
36763685
Err(e) => {
36773686
let (close_channel, res) = convert_chan_err!(self, e, short_to_id, chan, channel_id);
36783687
handle_errors.push((chan.get_counterparty_node_id(), Err(res)));
3688+
// ChannelClosed event is generated by handle_error for us
36793689
!close_channel
36803690
}
36813691
}
@@ -4089,6 +4099,7 @@ where
40894099
msg: update
40904100
});
40914101
}
4102+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: channel.channel_id(), err: format!("Channel has been closed onchain!") });
40924103
pending_msg_events.push(events::MessageSendEvent::HandleError {
40934104
node_id: channel.get_counterparty_node_id(),
40944105
action: msgs::ErrorAction::SendErrorMessage { msg: e },
@@ -4279,6 +4290,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
42794290
msg: update
42804291
});
42814292
}
4293+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: chan.channel_id(), err: format!("Peer disconnected with no new connection possible") });
42824294
false
42834295
} else {
42844296
true
@@ -4293,6 +4305,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
42934305
if let Some(short_id) = chan.get_short_channel_id() {
42944306
short_to_id.remove(&short_id);
42954307
}
4308+
self.pending_events.lock().unwrap().push(events::Event::ChannelClosed { channel_id: chan.channel_id(), err: format!("Disconnected chan aleady shutdown state!") });
42964309
return false;
42974310
} else {
42984311
no_channels_remain = false;

0 commit comments

Comments
 (0)