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

Refactor channel state in lightningd #6628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e32118a
poetry: run poetry update.
rustyrussell Oct 1, 2023
35aa3bc
contrib/pyln-grpc-proto/ regenerate.
rustyrussell Oct 1, 2023
0f29c80
pytest: fix flake in upfront warning.
rustyrussell Oct 1, 2023
e82fa35
patch remove-developer-test-annotations.patch
rustyrussell Oct 1, 2023
0050dbc
doc: fix listpeerchannels schema to allow CHANNELD_AWAITING_SPLICE in…
rustyrussell Oct 1, 2023
4bef9df
pytest: make test_splice_gossip more precise.
rustyrussell Oct 1, 2023
bb8c49f
lightningd: disconnect on *any* transient error, except abort
rustyrussell Oct 1, 2023
4162cd9
lightningd: clean up channel_tell_depth.
rustyrussell Oct 1, 2023
00fabc5
lightningd: don't report original depth once splice started.
rustyrussell Oct 1, 2023
441e61c
lightningd: make dualopen_tell_depth match channeld_tell_depth.
rustyrussell Oct 1, 2023
d32177d
lightningd: fold funding tx depth into a single function.
rustyrussell Oct 1, 2023
2b2caa5
lightningd: generalize peer_any_active_channel to peer_any_channel.
rustyrussell Oct 1, 2023
f55c207
lightningd/channel.h: clean up channel states.
rustyrussell Oct 1, 2023
1c9722d
lightningd: remove peer_any_unsaved_channel and use peer_any_channel.
rustyrussell Oct 1, 2023
d9c54df
wallet: add standard sanity-check function for channel_state.
rustyrussell Oct 1, 2023
947a516
lightningd/channel.h: rename channel_unsaved to the more explicit cha…
rustyrussell Oct 1, 2023
e95202a
common/json_stream, lightningd/notification: clean up function APIs
rustyrussell Oct 1, 2023
eef8c96
doc: introduce new state DUALOPEND_OPEN_COMMITTED.
rustyrussell Oct 1, 2023
cf373f9
lightningd: split DUALOPEND_OPEN_INIT into DUALOPEND_OPEN_INIT and DU…
rustyrussell Oct 1, 2023
e326f85
lightningd: make channel-query functions all take state.
rustyrussell Oct 1, 2023
055d600
lightningd: remove watch_tx() in favor of watch_txid().
rustyrussell Oct 1, 2023
add836e
lightningd: make watch_txid more generic.
rustyrussell Oct 1, 2023
b95e2fa
lightningd: fix watch on existing tx.
rustyrussell Oct 1, 2023
5dabdea
lightningd: don't share funding_depth_cb for non-funding txs.
rustyrussell Oct 1, 2023
d54226b
lightningd: fix bug where we didn't correctly change outpoint of spli…
rustyrussell Oct 1, 2023
bd5e8d2
lightningd: ensure we *always* watch channel spend.
rustyrussell Oct 1, 2023
8fea8cd
lightningd: fix dual-funding case where we coop close and an RBF conf…
rustyrussell Oct 1, 2023
d333f19
lightningd: simplify funding_depth_cb now it only handles main fundin…
rustyrussell Oct 1, 2023
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
2 changes: 2 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"CLOSINGD_COMPLETE": 5,
"CLOSINGD_SIGEXCHANGE": 4,
"DUALOPEND_AWAITING_LOCKIN": 10,
"DUALOPEND_OPEN_COMMITTED": 12,
"DUALOPEND_OPEN_INIT": 9,
"FUNDING_SPEND_SEEN": 7,
"ONCHAIN": 8,
Expand Down Expand Up @@ -251,6 +252,7 @@
"CLOSINGD_COMPLETE": 5,
"CLOSINGD_SIGEXCHANGE": 4,
"DUALOPEND_AWAITING_LOCKIN": 10,
"DUALOPEND_OPEN_COMMITTED": 11,
"DUALOPEND_OPEN_INIT": 9,
"FUNDING_SPEND_SEEN": 7,
"ONCHAIN": 8,
Expand Down
2 changes: 2 additions & 0 deletions cln-grpc/proto/node.proto

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

8 changes: 8 additions & 0 deletions cln-rpc/src/model.rs

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

6 changes: 3 additions & 3 deletions common/json_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,15 @@ void json_add_timestr(struct json_stream *result, const char *fieldname,

void json_add_timeiso(struct json_stream *result,
const char *fieldname,
struct timeabs *time)
struct timeabs time)
{
char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ")];
char iso8601_s[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ")];

strftime(iso8601_msec_fmt, sizeof(iso8601_msec_fmt),
"%FT%T.%%03dZ", gmtime(&time->ts.tv_sec));
"%FT%T.%%03dZ", gmtime(&time.ts.tv_sec));
snprintf(iso8601_s, sizeof(iso8601_s),
iso8601_msec_fmt, (int) time->ts.tv_nsec / 1000000);
iso8601_msec_fmt, (int) time.ts.tv_nsec / 1000000);

