lightningd/lightningd.h: Maintain a round-robin list of channels.

This commit is contained in:
ZmnSCPxj jxPCSnmZ 2020-08-05 13:30:56 +08:00 committed by Rusty Russell
parent f50951a0d6
commit a9a11265dd
5 changed files with 15 additions and 0 deletions

View File

@ -110,6 +110,8 @@ static void destroy_channel(struct channel *channel)
channel_set_owner(channel, NULL);
list_del_from(&channel->peer->channels, &channel->list);
list_del(&channel->rr_list);
}
void delete_channel(struct channel *channel STEALS)
@ -275,6 +277,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
channel->forgets = tal_arr(channel, struct command *, 0);
list_add_tail(&peer->channels, &channel->list);
list_add_tail(&peer->ld->rr_channels, &channel->rr_list);
tal_add_destructor(channel, destroy_channel);
/* Make sure we see any spends using this key */

View File

@ -136,6 +136,9 @@ struct channel {
/* Any commands trying to forget us. */
struct command **forgets;
/* Our position in the round-robin list. */
struct list_node rr_list;
};
struct channel *new_channel(struct peer *peer, u64 dbid,

View File

@ -285,6 +285,11 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
*/
ld->exit_code = NULL;
/*~ We maintain a round-robin list of channels.
* This round-robin list of channels is used to ensure that
* each invoice we generate has a different set of channels. */
list_head_init(&ld->rr_channels);
return ld;
}

View File

@ -274,6 +274,9 @@ struct lightningd {
/* If non-NULL, contains the exit code to use. */
int *exit_code;
/* The round-robin list of channels, for use when doing MPP. */
struct list_head rr_channels;
};
/* Turning this on allows a tal allocation to return NULL, rather than aborting.

View File

@ -1498,6 +1498,7 @@ int main(int argc, const char *argv[])
/* Only elements in ld we should access */
list_head_init(&ld->peers);
list_head_init(&ld->rr_channels);
node_id_from_hexstr("02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66, &ld->id);
/* Accessed in peer destructor sanity check */
htlc_in_map_init(&ld->htlcs_in);