diff --git a/common/amount.c b/common/amount.c index 3736d2913..ddea6569c 100644 --- a/common/amount.c +++ b/common/amount.c @@ -357,6 +357,11 @@ bool amount_sat_eq(struct amount_sat a, struct amount_sat b) return a.satoshis == b.satoshis; } +bool amount_sat_zero(struct amount_sat a) +{ + return a.satoshis == 0; +} + bool amount_msat_eq(struct amount_msat a, struct amount_msat b) { return a.millisatoshis == b.millisatoshis; diff --git a/common/amount.h b/common/amount.h index 58df61c5c..46d95d99d 100644 --- a/common/amount.h +++ b/common/amount.h @@ -94,6 +94,9 @@ struct amount_sat amount_sat_div(struct amount_sat sat, u64 div); bool amount_sat_eq(struct amount_sat a, struct amount_sat b); bool amount_msat_eq(struct amount_msat a, struct amount_msat b); +/* Is a zero? */ +bool amount_sat_zero(struct amount_sat a); + /* Is a > b? */ bool amount_sat_greater(struct amount_sat a, struct amount_sat b); bool amount_msat_greater(struct amount_msat a, struct amount_msat b); diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 988894ce2..7413812ad 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -619,11 +619,11 @@ rbf_channel_hook_deserialize(struct rbf_channel_payload *payload, fatal("Plugin failed to supply our_funding_msat field"); if (payload->psbt - && amount_sat_eq(payload->our_funding, AMOUNT_SAT(0))) + && amount_sat_zero(payload->our_funding)) fatal("Plugin failed to supply our_funding_msat field"); if (!payload->psbt && - !amount_sat_eq(payload->our_funding, AMOUNT_SAT(0))) { + !amount_sat_zero(payload->our_funding)) { log_broken(channel->log, "`our_funding_msat` returned" " but no `psbt` present. %.*s", @@ -777,11 +777,11 @@ openchannel2_hook_deserialize(struct openchannel2_payload *payload, fatal("Plugin failed to supply our_funding_msat field"); if (payload->psbt - && amount_sat_eq(payload->accepter_funding, AMOUNT_SAT(0))) + && amount_sat_zero(payload->accepter_funding)) fatal("Plugin failed to supply our_funding_msat field"); if (!payload->psbt - && !amount_sat_eq(payload->accepter_funding, AMOUNT_SAT(0))) { + && !amount_sat_zero(payload->accepter_funding)) { /* Gotta give a PSBT if you set the accepter_funding amount */ /* Let dualopend know we've failed */ payload->err_msg = "Client error. Unable to continue"; diff --git a/plugins/funder.c b/plugins/funder.c index 7259334fc..891154dc6 100644 --- a/plugins/funder.c +++ b/plugins/funder.c @@ -427,7 +427,7 @@ listfunds_success(struct command *cmd, &info->our_funding), funding_err ? funding_err : ""); - if (amount_sat_eq(info->our_funding, AMOUNT_SAT(0))) + if (amount_sat_zero(info->our_funding)) return command_hook_success(cmd); plugin_log(cmd->plugin, LOG_DBG, diff --git a/plugins/funder_policy.c b/plugins/funder_policy.c index 4ded29088..428b4c42f 100644 --- a/plugins/funder_policy.c +++ b/plugins/funder_policy.c @@ -220,7 +220,7 @@ calculate_our_funding(struct funder_policy *policy, /* Figure out amount of actual headroom we have */ if (!amount_sat_sub(&avail_channel_space, channel_max, their_funding) - || amount_sat_eq(avail_channel_space, AMOUNT_SAT(0))) { + || amount_sat_zero(avail_channel_space)) { *our_funding = AMOUNT_SAT(0); return tal_fmt(tmpctx, "No space available in channel." " channel_max %s, their_funding %s", @@ -234,7 +234,7 @@ calculate_our_funding(struct funder_policy *policy, * 'reserve_tank' */ if (!amount_sat_sub(&net_available_funds, available_funds, policy->reserve_tank) - || amount_sat_eq(net_available_funds, AMOUNT_SAT(0))) { + || amount_sat_zero(net_available_funds)) { *our_funding = AMOUNT_SAT(0); return tal_fmt(tmpctx, "Reserve tank too low." " available_funds %s, reserve_tank requires %s", @@ -272,7 +272,7 @@ calculate_our_funding(struct funder_policy *policy, *our_funding = apply_policy(policy, their_funding, available_funds); /* Don't return an 'error' if we're already at 0 */ - if (amount_sat_eq(*our_funding, AMOUNT_SAT(0))) + if (amount_sat_zero(*our_funding)) return NULL; /* our_funding is probably sane, so let's fuzz this amount a bit */