forward_to is where we're actually sending it (or NULL), and * forward_scid is where they asked to send it (or NULL). */
| 810 | /* forward_to is where we're actually sending it (or NULL), and |
| 811 | * forward_scid is where they asked to send it (or NULL). */ |
| 812 | static void forward_htlc(struct htlc_in *hin, |
| 813 | u32 cltv_expiry, |
| 814 | struct amount_msat amt_to_forward, |
| 815 | u32 outgoing_cltv_value, |
| 816 | const struct short_channel_id *forward_scid, |
| 817 | const struct channel_id *forward_to, |
| 818 | const u8 next_onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)], |
| 819 | const struct pubkey *next_path_key, |
| 820 | const struct tlv_field *extra_tlvs) |
| 821 | { |
| 822 | const u8 *failmsg; |
| 823 | struct lightningd *ld = hin->key.channel->peer->ld; |
| 824 | struct channel *next; |
| 825 | struct htlc_out *hout = NULL; |
| 826 | |
| 827 | if (forward_to) { |
| 828 | next = channel_by_cid(ld, forward_to); |
| 829 | /* Update this to where we're actually trying to send. */ |
| 830 | if (next) { |
| 831 | struct short_channel_id next_scid; |
| 832 | next_scid = channel_scid_or_local_alias(next); |
| 833 | forward_scid = tal_dup(tmpctx, struct short_channel_id, |
| 834 | &next_scid); |
| 835 | } |
| 836 | } else |
| 837 | next = NULL; |
| 838 | |
| 839 | /* Unknown peer, or peer not ready. */ |
| 840 | if (!next || !channel_state_can_add_htlc(next->state)) { |
| 841 | local_fail_in_htlc(hin, take(towire_unknown_next_peer(NULL))); |
| 842 | wallet_forwarded_payment_add(hin->key.channel->peer->ld->wallet, |
| 843 | hin, FORWARD_STYLE_TLV, |
| 844 | forward_scid, NULL, |
| 845 | FORWARD_LOCAL_FAILED, |
| 846 | WIRE_UNKNOWN_NEXT_PEER); |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | /* BOLT #7: |
| 851 | * |
| 852 | * The origin node: |
| 853 | * - SHOULD accept HTLCs that pay a fee equal to or greater than: |
| 854 | * - fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 ) |
| 855 | */ |
| 856 | if (!check_fwd_amount(hin, amt_to_forward, hin->msat, |
| 857 | next->feerate_base, |
| 858 | next->feerate_ppm)) { |
| 859 | /* BOLT #7: |
| 860 | * - If it creates a new `channel_update` with updated channel parameters: |
| 861 | * - SHOULD keep accepting the previous channel parameters for 10 minutes |
| 862 | */ |
| 863 | if (!timemono_before(time_mono(), next->old_feerate_timeout) |
| 864 | || !check_fwd_amount(hin, amt_to_forward, hin->msat, |
| 865 | next->old_feerate_base, |
| 866 | next->old_feerate_ppm)) { |
| 867 | failmsg = towire_fee_insufficient(tmpctx, hin->msat, |
| 868 | channel_update_for_error(tmpctx, |
| 869 | hin, next)); |
no test coverage detected