Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listclosedchannels command #5967

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions common/channel_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,17 @@ struct channel_type *channel_type_accept(const tal_t *ctx,

return NULL;
}

/* Return an array of feature strings indicating channel type. */
const char **channel_type_name(const tal_t *ctx, const struct channel_type *t)
{
const char **names = tal_arr(ctx, const char *, 0);

for (size_t i = 0; i < tal_bytelen(t->features) * CHAR_BIT; i++) {
if (!feature_is_set(t->features, i))
continue;
tal_arr_expand(&names,
feature_name(names, i) + strlen("option_"));
}
return names;
}
3 changes: 3 additions & 0 deletions common/channel_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ struct channel_type *channel_type_accept(const tal_t *ctx,
const u8 *t,
const struct feature_set *our_features,
const u8 *their_features);

/* Return an array of feature strings indicating channel type. */
const char **channel_type_name(const tal_t *ctx, const struct channel_type *t);
#endif /* LIGHTNING_COMMON_CHANNEL_TYPE_H */
130 changes: 130 additions & 0 deletions common/test/run-channel_type.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "config.h"
#include "../channel_type.c"
#include "../features.c"
#include <ccan/tal/str/str.h>
#include <common/setup.h>
#include <stdio.h>

/* AUTOGENERATED MOCKS START */
/* Generated stub for amount_asset_is_main */
bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
{ fprintf(stderr, "amount_asset_is_main called!\n"); abort(); }
/* Generated stub for amount_asset_to_sat */
struct amount_sat amount_asset_to_sat(struct amount_asset *asset UNNEEDED)
{ fprintf(stderr, "amount_asset_to_sat called!\n"); abort(); }
/* Generated stub for amount_sat */
struct amount_sat amount_sat(u64 satoshis UNNEEDED)
{ fprintf(stderr, "amount_sat called!\n"); abort(); }
/* Generated stub for amount_sat_add */
bool amount_sat_add(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,
struct amount_sat b UNNEEDED)
{ fprintf(stderr, "amount_sat_add called!\n"); abort(); }
/* Generated stub for amount_sat_eq */
bool amount_sat_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ fprintf(stderr, "amount_sat_eq called!\n"); abort(); }
/* Generated stub for amount_sat_greater_eq */
bool amount_sat_greater_eq(struct amount_sat a UNNEEDED, struct amount_sat b UNNEEDED)
{ fprintf(stderr, "amount_sat_greater_eq called!\n"); abort(); }
/* Generated stub for amount_sat_sub */
bool amount_sat_sub(struct amount_sat *val UNNEEDED,
struct amount_sat a UNNEEDED,
struct amount_sat b UNNEEDED)
{ fprintf(stderr, "amount_sat_sub called!\n"); abort(); }
/* Generated stub for amount_sat_to_asset */
struct amount_asset amount_sat_to_asset(struct amount_sat *sat UNNEEDED, const u8 *asset UNNEEDED)
{ fprintf(stderr, "amount_sat_to_asset called!\n"); abort(); }
/* Generated stub for amount_tx_fee */
struct amount_sat amount_tx_fee(u32 fee_per_kw UNNEEDED, size_t weight UNNEEDED)
{ fprintf(stderr, "amount_tx_fee called!\n"); abort(); }
/* Generated stub for fromwire */
const u8 *fromwire(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, void *copy UNNEEDED, size_t n UNNEEDED)
{ fprintf(stderr, "fromwire called!\n"); abort(); }
/* Generated stub for fromwire_bool */
bool fromwire_bool(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bool called!\n"); abort(); }
/* Generated stub for fromwire_fail */
void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
/* Generated stub for fromwire_secp256k1_ecdsa_signature */
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
secp256k1_ecdsa_signature *signature UNNEEDED)
{ fprintf(stderr, "fromwire_secp256k1_ecdsa_signature called!\n"); abort(); }
/* Generated stub for fromwire_sha256 */
void fromwire_sha256(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct sha256 *sha256 UNNEEDED)
{ fprintf(stderr, "fromwire_sha256 called!\n"); abort(); }
/* Generated stub for fromwire_tal_arrn */
u8 *fromwire_tal_arrn(const tal_t *ctx UNNEEDED,
const u8 **cursor UNNEEDED, size_t *max UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_tal_arrn called!\n"); abort(); }
/* Generated stub for fromwire_u16 */
u16 fromwire_u16(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u16 called!\n"); abort(); }
/* Generated stub for fromwire_u32 */
u32 fromwire_u32(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u32 called!\n"); abort(); }
/* Generated stub for fromwire_u64 */
u64 fromwire_u64(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u64 called!\n"); abort(); }
/* Generated stub for fromwire_u8 */
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
/* Generated stub for fromwire_u8_array */
void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_u8_array called!\n"); abort(); }
/* Generated stub for towire */
void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "towire called!\n"); abort(); }
/* Generated stub for towire_bool */
void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED)
{ fprintf(stderr, "towire_bool called!\n"); abort(); }
/* Generated stub for towire_secp256k1_ecdsa_signature */
void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
const secp256k1_ecdsa_signature *signature UNNEEDED)
{ fprintf(stderr, "towire_secp256k1_ecdsa_signature called!\n"); abort(); }
/* Generated stub for towire_sha256 */
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
{ fprintf(stderr, "towire_sha256 called!\n"); abort(); }
/* Generated stub for towire_u16 */
void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED)
{ fprintf(stderr, "towire_u16 called!\n"); abort(); }
/* Generated stub for towire_u32 */
void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED)
{ fprintf(stderr, "towire_u32 called!\n"); abort(); }
/* Generated stub for towire_u64 */
void towire_u64(u8 **pptr UNNEEDED, u64 v UNNEEDED)
{ fprintf(stderr, "towire_u64 called!\n"); abort(); }
/* Generated stub for towire_u8 */
void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
{ fprintf(stderr, "towire_u8 called!\n"); abort(); }
/* Generated stub for towire_u8_array */
void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "towire_u8_array called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

