Browse Source

onion: Pass the position and type of the failing TLV type out

We'll need this when returning an error to the sender.
travis-debug
Christian Decker 5 years ago
parent
commit
959687bf6d
  1. 9
      common/onion.c
  2. 4
      common/onion.h
  3. 6
      lightningd/peer_htlcs.c
  4. 7
      wallet/test/run-wallet.c

9
common/onion.c

@ -205,7 +205,9 @@ size_t onion_payload_length(const u8 *raw_payload, size_t len,
}
struct onion_payload *onion_decode(const tal_t *ctx,
const struct route_step *rs)
const struct route_step *rs,
u64 *failtlvtype,
size_t *failtlvpos)
{
struct onion_payload *p = tal(ctx, struct onion_payload);
const u8 *cursor = rs->raw_payload;
@ -245,9 +247,10 @@ struct onion_payload *onion_decode(const tal_t *ctx,
if (!fromwire_tlv_payload(&cursor, &max, tlv))
goto fail;
if (!tlv_payload_is_valid(tlv, failtlvpos))
if (!tlv_payload_is_valid(tlv, failtlvpos)) {
*failtlvtype = tlv->fields[*failtlvpos].numtype;
goto fail;
}
/* BOLT #4:
*

4
common/onion.h

@ -59,6 +59,8 @@ size_t onion_payload_length(const u8 *raw_payload, size_t len,
* If the payload is not valid, returns NULL.
*/
struct onion_payload *onion_decode(const tal_t *ctx,
const struct route_step *rs);
const struct route_step *rs,
u64 *failtlvtype,
size_t *failtlvpos);
#endif /* LIGHTNING_COMMON_ONION_H */

6
lightningd/peer_htlcs.c

@ -780,6 +780,8 @@ struct htlc_accepted_hook_payload {
struct channel *channel;
struct lightningd *ld;
u8 *next_onion;
u64 failtlvtype;
size_t failtlvpos;
};
/* The possible return value types that a plugin may return for the
@ -1116,7 +1118,9 @@ static bool peer_accepted_htlc(const tal_t *ctx,
hook_payload = tal(hin, struct htlc_accepted_hook_payload);
hook_payload->route_step = tal_steal(hook_payload, rs);
hook_payload->payload = onion_decode(hook_payload, rs);
hook_payload->payload = onion_decode(hook_payload, rs,
&hook_payload->failtlvtype,
&hook_payload->failtlvpos);
hook_payload->ld = ld;
hook_payload->hin = hin;
hook_payload->channel = channel;

7
wallet/test/run-wallet.c

@ -411,7 +411,9 @@ enum watch_result onchaind_funding_spent(struct channel *channel UNNEEDED,
{ fprintf(stderr, "onchaind_funding_spent called!\n"); abort(); }
/* Generated stub for onion_decode */
struct onion_payload *onion_decode(const tal_t *ctx UNNEEDED,
const struct route_step *rs UNNEEDED)
const struct route_step *rs UNNEEDED,
u64 *failtlvtype UNNEEDED,
size_t *failtlvpos UNNEEDED)
{ fprintf(stderr, "onion_decode called!\n"); abort(); }
/* Generated stub for onion_type_name */
const char *onion_type_name(int e UNNEEDED)
@ -654,6 +656,9 @@ u8 *towire_incorrect_cltv_expiry(const tal_t *ctx UNNEEDED, u32 cltv_expiry UNNE
/* Generated stub for towire_incorrect_or_unknown_payment_details */
u8 *towire_incorrect_or_unknown_payment_details(const tal_t *ctx UNNEEDED, struct amount_msat htlc_msat UNNEEDED, u32 height UNNEEDED)
{ fprintf(stderr, "towire_incorrect_or_unknown_payment_details called!\n"); abort(); }
/* Generated stub for towire_invalid_onion_payload */
u8 *towire_invalid_onion_payload(const tal_t *ctx UNNEEDED, varint type UNNEEDED, u16 offset UNNEEDED)
{ fprintf(stderr, "towire_invalid_onion_payload called!\n"); abort(); }
/* Generated stub for towire_invalid_realm */
u8 *towire_invalid_realm(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "towire_invalid_realm called!\n"); abort(); }

Loading…
Cancel
Save