From 6bbea741d189857dfcef18b9582a469de8943333 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 30 Jul 2018 13:16:20 +0200 Subject: [PATCH] pay: Strip the type prefix from nested channel_updates This is the counterpart for the previous commit, stripping the type prefix channel_update, to be consistent with lnd and eclair which do it like this. --- channeld/channel.c | 17 +++++++++++++++-- lightningd/pay.c | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 6cb87be51..a8d2599ea 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -818,7 +818,7 @@ static u8 *foreign_channel_update(const tal_t *ctx, struct peer *peer, const struct short_channel_id *scid) { - u8 *msg, *update; + u8 *msg, *update, *channel_update; msg = towire_gossip_get_update(NULL, scid); msg = gossipd_wait_sync_reply(tmpctx, peer, take(msg), @@ -826,7 +826,20 @@ static u8 *foreign_channel_update(const tal_t *ctx, if (!fromwire_gossip_get_update_reply(ctx, msg, &update)) status_failed(STATUS_FAIL_GOSSIP_IO, "Invalid update reply"); - return update; + + /* Strip the type from the channel_update. Due to the specification + * being underspecified, some implementations skipped the type + * prefix. Since we are in the minority we adapt (See #1730 and + * lightningnetwork/lnd#1599 for details). */ + if (update && fromwire_peektype(update) == WIRE_CHANNEL_UPDATE) { + assert(tal_bytelen(update) > 2); + channel_update = tal_arr(ctx, u8, 0); + towire(&channel_update, update + 2, tal_bytelen(update) - 2); + tal_free(update); + return channel_update; + } else { + return update; + } } static u8 *make_failmsg(const tal_t *ctx, diff --git a/lightningd/pay.c b/lightningd/pay.c index 5f30e3286..0aa7574a8 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -402,6 +402,7 @@ static void report_routing_failure(struct log *log, type_to_string(tmpctx, struct short_channel_id, &fail->erring_channel), tal_hex(tmpctx, fail->channel_update)); + gossip_msg = towire_gossip_routing_failure(tmpctx, &fail->erring_node, &fail->erring_channel,