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

Function init_reply

onchaind/onchaind.c:1721–1766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1719}
1720
1721static struct htlcs_info *init_reply(const tal_t *ctx, const char *what)
1722{
1723 struct htlcs_info *htlcs_info = tal(ctx, struct htlcs_info);
1724 const u8 *msg;
1725 struct htlc_with_tells *htlcs;
1726
1727 /* commit_num is 0 for mutual close, but we don't care about HTLCs
1728 * then anyway. */
1729
1730 /* Send init_reply first, so billboard gets credited to ONCHAIND */
1731 wire_sync_write(REQ_FD,
1732 take(towire_onchaind_init_reply(NULL, commit_num)));
1733
1734 peer_billboard(true, what);
1735
1736 /* Read in htlcs (ignoring everything else for now) */
1737 msg = queue_until_msg(tmpctx, WIRE_ONCHAIND_HTLCS);
1738 if (!fromwire_onchaind_htlcs(htlcs_info, msg,
1739 &htlcs_info->htlcs,
1740 &htlcs_info->tell_if_missing,
1741 &htlcs_info->tell_immediately))
1742 master_badmsg(WIRE_ONCHAIND_HTLCS, msg);
1743
1744 /* One convenient structure, so we sort them together! */
1745 htlcs = tal_arr(tmpctx, struct htlc_with_tells, tal_count(htlcs_info->htlcs));
1746 for (size_t i = 0; i < tal_count(htlcs); i++) {
1747 htlcs[i].htlc = htlcs_info->htlcs[i];
1748 htlcs[i].tell_if_missing = htlcs_info->tell_if_missing[i];
1749 htlcs[i].tell_immediately = htlcs_info->tell_immediately[i];
1750 }
1751
1752 /* Sort by CLTV, so matches are in CLTV order (and easy to skip dups) */
1753 asort(htlcs, tal_count(htlcs), cmp_htlc_with_tells_cltv, NULL);
1754
1755 /* Now put them back (prev were allocated off tmpctx) */
1756 htlcs_info->htlcs = tal_arr(htlcs_info, struct htlc_stub, tal_count(htlcs));
1757 htlcs_info->tell_if_missing = tal_arr(htlcs_info, bool, tal_count(htlcs));
1758 htlcs_info->tell_immediately = tal_arr(htlcs_info, bool, tal_count(htlcs));
1759 for (size_t i = 0; i < tal_count(htlcs); i++) {
1760 htlcs_info->htlcs[i] = htlcs[i].htlc;
1761 htlcs_info->tell_if_missing[i] = htlcs[i].tell_if_missing;
1762 htlcs_info->tell_immediately[i] = htlcs[i].tell_immediately;
1763 }
1764
1765 return htlcs_info;
1766}
1767
1768static void handle_mutual_close(struct tracked_output **outs,
1769 const struct tx_parts *tx)

Callers 5

handle_mutual_closeFunction · 0.85
handle_our_unilateralFunction · 0.85
handle_their_cheatFunction · 0.85
handle_their_unilateralFunction · 0.85

Calls 6

queue_until_msgFunction · 0.85
fromwire_onchaind_htlcsFunction · 0.85
wire_sync_writeFunction · 0.50
peer_billboardFunction · 0.50
master_badmsgFunction · 0.50

Tested by

no test coverage detected