diff --git a/lightningd/channel.c b/lightningd/channel.c index 59f8b3633..5c641c351 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -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 */ diff --git a/lightningd/channel.h b/lightningd/channel.h index ea9e2f814..3d817c00e 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -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, diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 44b56c7d1..8928e9463 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -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; } diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 5ad15243e..603be2003 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -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. diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index b66c2193d..69fb47d27 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -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);