| 134 | } |
| 135 | |
| 136 | void htlc_set_add_(struct lightningd *ld, |
| 137 | struct logger *log, |
| 138 | struct amount_msat msat, |
| 139 | struct amount_msat total_msat, |
| 140 | const struct amount_msat *invoice_msat_override, |
| 141 | const struct sha256 *payment_hash, |
| 142 | const struct secret *payment_secret, |
| 143 | void (*fail)(void *, const u8 *), |
| 144 | void (*succeeded)(void *, const struct preimage *), |
| 145 | void *arg) |
| 146 | { |
| 147 | struct incoming_payment *inpay; |
| 148 | struct htlc_set *set; |
| 149 | const struct invoice_details *details; |
| 150 | const char *err; |
| 151 | |
| 152 | /* BOLT #4: |
| 153 | * The final node: |
| 154 | * - MUST fail the HTLC if dictated by Requirements under |
| 155 | * [Failure Messages](#failure-messages) |
| 156 | * - Note: "amount paid" specified there is the `total_msat` field. |
| 157 | */ |
| 158 | details = invoice_check_payment(tmpctx, ld, payment_hash, total_msat, |
| 159 | invoice_msat_override, payment_secret, |
| 160 | &err); |
| 161 | if (!details) { |
| 162 | log_debug(log, "payment failed: %s", err); |
| 163 | fail(arg, take(failmsg_incorrect_or_unknown(NULL, ld, msat))); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | /* If we insist on a payment secret, it must always have it */ |
| 168 | if (feature_is_set(details->features, COMPULSORY_FEATURE(OPT_PAYMENT_SECRET)) |
| 169 | && !payment_secret) { |
| 170 | log_debug(log, |
| 171 | "Missing payment_secret, but required for %s", |
| 172 | fmt_sha256(tmpctx, payment_hash)); |
| 173 | fail(arg, take(failmsg_incorrect_or_unknown(NULL, ld, msat))); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | /* BOLT #4: |
| 178 | * - otherwise, if it supports `basic_mpp`: |
| 179 | * - MUST add it to the HTLC set corresponding to that `payment_hash`. |
| 180 | */ |
| 181 | inpay = new_inpay(arg, log, msat, fail, succeeded, arg); |
| 182 | set = htlc_set_map_get(ld->htlc_sets, payment_hash); |
| 183 | if (!set) |
| 184 | set = new_htlc_set(ld, inpay, payment_hash, total_msat); |
| 185 | else { |
| 186 | /* BOLT #4: |
| 187 | * |
| 188 | * otherwise, if it supports `basic_mpp`: |
| 189 | * ... |
| 190 | * - otherwise, if the total `amt_to_forward` of this HTLC set is |
| 191 | * less than `total_msat`: |
| 192 | * ... |
| 193 | * - MUST require `payment_secret` for all HTLCs in the set. |
nothing calls this directly
no test coverage detected