Skip to content

Commit 987a809

Browse files
committed
Merge #11882: Disable default fallbackfee on mainnet
3f592b8 [QA] add wallet-rbf test (Jonas Schnelli) 8222e05 Disable wallet fallbackfee by default on mainnet (Jonas Schnelli) Pull request description: Removes the default fallback fee on mainnet (but keeps it on testnet/regtest). Transactions using the fallbackfee in case the fallback fee has not been set are getting rejected. Tree-SHA512: e54d2594b7f954e640cc513a18b0bfbe189f15e15bdeed4fe02b7677f939bca1731fef781b073127ffd4ce08a595fb118259b8826cdaa077ff7d5ae9495810db
2 parents 5c2aff8 + 3f592b8 commit 987a809

File tree

10 files changed

+58
-0
lines changed

10 files changed

+58
-0
lines changed

src/chainparams.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ class CMainParams : public CChainParams {
175175
// (the tx=... number in the SetBestChain debug.log lines)
176176
3.5 // * estimated number of transactions per second after that timestamp
177177
};
178+
179+
/* disable fallback fee on mainnet */
180+
m_fallback_fee_enabled = false;
178181
}
179182
};
180183

@@ -266,6 +269,8 @@ class CTestNetParams : public CChainParams {
266269
0.09
267270
};
268271

272+
/* enable fallback fee on testnet */
273+
m_fallback_fee_enabled = true;
269274
}
270275
};
271276

@@ -343,6 +348,9 @@ class CRegTestParams : public CChainParams {
343348
base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
344349

345350
bech32_hrp = "bcrt";
351+
352+
/* enable fallback fee on regtest */
353+
m_fallback_fee_enabled = true;
346354
}
347355
};
348356

src/chainparams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class CChainParams
6565
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
6666
/** Return the BIP70 network string (main, test or regtest) */
6767
std::string NetworkIDString() const { return strNetworkID; }
68+
/** Return true if the fallback fee is by default enabled for this network */
69+
bool IsFallbackFeeEnabled() const { return m_fallback_fee_enabled; }
6870
/** Return the list of hostnames to look up for DNS seeds */
6971
const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
7072
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
@@ -91,6 +93,7 @@ class CChainParams
9193
bool fMineBlocksOnDemand;
9294
CCheckpointData checkpointData;
9395
ChainTxData chainTxData;
96+
bool m_fallback_fee_enabled;
9497
};
9598

