MCPcopy Create free account
hub / github.com/ElementsProject/lightning / fundchannel_start

Function fundchannel_start

lightningd/opening_control.c:1191–1249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1189}
1190
1191static struct command_result *fundchannel_start(struct command *cmd,
1192 struct peer *peer,
1193 struct funding_channel *fc STEALS,
1194 const struct channel_id *tmp_channel_id,
1195 u32 mindepth,
1196 struct amount_sat *reserve STEALS)
1197{
1198 int fds[2];
1199
1200 /* Re-check in case it's changed */
1201 if (!peer->uncommitted_channel) {
1202 log_debug(cmd->ld->log, "fundchannel_start: allocating uncommitted_channel");
1203 peer->uncommitted_channel = new_uncommitted_channel(peer);
1204 } else
1205 log_debug(cmd->ld->log, "fundchannel_start: reusing uncommitted_channel");
1206
1207 if (peer->uncommitted_channel->fc) {
1208 return command_fail(cmd, LIGHTNINGD, "Already funding channel");
1209 }
1210
1211 if (peer->uncommitted_channel->got_offer) {
1212 return command_fail(cmd, LIGHTNINGD,
1213 "Have in-progress "
1214 "`open_channel` from "
1215 "peer");
1216 }
1217
1218 peer->uncommitted_channel->cid = *tmp_channel_id;
1219
1220 peer->uncommitted_channel->fc = tal_steal(peer->uncommitted_channel, fc);
1221 fc->uc = peer->uncommitted_channel;
1222
1223 fc->uc->minimum_depth = mindepth;
1224
1225 fc->uc->reserve = tal_steal(fc->uc, reserve);
1226
1227 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
1228 return command_fail(cmd, FUND_MAX_EXCEEDED,
1229 "Failed to create socketpair: %s",
1230 strerror(errno));
1231 }
1232 if (!peer_start_openingd(peer, new_peer_fd(cmd, fds[0]))) {
1233 close(fds[1]);
1234 /* FIXME: gets completed by failure path above! */
1235 return command_its_complicated("completed by peer_start_openingd");
1236 }
1237
1238 /* Tell it to start funding */
1239 subd_send_msg(peer->uncommitted_channel->open_daemon, fc->open_msg);
1240
1241 /* Tell connectd connect this to this channel id. */
1242 subd_send_msg(peer->ld->connectd,
1243 take(towire_connectd_peer_connect_subd(NULL,
1244 &peer->id,
1245 peer->connectd_counter,
1246 &peer->uncommitted_channel->cid)));
1247 subd_send_fd(peer->ld->connectd, fds[1]);
1248 return command_still_pending(cmd);

Callers 2

json_fundchannel_startFunction · 0.85

Calls 9

new_uncommitted_channelFunction · 0.70
command_failFunction · 0.70
peer_start_openingdFunction · 0.70
new_peer_fdFunction · 0.70
command_its_complicatedFunction · 0.70
subd_send_msgFunction · 0.70
subd_send_fdFunction · 0.70
command_still_pendingFunction · 0.70

Tested by

no test coverage detected