Skip to content

Commit edbe4f8

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26611: wallet: Change coin selection fee assert to error
3eb041f wallet: Change coin selection fee assert to error (Andrew Chow) c6e7f22 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 3eb041f aureleoules: ACK 3eb041f furszy: ACK 3eb041f Tree-SHA512: 118c13d7cdfce492080edd4cb12e6d960695377b978c7573f9c58b6d918664afd0e8e591eed0605d08ac756fa8eceed456349de5f3a025174069abf369bb5a5f
2 parents 5d9b530 + 3eb041f commit edbe4f8

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/util/check.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
#include <cstdlib>
1515
#include <string>
1616

17+
std::string StrFormatInternalBug(const char* msg, const char* file, int line, const char* func)
18+
{
19+
return strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT);
20+
}
1721

1822
NonFatalCheckError::NonFatalCheckError(const char* msg, const char* file, int line, const char* func)
19-
: std::runtime_error{
20-
strprintf("Internal bug detected: \"%s\"\n%s:%d (%s)\nPlease report this issue here: %s\n", msg, file, line, func, PACKAGE_BUGREPORT)}
23+
: std::runtime_error{StrFormatInternalBug(msg, file, line, func)}
2124
{
2225
}
2326

src/util/check.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
#include <stdexcept>
1111
#include <utility>
1212

13+
std::string StrFormatInternalBug(const char* msg, const char* file, int line, const char* func);
14+
1315
class NonFatalCheckError : public std::runtime_error
1416
{
1517
public:
1618
NonFatalCheckError(const char* msg, const char* file, int line, const char* func);
1719
};
1820

21+
#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__)
22+
1923
/** Helper for CHECK_NONFATAL() */
2024
template <typename T>
2125
T&& inline_check_non_fatal(LIFETIMEBOUND T&& val, const char* file, int line, const char* func, const char* assertion)

src/wallet/spend.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,9 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
955955

956956
// The only time that fee_needed should be less than the amount available for fees is when
957957
// we are subtracting the fee from the outputs. If this occurs at any other time, it is a bug.
958-
assert(coin_selection_params.m_subtract_fee_outputs || fee_needed <= nFeeRet);
958+
if (!coin_selection_params.m_subtract_fee_outputs && fee_needed > nFeeRet) {
959+
return util::Error{Untranslated(STR_INTERNAL_BUG("Fee needed > fee paid"))};
960+
}
959961

960962
// If there is a change output and we overpay the fees then increase the change to match the fee needed
961963
if (nChangePosInOut != -1 && fee_needed < nFeeRet) {

0 commit comments

Comments
 (0)