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

Function handle_peer_commit_sig

channeld/channeld.c:1584–1749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1582}
1583
1584static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
1585{
1586 struct channel_id channel_id;
1587 struct bitcoin_signature commit_sig;
1588 secp256k1_ecdsa_signature *raw_sigs;
1589 struct bitcoin_signature *htlc_sigs;
1590 struct pubkey remote_htlckey;
1591 struct bitcoin_tx **txs;
1592 const struct htlc **htlc_map, **changed_htlcs;
1593 const u8 *funding_wscript;
1594 size_t i;
1595 struct simple_htlc **htlcs;
1596 const u8 * msg2;
1597
1598 changed_htlcs = tal_arr(msg, const struct htlc *, 0);
1599 if (!channel_rcvd_commit(peer->channel, &changed_htlcs)) {
1600 /* BOLT #2:
1601 *
1602 * A sending node:
1603 * - MUST NOT send a `commitment_signed` message that does not
1604 * include any updates.
1605 */
1606 status_debug("Oh hi LND! Empty commitment at #%"PRIu64,
1607 peer->next_index[LOCAL]);
1608 if (peer->last_empty_commitment == peer->next_index[LOCAL] - 1)
1609 peer_failed_warn(peer->pps, &peer->channel_id,
1610 "commit_sig with no changes (again!)");
1611 peer->last_empty_commitment = peer->next_index[LOCAL];
1612 }
1613
1614 /* We were supposed to check this was affordable as we go. */
1615 if (peer->channel->opener == REMOTE) {
1616 status_debug("Feerates are %u/%u",
1617 channel_feerate(peer->channel, LOCAL),
1618 channel_feerate(peer->channel, REMOTE));
1619 assert(can_opener_afford_feerate(peer->channel,
1620 channel_feerate(peer->channel,
1621 LOCAL)));
1622 }
1623
1624 if (!fromwire_commitment_signed(tmpctx, msg,
1625 &channel_id, &commit_sig.s, &raw_sigs))
1626 peer_failed_warn(peer->pps, &peer->channel_id,
1627 "Bad commit_sig %s", tal_hex(msg, msg));
1628 /* SIGHASH_ALL is implied. */
1629 commit_sig.sighash_type = SIGHASH_ALL;
1630 htlc_sigs = unraw_sigs(tmpctx, raw_sigs,
1631 channel_has(peer->channel, OPT_ANCHOR_OUTPUTS));
1632
1633 txs =
1634 channel_txs(tmpctx, &htlc_map, NULL,
1635 &funding_wscript, peer->channel, &peer->next_local_per_commit,
1636 peer->next_index[LOCAL], LOCAL);
1637
1638 /* Set the commit_sig on the commitment tx psbt */
1639 if (!psbt_input_set_signature(txs[0]->psbt, 0,
1640 &peer->channel->funding_pubkey[REMOTE],
1641 &commit_sig))

Callers 1

peer_inFunction · 0.85

Calls 15

channel_rcvd_commitFunction · 0.85
peer_failed_warnFunction · 0.85
channel_feerateFunction · 0.85
tal_hexFunction · 0.85
unraw_sigsFunction · 0.85
channel_txsFunction · 0.85
psbt_input_set_signatureFunction · 0.85
derive_simple_keyFunction · 0.85
check_tx_sigFunction · 0.85
dump_htlcsFunction · 0.85

Tested by

no test coverage detected