forward_to is where we're actually sending it (or NULL), and * forward_scid is where they asked to send it (or NULL). */
| 854 | /* forward_to is where we're actually sending it (or NULL), and |
| 855 | * forward_scid is where they asked to send it (or NULL). */ |
| 856 | static void forward_htlc(struct htlc_in *hin, |
| 857 | u32 cltv_expiry, |
| 858 | struct amount_msat amt_to_forward, |
| 859 | u32 outgoing_cltv_value, |
| 860 | const struct short_channel_id *forward_scid, |
| 861 | const struct channel_id *forward_to, |
| 862 | const u8 next_onion[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)], |
| 863 | const struct pubkey *next_path_key, |
| 864 | const struct tlv_field *extra_tlvs) |
| 865 | { |
| 866 | const u8 *failmsg; |
| 867 | struct lightningd *ld = hin->key.channel->peer->ld; |
| 868 | struct channel *next; |
| 869 | struct htlc_out *hout = NULL; |
| 870 | |
| 871 | if (forward_to) { |
| 872 | next = channel_by_cid(ld, forward_to); |
| 873 | /* Update this to where we're actually trying to send. */ |
| 874 | if (next) { |
| 875 | struct short_channel_id next_scid; |
| 876 | next_scid = channel_scid_or_local_alias(next); |
| 877 | forward_scid = tal_dup(tmpctx, struct short_channel_id, |
| 878 | &next_scid); |
| 879 | } |
| 880 | } else |
| 881 | next = NULL; |
| 882 | |
| 883 | /* Unknown peer, or peer not ready. */ |
| 884 | if (!next || !channel_state_can_add_htlc(next->state)) { |
| 885 | local_fail_in_htlc(hin, take(towire_unknown_next_peer(NULL))); |
| 886 | wallet_forwarded_payment_add(hin->key.channel->peer->ld->wallet, |
| 887 | hin, FORWARD_STYLE_TLV, |
| 888 | forward_scid, NULL, |
| 889 | FORWARD_LOCAL_FAILED, |
| 890 | WIRE_UNKNOWN_NEXT_PEER); |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | /* BOLT #7: |
| 895 | * |
| 896 | * The origin node: |
| 897 | * - SHOULD accept HTLCs that pay a fee equal to or greater than: |
| 898 | * - fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 ) |
| 899 | */ |
| 900 | if (!check_fwd_amount(hin, amt_to_forward, hin->msat, |
| 901 | next->feerate_base, |
| 902 | next->feerate_ppm)) { |
| 903 | /* BOLT #7: |
| 904 | * - If it creates a new `channel_update` with updated channel parameters: |
| 905 | * - SHOULD keep accepting the previous channel parameters for 10 minutes |
| 906 | */ |
| 907 | if (!timemono_before(time_mono(), next->old_feerate_timeout) |
| 908 | || !check_fwd_amount(hin, amt_to_forward, hin->msat, |
| 909 | next->old_feerate_base, |
| 910 | next->old_feerate_ppm)) { |
| 911 | failmsg = towire_fee_insufficient(tmpctx, hin->msat, |
| 912 | channel_update_for_error(tmpctx, |
| 913 | hin, next)); |
no test coverage detected