lightningd/opening_control.c: Skip over channels which are already stored, and don't create new peer if it already exits. Changelog-None

This commit is contained in:
adi2011
2022-08-19 00:30:13 +05:30
committed by neil saitug
parent 9219e778a1
commit 23b675922f

View File

@@ -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);