Merge bitcoin/bitcoin#26611: wallet: Change coin selection fee assert to error

3eb041f014 wallet: Change coin selection fee assert to error (Andrew Chow)
c6e7f224c1 util: Add StrFormatInternalBug and STR_INTERNAL_BUG (MarcoFalke)

Pull request description:

  Returning an error instead of asserting for the low fee check will be better as it does not crash the node and instructs users to report the bug.

ACKs for top commit:
  S3RK:
    ACK 3eb041f014
  aureleoules:
    ACK 3eb041f014
  furszy:
    ACK 3eb041f0

Tree-SHA512: 118c13d7cdfce492080edd4cb12e6d960695377b978c7573f9c58b6d918664afd0e8e591eed0605d08ac756fa8eceed456349de5f3a025174069abf369bb5a5f
This commit is contained in:
MarcoFalke 2022-12-06 10:30:54 +01:00
commit edbe4f808a
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
3 changed files with 12 additions and 3 deletions

View file

@ -14,10 +14,13 @@
#include <cstdlib>
#include <string>
std::string StrFormatInternalBug(const char* msg, const char* file, int line, const char* func)
{
return strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT);
}
NonFatalCheckError::NonFatalCheckError(const char* msg, const char* file, int line, const char* func)
: std::runtime_error{
strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT)}
: std::runtime_error{StrFormatInternalBug(msg, file, line, func)}
{
}

View file

@ -10,12 +10,16 @@
#include <stdexcept>
#include <utility>
std::string StrFormatInternalBug(const char* msg, const char* file, int line, const char* func);
class NonFatalCheckError : public std::runtime_error
{
public:
NonFatalCheckError(const char* msg, const char* file, int line, const char* func);
};
#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__)
/** Helper for CHECK_NONFATAL() */
template <typename T>
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)

View file

@ -955,7 +955,9 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
// The only time that fee_needed should be less than the amount available for fees is when
// we are subtracting the fee from the outputs. If this occurs at any other time, it is a bug.
assert(coin_selection_params.m_subtract_fee_outputs || fee_needed <= nFeeRet);
if (!coin_selection_params.m_subtract_fee_outputs && fee_needed > nFeeRet) {
return util::Error{Untranslated(STR_INTERNAL_BUG("Fee needed > fee paid"))};
}
// If there is a change output and we overpay the fees then increase the change to match the fee needed
if (nChangePosInOut != -1 && fee_needed < nFeeRet) {