mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 23:54:22 +01:00
channel: skip unsaved channels
Now that "peer->channels" contains `unsaved` channels, skip overthem where appropriate
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user