Skip to content

Commit 9522b53

Browse files
committed
rpc: bumpfee: handle errors more gracefully
1 parent f626594 commit 9522b53

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
27332733
" \"txid\": \"value\", (string) The id of the new transaction\n"
27342734
" \"origfee\": n, (numeric) Fee of the replaced transaction\n"
27352735
" \"fee\": n, (numeric) Fee of the new transaction\n"
2736+
" \"errors\": [ str... ] (json array of strings) Errors encountered during processing (may be empty)\n"
27362737
"}\n"
27372738
"\nExamples:\n"
27382739
"\nBump the fee, get the new transaction\'s txid\n" +
@@ -2945,23 +2946,32 @@ UniValue bumpfee(const JSONRPCRequest& request)
29452946
CWalletTx wtxBumped(pwalletMain, MakeTransactionRef(std::move(tx)));
29462947
wtxBumped.mapValue["replaces_txid"] = hash.ToString();
29472948
CValidationState state;
2948-
if (!pwalletMain->CommitTransaction(wtxBumped, reservekey, g_connman.get(), state) || !state.IsValid()) {
2949+
if (!pwalletMain->CommitTransaction(wtxBumped, reservekey, g_connman.get(), state)) {
2950+
// NOTE: CommitTransaction never returns false, so this should never happen.
29492951
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason()));
29502952
}
29512953

2954+
UniValue vErrors(UniValue::VARR);
2955+
if (state.IsInvalid()) {
2956+
// This can happen if the mempool rejected the transaction. Report
2957+
// what happened in the "errors" response.
2958+
vErrors.push_back(strprintf("Error: The transaction was rejected: %s", FormatStateMessage(state)));
2959+
}
2960+
29522961
// mark the original tx as bumped
29532962
if (!pwalletMain->MarkReplaced(wtx.GetHash(), wtxBumped.GetHash())) {
29542963
// TODO: see if JSON-RPC has a standard way of returning a response
29552964
// along with an exception. It would be good to return information about
29562965
// wtxBumped to the caller even if marking the original transaction
29572966
// replaced does not succeed for some reason.
2958-
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Created new bumpfee transaction but could not mark the original transaction as replaced.");
2967+
vErrors.push_back("Error: Created new bumpfee transaction but could not mark the original transaction as replaced.");
29592968
}
29602969

29612970
UniValue result(UniValue::VOBJ);
29622971
result.push_back(Pair("txid", wtxBumped.GetHash().GetHex()));
29632972
result.push_back(Pair("origfee", ValueFromAmount(nOldFee)));
29642973
result.push_back(Pair("fee", ValueFromAmount(nNewFee)));
2974+
result.push_back(Pair("errors", vErrors));
29652975

29662976
return result;
29672977
}

0 commit comments

Comments
 (0)