MCPcopy Create free account
hub / github.com/ElementsProject/lightning / forward_htlc

Function forward_htlc

lightningd/peer_htlcs.c:675–803  ·  view source on GitHub ↗

forward_to is where we're actually sending it (or NULL), and * forward_scid is where they asked to send it (or NULL). */

Source from the content-addressed store, hash-verified

673/* forward_to is where we're actually sending it (or NULL), and
674 * forward_scid is where they asked to send it (or NULL). */
675static void forward_htlc(struct htlc_in *hin,
676 u32 cltv_expiry,
677 struct amount_msat amt_to_forward,
678 u32 outgoing_cltv_value,
679 const struct short_channel_id *forward_scid,
680 const struct channel_id *forward_to,
681 const u8 next_onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)],
682 const struct pubkey *next_blinding)
683{
684 const u8 *failmsg;
685 struct lightningd *ld = hin->key.channel->peer->ld;
686 struct channel *next;
687 struct htlc_out *hout = NULL;
688
689 if (forward_to) {
690 next = channel_by_cid(ld, forward_to);
691 /* Update this to where we're actually trying to send. */
692 if (next)
693 forward_scid = channel_scid_or_local_alias(next);
694 }else
695 next = NULL;
696
697 /* Unknown peer, or peer not ready. */
698 if (!next || !channel_active(next)) {
699 local_fail_in_htlc(hin, take(towire_unknown_next_peer(NULL)));
700 wallet_forwarded_payment_add(hin->key.channel->peer->ld->wallet,
701 hin, FORWARD_STYLE_TLV,
702 forward_scid, NULL,
703 FORWARD_LOCAL_FAILED,
704 WIRE_UNKNOWN_NEXT_PEER);
705 return;
706 }
707
708 /* BOLT #7:
709 *
710 * The origin node:
711 * - SHOULD accept HTLCs that pay a fee equal to or greater than:
712 * - fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 )
713 */
714 if (!check_fwd_amount(hin, amt_to_forward, hin->msat,
715 next->feerate_base,
716 next->feerate_ppm)) {
717 /* BOLT #7:
718 * - If it creates a new `channel_update` with updated channel parameters:
719 * - SHOULD keep accepting the previous channel parameters for 10 minutes
720 */
721 if (!time_before(time_now(), next->old_feerate_timeout)
722 || !check_fwd_amount(hin, amt_to_forward, hin->msat,
723 next->old_feerate_base,
724 next->old_feerate_ppm)) {
725 failmsg = towire_fee_insufficient(tmpctx, hin->msat,
726 get_channel_update(next));
727 goto fail;
728 }
729 log_info(hin->key.channel->log,
730 "Allowing payment using older feerate");
731 }
732

Callers 1

htlc_accepted_hook_finalFunction · 0.85

Calls 15

channel_by_cidFunction · 0.85
channel_activeFunction · 0.85
local_fail_in_htlcFunction · 0.85
towire_unknown_next_peerFunction · 0.85
check_fwd_amountFunction · 0.85
time_beforeFunction · 0.85
time_nowFunction · 0.85
towire_fee_insufficientFunction · 0.85
log_infoClass · 0.85
amount_msat_greaterFunction · 0.85

Tested by

no test coverage detected