json_add_string(result, fieldname, iso8601_s);
}
Expand Down
2 changes: 1 addition & 1 deletion common/json_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void json_add_timestr(struct json_stream *result, const char *fieldname,
/* Add ISO_8601 timestamp string, i.e. "2019-09-07T15:50+01:00" */
void json_add_timeiso(struct json_stream *result,
const char *fieldname,
struct timeabs *time);
struct timeabs time);

/* Add any json token */
void json_add_tok(struct json_stream *result, const char *fieldname,
Expand Down
787 changes: 393 additions & 394 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion contrib/pyln-grpc-proto/pyln/grpc/primitives_pb2.py

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

4 changes: 2 additions & 2 deletions doc/lightning-listfunds.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ On success, an object is returned, containing:
- **funding\_txid** (txid): funding transaction id
- **funding\_output** (u32): the 0-based index of the output in the funding transaction
- **connected** (boolean): whether the channel peer is connected
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "DUALOPEND\_OPEN\_COMMITTED")
- **channel\_id** (hash): The full channel\_id (funding txid Xored with output number) *(added v23.05)*

If **state** is "CHANNELD\_NORMAL":
Expand Down Expand Up @@ -74,4 +74,4 @@ RESOURCES

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

[comment]: # ( SHA256STAMP:02deef0c91e587aafe3a4b75fa45075c7246566b4baf1e73e00564d36d5a38f4)
[comment]: # ( SHA256STAMP:f4b639bb4e7a4544e7015a67225c1ead6a2e0b9817eca5b328908576f1d17dd2)
8 changes: 4 additions & 4 deletions doc/lightning-listpeerchannels.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ On success, an object containing **channels** is returned. It is an array of ob

- **peer\_id** (pubkey): Node Public key
- **peer\_connected** (boolean): A boolean flag that is set to true if the peer is online
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "CHANNELD\_AWAITING\_SPLICE")
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "CHANNELD\_AWAITING\_SPLICE", "DUALOPEND\_OPEN\_COMMITTED")
- **opener** (string): Who initiated the channel (one of "local", "remote")
- **features** (array of strings):
- BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_anchors\_zero\_fee\_htlc\_tx", "option\_scid\_alias", "option\_zeroconf")
Expand Down Expand Up @@ -89,8 +89,8 @@ On success, an object containing **channels** is returned. It is an array of ob
- **remote** (short\_channel\_id, optional): An alias assigned by the remote node to this channel, usable in routehints and invoices
- **state\_changes** (array of objects, optional): Prior state changes:
- **timestamp** (string): UTC timestamp of form YYYY-mm-ddTHH:MM:SS.%03dZ
- **old\_state** (string): Previous state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **new\_state** (string): New state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **old\_state** (string): Previous state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "DUALOPEND\_OPEN\_COMMITTED", "CHANNELD\_AWAITING\_SPLICE")
- **new\_state** (string): New state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "DUALOPEND\_OPEN\_COMMITTED", "CHANNELD\_AWAITING\_SPLICE")
- **cause** (string): What caused the change (one of "unknown", "local", "user", "remote", "protocol", "onchain")
- **message** (string): Human-readable explanation
- **status** (array of strings, optional):
Expand Down Expand Up @@ -196,4 +196,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:359d0035f98350d2de5f539ce8d2c3d82ccf633d3cbee4ed992a71687a25770a)
[comment]: # ( SHA256STAMP:c69bd45ebbfc508c0b3998d6b875993d321f26dc4e8ba88830999851623e5206)
8 changes: 4 additions & 4 deletions doc/lightning-listpeers.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ On success, an object containing **peers** is returned. It is an array of objec
- **node\_id** (pubkey): The peer this is associated with
- **data** (hex): The IO which occurred
- **channels** (array of objects, optional) **deprecated, removal in v23.11**:
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **state** (string): the channel state, in particular "CHANNELD\_NORMAL" means the channel can be used normally (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "DUALOPEND\_OPEN\_COMMITTED")
- **opener** (string): Who initiated the channel (one of "local", "remote")
- **features** (array of strings):
- BOLT #9 features which apply to this channel (one of "option\_static\_remotekey", "option\_anchor\_outputs", "option\_scid\_alias", "option\_zeroconf")
Expand Down Expand Up @@ -123,8 +123,8 @@ On success, an object containing **peers** is returned. It is an array of objec
- **remote** (short\_channel\_id, optional): An alias assigned by the remote node to this channel, usable in routehints and invoices
- **state\_changes** (array of objects, optional): Prior state changes:
- **timestamp** (string): UTC timestamp of form YYYY-mm-ddTHH:MM:SS.%03dZ
- **old\_state** (string): Previous state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **new\_state** (string): New state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN")
- **old\_state** (string): Previous state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "DUALOPEND\_OPEN\_COMMITTED")
- **new\_state** (string): New state (one of "OPENINGD", "CHANNELD\_AWAITING\_LOCKIN", "CHANNELD\_NORMAL", "CHANNELD\_SHUTTING\_DOWN", "CLOSINGD\_SIGEXCHANGE", "CLOSINGD\_COMPLETE", "AWAITING\_UNILATERAL", "FUNDING\_SPEND\_SEEN", "ONCHAIN", "DUALOPEND\_OPEN\_INIT", "DUALOPEND\_AWAITING\_LOCKIN", "DUALOPEND\_OPEN\_COMMITTED")
- **cause** (string): What caused the change (one of "unknown", "local", "user", "remote", "protocol", "onchain")
- **message** (string): Human-readable explanation
- **status** (array of strings, optional):
Expand Down Expand Up @@ -399,4 +399,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightning/bolts/blob/master/09-features.md>

