| 62 | } |
| 63 | |
| 64 | static bool handle_blinded_forward(const tal_t *ctx, |
| 65 | struct onion_payload *p, |
| 66 | struct amount_msat amount_in, |
| 67 | u32 cltv_expiry, |
| 68 | const struct tlv_payload *tlv, |
| 69 | const struct tlv_encrypted_data_tlv *enc, |
| 70 | u64 *failtlvtype, |
| 71 | const char **explanation) |
| 72 | { |
| 73 | u64 amt = amount_in.millisatoshis; /* Raw: allowed to wrap */ |
| 74 | |
| 75 | if (!check_nonfinal_tlv(tlv, failtlvtype)) { |
| 76 | if (explanation) |
| 77 | *explanation = tal_fmt(ctx, "unexpected tlv type %"PRIu64, *failtlvtype); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | /* BOLT #4: |
| 82 | * - If it is not the final node: |
| 83 | *... |
| 84 | * - MUST return an error if `encrypted_recipient_data` does not |
| 85 | * contain either `short_channel_id` or `next_node_id`. |
| 86 | */ |
| 87 | if (!enc->short_channel_id && !enc->next_node_id) { |
| 88 | if (explanation) |
| 89 | *explanation = tal_fmt(ctx, "neither short_channel_id nor next_node_id present"); |
| 90 | *failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA; |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | if (enc->short_channel_id) { |
| 95 | p->forward_channel = tal_dup(p, struct short_channel_id, |
| 96 | enc->short_channel_id); |
| 97 | p->forward_node_id = NULL; |
| 98 | } else { |
| 99 | p->forward_channel = NULL; |
| 100 | p->forward_node_id = tal_dup(p, struct pubkey, |
| 101 | enc->next_node_id); |
| 102 | } |
| 103 | |
| 104 | p->total_msat = NULL; |
| 105 | |
| 106 | /* BOLT #4: |
| 107 | * - If it is not the final node: |
| 108 | *... |
| 109 | * - MUST return an error if `encrypted_recipient_data` does not |
| 110 | * contain `payment_relay`. |
| 111 | */ |
| 112 | if (!enc->payment_relay) { |
| 113 | if (explanation) |
| 114 | *explanation = tal_fmt(ctx, "missing payment_relay"); |
| 115 | *failtlvtype = TLV_PAYLOAD_ENCRYPTED_RECIPIENT_DATA; |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | /* FIXME: Put these formulae in BOLT 4! */ |
| 120 | /* amt_to_forward = ceil((amount_msat - fee_base_msat) * 1000000 / (1000000 + fee_proportional_millionths)) */ |
| 121 | /* If these values are crap, that's OK: the HTLC will fail. */ |
no test coverage detected