From 23b675922ff6d3c8b346a3c145d48e64750fb101 Mon Sep 17 00:00:00 2001 From: adi2011 Date: Fri, 19 Aug 2022 00:30:13 +0530 Subject: [PATCH] lightningd/opening_control.c: Skip over channels which are already stored, and don't create new peer if it already exits. Changelog-None --- lightningd/opening_control.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 8a24ee69c..3e740844c 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -1299,11 +1299,21 @@ static struct channel *stub_chan(struct command *cmd, "647de4443938ae2dbafe2b9" "01", 144); - peer = new_peer(cmd->ld, - 0, - &nodeid, - &addr, - false); + /* If the channel is already stored, return NULL. */ + peer = peer_by_id(cmd->ld, &nodeid); + if (peer) { + if (find_channel_by_id(peer, &cid)) { + log_debug(cmd->ld->log, "channel %s already exists!", + type_to_string(tmpctx, struct channel_id, &cid)); + return NULL; + } + } else { + peer = new_peer(cmd->ld, + 0, + &nodeid, + &addr, + false); + } ld = cmd->ld; feerate = FEERATE_FLOOR; @@ -1453,6 +1463,10 @@ static struct command_result *json_recoverchannel(struct command *cmd, scb_chan->funding_sats, scb_chan->type); + /* Returns NULL only when channel already exists, so we skip over it. */ + if (channel == NULL) + continue; + /* Now we put this in the database. */ wallet_channel_insert(ld->wallet, channel);