channel: skip unsaved channels

Now that "peer->channels" contains `unsaved` channels, skip overthem
where appropriate
This commit is contained in:
niftynei 2021-01-21 18:55:23 -06:00 committed by neil saitug
parent b9f867b1dd
commit da81d4bced
13 changed files with 86 additions and 11 deletions

View File

@ -508,6 +508,15 @@ struct channel *active_channel_by_id(struct lightningd *ld,
return peer_active_channel(peer);
}
struct channel *unsaved_channel_by_id(struct lightningd *ld,
const struct node_id *id)
{
struct peer *peer = peer_by_id(ld, id);
if (!peer)
return NULL;
return peer_unsaved_channel(peer);
}
struct channel *active_channel_by_scid(struct lightningd *ld,
const struct short_channel_id *scid)
{

View File

@ -333,6 +333,10 @@ struct channel *active_channel_by_id(struct lightningd *ld,
const struct node_id *id,
struct uncommitted_channel **uc);
/* Get unsaved channel for peer */
struct channel *unsaved_channel_by_id(struct lightningd *ld,
const struct node_id *id);
struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid);
struct channel *active_channel_by_scid(struct lightningd *ld,

View File

@ -714,10 +714,13 @@ void channel_notify_new_block(struct lightningd *ld,
size_t i;
list_for_each (&ld->peers, peer, list) {
list_for_each (&peer->channels, channel, list)
list_for_each (&peer->channels, channel, list) {
if (channel_unsaved(channel))
continue;
if (is_fundee_should_forget(ld, channel, block_height)) {
tal_arr_expand(&to_forget, channel);
}
}
}
/* Need to forget in a separate loop, else the above

View File

@ -19,6 +19,7 @@
#include <hsmd/capabilities.h>
#include <lightningd/channel.h>
#include <lightningd/connect_control.h>
#include <lightningd/dual_open_control.h>
#include <lightningd/hsm_control.h>
#include <lightningd/json.h>
#include <lightningd/jsonrpc.h>
@ -284,6 +285,14 @@ static void peer_please_disconnect(struct lightningd *ld, const u8 *msg)
kill_uncommitted_channel(uc, "Reconnected");
else if (c)
channel_fail_reconnect(c, "Reconnected");
#if EXPERIMENTAL_FEATURES
else {
/* v2 has unsaved channels, not uncommitted_chans */
c = unsaved_channel_by_id(ld, &id);
if (c)
kill_unsaved_channel(c, "Reconnected");
}
#endif /* EXPERIMENTAL_FEATURES */
}
static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fds)

View File

@ -55,6 +55,20 @@ unsaved_channel_disconnect(struct channel *channel,
notify_disconnect(channel->peer->ld, &channel->peer->id);
}
void kill_unsaved_channel(struct channel *channel,
const char *why)
{
log_info(channel->log, "Killing dualopend: %s", why);
/* Close dualopend */
if (channel->owner) {
subd_release_channel(channel->owner, channel);
channel->owner = NULL;
}
unsaved_channel_disconnect(channel, LOG_INFORM, why);
tal_free(channel);
}
static struct channel_inflight *
channel_current_inflight(struct channel *channel)

View File

@ -19,4 +19,6 @@ void dualopen_tell_depth(struct subd *dualopend,
struct channel *channel,
const struct bitcoin_txid *txid,
u32 depth);
void kill_unsaved_channel(struct channel *channel,
const char *why);
#endif /* LIGHTNING_LIGHTNINGD_DUAL_OPEN_CONTROL_H */

View File

