From d3edfc802888b2df49a1db8b24a32ccc6ca81237 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 30 Jul 2018 18:01:34 +0200 Subject: [PATCH] onion: Print the extracted channel_update and onionreply to debug This adds one line with the onion and the channel_update we extract from it. This in turn allows us to check that the channel_update in the onion is not type prefixed, and that we patch it correctly before passing it to gossipd. --- CHANGELOG.md | 4 +++- lightningd/pay.c | 11 +++++++++-- tests/test_lightningd.py | 7 +++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53569a987..d5f7239b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,8 @@ changes. - Fixed crash when shutting down during opening a channel (#1737) - Don't lose track of our own output when applying penalty transaction (#1738) - Protocol: `channel_update` inside error messages now refers to correct channel. +- Stripping type prefix from `channel_update`s that are nested in an onion reply + to be compatible with eclair and lnd (#1730). ### Security @@ -84,7 +86,7 @@ changes. - JSON API: `getlog` result field `creation_time`. Use `created_at`. - JSON API: `getpeers` result field `channel_reserve_satoshis`. Use `their_channel_reserve_satoshis`. - JSON API: `getpeers` result field `to_self_delay`. Use `their_to_self_delay`. - + [Unreleased]: https://github.com/ElementsProject/lightning/compare/v0.6...HEAD [0.6]: https://github.com/ElementsProject/lightning/releases/tag/v0.6 diff --git a/lightningd/pay.c b/lightningd/pay.c index 0aa7574a8..07a73ad15 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -297,7 +297,8 @@ remote_routing_failure(const tal_t *ctx, bool *p_retry_plausible, bool *p_report_to_gossipd, const struct wallet_payment *payment, - const struct onionreply *failure) + const struct onionreply *failure, + struct log *log) { enum onion_type failcode = fromwire_peektype(failure->msg); u8 *channel_update; @@ -318,6 +319,11 @@ remote_routing_failure(const tal_t *ctx, channel_update = channel_update_from_onion_error(routing_failure, failure->msg); + if (channel_update) + log_debug(log, "Extracted channel_update %s from onionreply %s", + tal_hex(tmpctx, channel_update), + tal_hex(tmpctx, failure->msg)); + retry_plausible = true; report_to_gossipd = true; @@ -521,7 +527,8 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout, fail = remote_routing_failure(tmpctx, &retry_plausible, &report_to_gossipd, - payment, reply); + payment, reply, + hout->key.channel->log); } } diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index 4c37d9752..51125c654 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -4725,6 +4725,13 @@ class LightningDTests(BaseLightningDTests): self.assertRaisesRegex(RpcError, 'WIRE_TEMPORARY_CHANNEL_FAILURE', l1.rpc.waitsendpay, inv['payment_hash']) + # Make sure we get an onionreply, without the type prefix of the nested + # channel_update, and it should patch it to include a type prefix. The + # prefix 0x0102 should be in the channel_update, but not in the + # onionreply (negation of 0x0102 in the RE) + l1.daemon.wait_for_log(r'Extracted channel_update 0102.*from onionreply 10070080(?!.*0102)') + + # And now monitor for l1 to apply the channel_update we just extracted l1.daemon.wait_for_log('Received channel_update for channel {}\(.\) now DISABLED was ACTIVE \(from error\)'.format(chanid2)) def test_address(self):