static void assert_names_eq(const char **names, const char *expected)
{
char **expected_names = tal_strsplit(tmpctx, expected, " ", STR_EMPTY_OK);

assert(tal_count(expected_names) == tal_count(names) + 1);
for (size_t i = 0; i < tal_count(names); i++)
assert(streq(expected_names[i], names[i]));
}

int main(int argc, char *argv[])
{
struct channel_type t;

common_setup(argv[0]);

assert_names_eq(channel_type_name(tmpctx, channel_type_none(tmpctx)), "");
assert_names_eq(channel_type_name(tmpctx, channel_type_static_remotekey(tmpctx)),
"static_remotekey/even");
assert_names_eq(channel_type_name(tmpctx, channel_type_anchor_outputs(tmpctx)),
"static_remotekey/even anchor_outputs/even");

t.features = tal_arr(tmpctx, u8, 0);
set_feature_bit(&t.features, 1000);
assert_names_eq(channel_type_name(tmpctx, &t), "unknown_1000/even");
common_shutdown();
}
19 changes: 15 additions & 4 deletions db/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ void db_bind_pubkey(struct db_stmt *stmt, int pos, const struct pubkey *pk)
db_bind_blob(stmt, pos, der, PUBKEY_CMPR_LEN);
}

void db_bind_scid(struct db_stmt *stmt, int col,
const struct short_channel_id *id)
void db_bind_short_channel_id(struct db_stmt *stmt, int col,
const struct short_channel_id *id)
{
db_bind_u64(stmt, col, id->u64);
}
Expand Down Expand Up @@ -361,12 +361,23 @@ void db_col_pubkey(struct db_stmt *stmt,
assert(ok);
}

void db_col_scid(struct db_stmt *stmt, const char *colname,
struct short_channel_id *dest)
void db_col_short_channel_id(struct db_stmt *stmt, const char *colname,
struct short_channel_id *dest)
{
dest->u64 = db_col_u64(stmt, colname);
}

void *db_col_optional_(tal_t *dst,
struct db_stmt *stmt, const char *colname,
void (*colfn)(struct db_stmt *, const char *, void *))
{
if (db_col_is_null(stmt, colname))
return tal_free(dst);

colfn(stmt, colname, dst);
return dst;
}

