mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
htlc_wire: rename malformed to failcode in struct failed_htlc.
I'm not completely convinced that it's only ever set to a failcode with the BADONION bit set, especially after the previous patches in this series. Now that channeld can handle arbitrary failcodes passed this way, simply rename it. We add marshalling assertions that only one of failcode and failreason is set, and we unmarshal an empty 'fail' to NULL (just the the generated unmarshalling code does). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
5a184c24e8
commit
68a8eeea21
@ -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 {
|
||||
|
@ -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++) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user