Skip to content

Commit 93e21d5

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 0df398c commit 93e21d5

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

lightningd/channel.c

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

90-
void delete_channel(struct channel *channel STEALS, bool completely_eliminate)
90+
void delete_channel(struct channel *channel STEALS,
91+
bool completely_eliminate)
9192
{
9293
const u8 *msg;
9394
struct peer *peer = channel->peer;
@@ -111,6 +112,16 @@ void delete_channel(struct channel *channel STEALS, bool completely_eliminate)
111112
fatal("HSM gave bad hsm_forget_channel_reply %s", tal_hex(msg, msg));
112113
}
113114

115+
notify_channel_state_changed(channel->peer->ld,
116+
&channel->peer->id,
117+
&channel->cid,
118+
channel->scid,
119+
time_now(),
120+
channel->state,
121+
CLOSED,
122+
REASON_UNKNOWN,
123+
NULL);
124+
114125
tal_free(channel);
115126

116127
maybe_delete_peer(peer);

lightningd/channel.h

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

495495
/* Only set completely_eliminate for never-existed channels */
496-
void delete_channel(struct channel *channel STEALS, bool completely_eliminate);
496+
void delete_channel(struct channel *channel STEALS,
497+
bool completely_eliminate);
497498

498499
/* Add a historic (public) short_channel_id to this channel */
499500
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
@@ -758,17 +758,6 @@ void notify_channel_mvt(struct lightningd *ld UNNEEDED,
758758
void notify_channel_open_failed(struct lightningd *ld UNNEEDED,
759759
const struct channel_id *cid UNNEEDED)
760760
{ fprintf(stderr, "notify_channel_open_failed called!\n"); abort(); }
761-
/* Generated stub for notify_channel_state_changed */
762-
void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
763-
const struct node_id *peer_id UNNEEDED,
764-
const struct channel_id *cid UNNEEDED,
765-
const struct short_channel_id *scid UNNEEDED,
766-
struct timeabs timestamp UNNEEDED,
767-
enum channel_state old_state UNNEEDED,
768-
enum channel_state new_state UNNEEDED,
769-
enum state_change cause UNNEEDED,
770-
const char *message UNNEEDED)
771-
{ fprintf(stderr, "notify_channel_state_changed called!\n"); abort(); }
772761
/* Generated stub for notify_connect */
773762
void notify_connect(struct lightningd *ld UNNEEDED,
774763
const struct node_id *nodeid UNNEEDED,
@@ -1313,6 +1302,17 @@ u8 *wire_sync_read(const tal_t *ctx UNNEEDED, int fd UNNEEDED)
13131302
void plugin_hook_db_sync(struct db *db UNNEEDED)
13141303
{
13151304
}
1305+
void notify_channel_state_changed(struct lightningd *ld UNNEEDED,
1306+
const struct node_id *peer_id UNNEEDED,
1307+
const struct channel_id *cid UNNEEDED,
1308+
const struct short_channel_id *scid UNNEEDED,
1309+
struct timeabs timestamp UNNEEDED,
1310+
enum channel_state old_state UNNEEDED,
1311+
enum channel_state new_state UNNEEDED,
1312+
enum state_change cause UNNEEDED,
1313+
const char *message UNNEEDED)
1314+
{
1315+
}
13161316
bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED,
13171317
struct basepoints *basepoints,
13181318
struct pubkey *funding_pubkey)

0 commit comments

Comments
 (0)