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

Function wallet_update_channel_commit

lightningd/dual_open_control.c:1429–1503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1427}
1428
1429static bool
1430wallet_update_channel_commit(struct lightningd *ld,
1431 struct channel *channel,
1432 struct channel_inflight *inflight,
1433 struct bitcoin_tx *remote_commit,
1434 struct bitcoin_signature *remote_commit_sig)
1435{
1436 /*~ Only the candidate channel->funding names gets to be the
1437 * channel's commitment. Before promotion that is always the latest
1438 * attempt (wallet_update_channel moved channel->funding to it); after
1439 * promotion an attempt still completing belongs to its inflight only,
1440 * see wallet_add_inflight_attempt. */
1441 if (bitcoin_outpoint_eq(&inflight->funding->outpoint,
1442 &channel->funding)) {
1443 channel_set_last_tx(channel,
1444 tal_steal(channel, remote_commit),
1445 remote_commit_sig);
1446 } else {
1447 log_info(channel->log,
1448 "Not updating channel commitment from RBF attempt %s:"
1449 " funding is %s",
1450 fmt_bitcoin_txid(tmpctx,
1451 &inflight->funding->outpoint.txid),
1452 fmt_bitcoin_txid(tmpctx, &channel->funding.txid));
1453 }
1454
1455 /* We can't call channel_set_state here: channel isn't in db, so
1456 * really this is a "channel creation" event. */
1457 if (channel->state == DUALOPEND_OPEN_COMMIT_READY) {
1458 bool was_important;
1459
1460 /* Does peer currently have an important channel? */
1461 was_important = peer_any_channel(channel->peer,
1462 channel_important_filter, NULL, NULL);
1463 log_info(channel->log, "State changed from %s to %s",
1464 channel_state_name(channel),
1465 channel_state_str(DUALOPEND_OPEN_COMMITTED));
1466 channel->state = DUALOPEND_OPEN_COMMITTED;
1467 notify_channel_state_changed(channel->peer->ld,
1468 &channel->peer->id,
1469 &channel->cid,
1470 channel->scid,
1471 clock_time(),
1472 DUALOPEND_OPEN_COMMIT_READY,
1473 DUALOPEND_OPEN_COMMITTED,
1474 REASON_REMOTE,
1475 "Commitment transaction committed");
1476 tell_connectd_peer_importance(channel->peer, was_important);
1477 }
1478
1479 /* Update in database */
1480 wallet_channel_save(ld->wallet, channel);
1481
1482 /* Set inflight data & update */
1483 if (inflight->last_tx) {
1484 struct bitcoin_txid txid, inflight_txid;
1485 /* confirm they're the same tx! */
1486 bitcoin_txid(remote_commit, &txid);

Callers 1

handle_commit_receivedFunction · 0.85

Calls 13

log_infoClass · 0.85
fmt_bitcoin_txidFunction · 0.85
clock_timeFunction · 0.85
wallet_inflight_saveFunction · 0.85
channel_set_last_txFunction · 0.70
channel_state_nameFunction · 0.70
channel_state_strFunction · 0.70
bitcoin_txidClass · 0.70
channel_fail_permanentFunction · 0.70
inflight_set_last_txFunction · 0.70

Tested by

no test coverage detected