common: add amount_msat_deduct / amount_msat_deduct_sub.

I added amount_msat_accumulate for the "a+=b" case, but I was struggling
with a name for the subtractive equivalent.  After some prompting, ChatGPT
suggested deduct.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-11-13 15:38:31 +10:30
parent 0b8239f3d6
commit 35f65c5d91
21 changed files with 75 additions and 67 deletions

View File

@@ -657,9 +657,8 @@ static struct amount_msat calc_capacity(struct info *info,
if (!short_channel_id_dir_eq(&info->reservations[i]->scidd, scidd))
continue;
/* We should never use more that we have! */
if (!amount_msat_sub(&dynamic_capacity,
dynamic_capacity,
info->reservations[i]->amount))
if (!amount_msat_deduct(&dynamic_capacity,
info->reservations[i]->amount))
abort();
status_debug("... minus reservation %s",
fmt_amount_msat(tmpctx, info->reservations[i]->amount));