| 1818 | } |
| 1819 | |
| 1820 | static size_t resolve_our_htlc_ourcommit(struct tracked_output *out, |
| 1821 | const size_t *matches, |
| 1822 | const struct htlc_stub *htlcs, |
| 1823 | u8 **htlc_scripts) |
| 1824 | { |
| 1825 | struct bitcoin_tx *tx = NULL; |
| 1826 | size_t i; |
| 1827 | struct amount_sat fee; |
| 1828 | struct amount_msat htlc_amount; |
| 1829 | const u8 *msg, *htlc_wscript; |
| 1830 | |
| 1831 | if (!amount_sat_to_msat(&htlc_amount, out->sat)) |
| 1832 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1833 | "Overflow in our_htlc output %s", |
| 1834 | fmt_amount_sat(tmpctx, out->sat)); |
| 1835 | |
| 1836 | assert(tal_count(matches)); |
| 1837 | |
| 1838 | /* These htlcs are all possibilities, but signature will only match |
| 1839 | * one with the correct cltv: check which that is. */ |
| 1840 | for (i = 0; i < tal_count(matches); i++) { |
| 1841 | /* Skip over duplicate HTLCs, since we only need one. */ |
| 1842 | if (i > 0 |
| 1843 | && (htlcs[matches[i]].cltv_expiry |
| 1844 | == htlcs[matches[i-1]].cltv_expiry)) |
| 1845 | continue; |
| 1846 | |
| 1847 | /* BOLT #5: |
| 1848 | * |
| 1849 | * A node: |
| 1850 | * ... |
| 1851 | * - if the commitment transaction HTLC output has *timed out* |
| 1852 | * and hasn't been *resolved*: |
| 1853 | * - MUST *resolve* the output by spending it using the |
| 1854 | * HTLC-timeout transaction. |
| 1855 | */ |
| 1856 | tx = htlc_timeout_tx(tmpctx, chainparams, |
| 1857 | &out->outpoint, |
| 1858 | htlc_scripts[matches[i]], htlc_amount, |
| 1859 | htlcs[matches[i]].cltv_expiry, |
| 1860 | to_self_delay[LOCAL], 0, keyset, |
| 1861 | option_anchor_outputs, |
| 1862 | option_anchors_zero_fee_htlc_tx); |
| 1863 | |
| 1864 | if (set_htlc_timeout_fee(tx, out->remote_htlc_sig, |
| 1865 | htlc_scripts[matches[i]])) |
| 1866 | break; |
| 1867 | } |
| 1868 | |
| 1869 | /* Since there's been trouble with this before, we go to some length |
| 1870 | * to give details here! */ |
| 1871 | if (i == tal_count(matches)) { |
| 1872 | char *cltvs, *wscripts; |
| 1873 | |
| 1874 | cltvs = tal_fmt(tmpctx, "%u", htlcs[matches[0]].cltv_expiry); |
| 1875 | wscripts = tal_hex(tmpctx, htlc_scripts[matches[0]]); |
| 1876 | |
| 1877 | for (i = 1; i < tal_count(matches); i++) { |