Skip to content

Commit

Permalink
lease_rates: lease_rates_eq.
Browse files Browse the repository at this point in the history
We don't actually use the NULL-is-equal in the one caller, so ignore that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and niftynei committed Jul 15, 2021
1 parent e4db4dc commit 04497c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
29 changes: 4 additions & 25 deletions common/lease_rates.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,15 @@
#include <common/lease_rates.h>
#include <common/overflows.h>
#include <common/type_to_string.h>
#include <wire/peer_wire.h>

/* FIXME: Is there a better way to do this ? */
bool lease_rates_eq(struct lease_rates *l1,
struct lease_rates *l2)
{
if (!l1 != !l2)
return false;

if (!l1)
return true;

return l1->funding_weight == l2->funding_weight
&& l1->channel_fee_max_base_msat == l2->channel_fee_max_base_msat
&& l1->channel_fee_max_proportional_thousandths == l2->channel_fee_max_proportional_thousandths
&& l1->lease_fee_base_sat == l2->lease_fee_base_sat
&& l1->lease_fee_basis == l2->lease_fee_basis;
}

bool lease_rates_empty(struct lease_rates *rates)
bool lease_rates_empty(const struct lease_rates *rates)
{
/* static means it's zero initialized */
static const struct lease_rates zero;
if (!rates)
return true;

/* FIXME: why can't i do memeqzero? */
return rates->funding_weight == 0
&& rates->channel_fee_max_base_msat == 0
&& rates->channel_fee_max_proportional_thousandths == 0
&& rates->lease_fee_base_sat == 0
&& rates->lease_fee_basis == 0;
return lease_rates_eq(rates, &zero);
}

void lease_rates_get_commitment(struct pubkey *pubkey,
Expand Down
12 changes: 9 additions & 3 deletions common/lease_rates.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIGHTNING_COMMON_LEASE_RATES_H
#include "config.h"
#include <stdbool.h>
#include <wire/peer_wire.h>

struct amount_msat;
struct amount_sat;
Expand All @@ -11,16 +12,21 @@ struct sha256;

#define LEASE_RATE_DURATION 4032

bool lease_rates_empty(struct lease_rates *rates);
bool lease_rates_empty(const struct lease_rates *rates);

void lease_rates_get_commitment(struct pubkey *pubkey,
u32 lease_expiry,
u32 chan_fee_msat,
u16 chan_fee_ppt,
struct sha256 *sha);

bool lease_rates_eq(struct lease_rates *l1,
struct lease_rates *l2);
/* lease_rates_eq: has 2 padding bytes after third field */
STRUCTEQ_DEF(lease_rates, 2,
funding_weight,
lease_fee_basis,
channel_fee_max_proportional_thousandths,
lease_fee_base_sat,
channel_fee_max_base_msat);

bool lease_rates_calc_fee(struct lease_rates *rates,
struct amount_sat accept_funding_sats,
Expand Down

0 comments on commit 04497c7

Please sign in to comment.