lightningd: notify plugins when finalizing channel

Changelog-Added: Plugins now receive `channel_state_changed` notification upon final change to `CLOSED` state.
This commit is contained in:
Matt Whitlock
2025-11-18 11:04:56 +10:30
committed by Rusty Russell
parent 7c7f1e4235
commit cbfe1a9996
8 changed files with 36 additions and 24 deletions

View File

@@ -4227,5 +4227,5 @@ message ChannelStateChangedNotification {
optional ChannelState old_state = 5;
ChannelState new_state = 6;
ChannelStateChangedCause cause = 7;
string message = 8;
optional string message = 8;
}

View File

@@ -4518,7 +4518,7 @@ impl From<notifications::ChannelStateChangedNotification> for pb::ChannelStateCh
Self {
cause: c.cause as i32,
channel_id: <Sha256 as AsRef<[u8]>>::as_ref(&c.channel_id).to_vec(), // Rule #2 for type hash
message: c.message, // Rule #2 for type string
message: c.message, // Rule #2 for type string?
new_state: c.new_state as i32,
old_state: c.old_state.map(|v| v as i32),
peer_id: c.peer_id.serialize().to_vec(), // Rule #2 for type pubkey

View File

@@ -192,6 +192,8 @@ impl ToString for ChannelStateChangedCause {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ChannelStateChangedNotification {
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub old_state: Option<ChannelState>,
#[serde(skip_serializing_if = "Option::is_none")]
@@ -201,7 +203,6 @@ pub struct ChannelStateChangedNotification {
// Path `channel_state_changed.new_state`
pub new_state: ChannelState,
pub channel_id: Sha256,
pub message: String,
pub peer_id: PublicKey,
pub timestamp: String,
}

View File

@@ -37659,8 +37659,7 @@
"channel_id",
"timestamp",
"new_state",
"cause",
"message"
"cause"
],
"properties": {
"peer_id": {

File diff suppressed because one or more lines are too long

View File

@@ -85,7 +85,8 @@ static void destroy_channel(struct channel *channel)
list_del_from(&channel->peer->channels, &channel->list);
}
void delete_channel(struct channel *channel STEALS, bool completely_eliminate)
void delete_channel(struct channel *channel STEALS,
bool completely_eliminate)
{
const u8 *msg;
struct peer *peer = channel->peer;
@@ -109,6 +110,16 @@ void delete_channel(struct channel *channel STEALS, bool completely_eliminate)
fatal("HSM gave bad hsm_forget_channel_reply %s", tal_hex(msg, msg));
}
notify_channel_state_changed(channel->peer->ld,
&channel->peer->id,
&channel->cid,
channel->scid,
clock_time(),
channel->state,
CLOSED,
REASON_UNKNOWN,
NULL);
tal_free(channel);
maybe_delete_peer(peer);

View File

@@ -490,7 +490,8 @@ channel_current_inflight(const struct channel *channel);
u32 channel_last_funding_feerate(const struct channel *channel);
/* Only set completely_eliminate for never-existed channels */
void delete_channel(struct channel *channel STEALS, bool completely_eliminate);
void delete_channel(struct channel *channel STEALS,
bool completely_eliminate);
/* Add a historic (public) short_channel_id to this channel */
void channel_add_old_scid(struct channel *channel,

View File

@@ -503,17 +503,6 @@ void notify_channel_mvt(struct lightningd *ld UNNEEDED,
void notify_channel_open_failed(struct lightningd *ld UNNEEDED,
const struct channel_id *cid UNNEEDED)
{ fprintf(stderr, "notify_channel_open_failed called!\n"); abort(); }
/* Generated stub for notify_channel_state_changed */
void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
const struct node_id *peer_id UNNEEDED,
const struct channel_id *cid UNNEEDED,
const struct short_channel_id *scid UNNEEDED,
struct timeabs timestamp UNNEEDED,
enum channel_state old_state UNNEEDED,
enum channel_state new_state UNNEEDED,
enum state_change cause UNNEEDED,
const char *message UNNEEDED)
{ fprintf(stderr, "notify_channel_state_changed called!\n"); abort(); }
/* Generated stub for notify_connect */
void notify_connect(struct lightningd *ld UNNEEDED,
const struct node_id *nodeid UNNEEDED,
@@ -810,6 +799,17 @@ u8 *wire_sync_read(const tal_t *ctx UNNEEDED, int fd UNNEEDED)
void plugin_hook_db_sync(struct db *db UNNEEDED)
{
}
void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
const struct node_id *peer_id UNNEEDED,
const struct channel_id *cid UNNEEDED,
const struct short_channel_id *scid UNNEEDED,
struct timeabs timestamp UNNEEDED,
enum channel_state old_state UNNEEDED,
enum channel_state new_state UNNEEDED,
enum state_change cause UNNEEDED,
const char *message UNNEEDED)
{
}
bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED,
struct basepoints *basepoints,
struct pubkey *funding_pubkey)