| 1731 | } |
| 1732 | |
| 1733 | static 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, |
nothing calls this directly
no test coverage detected