MCPcopy Create free account
hub / github.com/ElementsProject/lightning / payment_listpeerchannels_success

Function payment_listpeerchannels_success

plugins/libplugin-pay.c:975–1036  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

973}
974
975static struct command_result *
976payment_listpeerchannels_success(struct command *cmd,
977 const char *method,
978 const char *buffer,
979 const jsmntok_t *toks,
980 struct payment *p)
981{
982 /* The maximum amount we may end up trying to send. This
983 * includes the value and the full fee budget. If the
984 * available funds are below this, we emit a warning. */
985 struct amount_msat maxrequired, spendable;
986
987 if (!amount_msat_add(&maxrequired, p->getroute->amount,
988 p->constraints.fee_budget)) {
989 paymod_log(p, LOG_BROKEN,
990 "amount_msat overflow computing the fee budget");
991 return payment_getroute(p);
992 }
993
994 p->mods = gossmods_from_listpeerchannels(
995 p, p->local_id, buffer, toks, true, gossmod_add_localchan, NULL);
996 if (!payment_listpeerchannels_balance_sum(p, buffer, toks,
997 &spendable)) {
998 paymod_log(p, LOG_UNUSUAL,
999 "Unable to get total spendable amount from "
1000 "listpeerchannels. Skipping affordability check.");
1001
1002 /* Keep your fingers crossed, we may still succeed. */
1003 return payment_getroute(p);
1004 }
1005
1006 /* Pre-flight check: can we even afford the full amount of the
1007 * payment? And if yes, can we afford the full amount with the
1008 * full fee budget? If the former fails, we fail immediately,
1009 * for the latter we log a warning, so we can root-cause this
1010 * a bit better if we then run into routing issues. */
1011 if (amount_msat_greater(p->getroute->amount, spendable)) {
1012 paymod_log(p, LOG_UNUSUAL,
1013 "Insufficient funds to perform the payment: "
1014 "spendable=%s < payment=%s",
1015 fmt_amount_msat(tmpctx, spendable),
1016 fmt_amount_msat(tmpctx, p->getroute->amount));
1017 return payment_abort(p, PAY_INSUFFICIENT_FUNDS,
1018 "Insufficient funds to perform the payment: "
1019 "spendable=%s < payment=%s",
1020 fmt_amount_msat(tmpctx, spendable),
1021 fmt_amount_msat(tmpctx, p->getroute->amount));
1022 } else if (amount_msat_greater(maxrequired, spendable)) {
1023 char *msg = tal_fmt(
1024 tmpctx,
1025 "We do not have sufficient funds to pay for the specified "
1026 "fee budget: spendable=%s < payment=%s + budget=%s. This "
1027 "may cause a failed payment, but we'll try anyway.",
1028 fmt_amount_msat(tmpctx, spendable),
1029 fmt_amount_msat(tmpctx, p->getroute->amount),
1030 fmt_amount_msat(tmpctx, p->constraints.fee_budget));
1031
1032 plugin_notify_message(payment_cmd(p), LOG_INFORM, "%s", msg);

Callers

nothing calls this directly

Calls 9

amount_msat_addFunction · 0.85
paymod_logFunction · 0.85
payment_getrouteFunction · 0.85
amount_msat_greaterFunction · 0.85
payment_abortFunction · 0.85
payment_cmdFunction · 0.85
plugin_notify_messageFunction · 0.70
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected