Skip to content

Commit a76dc40

Browse files
MarcoFalkeTom Trevethan
authored andcommitted
Merge bitcoin/bitcoin#24502: wallet: don't create long chains by default
da2bc86 [wallet] don't create long chains by default (glozow) Additional functional test for too-long-chains rejected. Pull request description: Default mempool policy doesn't let you have chains longer than 25 transactions. This is locally configurable of course, but it's not really safe to assume that a chain longer than 25 transactions will propagate. Thus, the wallet should probably avoid creating such transactions by default; set `DEFAULT_WALLET_REJECT_LONG_CHAINS` to true. Closes #9752 Closes #10004 ACKs for top commit: MarcoFalke: re-ACK da2bc86 only change is fixing typos in tests 🎏 Tree-SHA512: 65d8e4ec437fe928adf554aa7e819a52e0599b403d5310895f4e371e99bbc838219b3097c4d2f775bc870ac617ef6b4227b94291f2b376f824f14e8f2b152f31
1 parent 2d6711c commit a76dc40

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
9898
//! Default for -spendzeroconfchange
9999
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
100100
//! Default for -walletrejectlongchains
101-
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS = false;
101+
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS{true};
102102
//! -txconfirmtarget default
103103
static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
104104
//! -walletrbf default

test/functional/wallet_balance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def set_test_params(self):
5353
self.num_nodes = 2
5454
self.setup_clean_chain = True
5555
self.extra_args = [
56-
['-limitdescendantcount=3'], # Limit mempool descendants as a hack to have wallet txs rejected from the mempool
56+
# Limit mempool descendants as a hack to have wallet txs rejected from the mempool.
57+
# Set walletrejectlongchains=0 so the wallet still creates the transactions.
58+
['-limitdescendantcount=3', '-walletrejectlongchains=0'],
5759
[],
5860
]
5961

test/functional/wallet_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def set_test_params(self):
2727
self.extra_args = [[
2828
"-acceptnonstdtxn=1",
2929
"-bech32_hrp=bcrt",
30+
"-walletrejectlongchains=0"
3031
]] * self.num_nodes
3132
self.setup_clean_chain = True
3233
self.supports_cli = False
@@ -573,7 +574,7 @@ def run_test(self):
573574
self.log.info("Test -reindex")
574575
self.stop_nodes()
575576
# set lower ancestor limit for later
576-
self.start_node(0, ['-reindex', "-limitancestorcount=" + str(chainlimit)])
577+
self.start_node(0, ['-reindex', "-walletrejectlongchains=0", "-limitancestorcount=" + str(chainlimit)])
577578
self.start_node(1, ['-reindex', "-limitancestorcount=" + str(chainlimit)])
578579
self.start_node(2, ['-reindex', "-limitancestorcount=" + str(chainlimit)])
579580
# reindex will leave rpc warm up "early"; Wait for it to finish

test/functional/wallet_create_tx.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def run_test(self):
2929

3030
self.test_anti_fee_sniping()
3131
self.test_tx_size_too_large()
32+
self.test_create_too_long_mempool_chain()
3233

3334
def test_anti_fee_sniping(self):
3435
self.log.info('Check that we have some (old) blocks and that anti-fee-sniping is disabled')
@@ -80,6 +81,31 @@ def test_tx_size_too_large(self):
8081
)
8182
self.nodes[0].settxfee(0)
8283

84+
def test_create_too_long_mempool_chain(self):
85+
self.log.info('Check too-long mempool chain error')
86+
df_wallet = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
87+
88+
self.nodes[0].createwallet("too_long")
89+
test_wallet = self.nodes[0].get_wallet_rpc("too_long")
90+
91+
tx_data = df_wallet.send(outputs=[{test_wallet.getnewaddress(): 25}], options={"change_position": 0})
92+
txid = tx_data['txid']
93+
vout = 1
94+
95+
options = {"change_position": 0, "add_inputs": False}
96+
for i in range(1, 25):
97+
options['inputs'] = [{'txid': txid, 'vout': vout}]
98+
tx_data = test_wallet.send(outputs=[{test_wallet.getnewaddress(): 25 - i}], options=options)
99+
txid = tx_data['txid']
100+
101+
options = {"include_unsafe": True, 'add_inputs': True}
102+
# Sending one more chained transaction will fail
103+
assert_raises_rpc_error(-4, "Insufficient funds",
104+
test_wallet.send, outputs=[{test_wallet.getnewaddress(): 0.3}], options=options)
105+
106+
test_wallet.unloadwallet()
107+
108+
83109

84110
if __name__ == '__main__':
85111
CreateTxWalletTest().main()

0 commit comments

Comments
 (0)