| 3329 | } |
| 3330 | |
| 3331 | static struct command_result *openchannel_init(struct command *cmd, |
| 3332 | struct peer *peer, |
| 3333 | struct amount_sat amount, |
| 3334 | struct amount_sat request_amt, |
| 3335 | const struct wally_psbt *psbt, |
| 3336 | u32 feerate_per_kw_funding, |
| 3337 | u32 feerate_per_kw, |
| 3338 | const u8 *our_upfront_shutdown_script, |
| 3339 | bool announce_channel, |
| 3340 | const struct lease_rates *rates, |
| 3341 | const struct channel_type *ctype) |
| 3342 | { |
| 3343 | u32 *our_upfront_shutdown_script_wallet_index; |
| 3344 | u32 found_wallet_index; |
| 3345 | u32 anchor_feerate; |
| 3346 | struct channel *channel; |
| 3347 | struct open_attempt *oa; |
| 3348 | int fds[2]; |
| 3349 | |
| 3350 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { |
| 3351 | return command_fail(cmd, FUND_MAX_EXCEEDED, |
| 3352 | "Failed to create socketpair: %s", |
| 3353 | strerror(errno)); |
| 3354 | } |
| 3355 | |
| 3356 | /* Now we can't fail, create channel */ |
| 3357 | channel = new_unsaved_channel(peer, |
| 3358 | peer->ld->config.fee_base, |
| 3359 | peer->ld->config.fee_per_satoshi); |
| 3360 | /* We derive initial channel_id *now*, so we can tell it to connectd. */ |
| 3361 | derive_tmp_channel_id(&channel->cid, |
| 3362 | &channel->local_basepoints.revocation); |
| 3363 | |
| 3364 | /* Get a new open_attempt going */ |
| 3365 | channel->opener = LOCAL; |
| 3366 | channel->open_attempt = oa = new_channel_open_attempt(channel); |
| 3367 | channel->channel_flags = OUR_CHANNEL_FLAGS; |
| 3368 | oa->funding = amount; |
| 3369 | oa->cmd = cmd; |
| 3370 | |
| 3371 | if (!announce_channel) { |
| 3372 | channel->channel_flags &= ~CHANNEL_FLAGS_ANNOUNCE_CHANNEL; |
| 3373 | log_info(peer->ld->log, |
| 3374 | "Will open private channel with node %s", |
| 3375 | fmt_node_id(tmpctx, &peer->id)); |
| 3376 | } |
| 3377 | |
| 3378 | /* Needs to be stolen away from cmd */ |
| 3379 | if (our_upfront_shutdown_script) |
| 3380 | oa->our_upfront_shutdown_script |
| 3381 | = tal_steal(oa, our_upfront_shutdown_script); |
| 3382 | |
| 3383 | /* Determine the wallet index for our_upfront_shutdown_script, |
| 3384 | * NULL if not found. */ |
| 3385 | if (wallet_can_spend(cmd->ld->wallet, |
| 3386 | oa->our_upfront_shutdown_script, |
| 3387 | tal_bytelen(oa->our_upfront_shutdown_script), |
| 3388 | &found_wallet_index, NULL)) { |
no test coverage detected