| 222 | } |
| 223 | |
| 224 | static void fail_in_htlc(struct htlc_in *hin, |
| 225 | const struct onionreply *failonion TAKES) |
| 226 | { |
| 227 | struct failed_htlc *failed_htlc; |
| 228 | assert(!hin->preimage); |
| 229 | |
| 230 | hin->failonion = dup_onionreply(hin, failonion); |
| 231 | |
| 232 | /* We update state now to signal it's in progress, for persistence. */ |
| 233 | htlc_in_update_state(hin->key.channel, hin, SENT_REMOVE_HTLC); |
| 234 | htlc_in_check(hin, __func__); |
| 235 | |
| 236 | failed_htlc = mk_failed_htlc(tmpctx, hin, hin->failonion); |
| 237 | |
| 238 | bool we_filled = false; |
| 239 | wallet_htlc_update(hin->key.channel->peer->ld->wallet, |
| 240 | hin->dbid, hin->hstate, |
| 241 | hin->preimage, |
| 242 | max_unsigned(hin->key.channel->next_index[LOCAL], |
| 243 | hin->key.channel->next_index[REMOTE]), |
| 244 | hin->badonion, |
| 245 | hin->failonion, NULL, &we_filled, |
| 246 | hin->key.id, |
| 247 | hin->key.channel, |
| 248 | REMOTE, |
| 249 | &hin->payment_hash, |
| 250 | hin->cltv_expiry, |
| 251 | hin->msat); |
| 252 | |
| 253 | tell_channeld_htlc_failed(hin, failed_htlc); |
| 254 | } |
| 255 | |
| 256 | /* Immediately fail HTLC with a BADONION code */ |
| 257 | static void local_fail_in_htlc_badonion(struct htlc_in *hin, |
no test coverage detected