| 383 | } |
| 384 | |
| 385 | void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage) |
| 386 | { |
| 387 | u8 *msg; |
| 388 | struct channel *channel = hin->key.channel; |
| 389 | |
| 390 | if (hin->hstate != RCVD_ADD_ACK_REVOCATION) { |
| 391 | log_debug(channel->log, |
| 392 | "HTLC fulfilled, but not ready any more (%s).", |
| 393 | htlc_state_name(hin->hstate)); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | hin->preimage = tal_dup(hin, struct preimage, preimage); |
| 398 | |
| 399 | /* We update state now to signal it's in progress, for persistence. */ |
| 400 | htlc_in_update_state(channel, hin, SENT_REMOVE_HTLC); |
| 401 | |
| 402 | htlc_in_check(hin, __func__); |
| 403 | |
| 404 | /* Update channel stats */ |
| 405 | channel_stats_incr_in_fulfilled(channel, hin->msat); |
| 406 | |
| 407 | /* No owner? We'll either send to channeld in peer_htlcs, or |
| 408 | * onchaind in onchaind_tell_fulfill. */ |
| 409 | if (!channel->owner) { |
| 410 | log_debug(channel->log, "HTLC fulfilled, but no owner."); |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | if (streq(channel->owner->name, "onchaind")) { |
| 415 | msg = towire_onchaind_known_preimage(hin, preimage); |
| 416 | } else { |
| 417 | struct fulfilled_htlc fulfilled_htlc; |
| 418 | fulfilled_htlc.id = hin->key.id; |
| 419 | fulfilled_htlc.payment_preimage = *preimage; |
| 420 | msg = towire_channeld_fulfill_htlc(hin, &fulfilled_htlc); |
| 421 | } |
| 422 | subd_send_msg(channel->owner, take(msg)); |
| 423 | } |
| 424 | |
| 425 | /* HTLC-specific wrappers */ |
| 426 | static void htlc_set_fulfill_htlc(struct htlc_in *hin, |
no test coverage detected