@ -1148,6 +1148,11 @@ void peer_connected(struct lightningd *ld, const u8 *msg,
assert(!peer->uncommitted_channel);
hook_payload->channel = peer_active_channel(peer);
/* It might be v2 opening, though, since we hang onto these */
if (!hook_payload->channel)
hook_payload->channel = peer_unsaved_channel(peer);
assert(hook_payload->channel);
plugin_hook_call_peer_connected(ld, hook_payload);
}
@ -1472,6 +1477,12 @@ static struct command_result *json_close(struct command *cmd,
return command_success(cmd, json_stream_success(cmd));
}
#if EXPERIMENTAL_FEATURES
if ((channel = peer_unsaved_channel(peer))) {
kill_unsaved_channel(channel, "close command called");
return command_success(cmd, json_stream_success(cmd));
}
#endif /* EXPERIMENTAL_FEATURES */
return command_fail(cmd, LIGHTNINGD,
"Peer has no active channel");
}
@ -1641,6 +1652,8 @@ static void activate_peer(struct peer *peer, u32 delay)
}
list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
continue;
/* Watching lockin may be unnecessary, but it's harmless. */
channel_watch_funding(ld, channel);
}
@ -1735,6 +1748,13 @@ static struct command_result *json_disconnect(struct command *cmd,
return command_fail(cmd, LIGHTNINGD, "Peer is in state %s",
channel_state_name(channel));
}
#if EXPERIMENTAL_FEATURES
channel = peer_unsaved_channel(peer);
if (channel) {
kill_unsaved_channel(channel, "disconnect command");
return command_success(cmd, json_stream_success(cmd));
}
#endif /* EXPERIMENTAL_FEATURES */
if (!peer->uncommitted_channel) {
return command_fail(cmd, LIGHTNINGD, "Peer not connected");
}
@ -1775,7 +1795,9 @@ static struct command_result *json_getinfo(struct command *cmd,
num_peers++;
list_for_each(&peer->channels, channel, list) {
if (channel->state == CHANNELD_AWAITING_LOCKIN) {
if (channel->state == CHANNELD_AWAITING_LOCKIN
|| channel->state == DUALOPEND_AWAITING_LOCKIN
|| channel->state == DUALOPEND_OPEN_INIT) {
pending_channels++;
} else if (channel_active(channel)) {
active_channels++;
@ -2339,10 +2361,11 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
"or `dev-fail` instead.");
}
bitcoind_getutxout(cmd->ld->topology->bitcoind,
&forget->channel->funding_txid,
forget->channel->funding_outnum,
process_dev_forget_channel, forget);
if (!channel_unsaved(forget->channel))
bitcoind_getutxout(cmd->ld->topology->bitcoind,
&forget->channel->funding_txid,
forget->channel->funding_outnum,
process_dev_forget_channel, forget);
return command_still_pending(cmd);
}

View File

@ -366,6 +366,10 @@ bool json_tok_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEE
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "kill_uncommitted_channel called!\n"); abort(); }
/* Generated stub for kill_unsaved_channel */
void kill_unsaved_channel(struct channel *channel UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "kill_unsaved_channel called!\n"); abort(); }
/* Generated stub for log_ */
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED,
const struct node_id *node_id UNNEEDED,

View File

@ -1834,4 +1834,4 @@ struct db_query db_postgres_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
// SHA256STAMP:9db19d2c8ea068737d26c097552cb01a25c884ee904fd8901e12445bacff45db
// SHA256STAMP:6b28c95645d860341a96102fc5f9240eaae6d10c30feb69459f42e78026de2b6

View File

@ -1834,4 +1834,4 @@ struct db_query db_sqlite3_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
// SHA256STAMP:9db19d2c8ea068737d26c097552cb01a25c884ee904fd8901e12445bacff45db
// SHA256STAMP:6b28c95645d860341a96102fc5f9240eaae6d10c30feb69459f42e78026de2b6

View File

@ -1202,11 +1202,11 @@ msgstr ""
msgid "not a valid SQL statement"
msgstr ""
#: wallet/test/run-wallet.c:1400
#: wallet/test/run-wallet.c:1404
msgid "SELECT COUNT(1) FROM channel_funding_inflights WHERE channel_id = ?;"
msgstr ""
#: wallet/test/run-wallet.c:1598
#: wallet/test/run-wallet.c:1602
msgid "INSERT INTO channels (id) VALUES (1);"
msgstr ""
# SHA256STAMP:0bc40d2193358aa8f18c22aa844a9fae0d35341127b4d35cf15ea925a2f3fab9
# SHA256STAMP:b9f3498738d18d7ed02f83699d902e480e8d75289b18deb5c2d5fe9d1f66c149

View File

@ -413,6 +413,10 @@ bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "kill_uncommitted_channel called!\n"); abort(); }
/* Generated stub for kill_unsaved_channel */
void kill_unsaved_channel(struct channel *channel UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "kill_unsaved_channel called!\n"); abort(); }
/* Generated stub for new_channel_mvt_invoice_hin */
struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx UNNEEDED,
struct htlc_in *hin UNNEEDED,

View File

@ -337,6 +337,9 @@ static struct command_result *json_listfunds(struct command *cmd,
list_for_each(&cmd->ld->peers, p, list) {
struct channel *c;
list_for_each(&p->channels, c, list) {
/* We don't print out uncommitted channels */
if (channel_unsaved(c))
continue;
json_object_start(response, NULL);
json_add_node_id(response, "peer_id", &p->id);
/* Mirrors logic in listpeers */