Skip to content

Commit

Permalink
lightningd/opening_control.c: Skip over channels which are already st…
Browse files Browse the repository at this point in the history
…ored, and don't create new peer if it already exits. Changelog-None
  • Loading branch information
adi2011 authored and niftynei committed Aug 19, 2022
1 parent 9219e77 commit 23b6759
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 23b6759

Please sign in to comment.