diff --git a/channeld/channel.c b/channeld/channel.c index 215bccdfc..537d93752 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -1990,35 +1990,37 @@ static void handle_fail(struct peer *peer, const u8 *inmsg) u8 *msg; u64 id; u8 *errpkt; - u16 malformed; + u16 failcode; enum channel_remove_err e; struct htlc *h; - if (!fromwire_channel_fail_htlc(inmsg, inmsg, NULL, &id, &malformed, - &errpkt)) + if (!fromwire_channel_fail_htlc(inmsg, inmsg, NULL, &id, &errpkt, + &failcode)) master_badmsg(WIRE_CHANNEL_FAIL_HTLC, inmsg); - if (malformed && !(malformed & BADONION)) + if ((failcode & BADONION) && tal_len(errpkt)) status_failed(STATUS_FAIL_MASTER_IO, - "Invalid channel_fail_htlc: bad malformed 0x%x", - malformed); + "Invalid channel_fail_htlc: %s with errpkt?", + onion_type_name(failcode)); e = channel_fail_htlc(peer->channel, REMOTE, id, &h); switch (e) { case CHANNEL_ERR_REMOVE_OK: - if (malformed) { + if (failcode & BADONION) { struct sha256 sha256_of_onion; status_trace("Failing %"PRIu64" with code %u", - id, malformed); + id, failcode); sha256(&sha256_of_onion, h->routing, tal_len(h->routing)); msg = towire_update_fail_malformed_htlc(peer, &peer->channel_id, id, &sha256_of_onion, - malformed); + failcode); } else { + u8 *reply = wrap_onionreply(inmsg, h->shared_secret, + errpkt); msg = towire_update_fail_htlc(peer, &peer->channel_id, - id, errpkt); + id, reply); } msg_enqueue(&peer->peer_out, take(msg)); start_commit_timer(peer); diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 5f72ae1d4..190a9a7d5 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -92,11 +92,11 @@ channel_fulfill_htlc,,payment_preimage,struct preimage # Main daemon says HTLC failed channel_fail_htlc,1006 channel_fail_htlc,,id,u64 -# If malformed is non-zero, it's a BADONION code -channel_fail_htlc,,malformed,u16 -# Otherwise, error_pkt contains failreason. +# If this is non-zero length, you need to wrap this and pass it on. channel_fail_htlc,,len,u16 channel_fail_htlc,,error_pkt,len*u8 +# If it errcode is != 0, it's a local error, otherwise we're passing thru. +channel_fail_htlc,,errcode,u16 # Ping/pong test. channel_ping,1011 diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 14161830b..514a7877b 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -99,18 +99,13 @@ static void fail_in_htlc(struct htlc_in *hin, subd_send_msg(hin->key.peer->owner, take(towire_channel_fail_htlc(hin, hin->key.id, - hin->failcode, - NULL))); + NULL, + hin->failcode))); } else { - u8 *reply; - - /* This obfuscates the message, whether local or forwarded. */ - reply = wrap_onionreply(hin, &hin->shared_secret, - hin->failuremsg); subd_send_msg(hin->key.peer->owner, take(towire_channel_fail_htlc(hin, hin->key.id, - 0, reply))); - tal_free(reply); + hin->failuremsg, + 0))); } }