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

Function openchannel_init

lightningd/dual_open_control.c:3286–3388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3284}
3285
3286static struct command_result *openchannel_init(struct command *cmd,
3287 struct peer *peer,
3288 struct amount_sat amount,
3289 struct amount_sat request_amt,
3290 const struct wally_psbt *psbt,
3291 u32 feerate_per_kw_funding,
3292 u32 feerate_per_kw,
3293 const u8 *our_upfront_shutdown_script,
3294 bool announce_channel,
3295 const struct lease_rates *rates,
3296 const struct channel_type *ctype)
3297{
3298 u32 *our_upfront_shutdown_script_wallet_index;
3299 u32 found_wallet_index;
3300 u32 anchor_feerate;
3301 struct channel *channel;
3302 struct open_attempt *oa;
3303 int fds[2];
3304
3305 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
3306 return command_fail(cmd, FUND_MAX_EXCEEDED,
3307 "Failed to create socketpair: %s",
3308 strerror(errno));
3309 }
3310
3311 /* Now we can't fail, create channel */
3312 channel = new_unsaved_channel(peer,
3313 peer->ld->config.fee_base,
3314 peer->ld->config.fee_per_satoshi);
3315 /* We derive initial channel_id *now*, so we can tell it to connectd. */
3316 derive_tmp_channel_id(&channel->cid,
3317 &channel->local_basepoints.revocation);
3318
3319 /* Get a new open_attempt going */
3320 channel->opener = LOCAL;
3321 channel->open_attempt = oa = new_channel_open_attempt(channel);
3322 channel->channel_flags = OUR_CHANNEL_FLAGS;
3323 oa->funding = amount;
3324 oa->cmd = cmd;
3325
3326 if (!announce_channel) {
3327 channel->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL;
3328 log_info(peer->ld->log,
3329 "Will open private channel with node %s",
3330 fmt_node_id(tmpctx, &peer->id));
3331 }
3332
3333 /* Needs to be stolen away from cmd */
3334 if (our_upfront_shutdown_script)
3335 oa->our_upfront_shutdown_script
3336 = tal_steal(oa, our_upfront_shutdown_script);
3337
3338 /* Determine the wallet index for our_upfront_shutdown_script,
3339 * NULL if not found. */
3340 if (wallet_can_spend(cmd->ld->wallet,
3341 oa->our_upfront_shutdown_script,
3342 tal_bytelen(oa->our_upfront_shutdown_script),
3343 &found_wallet_index, NULL)) {

Callers 2

json_openchannel_initFunction · 0.70

Calls 15

derive_tmp_channel_idFunction · 0.85
new_channel_open_attemptFunction · 0.85
log_infoClass · 0.85
fmt_node_idFunction · 0.85
wallet_can_spendFunction · 0.85
tal_bytelenFunction · 0.85
amount_sat_is_zeroFunction · 0.85
command_failFunction · 0.70
new_unsaved_channelFunction · 0.70
unilateral_feerateFunction · 0.70
get_feerate_floorFunction · 0.70
get_block_heightFunction · 0.70

Tested by

no test coverage detected