Skip to content

Commit

Permalink
feat: adds state_changes to listpeers output
Browse files Browse the repository at this point in the history
Changelog-Added: RCP: Added 'state_changes' history to listpeers channels
  • Loading branch information
m-schmoock committed Nov 4, 2020
1 parent f248e51 commit 86c49cd
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 73 deletions.
10 changes: 10 additions & 0 deletions lightningd/channel_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define LIGHTNING_LIGHTNINGD_CHANNEL_STATE_H
#include "config.h"

#include <ccan/time/time.h>

/* These are in the database, so don't renumber them! */
enum channel_state {
/* In channeld, still waiting for lockin. */
Expand Down Expand Up @@ -54,4 +56,12 @@ enum state_change {
REASON_ONCHAIN
};

struct state_change_entry {
struct timeabs timestamp;
enum channel_state old_state;
enum channel_state new_state;
enum state_change cause;
char *message;
};

#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_STATE_H */
18 changes: 18 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ static void json_add_channel(struct lightningd *ld,
struct amount_msat funding_msat, peer_msats, our_msats;
struct amount_sat peer_funded_sats;
struct peer *p = channel->peer;
struct state_change_entry *state_changes;

json_object_start(response, key);
json_add_string(response, "state", channel_state_name(channel));
Expand Down Expand Up @@ -927,6 +928,23 @@ static void json_add_channel(struct lightningd *ld,
json_add_num(response, "max_accepted_htlcs",
channel->our_config.max_accepted_htlcs);

state_changes = wallet_state_change_get(ld->wallet, response, channel->dbid);
json_array_start(response, "state_changes");
for (size_t i = 0; i < tal_count(state_changes); i++) {
json_object_start(response, NULL);
json_add_timeiso(response, "timestamp",
&state_changes[i].timestamp);
json_add_string(response, "old_state",
channel_state_str(state_changes[i].old_state));
json_add_string(response, "new_state",
channel_state_str(state_changes[i].new_state));
json_add_string(response, "cause",
channel_change_state_reason_str(state_changes[i].cause));
json_add_string(response, "message", state_changes[i].message);
json_object_end(response);
}
json_array_end(response);

json_array_start(response, "status");
for (size_t i = 0; i < ARRAY_SIZE(channel->billboard.permanent); i++) {
if (!channel->billboard.permanent[i])
Expand Down
11 changes: 11 additions & 0 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void broadcast_tx(struct chain_topology *topo UNNEEDED,
bool success UNNEEDED,
const char *err))
{ fprintf(stderr, "broadcast_tx called!\n"); abort(); }
/* Generated stub for channel_change_state_reason_str */
const char *channel_change_state_reason_str(enum state_change reason UNNEEDED)
{ fprintf(stderr, "channel_change_state_reason_str called!\n"); abort(); }
/* Generated stub for channel_fail_forget */
void channel_fail_forget(struct channel *channel UNNEEDED, const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "channel_fail_forget called!\n"); abort(); }
Expand Down Expand Up @@ -82,6 +85,9 @@ void channel_set_state(struct channel *channel UNNEEDED,
/* Generated stub for channel_state_name */
const char *channel_state_name(const struct channel *channel UNNEEDED)
{ fprintf(stderr, "channel_state_name called!\n"); abort(); }
/* Generated stub for channel_state_str */
const char *channel_state_str(enum channel_state state UNNEEDED)
{ fprintf(stderr, "channel_state_str called!\n"); abort(); }
/* Generated stub for channel_tell_depth */
bool channel_tell_depth(struct lightningd *ld UNNEEDED,
struct channel *channel UNNEEDED,
Expand Down Expand Up @@ -657,6 +663,11 @@ void wallet_invoice_waitone(const tal_t *ctx UNNEEDED,
/* Generated stub for wallet_peer_delete */
void wallet_peer_delete(struct wallet *w UNNEEDED, u64 peer_dbid UNNEEDED)
{ fprintf(stderr, "wallet_peer_delete called!\n"); abort(); }
/* Generated stub for wallet_state_change_get */
struct state_change_entry *wallet_state_change_get(struct wallet *w UNNEEDED,
const tal_t *ctx UNNEEDED,
u64 channel_id UNNEEDED)
{ fprintf(stderr, "wallet_state_change_get called!\n"); abort(); }
/* Generated stub for wallet_total_forward_fees */
struct amount_msat wallet_total_forward_fees(struct wallet *w UNNEEDED)
{ fprintf(stderr, "wallet_total_forward_fees called!\n"); abort(); }
Expand Down
10 changes: 8 additions & 2 deletions wallet/db_postgres_sqlgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions wallet/db_sqlite3_sqlgen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 86c49cd

Please sign in to comment.