From 3f57249f085099fca3d60b6297b5b14995ffe48d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 28 Aug 2020 12:03:57 +0930 Subject: [PATCH] reservation: return FUNDING_STILL_SYNCING_BITCOIN if we might be missing funds. This is useful, and also makes us pass the testsuite. Signed-off-by: Rusty Russell --- wallet/reservation.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/wallet/reservation.c b/wallet/reservation.c index 2e0d02c95..7680614f0 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -310,19 +310,22 @@ static struct command_result *json_fundpsbt(struct command *cmd, } /* If they said "all", we expect to run out of utxos. */ - if (all) { - /* If we have none at all though, fail */ - if (!tal_count(utxos)) - return command_fail(cmd, FUND_CANNOT_AFFORD, - "No available UTXOs"); + if (all && tal_count(utxos)) break; - } + + /* Since it's possible the lack of utxos is because we haven't + * finished syncing yet, report a sync timing error first */ + if (!topology_synced(cmd->ld->topology)) + return command_fail(cmd, + FUNDING_STILL_SYNCING_BITCOIN, + "Cannot afford: still syncing with bitcoin network..."); return command_fail(cmd, FUND_CANNOT_AFFORD, "Could not afford %s using all %zu available UTXOs: %s short", - type_to_string(tmpctx, - struct amount_sat, - amount), + all ? "all" + : type_to_string(tmpctx, + struct amount_sat, + amount), tal_count(utxos), all ? "all" : type_to_string(tmpctx, @@ -334,11 +337,16 @@ static struct command_result *json_fundpsbt(struct command *cmd, /* Anything above 0 is "excess" */ if (!inputs_sufficient(input, AMOUNT_SAT(0), *feerate_per_kw, *weight, - &diff)) + &diff)) { + if (!topology_synced(cmd->ld->topology)) + return command_fail(cmd, + FUNDING_STILL_SYNCING_BITCOIN, + "Cannot afford: still syncing with bitcoin network..."); return command_fail(cmd, FUND_CANNOT_AFFORD, "All %zu inputs could not afford" " fees", tal_count(utxos)); + } } return finish_psbt(cmd, utxos, *feerate_per_kw, *weight, diff, *reserve,