| 315 | } |
| 316 | |
| 317 | void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage) |
| 318 | { |
| 319 | u8 *msg; |
| 320 | struct channel *channel = hin->key.channel; |
| 321 | struct wallet *wallet = channel->peer->ld->wallet; |
| 322 | |
| 323 | if (hin->hstate != RCVD_ADD_ACK_REVOCATION) { |
| 324 | log_debug(channel->log, |
| 325 | "HTLC fulfilled, but not ready any more (%s).", |
| 326 | htlc_state_name(hin->hstate)); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | hin->preimage = tal_dup(hin, struct preimage, preimage); |
| 331 | |
| 332 | /* We update state now to signal it's in progress, for persistence. */ |
| 333 | htlc_in_update_state(channel, hin, SENT_REMOVE_HTLC); |
| 334 | |
| 335 | htlc_in_check(hin, __func__); |
| 336 | |
| 337 | /* Update channel stats */ |
| 338 | wallet_channel_stats_incr_in_fulfilled(wallet, |
| 339 | channel->dbid, |
| 340 | hin->msat); |
| 341 | |
| 342 | /* No owner? We'll either send to channeld in peer_htlcs, or |
| 343 | * onchaind in onchaind_tell_fulfill. */ |
| 344 | if (!channel->owner) { |
| 345 | log_debug(channel->log, "HTLC fulfilled, but no owner."); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | if (channel_on_chain(channel)) { |
| 350 | msg = towire_onchaind_known_preimage(hin, preimage); |
| 351 | } else { |
| 352 | struct fulfilled_htlc fulfilled_htlc; |
| 353 | fulfilled_htlc.id = hin->key.id; |
| 354 | fulfilled_htlc.payment_preimage = *preimage; |
| 355 | msg = towire_channeld_fulfill_htlc(hin, &fulfilled_htlc); |
| 356 | } |
| 357 | subd_send_msg(channel->owner, take(msg)); |
| 358 | } |
| 359 | |
| 360 | static void handle_localpay(struct htlc_in *hin, |
| 361 | struct amount_msat amt_to_forward, |
no test coverage detected