Skip to content

Commit cbfe1a9

Browse files
whitslackrustyrussell
authored andcommitted
lightningd: notify plugins when finalizing channel
Changelog-Added: Plugins now receive `channel_state_changed` notification upon final change to `CLOSED` state.
1 parent 7c7f1e4 commit cbfe1a9

File tree

8 files changed

+36
-24
lines changed

8 files changed

+36
-24
lines changed

cln-grpc/proto/node.proto

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-grpc/src/convert.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cln-rpc/src/notifications.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ impl ToString for ChannelStateChangedCause {
192192

193193
#[derive(Clone, Debug, Deserialize, Serialize)]
194194
pub struct ChannelStateChangedNotification {
195+
#[serde(skip_serializing_if = "Option::is_none")]
196+
pub message: Option<String>,
195197
#[serde(skip_serializing_if = "Option::is_none")]
196198
pub old_state: Option<ChannelState>,
197199
#[serde(skip_serializing_if = "Option::is_none")]
@@ -201,7 +203,6 @@ pub struct ChannelStateChangedNotification {
201203
// Path `channel_state_changed.new_state`
202204
pub new_state: ChannelState,
203205
pub channel_id: Sha256,
204-
pub message: String,
205206
pub peer_id: PublicKey,
206207
pub timestamp: String,
207208
}

contrib/msggen/msggen/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37659,8 +37659,7 @@
3765937659
"channel_id",
3766037660
"timestamp",
3766137661
"new_state",
37662-
"cause",
37663-
"message"
37662+
"cause"
3766437663
],
3766537664
"properties": {
3766637665
"peer_id": {

contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lightningd/channel.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ static void destroy_channel(struct channel *channel)
8585
list_del_from(&channel->peer->channels, &channel->list);
8686
}
8787

88-
void delete_channel(struct channel *channel STEALS, bool completely_eliminate)
88+
void delete_channel(struct channel *channel STEALS,
89+
bool completely_eliminate)
8990
{
9091
const u8 *msg;
9192
struct peer *peer = channel->peer;
@@ -109,6 +110,16 @@ void delete_channel(struct channel *channel STEALS, bool completely_eliminate)
109110
fatal("HSM gave bad hsm_forget_channel_reply %s", tal_hex(msg, msg));
110111
}
111112

113+
notify_channel_state_changed(channel->peer->ld,
114+
&channel->peer->id,
115+
&channel->cid,
116+
channel->scid,
117+
clock_time(),
118+
channel->state,
119+
CLOSED,
120+
REASON_UNKNOWN,
121+
NULL);
122+
112123
tal_free(channel);
113124

114125
maybe_delete_peer(peer);

lightningd/channel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ channel_current_inflight(const struct channel *channel);
490490
u32 channel_last_funding_feerate(const struct channel *channel);
491491

492492
/* Only set completely_eliminate for never-existed channels */
493-
void delete_channel(struct channel *channel STEALS, bool completely_eliminate);
493+
void delete_channel(struct channel *channel STEALS,
494+
bool completely_eliminate);
494495

495496
/* Add a historic (public) short_channel_id to this channel */
496497
void channel_add_old_scid(struct channel *channel,

wallet/test/run-wallet.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -503,17 +503,6 @@ void notify_channel_mvt(struct lightningd *ld UNNEEDED,
503503
void notify_channel_open_failed(struct lightningd *ld UNNEEDED,
504504
const struct channel_id *cid UNNEEDED)
505505
{ fprintf(stderr, "notify_channel_open_failed called!\n"); abort(); }
506-
/* Generated stub for notify_channel_state_changed */
507-
void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
508-
const struct node_id *peer_id UNNEEDED,
509-
const struct channel_id *cid UNNEEDED,
510-
const struct short_channel_id *scid UNNEEDED,
511-
struct timeabs timestamp UNNEEDED,
512-
enum channel_state old_state UNNEEDED,
513-
enum channel_state new_state UNNEEDED,
514-
enum state_change cause UNNEEDED,
515-
const char *message UNNEEDED)
516-
{ fprintf(stderr, "notify_channel_state_changed called!\n"); abort(); }
517506
/* Generated stub for notify_connect */
518507
void notify_connect(struct lightningd *ld UNNEEDED,
519508
const struct node_id *nodeid UNNEEDED,
@@ -810,6 +799,17 @@ u8 *wire_sync_read(const tal_t *ctx UNNEEDED, int fd UNNEEDED)
810799
void plugin_hook_db_sync(struct db *db UNNEEDED)
811800
{
812801
}
802+
void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
803+
const struct node_id *peer_id UNNEEDED,
804+
const struct channel_id *cid UNNEEDED,
805+
const struct short_channel_id *scid UNNEEDED,
806+
struct timeabs timestamp UNNEEDED,
807+
enum channel_state old_state UNNEEDED,
808+
enum channel_state new_state UNNEEDED,
809+
enum state_change cause UNNEEDED,
810+
const char *message UNNEEDED)
811+
{
812+
}
813813
bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED,
814814
struct basepoints *basepoints,
815815
struct pubkey *funding_pubkey)

0 commit comments

Comments
 (0)