From cf09314b3ba8ffdb963d69b079038a4554e615ef Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 11 Aug 2024 15:14:37 +0200 Subject: [PATCH] pay: Rename overall_capacity to just capacity Suggested-by: Rusty Russell <@rustyrussell> --- plugins/channel_hint.c | 18 ++++++++++-------- plugins/channel_hint.h | 5 +++-- plugins/libplugin-pay.c | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/channel_hint.c b/plugins/channel_hint.c index 8bb6c0fcb..fdf91081d 100644 --- a/plugins/channel_hint.c +++ b/plugins/channel_hint.c @@ -9,8 +9,8 @@ void channel_hint_to_json(const char *name, const struct channel_hint *hint, json_add_short_channel_id_dir(dest, "scid", hint->scid); json_add_amount_msat(dest, "estimated_capacity_msat", hint->estimated_capacity); - json_add_amount_msat(dest, "overall_capacity_msat", - hint->overall_capacity); + json_add_amount_msat(dest, "capacity_msat", + hint->capacity); json_add_bool(dest, "enabled", hint->enabled); json_object_end(dest); } @@ -38,7 +38,7 @@ bool channel_hint_update(const struct timeabs now, struct channel_hint *hint) */ struct amount_msat refill; u64 seconds = now.ts.tv_sec - hint->timestamp; - if (!amount_msat_mul(&refill, hint->overall_capacity, seconds)) + if (!amount_msat_mul(&refill, hint->capacity, seconds)) abort(); refill = amount_msat_div(refill, PAY_REFILL_TIME); @@ -48,8 +48,8 @@ bool channel_hint_update(const struct timeabs now, struct channel_hint *hint) /* Clamp the value to the `overall_capacity` */ if (amount_msat_greater(hint->estimated_capacity, - hint->overall_capacity)) - hint->estimated_capacity = hint->overall_capacity; + hint->capacity)) + hint->estimated_capacity = hint->capacity; /* TODO This is rather coarse. We could map the disabled flag to having 0msat capacity, and then relax from there. But it'd @@ -65,7 +65,7 @@ bool channel_hint_update(const struct timeabs now, struct channel_hint *hint) /* We report this hint as useless, if the hint does not * restrict the channel, i.e., if it is enabled and the * estimate is the same as the overall capacity. */ - return !hint->enabled || amount_msat_greater(hint->overall_capacity, + return !hint->enabled || amount_msat_greater(hint->capacity, hint->estimated_capacity); } @@ -85,11 +85,13 @@ struct channel_hint *channel_hint_from_json(const tal_t *ctx, *jhint = json_get_member(buffer, payload, "channel_hint"); struct channel_hint *hint = tal(ctx, struct channel_hint); - ret = json_scan(ctx, buffer, toks, - "{timestamp:%,scid:%,estimated_capacity_msat:%,overall_capacity_msat:%,enabled:%}", + + ret = json_scan(ctx, buffer, jhint, + "{timestamp:%,scid:%,estimated_capacity_msat:%,capacity_sat:%,enabled:%}", JSON_SCAN(json_to_u32, &hint->timestamp), JSON_SCAN(json_to_short_channel_id_dir, &hint->scid), JSON_SCAN(json_to_msat, &hint->estimated_capacity), + JSON_SCAN(json_to_msat, &hint->capacity), JSON_SCAN(json_to_bool, &hint->enabled)); if (ret != NULL) diff --git a/plugins/channel_hint.h b/plugins/channel_hint.h index f41684196..cf25f8d79 100644 --- a/plugins/channel_hint.h +++ b/plugins/channel_hint.h @@ -43,7 +43,7 @@ struct channel_hint { /* The total `amount_msat` that were used to fund the * channel. This is always smaller gte the * estimated_capacity */ - struct amount_msat overall_capacity; + struct amount_msat capacity; }; /* A collection of channel_hint instances, allowing us to handle and @@ -56,6 +56,7 @@ struct channel_hint_set { bool channel_hint_update(const struct timeabs now, struct channel_hint *hint); -void channel_hint_to_json(const char *name, const struct channel_hint *hint, struct json_stream *dest); +void channel_hint_to_json(const char *name, const struct channel_hint *hint, + struct json_stream *dest); #endif /* LIGHTNING_PLUGINS_CHANNEL_HINT_H */ diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 6a704cda2..9f07ade8b 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -467,7 +467,7 @@ static void channel_hints_update(struct payment *p, newhint.timestamp = timestamp; newhint.scid.scid = scid; newhint.scid.dir = direction; - newhint.overall_capacity = overall_capacity; + newhint.capacity = overall_capacity; if (local) { newhint.local = tal(root->channel_hints, struct local_hint); assert(htlc_budget); @@ -3539,7 +3539,7 @@ static void direct_pay_override(struct payment *p) { p->route[0].scid = hint->scid.scid; p->route[0].direction = hint->scid.dir; p->route[0].node_id = *p->route_destination; - p->route[0].total_amount = hint->overall_capacity; + p->route[0].total_amount = hint->capacity; paymod_log(p, LOG_DBG, "Found a direct channel (%s) with sufficient " "capacity, skipping route computation.",