lightningd: remove 'connected' flag from channel structure.

It's directly a product of "does it have a current owner subdaemon"
and "does that subdaemon talk to peers", so create a helper function
which just evaluates that instead.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-07-16 14:19:29 +09:30 committed by neil saitug
parent b8ed107743
commit 912ac25270
8 changed files with 12 additions and 26 deletions

View File

@ -22,14 +22,14 @@
void channel_set_owner(struct channel *channel, struct subd *owner)
{
struct subd *old_owner = channel->owner;
bool was_connected = channel_is_connected(channel);
channel->owner = owner;
if (old_owner) {
subd_release_channel(old_owner, channel);
if (channel->connected)
if (was_connected && !channel_is_connected(channel))
maybe_disconnect_peer(channel->peer->ld, channel->peer);
}
channel->connected = (owner && owner->talks_to_peer);
}
struct htlc_out *channel_has_htlc_out(struct channel *channel)
@ -239,8 +239,6 @@ struct channel *new_unsaved_channel(struct peer *peer,
channel->channel_update = NULL;
channel->alias[LOCAL] = channel->alias[REMOTE] = NULL;
/* Channel is connected! */
channel->connected = true;
channel->shutdown_scriptpubkey[REMOTE] = NULL;
channel->last_was_revoke = false;
channel->last_sent_commit = NULL;
@ -376,7 +374,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
u32 first_blocknum,
u32 min_possible_feerate,
u32 max_possible_feerate,
bool connected,
const struct basepoints *local_basepoints,
const struct pubkey *local_funding_pubkey,
const struct pubkey *future_per_commitment_point,
@ -485,7 +482,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->first_blocknum = first_blocknum;
channel->min_possible_feerate = min_possible_feerate;
channel->max_possible_feerate = max_possible_feerate;
channel->connected = connected;
channel->local_basepoints = *local_basepoints;
channel->local_funding_pubkey = *local_funding_pubkey;
channel->future_per_commitment_point
@ -980,6 +976,11 @@ void channel_fail_reconnect(struct channel *channel, const char *fmt, ...)
va_end(ap);
}
bool channel_is_connected(const struct channel *channel)
{
return channel->owner && channel->owner->talks_to_peer;
}
const struct short_channel_id *
channel_scid_or_local_alias(const struct channel *chan)
{

View File

@ -205,9 +205,6 @@ struct channel {
/* Feerate range */
u32 min_possible_feerate, max_possible_feerate;
/* Does gossipd need to know if the owner dies? (ie. not onchaind) */
bool connected;
/* Do we have an "impossible" future per_commitment_point from
* peer via option_data_loss_protect? */
const struct pubkey *future_per_commitment_point;
@ -267,6 +264,8 @@ struct channel {
struct scb_chan *scb;
};
bool channel_is_connected(const struct channel *channel);
/* For v2 opens, a channel that has not yet been committed/saved to disk */
struct channel *new_unsaved_channel(struct peer *peer,
u32 feerate_base,
@ -317,7 +316,6 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
u32 first_blocknum,
u32 min_possible_feerate,
u32 max_possible_feerate,
bool connected,
const struct basepoints *local_basepoints,
const struct pubkey *local_funding_pubkey,
const struct pubkey *future_per_commitment_point,

View File

@ -677,12 +677,9 @@ void maybe_disconnect_peer(struct lightningd *ld, struct peer *peer)
if (peer->uncommitted_channel)
return;
list_for_each(&peer->channels, channel, list) {
if (!channel->owner)
continue;
if (channel->owner->talks_to_peer)
list_for_each(&peer->channels, channel, list)
if (channel_is_connected(channel))
return;
}
/* If shutting down, connectd no longer exists */
if (!ld->connectd) {

View File

@ -1234,9 +1234,6 @@ wallet_commit_channel(struct lightningd *ld,
channel->scb->funding_sats = total_funding;
channel->scb->type = channel_type_dup(channel->scb, channel->type);
/* We are connected */
channel->connected = true;
if (our_upfront_shutdown_script)
channel->shutdown_scriptpubkey[LOCAL]
= tal_steal(channel, our_upfront_shutdown_script);

View File

@ -202,8 +202,6 @@ wallet_commit_channel(struct lightningd *ld,
* in theory, but it's only used for timing out. */
get_network_blockheight(ld->topology),
feerate, feerate,
/* We are connected */
true,
&uc->local_basepoints,
&uc->local_funding_pubkey,
NULL,
@ -1363,7 +1361,6 @@ static struct channel *stub_chan(struct command *cmd,
get_network_blockheight(ld->topology),
FEERATE_FLOOR,
funding_sats.satoshis / MINIMUM_TX_WEIGHT * 1000 /* Raw: convert to feerate */,
false,
&basepoints,
&localFundingPubkey,
NULL,

View File

@ -1608,7 +1608,6 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
100, /* first_blocknum */
100, /* min_possible_feerate */
10000, /* max_possible_feerate */
false,
&basepoints,
&pk, NULL,
1000, 100,

View File

@ -1500,8 +1500,6 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
db_col_u64(stmt, "first_blocknum"),
db_col_int(stmt, "min_possible_feerate"),
db_col_int(stmt, "max_possible_feerate"),
/* Not connected */
false,
&local_basepoints, &local_funding_pubkey,
future_per_commitment_point,
db_col_int(stmt, "feerate_base"),

View File

@ -342,9 +342,8 @@ static struct command_result *json_listfunds(struct command *cmd,
continue;
json_object_start(response, NULL);
json_add_node_id(response, "peer_id", &p->id);
/* Mirrors logic in listpeers */
json_add_bool(response, "connected",
channel_active(c) && c->connected);
channel_is_connected(c));
json_add_string(response, "state",
channel_state_name(c));
if (c->scid)