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:
Rusty Russell
2018-07-02 14:00:22 +09:30
committed by Christian Decker
parent 5a184c24e8
commit 68a8eeea21
5 changed files with 20 additions and 12 deletions

View File

@@ -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;