diff --git a/channeld/channel.c b/channeld/channel.c index 1851c28b8..902fc35e2 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -1214,7 +1214,7 @@ static u8 *got_commitsig_msg(const tal_t *ctx, f = tal_arr_append(&failed); *f = tal(failed, struct failed_htlc); (*f)->id = htlc->id; - (*f)->malformed = htlc->failcode; + (*f)->failcode = htlc->failcode; (*f)->failreason = cast_const(u8 *, htlc->fail); } } else { diff --git a/channeld/full_channel.c b/channeld/full_channel.c index b93a2a80f..ad85d5c94 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -1048,13 +1048,14 @@ bool channel_force_htlcs(struct channel *channel, htlc_state_name(htlc->state)); return false; } - if (failed[i]->malformed) - htlc->failcode = failed[i]->malformed; - else + htlc->failcode = failed[i]->failcode; + if (failed[i]->failreason) htlc->fail = tal_dup_arr(htlc, u8, failed[i]->failreason, tal_len(failed[i]->failreason), 0); + else + htlc->fail = NULL; } for (i = 0; i < tal_count(htlcs); i++) { diff --git a/common/htlc_wire.c b/common/htlc_wire.c index 52d6dfaab..796465f1b 100644 --- a/common/htlc_wire.c +++ b/common/htlc_wire.c @@ -25,8 +25,11 @@ void towire_fulfilled_htlc(u8 **pptr, const struct fulfilled_htlc *fulfilled) void towire_failed_htlc(u8 **pptr, const struct failed_htlc *failed) { + /* Only one can be set. */ + assert(failed->failcode || tal_len(failed->failreason)); + assert(!failed->failcode || !tal_len(failed->failreason)); towire_u64(pptr, failed->id); - towire_u16(pptr, failed->malformed); + towire_u16(pptr, failed->failcode); towire_u16(pptr, tal_count(failed->failreason)); towire_u8_array(pptr, failed->failreason, tal_count(failed->failreason)); } @@ -84,9 +87,12 @@ struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, si struct failed_htlc *failed = tal(ctx, struct failed_htlc); failed->id = fromwire_u64(cursor, max); - failed->malformed = fromwire_u16(cursor, max); + failed->failcode = fromwire_u16(cursor, max); failreason_len = fromwire_u16(cursor, max); - failed->failreason = tal_arr(failed, u8, failreason_len); + if (failreason_len) + failed->failreason = tal_arr(failed, u8, failreason_len); + else + failed->failreason = NULL; fromwire_u8_array(cursor, max, failed->failreason, failreason_len); return failed; diff --git a/common/htlc_wire.h b/common/htlc_wire.h index 8be698d14..3d0d76a62 100644 --- a/common/htlc_wire.h +++ b/common/htlc_wire.h @@ -26,7 +26,8 @@ struct fulfilled_htlc { struct failed_htlc { u64 id; - enum onion_type malformed; + /* Either this is 0 and failreason non-NULL, or vice versa. */ + enum onion_type failcode; u8 *failreason; }; diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 888eed31e..8914dc756 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -771,8 +771,8 @@ static bool peer_failed_our_htlc(struct channel *channel, if (!htlc_out_update_state(channel, hout, RCVD_REMOVE_COMMIT)) return false; - hout->failcode = failed->malformed; - if (!failed->malformed) + hout->failcode = failed->failcode; + if (!failed->failcode) hout->failuremsg = tal_dup_arr(hout, u8, failed->failreason, tal_len(failed->failreason), 0); @@ -1384,7 +1384,7 @@ static void add_fulfill(u64 id, enum side side, } static void add_fail(u64 id, enum side side, - enum onion_type malformed, + enum onion_type failcode, const u8 *failuremsg, const struct failed_htlc ***failed_htlcs, enum side **failed_sides) @@ -1397,7 +1397,7 @@ static void add_fail(u64 id, enum side side, *f = tal(*failed_htlcs, struct failed_htlc); (*f)->id = id; - (*f)->malformed = malformed; + (*f)->failcode = failcode; if (failuremsg) (*f)->failreason = tal_dup_arr(*f, u8, failuremsg, tal_len(failuremsg), 0);