[comment]: # ( SHA256STAMP:7402bcd43be7c031c1e8e1ec7a4d58e94beb44ca48ba2f8f06e4ea908ab8940b)
[comment]: # ( SHA256STAMP:32075bc65e686b04617f4c1fa068b5fd0ac84afec057f06f19df6f56328d2dd9)
3 changes: 2 additions & 1 deletion doc/schemas/listfunds.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"DUALOPEND_OPEN_COMMITTED"
],
"description": "the channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
},
Expand Down
11 changes: 8 additions & 3 deletions doc/schemas/listpeerchannels.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN",
"CHANNELD_AWAITING_SPLICE"
"CHANNELD_AWAITING_SPLICE",
"DUALOPEND_OPEN_COMMITTED"
],
"description": "the channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
},
Expand Down Expand Up @@ -378,7 +379,9 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"DUALOPEND_OPEN_COMMITTED",
"CHANNELD_AWAITING_SPLICE"
],
"description": "Previous state"
},
Expand All @@ -395,7 +398,9 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"DUALOPEND_OPEN_COMMITTED",
"CHANNELD_AWAITING_SPLICE"
],
"description": "New state"
},
Expand Down
9 changes: 6 additions & 3 deletions doc/schemas/listpeers.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"DUALOPEND_OPEN_COMMITTED"
],
"description": "the channel state, in particular \"CHANNELD_NORMAL\" means the channel can be used normally"
},
Expand Down Expand Up @@ -493,7 +494,8 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"DUALOPEND_OPEN_COMMITTED"
],
"description": "Previous state"
},
Expand All @@ -510,7 +512,8 @@
"FUNDING_SPEND_SEEN",
"ONCHAIN",
"DUALOPEND_OPEN_INIT",
"DUALOPEND_AWAITING_LOCKIN"
"DUALOPEND_AWAITING_LOCKIN",
"DUALOPEND_OPEN_COMMITTED"
],
"description": "New state"
},
Expand Down
26 changes: 13 additions & 13 deletions lightningd/chaintopology.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,24 @@ void broadcast_tx_(struct chain_topology *topo,
}

static enum watch_result closeinfo_txid_confirmed(struct lightningd *ld,
struct channel *channel,
const struct bitcoin_txid *txid,
const struct bitcoin_tx *tx,
unsigned int depth)
unsigned int depth,
void *unused)
{
/* Sanity check. */
if (tx != NULL) {
struct bitcoin_txid txid2;

bitcoin_txid(tx, &txid2);
if (!bitcoin_txid_eq(txid, &txid2)) {
channel_internal_error(channel, "Txid for %s is not %s",
type_to_string(tmpctx,
struct bitcoin_tx,
tx),
type_to_string(tmpctx,
struct bitcoin_txid,
txid));
return DELETE_WATCH;
fatal("Txid for %s is not %s",
type_to_string(tmpctx,
struct bitcoin_tx,
tx),
type_to_string(tmpctx,
struct bitcoin_txid,
txid));
}
}

Expand Down Expand Up @@ -358,12 +357,13 @@ static void watch_for_utxo_reconfirmation(struct chain_topology *topo,
assert(unconfirmed[i]->close_info != NULL);
assert(unconfirmed[i]->blockheight == NULL);

if (find_txwatch(topo, &unconfirmed[i]->outpoint.txid, NULL))
if (find_txwatch(topo, &unconfirmed[i]->outpoint.txid,
closeinfo_txid_confirmed, NULL))
continue;

watch_txid(topo, topo, NULL,
watch_txid(topo, topo,
&unconfirmed[i]->outpoint.txid,
closeinfo_txid_confirmed);
closeinfo_txid_confirmed, NULL);
}
}

Expand Down
Loading
Loading