Skip to content

Commit 85ce1ff

Browse files
rustyrussellcdecker
authored andcommitted
channeld: allow creation of the three BADONION errors.
We use a dummy sha256 value at the moment. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 554c3ec commit 85ce1ff

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

channeld/channeld.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,8 @@ static u8 *make_failmsg(const tal_t *ctx,
805805
struct peer *peer,
806806
const struct htlc *htlc,
807807
enum onion_type failcode,
808-
const struct short_channel_id *scid)
808+
const struct short_channel_id *scid,
809+
const struct sha256 *sha256)
809810
{
810811
u8 *msg, *channel_update = NULL;
811812
u32 cltv_expiry = abs_locktime_to_blocks(&htlc->expiry);
@@ -877,9 +878,14 @@ static u8 *make_failmsg(const tal_t *ctx,
877878
msg = towire_final_incorrect_htlc_amount(ctx, htlc->msatoshi);
878879
goto done;
879880
case WIRE_INVALID_ONION_VERSION:
881+
msg = towire_invalid_onion_version(ctx, sha256);
882+
goto done;
880883
case WIRE_INVALID_ONION_HMAC:
884+
msg = towire_invalid_onion_hmac(ctx, sha256);
885+
goto done;
881886
case WIRE_INVALID_ONION_KEY:
882-
break;
887+
msg = towire_invalid_onion_key(ctx, sha256);
888+
goto done;
883889
}
884890
status_failed(STATUS_FAIL_INTERNAL_ERROR,
885891
"Asked to create failmsg %u (%s)",
@@ -1783,20 +1789,30 @@ static void send_fail_or_fulfill(struct peer *peer, const struct htlc *h)
17831789
{
17841790
u8 *msg;
17851791

1786-
if (h->failcode & BADONION) {
1787-
/* Malformed: use special reply since we can't onion. */
1792+
/* Note that if h->shared_secret is NULL, it means that we knew
1793+
* this HTLC was invalid, but we still needed to hand it to lightningd
1794+
* for the db, etc. So in that case, we use our own saved failcode.
1795+
*
1796+
* This also lets us distinguish between "we can't decode onion" and
1797+
* "next hop said it can't decode onion". That second case is the
1798+
* only case where we use a failcode for a non-local error. */
1799+
/* Malformed: use special reply since we can't onion. */
1800+
if (!h->shared_secret) {
17881801
struct sha256 sha256_of_onion;
17891802
sha256(&sha256_of_onion, h->routing, tal_count(h->routing));
17901803

17911804
msg = towire_update_fail_malformed_htlc(NULL, &peer->channel_id,
17921805
h->id, &sha256_of_onion,
1793-
h->failcode);
1806+
h->why_bad_onion);
17941807
} else if (h->failcode || h->fail) {
17951808
const u8 *onion;
17961809
if (h->failcode) {
1810+
/* FIXME: we need sha256_of_onion from peer. */
1811+
struct sha256 dummy;
1812+
memset(&dummy, 0, sizeof(dummy));
17971813
/* Local failure, make a message. */
17981814
u8 *failmsg = make_failmsg(tmpctx, peer, h, h->failcode,
1799-
h->failed_scid);
1815+
h->failed_scid, &dummy);
18001816
onion = create_onionreply(tmpctx, h->shared_secret,
18011817
failmsg);
18021818
} else /* Remote failure, just forward. */

0 commit comments

Comments
 (0)