mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
wire: add test for parsing optional version of channel_update
This commit is contained in:
committed by
Rusty Russell
parent
a289282bad
commit
1b6bd3fded
@@ -1063,7 +1063,17 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
|||||||
struct chan *chan;
|
struct chan *chan;
|
||||||
u8 direction;
|
u8 direction;
|
||||||
|
|
||||||
if (!fromwire_channel_update_option_channel_htlc_max(update, &signature, &chain_hash,
|
if (!fromwire_channel_update(update, &signature, &chain_hash,
|
||||||
|
&short_channel_id, ×tamp,
|
||||||
|
&message_flags, &channel_flags,
|
||||||
|
&expiry, &htlc_minimum_msat, &fee_base_msat,
|
||||||
|
&fee_proportional_millionths))
|
||||||
|
return false;
|
||||||
|
/* If it's flagged as containing the optional field, reparse for
|
||||||
|
* the optional field */
|
||||||
|
if ((message_flags & ROUTING_OPT_HTLC_MAX_MSAT) &&
|
||||||
|
!fromwire_channel_update_option_channel_htlc_max(
|
||||||
|
update, &signature, &chain_hash,
|
||||||
&short_channel_id, ×tamp,
|
&short_channel_id, ×tamp,
|
||||||
&message_flags, &channel_flags,
|
&message_flags, &channel_flags,
|
||||||
&expiry, &htlc_minimum_msat, &fee_base_msat,
|
&expiry, &htlc_minimum_msat, &fee_base_msat,
|
||||||
|
|||||||
@@ -132,6 +132,19 @@ struct msg_channel_update {
|
|||||||
struct bitcoin_blkid chain_hash;
|
struct bitcoin_blkid chain_hash;
|
||||||
struct short_channel_id short_channel_id;
|
struct short_channel_id short_channel_id;
|
||||||
};
|
};
|
||||||
|
struct msg_channel_update_opt_htlc_max {
|
||||||
|
secp256k1_ecdsa_signature signature;
|
||||||
|
u32 timestamp;
|
||||||
|
u8 message_flags;
|
||||||
|
u8 channel_flags;
|
||||||
|
u16 expiry;
|
||||||
|
u64 htlc_minimum_msat;
|
||||||
|
u32 fee_base_msat;
|
||||||
|
u32 fee_proportional_millionths;
|
||||||
|
u64 htlc_maximum_msat;
|
||||||
|
struct bitcoin_blkid chain_hash;
|
||||||
|
struct short_channel_id short_channel_id;
|
||||||
|
};
|
||||||
struct msg_funding_locked {
|
struct msg_funding_locked {
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct pubkey next_per_commitment_point;
|
struct pubkey next_per_commitment_point;
|
||||||
@@ -385,6 +398,22 @@ static void *towire_struct_channel_update(const tal_t *ctx,
|
|||||||
s->fee_proportional_millionths);
|
s->fee_proportional_millionths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *towire_struct_channel_update_opt_htlc_max(const tal_t *ctx,
|
||||||
|
const struct msg_channel_update_opt_htlc_max *s)
|
||||||
|
{
|
||||||
|
return towire_channel_update_option_channel_htlc_max(ctx,
|
||||||
|
&s->signature,
|
||||||
|
&s->chain_hash,
|
||||||
|
&s->short_channel_id,
|
||||||
|
s->timestamp,
|
||||||
|
s->message_flags,
|
||||||
|
s->channel_flags,
|
||||||
|
s->expiry,
|
||||||
|
s->htlc_minimum_msat,
|
||||||
|
s->fee_base_msat,
|
||||||
|
s->fee_proportional_millionths,
|
||||||
|
s->htlc_maximum_msat);
|
||||||
|
}
|
||||||
static struct msg_channel_update *fromwire_struct_channel_update(const tal_t *ctx, const void *p)
|
static struct msg_channel_update *fromwire_struct_channel_update(const tal_t *ctx, const void *p)
|
||||||
{
|
{
|
||||||
struct msg_channel_update *s = tal(ctx, struct msg_channel_update);
|
struct msg_channel_update *s = tal(ctx, struct msg_channel_update);
|
||||||
@@ -404,6 +433,27 @@ static struct msg_channel_update *fromwire_struct_channel_update(const tal_t *ct
|
|||||||
return tal_free(s);
|
return tal_free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct msg_channel_update_opt_htlc_max
|
||||||
|
*fromwire_struct_channel_update_opt_htlc_max(const tal_t *ctx, const void *p)
|
||||||
|
{
|
||||||
|
struct msg_channel_update_opt_htlc_max *s = tal(ctx, struct msg_channel_update_opt_htlc_max);
|
||||||
|
|
||||||
|
if (fromwire_channel_update_option_channel_htlc_max(p,
|
||||||
|
&s->signature,
|
||||||
|
&s->chain_hash,
|
||||||
|
&s->short_channel_id,
|
||||||
|
&s->timestamp,
|
||||||
|
&s->message_flags,
|
||||||
|
&s->channel_flags,
|
||||||
|
&s->expiry,
|
||||||
|
&s->htlc_minimum_msat,
|
||||||
|
&s->fee_base_msat,
|
||||||
|
&s->fee_proportional_millionths,
|
||||||
|
&s->htlc_maximum_msat))
|
||||||
|
return s;
|
||||||
|
return tal_free(s);
|
||||||
|
}
|
||||||
|
|
||||||
static void *towire_struct_funding_locked(const tal_t *ctx,
|
static void *towire_struct_funding_locked(const tal_t *ctx,
|
||||||
const struct msg_funding_locked *s)
|
const struct msg_funding_locked *s)
|
||||||
{
|
{
|
||||||
@@ -810,6 +860,13 @@ static bool channel_update_eq(const struct msg_channel_update *a,
|
|||||||
short_channel_id_eq(&a->short_channel_id, &b->short_channel_id);
|
short_channel_id_eq(&a->short_channel_id, &b->short_channel_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool channel_update_opt_htlc_max_eq(const struct msg_channel_update_opt_htlc_max *a,
|
||||||
|
const struct msg_channel_update_opt_htlc_max *b)
|
||||||
|
{
|
||||||
|
return eq_upto(a, b, short_channel_id) &&
|
||||||
|
short_channel_id_eq(&a->short_channel_id, &b->short_channel_id);
|
||||||
|
}
|
||||||
|
|
||||||
static bool accept_channel_eq(const struct msg_accept_channel *a,
|
static bool accept_channel_eq(const struct msg_accept_channel *a,
|
||||||
const struct msg_accept_channel *b)
|
const struct msg_accept_channel *b)
|
||||||
{
|
{
|
||||||
@@ -865,6 +922,7 @@ int main(void)
|
|||||||
struct msg_revoke_and_ack raa, *raa2;
|
struct msg_revoke_and_ack raa, *raa2;
|
||||||
struct msg_open_channel oc, *oc2;
|
struct msg_open_channel oc, *oc2;
|
||||||
struct msg_channel_update cu, *cu2;
|
struct msg_channel_update cu, *cu2;
|
||||||
|
struct msg_channel_update_opt_htlc_max cu_opt_htlc_max, *cu_opt_htlc_max2;
|
||||||
struct msg_accept_channel ac, *ac2;
|
struct msg_accept_channel ac, *ac2;
|
||||||
struct msg_update_add_htlc uah, *uah2;
|
struct msg_update_add_htlc uah, *uah2;
|
||||||
struct msg_node_announcement na, *na2;
|
struct msg_node_announcement na, *na2;
|
||||||
@@ -1013,6 +1071,13 @@ int main(void)
|
|||||||
assert(channel_update_eq(&cu, cu2));
|
assert(channel_update_eq(&cu, cu2));
|
||||||
test_corruption(&cu, cu2, channel_update);
|
test_corruption(&cu, cu2, channel_update);
|
||||||
|
|
||||||
|
memset(&cu_opt_htlc_max, 2, sizeof(cu_opt_htlc_max));
|
||||||
|
|
||||||
|
msg = towire_struct_channel_update_opt_htlc_max(ctx, &cu_opt_htlc_max);
|
||||||
|
cu_opt_htlc_max2 = fromwire_struct_channel_update_opt_htlc_max(ctx, msg);
|
||||||
|
assert(channel_update_opt_htlc_max_eq(&cu_opt_htlc_max, cu_opt_htlc_max2));
|
||||||
|
test_corruption(&cu_opt_htlc_max, cu_opt_htlc_max2, channel_update_opt_htlc_max);
|
||||||
|
|
||||||
memset(&ac, 2, sizeof(ac));
|
memset(&ac, 2, sizeof(ac));
|
||||||
set_pubkey(&ac.funding_pubkey);
|
set_pubkey(&ac.funding_pubkey);
|
||||||
set_pubkey(&ac.revocation_basepoint);
|
set_pubkey(&ac.revocation_basepoint);
|
||||||
|
|||||||
Reference in New Issue
Block a user