| 95 | } |
| 96 | |
| 97 | void htlc_set_add(struct lightningd *ld, |
| 98 | struct htlc_in *hin, |
| 99 | struct amount_msat total_msat, |
| 100 | const struct secret *payment_secret) |
| 101 | { |
| 102 | struct htlc_set *set; |
| 103 | const struct invoice_details *details; |
| 104 | |
| 105 | /* BOLT #4: |
| 106 | * The final node: |
| 107 | * - MUST fail the HTLC if dictated by Requirements under |
| 108 | * [Failure Messages](#failure-messages) |
| 109 | * - Note: "amount paid" specified there is the `total_msat` field. |
| 110 | */ |
| 111 | details = invoice_check_payment(tmpctx, ld, &hin->payment_hash, |
| 112 | total_msat, payment_secret); |
| 113 | if (!details) { |
| 114 | local_fail_in_htlc(hin, |
| 115 | take(failmsg_incorrect_or_unknown(NULL, ld, hin))); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | /* If we insist on a payment secret, it must always have it */ |
| 120 | if (feature_is_set(details->features, COMPULSORY_FEATURE(OPT_PAYMENT_SECRET)) |
| 121 | && !payment_secret) { |
| 122 | log_debug(ld->log, "Missing payment_secret, but required for %s", |
| 123 | type_to_string(tmpctx, struct sha256, |
| 124 | &hin->payment_hash)); |
| 125 | local_fail_in_htlc(hin, |
| 126 | take(failmsg_incorrect_or_unknown(NULL, ld, hin))); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | /* BOLT #4: |
| 131 | * - otherwise, if it supports `basic_mpp`: |
| 132 | * - MUST add it to the HTLC set corresponding to that `payment_hash`. |
| 133 | */ |
| 134 | set = htlc_set_map_get(&ld->htlc_sets, &hin->payment_hash); |
| 135 | if (!set) |
| 136 | set = new_htlc_set(ld, hin, total_msat); |
| 137 | else { |
| 138 | /* BOLT #4: |
| 139 | * |
| 140 | * if it supports `basic_mpp`: |
| 141 | * ... |
| 142 | * - otherwise, if the total `amount_msat` of this HTLC set is |
| 143 | * less than `total_msat`: |
| 144 | * ... |
| 145 | * - MUST require `payment_secret` for all HTLCs in the set. |
| 146 | */ |
| 147 | /* We check this now, since we want to fail with this as soon |
| 148 | * as possible, to avoid other probing attacks. */ |
| 149 | if (!payment_secret) { |
| 150 | local_fail_in_htlc(hin, take(failmsg_incorrect_or_unknown(NULL, ld, hin))); |
| 151 | return; |
| 152 | } |
| 153 | tal_arr_expand(&set->htlcs, hin); |
| 154 | } |
no test coverage detected