Skip to content

Commit 815640e

Browse files
committed
Merge #9295: [Wallet] Bugfix: Fundrawtransaction: don't terminate when keypool is empty
1a6eacb [QA] add fundrawtransaction test on a locked wallet with empty keypool (Jonas Schnelli) c24a4f5 [Wallet] Bugfix: FRT: don't terminate when keypool is empty (Jonas Schnelli)
2 parents 72bf1b3 + 1a6eacb commit 815640e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

qa/rpc-tests/fundrawtransaction.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,23 @@ def run_test(self):
484484
self.is_network_split=False
485485
self.sync_all()
486486

487+
# drain the keypool
488+
self.nodes[1].getnewaddress()
489+
inputs = []
490+
outputs = {self.nodes[0].getnewaddress():1.1}
491+
rawTx = self.nodes[1].createrawtransaction(inputs, outputs)
492+
# fund a transaction that requires a new key for the change output
493+
# creating the key must be impossible because the wallet is locked
494+
try:
495+
fundedTx = self.nodes[1].fundrawtransaction(rawTx)
496+
raise AssertionError("Wallet unlocked without passphrase")
497+
except JSONRPCException as e:
498+
assert('Keypool ran out' in e.error['message'])
499+
500+
#refill the keypool
501+
self.nodes[1].walletpassphrase("test", 100)
502+
self.nodes[1].walletlock()
503+
487504
try:
488505
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1.2)
489506
raise AssertionError("Wallet unlocked without passphrase")

src/wallet/wallet.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,11 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
23892389
CPubKey vchPubKey;
23902390
bool ret;
23912391
ret = reservekey.GetReservedKey(vchPubKey);
2392-
assert(ret); // should never fail, as we just unlocked
2392+
if (!ret)
2393+
{
2394+
strFailReason = _("Keypool ran out, please call keypoolrefill first");
2395+
return false;
2396+
}
23932397

23942398
scriptChange = GetScriptForDestination(vchPubKey.GetID());
23952399
}

0 commit comments

Comments
 (0)