struct short_channel_id *
db_col_short_channel_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char *colname)
{
Expand Down
22 changes: 18 additions & 4 deletions db/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void db_bind_node_id(struct db_stmt *stmt, int pos, const struct node_id *ni);
void db_bind_node_id_arr(struct db_stmt *stmt, int col,
const struct node_id *ids);
void db_bind_pubkey(struct db_stmt *stmt, int pos, const struct pubkey *p);
void db_bind_scid(struct db_stmt *stmt, int col,
const struct short_channel_id *id);
void db_bind_short_channel_id(struct db_stmt *stmt, int col,
const struct short_channel_id *id);
void db_bind_short_channel_id_arr(struct db_stmt *stmt, int col,
const struct short_channel_id *id);
void db_bind_signature(struct db_stmt *stmt, int col,
Expand Down Expand Up @@ -83,8 +83,8 @@ struct node_id *db_col_node_id_arr(const tal_t *ctx, struct db_stmt *stmt,
const char *colname);
void db_col_pubkey(struct db_stmt *stmt, const char *colname,
struct pubkey *p);
void db_col_scid(struct db_stmt *stmt, const char *colname,
struct short_channel_id *dest);
void db_col_short_channel_id(struct db_stmt *stmt, const char *colname,
struct short_channel_id *dest);
struct short_channel_id *
db_col_short_channel_id_arr(const tal_t *ctx, struct db_stmt *stmt, const char *colname);
bool db_col_signature(struct db_stmt *stmt, const char *colname,
Expand All @@ -105,6 +105,20 @@ void *db_col_arr_(const tal_t *ctx, struct db_stmt *stmt, const char *colname,
size_t bytes, const char *label, const char *caller);


/* Assumes void db_col_@type(stmt, colname, addr), and struct @type! */
#define db_col_optional(ctx, stmt, colname, type) \
((struct type *)db_col_optional_(tal(ctx, struct type), \
(stmt), (colname), \
typesafe_cb_cast(void (*)(struct db_stmt *, const char *, void *), \
void (*)(struct db_stmt *, const char *, struct type *), \
db_col_##type)))

void *WARN_UNUSED_RESULT db_col_optional_(tal_t *dst,
struct db_stmt *stmt,
const char *colname,
void (*colfn)(struct db_stmt *,
const char *, void *));

/* Some useful default variants */
int db_col_int_or_default(struct db_stmt *stmt, const char *colname, int def);
void db_col_amount_msat_or_default(struct db_stmt *stmt, const char *colname,
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ MANPAGES := doc/lightning-cli.1 \
doc/lightning-invoicerequest.7 \
doc/lightning-keysend.7 \
doc/lightning-listchannels.7 \
doc/lightning-listclosedchannels.7 \
doc/lightning-listdatastore.7 \
doc/lightning-listforwards.7 \
doc/lightning-listfunds.7 \
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Core Lightning Documentation
lightning-invoicerequest <lightning-invoicerequest.7.md>
lightning-keysend <lightning-keysend.7.md>
lightning-listchannels <lightning-listchannels.7.md>
lightning-listclosedchannels <lightning-listclosedchannels.7.md>
lightning-listconfigs <lightning-listconfigs.7.md>
lightning-listdatastore <lightning-listdatastore.7.md>
lightning-listforwards <lightning-listforwards.7.md>
Expand Down
79 changes: 79 additions & 0 deletions doc/lightning-listclosedchannels.7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
lightning-listclosedchannels -- Get data on our closed historical channels
==========================================================================

SYNOPSIS
--------

**listclosedchannels** \[*id*\]

DESCRIPTION
-----------

The **listclosedchannels** RPC command returns data on channels which
are otherwise forgotten (more than 100 blocks after they're completely
resolved onchain).

If no *id* is supplied, then channel data on all historical channels are given.

Supplying *id* will filter the results to only match channels to that peer. Note that prior to v23.05, old peers were forgotten.

RETURN VALUE
------------

[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, an object containing **closedchannels** is returned. It is an array of objects, where each object contains:

- **channel\_id** (hash): The full channel\_id (funding txid Xored with output number)
- **opener** (string): Who initiated the channel (one of "local", "remote")
- **private** (boolean): if False, we will not announce this channel
- **total\_local\_commitments** (u64): Number of commitment transaction we made
- **total\_remote\_commitments** (u64): Number of commitment transaction they made
- **total\_htlcs\_sent** (u64): Number of HTLCs we ever sent
- **funding\_txid** (txid): ID of the funding transaction
- **funding\_outnum** (u32): The 0-based output number of the funding transaction which opens the channel
- **leased** (boolean): Whether this channel was leased from `opener`
- **total\_msat** (msat): total amount in the channel
- **final\_to\_us\_msat** (msat): Our balance in final commitment transaction
- **min\_to\_us\_msat** (msat): Least amount owed to us ever. If the peer were to succesfully steal from us, this is the amount we would still retain.
- **max\_to\_us\_msat** (msat): Most amount owed to us ever. If we were to successfully steal from the peer, this is the amount we could potentially get.
- **close\_cause** (string): What caused the channel to close (one of "unknown", "local", "user", "remote", "protocol", "onchain")
- **peer\_id** (pubkey, optional): Peer public key (can be missing with pre-v23.05 closes!)
- **short\_channel\_id** (short\_channel\_id, optional): The short\_channel\_id
- **alias** (object, optional):
- **local** (short\_channel\_id, optional): An alias assigned by this node to this channel, used for outgoing payments
- **remote** (short\_channel\_id, optional): An alias assigned by the remote node to this channel, usable in routehints and invoices
- **closer** (string, optional): Who initiated the channel close (only present if closing) (one of "local", "remote")
- **channel\_type** (object, optional): channel\_type as negotiated with peer:
- **bits** (array of u32s): Each bit set in this channel\_type:
- Bit number
- **names** (array of strings): Feature name for each bit set in this channel\_type:
- Name of feature bit (one of "static\_remotekey/even", "anchor\_outputs/even", "anchors\_zero\_fee\_htlc\_tx/even", "scid\_alias/even", "zeroconf/even")
- **funding\_fee\_paid\_msat** (msat, optional): How much we paid to lease the channel (iff `leased` is true and `opener` is local)
- **funding\_fee\_rcvd\_msat** (msat, optional): How much they paid to lease the channel (iff `leased` is true and `opener` is remote)
- **funding\_pushed\_msat** (msat, optional): How much `opener` pushed immediate (if non-zero)
- **last\_commitment\_txid** (hash, optional): The final commitment tx's txid (or mutual close, if we accepted it). Not present for some very old, small channels pre-0.7.0.
- **last\_commitment\_fee\_msat** (msat, optional): The fee on `last_commitment_txid`

[comment]: # (GENERATE-FROM-SCHEMA-END)

On error the returned object will contain `code` and `message` properties,
with `code` being one of the following:

- -32602: If the given parameters are wrong.

AUTHOR
------

Rusty Russell <<rusty@blockstream.com>>.

SEE ALSO
--------

lightning-listpeerchannels(7)

RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning> Lightning

[comment]: # ( SHA256STAMP:0c368cb41f46a2124e9b3f0b760494d1f4b9c3b248267f56b887fbf96f26e176)
7 changes: 6 additions & 1 deletion doc/lightning-listpeerchannels.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ On success, an object containing **channels** is returned. It is an array of ob
- **features** (array of strings):
- BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_zeroconf")
- **scratch\_txid** (txid, optional): The txid we would use if we went onchain now
- **channel\_type** (object, optional): channel\_type as negotiated with peer *(added v23.05)*:
- **bits** (array of u32s): Each bit set in this channel\_type:
- Bit number
- **names** (array of strings): Feature name for each bit set in this channel\_type:
- Name of feature bit (one of "static\_remotekey/even", "anchor\_outputs/even", "anchors\_zero\_fee\_htlc\_tx/even", "scid\_alias/even", "zeroconf/even")
- **feerate** (object, optional): Feerates for the current tx:
- **perkw** (u32): Feerate per 1000 weight (i.e kSipa)
- **perkb** (u32): Feerate per 1000 virtual bytes
Expand Down Expand Up @@ -189,4 +194,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>

[comment]: # ( SHA256STAMP:f9919b6967137945cb49392d64a42bd159123b9d3bb83833c5df3bc777065d2e)
[comment]: # ( SHA256STAMP:1e589a9e6eace9134d04693dd00caa03da98dd40c2e65d3c675c9bee06daff7f)
Loading