9699
/**

src/qt/test/wallettests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ void TestGUI()
158158
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
159159
}
160160
bitdb.MakeMock();
161+
g_wallet_allow_fallback_fee = true;
162+
161163
std::unique_ptr<CWalletDBWrapper> dbw(new CWalletDBWrapper(&bitdb, "wallet_test.dat"));
162164
CWallet wallet(std::move(dbw));
163165
bool firstRun;

src/wallet/fees.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ CAmount GetMinimumFee(unsigned int nTxBytes, const CCoinControl& coin_control, c
5353
// if we don't have enough data for estimateSmartFee, then use fallbackFee
5454
fee_needed = CWallet::fallbackFee.GetFee(nTxBytes);
5555
if (feeCalc) feeCalc->reason = FeeReason::FALLBACK;
56+
57+
// directly return if fallback fee is disabled (feerate 0 == disabled)
58+
if (CWallet::fallbackFee.GetFee(1000) == 0) return fee_needed;
5659
}
5760
// Obey mempool min fee when using smart fee estimation
5861
CAmount min_mempool_fee = pool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFee(nTxBytes);

src/wallet/init.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <wallet/init.h>
77

8+
#include <chainparams.h>
89
#include <net.h>
910
#include <util.h>
1011
#include <utilmoneystr.h>
@@ -123,6 +124,8 @@ bool WalletParameterInteraction()
123124
_("This is the minimum transaction fee you pay on every transaction."));
124125
CWallet::minTxFee = CFeeRate(n);
125126
}
127+
128+
g_wallet_allow_fallback_fee = Params().IsFallbackFeeEnabled();
126129
if (gArgs.IsArgSet("-fallbackfee"))
127130
{
128131
CAmount nFeePerK = 0;
@@ -132,6 +135,7 @@ bool WalletParameterInteraction()
132135
InitWarning(AmountHighWarn("-fallbackfee") + " " +
133136
_("This is the transaction fee you may pay when fee estimates are not available."));
134137
CWallet::fallbackFee = CFeeRate(nFeePerK);
138+
g_wallet_allow_fallback_fee = nFeePerK != 0; //disable fallback fee in case value was set to 0, enable if non-null value
135139
}
136140
if (gArgs.IsArgSet("-discardfee"))
137141
{

src/wallet/test/wallet_test_fixture.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ WalletTestingSetup::WalletTestingSetup(const std::string& chainName):
1111
TestingSetup(chainName)
1212
{
1313
bitdb.MakeMock();
14+
g_wallet_allow_fallback_fee = true;
1415

1516
bool fFirstRun;
1617
g_address_type = OUTPUT_TYPE_DEFAULT;

src/wallet/wallet.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE;
4343
bool fWalletRbf = DEFAULT_WALLET_RBF;
4444
OutputType g_address_type = OUTPUT_TYPE_NONE;
4545
OutputType g_change_type = OUTPUT_TYPE_NONE;
46+
bool g_wallet_allow_fallback_fee = false; //<! will be defined via chainparams
4647

4748
const char * DEFAULT_WALLET_DAT = "wallet.dat";
4849
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
@@ -2918,6 +2919,11 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
29182919
}
29192920

29202921
nFeeNeeded = GetMinimumFee(nBytes, coin_control, ::mempool, ::feeEstimator, &feeCalc);
2922+
if (feeCalc.reason == FeeReason::FALLBACK && !g_wallet_allow_fallback_fee) {
2923+
// eventually allow a fallback fee
2924+
strFailReason = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee.");
2925+
return false;
2926+
}
29212927

29222928
// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
29232929
// because we must be at the maximum allowed fee.

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern CFeeRate payTxFee;
3939
extern unsigned int nTxConfirmTarget;
4040
extern bool bSpendZeroConfChange;
4141
extern bool fWalletRbf;
42+
extern bool g_wallet_allow_fallback_fee;
4243

4344
static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
4445
//! -paytxfee default
@@ -65,6 +66,7 @@ static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
6566
static const bool DEFAULT_WALLET_RBF = false;
6667
static const bool DEFAULT_WALLETBROADCAST = true;
6768
static const bool DEFAULT_DISABLE_WALLET = false;
69+
static const bool DEFAULT_WALLET_ALLOW_FALLBACKFEE = true;
6870

6971
extern const char * DEFAULT_WALLET_DAT;
7072

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
'feature_cltv.py',
127127
'rpc_uptime.py',
128128
'wallet_resendwallettransactions.py',
129+
'wallet_fallbackfee.py',
129130
'feature_minchainwork.py',
130131
'p2p_fingerprint.py',
131132
'feature_uacomment.py',

test/functional/wallet_fallbackfee.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2017 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test wallet replace-by-fee capabilities in conjunction with the fallbackfee."""
6+
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import *
8+
9+
class WalletRBFTest(BitcoinTestFramework):
10+
def set_test_params(self):
11+
self.num_nodes = 1
12+
self.setup_clean_chain = True
13+
14+
def run_test(self):
15+
self.nodes[0].generate(101)
16+
17+
# sending a transaction without fee estimations must be possible by default on regtest
18+
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
19+
20+
# test sending a tx with disabled fallback fee (must fail)
21+
self.restart_node(0, extra_args=["-fallbackfee=0"])
22+
assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
23+
assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].fundrawtransaction(self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1})))
24+
assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].sendfrom("", self.nodes[0].getnewaddress(), 1))
25+
assert_raises_rpc_error(-6, "Fee estimation failed", lambda: self.nodes[0].sendmany("", {self.nodes[0].getnewaddress(): 1}))
26+
27+
if __name__ == '__main__':
28+
WalletRBFTest().main()

0 commit comments

Comments
 (0)