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

Function wallet_commit_channel

lightningd/dual_open_control.c:1360–1520  ·  view source on GitHub ↗

Returns NULL if can't generate a key for this channel (Shouldn't happen) */

Source from the content-addressed store, hash-verified

1358
1359/* Returns NULL if can't generate a key for this channel (Shouldn't happen) */
1360static struct channel_inflight *
1361wallet_commit_channel(struct lightningd *ld,
1362 struct channel *channel,
1363 const struct bitcoin_outpoint *funding,
1364 struct amount_sat total_funding,
1365 struct amount_sat our_funding,
1366 struct channel_info *channel_info,
1367 u32 funding_feerate,
1368 u32 commitment_feerate,
1369 const u8 *our_upfront_shutdown_script,
1370 const u8 *remote_upfront_shutdown_script,
1371 struct wally_psbt *psbt STEALS,
1372 const struct amount_sat lease_amt,
1373 const u32 lease_blockheight_start,
1374 const u32 lease_expiry,
1375 const struct amount_sat lease_fee,
1376 secp256k1_ecdsa_signature *lease_commit_sig STEALS,
1377 const u32 lease_chan_max_msat,
1378 const u16 lease_chan_max_ppt,
1379 const struct channel_type *type)
1380{
1381 struct amount_msat our_msat, lease_fee_msat;
1382 struct channel_inflight *inflight;
1383 bool anysegwit = !chainparams->is_elements && feature_negotiated(channel->peer->ld->our_features,
1384 channel->peer->their_features,
1385 OPT_SHUTDOWN_ANYSEGWIT);
1386 bool was_important;
1387
1388 if (!amount_sat_to_msat(&our_msat, our_funding)) {
1389 log_broken(channel->log, "Unable to convert funds");
1390 return NULL;
1391 }
1392
1393 if (!amount_sat_to_msat(&lease_fee_msat, lease_fee)) {
1394 log_broken(channel->log, "Unable to convert lease fee");
1395 return NULL;
1396 }
1397
1398 /* Get a key to use for closing outputs from this tx. Prefer
1399 * P2TR, but we'll use BECH32 for older peers (but always P2TR
1400 * for our own onchian spends, if any). */
1401
1402 channel->final_key_idx = wallet_get_newindex(ld, anysegwit ? ADDR_P2TR : (ADDR_BECH32|ADDR_P2TR));
1403 if (channel->final_key_idx == -1) {
1404 log_broken(channel->log, "Can't get final key index");
1405 return NULL;
1406 }
1407
1408 /* Does peer currently have an important channel? */
1409 was_important = peer_any_channel(channel->peer,
1410 channel_important_filter, NULL, NULL);
1411
1412 assert(channel->state == DUALOPEND_OPEN_INIT);
1413 log_info(channel->log, "State changed from %s to %s",
1414 channel_state_name(channel),
1415 channel_state_str(DUALOPEND_OPEN_COMMIT_READY));
1416 channel->state = DUALOPEND_OPEN_COMMIT_READY;
1417 tell_connectd_peer_importance(channel->peer, was_important);

Callers 1

handle_commit_readyFunction · 0.70

Calls 15

feature_negotiatedFunction · 0.85
wallet_get_newindexFunction · 0.85
log_infoClass · 0.85
clock_timeFunction · 0.85
new_fee_statesFunction · 0.85
tal_freeFunction · 0.85
channel_type_dupFunction · 0.85
p2tr_for_keyidxFunction · 0.85
new_height_statesFunction · 0.85
wallet_channel_insertFunction · 0.85
add_channel_to_dbid_mapFunction · 0.85
wallet_inflight_addFunction · 0.85

Tested by

no test coverage detected