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

Function funding_depth_cb

lightningd/peer_control.c:1733–1846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1731}
1732
1733static enum watch_result funding_depth_cb(struct lightningd *ld,
1734 struct channel *channel,
1735 const struct bitcoin_txid *txid,
1736 const struct bitcoin_tx *tx,
1737 unsigned int depth)
1738{
1739 const char *txidstr;
1740 struct short_channel_id scid;
1741
1742 /* Sanity check, but we'll have to make an exception
1743 * for stub channels(1x1x1) */
1744 if (!check_funding_tx(tx, channel) && !is_stub_scid(channel->scid)) {
1745 channel_internal_error(channel, "Bad tx %s: %s",
1746 type_to_string(tmpctx,
1747 struct bitcoin_txid, txid),
1748 type_to_string(tmpctx,
1749 struct bitcoin_tx, tx));
1750 return DELETE_WATCH;
1751 }
1752
1753 txidstr = type_to_string(tmpctx, struct bitcoin_txid, txid);
1754 log_debug(channel->log, "Funding tx %s depth %u of %u",
1755 txidstr, depth, channel->minimum_depth);
1756 tal_free(txidstr);
1757
1758 bool min_depth_reached = depth >= channel->minimum_depth;
1759
1760 /* Reorg can change scid, so always update/save scid when possible (depth=0
1761 * means the stale block with our funding tx was removed) */
1762 if ((min_depth_reached && !channel->scid) || (depth && channel->scid)) {
1763 struct txlocator *loc;
1764 struct channel_inflight *inf;
1765
1766 /* Update the channel's info to the correct tx, if needed to
1767 * It's possible an 'inflight' has reached depth */
1768 if (!list_empty(&channel->inflights)) {
1769 inf = channel_inflight_find(channel, txid);
1770 if (!inf) {
1771 channel_fail_permanent(channel,
1772 REASON_LOCAL,
1773 "Txid %s for channel"
1774 " not found in inflights. (peer %s)",
1775 type_to_string(tmpctx,
1776 struct bitcoin_txid,
1777 txid),
1778 type_to_string(tmpctx,
1779 struct node_id,
1780 &channel->peer->id));
1781 return DELETE_WATCH;
1782 }
1783 update_channel_from_inflight(ld, channel, inf);
1784 }
1785
1786 wallet_annotate_txout(ld->wallet, &channel->funding,
1787 TX_CHANNEL_FUNDING, channel->dbid);
1788 loc = wallet_transaction_locate(tmpctx, ld->wallet, txid);
1789 if (!mk_short_channel_id(&scid,
1790 loc->blkheight, loc->index,

Callers

nothing calls this directly

Calls 15

check_funding_txFunction · 0.85
is_stub_scidFunction · 0.85
tal_freeFunction · 0.85
mk_short_channel_idFunction · 0.85
short_channel_id_to_strFunction · 0.85
channel_internal_errorFunction · 0.70
channel_inflight_findFunction · 0.70
channel_fail_permanentFunction · 0.70
subd_send_msgFunction · 0.70
channel_tell_depthFunction · 0.70

Tested by

no test coverage detected