| 427 | } |
| 428 | |
| 429 | void fulfill_htlc(struct htlc_in *hin, const struct preimage *preimage) |
| 430 | { |
| 431 | u8 *msg; |
| 432 | struct channel *channel = hin->key.channel; |
| 433 | |
| 434 | if (hin->hstate != RCVD_ADD_ACK_REVOCATION) { |
| 435 | log_debug(channel->log, |
| 436 | "HTLC fulfilled, but not ready any more (%s).", |
| 437 | htlc_state_name(hin->hstate)); |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | hin->preimage = tal_dup(hin, struct preimage, preimage); |
| 442 | |
| 443 | /* We update state now to signal it's in progress, for persistence. */ |
| 444 | htlc_in_update_state(channel, hin, SENT_REMOVE_HTLC); |
| 445 | |
| 446 | htlc_in_check(hin, __func__); |
| 447 | |
| 448 | /* Update channel stats */ |
| 449 | channel_stats_incr_in_fulfilled(channel, hin->msat); |
| 450 | |
| 451 | /* No owner? We'll either send to channeld in peer_htlcs, or |
| 452 | * onchaind in onchaind_tell_fulfill. */ |
| 453 | if (!channel->owner) { |
| 454 | log_debug(channel->log, "HTLC fulfilled, but no owner."); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | if (streq(channel->owner->name, "onchaind")) { |
| 459 | msg = towire_onchaind_known_preimage(hin, preimage); |
| 460 | } else { |
| 461 | struct fulfilled_htlc fulfilled_htlc; |
| 462 | fulfilled_htlc.id = hin->key.id; |
| 463 | fulfilled_htlc.payment_preimage = *preimage; |
| 464 | msg = towire_channeld_fulfill_htlc(hin, &fulfilled_htlc); |
| 465 | } |
| 466 | subd_send_msg(channel->owner, take(msg)); |
| 467 | } |
| 468 | |
| 469 | /* HTLC-specific wrappers */ |
| 470 | static void htlc_set_fulfill_htlc(struct htlc_in *hin, |
no test coverage detected