Skip to content

Commit 9be4f3e

Browse files
committed
wallet: walletpassphrase timeout to be set to MAX_SLEEP_TIME in non-mainnet
In this change we allow the timeout for walletpassphrase to be set to MAX_SLEEP_TIME, if set as 0 then we then use the MAX_SLEEP_TIME amount, this will only happen in non-mainnet context from PR 28403 added release notes for RPC Wallet Also tests were modified to use the max timeout amount using timeout=0
1 parent 8f7b9eb commit 9be4f3e

File tree

8 files changed

+27
-15
lines changed

8 files changed

+27
-15
lines changed

doc/release-notes-28454.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RPC Wallet
2+
----------
3+
4+
- The `walletpassphrase` call will now uses the value of 100,000,000 seconds (~3 years)
5+
if the user passes a `timeout` value of `0`. (#28454)

src/wallet/rpc/encrypt.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <rpc/util.h>
66
#include <wallet/rpc/util.h>
77
#include <wallet/wallet.h>
8+
#include <chainparams.h>
89

910

1011
namespace wallet {
@@ -18,7 +19,7 @@ RPCHelpMan walletpassphrase()
1819
"time that overrides the old one.\n",
1920
{
2021
{"passphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet passphrase"},
21-
{"timeout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The time to keep the decryption key in seconds; capped at 100000000 (~3 years)."},
22+
{"timeout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The time to keep the decryption key in seconds; capped at 100000000 (~3 years), will use cap if 0 specified in non-mainnet."},
2223
},
2324
RPCResult{RPCResult::Type::NONE, "", ""},
2425
RPCExamples{
@@ -59,6 +60,12 @@ RPCHelpMan walletpassphrase()
5960
}
6061
// Clamp timeout
6162
constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug?
63+
64+
// Allow sleep time to be set to max time by using zero in non mainnet
65+
if (Params().GetChainType() != ChainType::MAIN && nSleepTime == 0) {
66+
nSleepTime = MAX_SLEEP_TIME;
67+
}
68+
6269
if (nSleepTime > MAX_SLEEP_TIME) {
6370
nSleepTime = MAX_SLEEP_TIME;
6471
}

test/functional/wallet_createwallet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def run_test(self):
109109
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w4.getnewaddress)
110110
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", w4.getrawchangeaddress)
111111
# Now set a seed and it should work. Wallet should also be encrypted
112-
w4.walletpassphrase('pass', 60)
112+
w4.walletpassphrase('pass', 0)
113113
if self.options.descriptors:
114114
w4.importdescriptors([{
115115
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPcwuZGKp8TeWppSuLMiLe2d9PupB14QpPeQsqoj3LneJLhGHH13xESfvASyd4EFLJvLrG8b7DrLxEuV7hpF9uUc6XruKA1Wq/0h/*)'),
@@ -142,7 +142,7 @@ def run_test(self):
142142
self.nodes[0].createwallet(wallet_name='wblank', disable_private_keys=False, blank=True, passphrase='thisisapassphrase')
143143
wblank = node.get_wallet_rpc('wblank')
144144
assert_raises_rpc_error(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.", wblank.signmessage, "needanargument", "test")
145-
wblank.walletpassphrase('thisisapassphrase', 60)
145+
wblank.walletpassphrase('thisisapassphrase', 0)
146146
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", wblank.getnewaddress)
147147
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", wblank.getrawchangeaddress)
148148

@@ -151,7 +151,7 @@ def run_test(self):
151151
self.nodes[0].createwallet(wallet_name='w6', disable_private_keys=False, blank=False, passphrase='thisisapassphrase')
152152
w6 = node.get_wallet_rpc('w6')
153153
assert_raises_rpc_error(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.", w6.signmessage, "needanargument", "test")
154-
w6.walletpassphrase('thisisapassphrase', 60)
154+
w6.walletpassphrase('thisisapassphrase', 0)
155155
w6.signmessage(w6.getnewaddress('', 'legacy'), "test")
156156
w6.keypoolrefill(1)
157157
# There should only be 1 key for legacy, 3 for descriptors

test/functional/wallet_descriptor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def run_test(self):
129129

130130
# Encrypt wallet 0
131131
send_wrpc.encryptwallet('pass')
132-
send_wrpc.walletpassphrase('pass', 10)
132+
send_wrpc.walletpassphrase('pass', 0)
133133
addr = send_wrpc.getnewaddress()
134134
info2 = send_wrpc.getaddressinfo(addr)
135135
assert info1['hdmasterfingerprint'] != info2['hdmasterfingerprint']
@@ -143,7 +143,7 @@ def run_test(self):
143143
send_wrpc.getnewaddress()
144144

145145
self.log.info("Test that unlock is needed when deriving only hardened keys in an encrypted wallet")
146-
send_wrpc.walletpassphrase('pass', 10)
146+
send_wrpc.walletpassphrase('pass', 0)
147147
send_wrpc.importdescriptors([{
148148
"desc": "wpkh(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/*h)#y4dfsj7n",
149149
"timestamp": "now",

test/functional/wallet_dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def run_test(self):
173173

174174
# encrypt wallet, restart, unlock and dump
175175
self.nodes[0].encryptwallet('test')
176-
self.nodes[0].walletpassphrase('test', 100)
176+
self.nodes[0].walletpassphrase('test', 0)
177177
# Should be a no-op:
178178
self.nodes[0].keypoolrefill()
179179
self.nodes[0].dumpwallet(wallet_enc_dump)

test/functional/wallet_encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def run_test(self):
9696
passphrase_with_nulls = "Phrase\0With\0Nulls"
9797
self.nodes[0].walletpassphrasechange(passphrase2, passphrase_with_nulls)
9898
# walletpassphrasechange should not stop at null characters
99-
assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase_with_nulls.partition("\0")[0], 10)
100-
self.nodes[0].walletpassphrase(passphrase_with_nulls, 10)
99+
assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase_with_nulls.partition("\0")[0], 0)
100+
self.nodes[0].walletpassphrase(passphrase_with_nulls, 0)
101101
sig = self.nodes[0].signmessage(address, msg)
102102
assert self.nodes[0].verifymessage(address, sig, msg)
103103
self.nodes[0].walletlock()

test/functional/wallet_fundrawtransaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def test_locked_wallet(self):
582582
wallet.encryptwallet("test")
583583

584584
if self.options.descriptors:
585-
wallet.walletpassphrase('test', 10)
585+
wallet.walletpassphrase('test', 0)
586586
wallet.importdescriptors([{
587587
'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/0h/*h)'),
588588
'timestamp': 'now',
@@ -620,7 +620,7 @@ def test_locked_wallet(self):
620620
assert_raises_rpc_error(-4, "Transaction needs a change address, but we can't generate it.", wallet.fundrawtransaction, rawtx)
621621

622622
# Refill the keypool.
623-
wallet.walletpassphrase("test", 100)
623+
wallet.walletpassphrase("test", 0)
624624
wallet.keypoolrefill(8) #need to refill the keypool to get an internal change address
625625
wallet.walletlock()
626626

@@ -635,7 +635,7 @@ def test_locked_wallet(self):
635635
assert fundedTx["changepos"] != -1
636636

637637
# Now we need to unlock.
638-
wallet.walletpassphrase("test", 600)
638+
wallet.walletpassphrase("test", 0)
639639
signedTx = wallet.signrawtransactionwithwallet(fundedTx['hex'])
640640
wallet.sendrawtransaction(signedTx['hex'])
641641
self.generate(self.nodes[1], 1)

test/functional/wallet_keypool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run_test(self):
8585
assert_raises_rpc_error(-12, "Error: Keypool ran out, please call keypoolrefill first", nodes[0].getnewaddress)
8686

8787
# put six (plus 2) new keys in the keypool (100% external-, +100% internal-keys, 1 in min)
88-
nodes[0].walletpassphrase('test', 12000)
88+
nodes[0].walletpassphrase('test', 0)
8989
nodes[0].keypoolrefill(6)
9090
nodes[0].walletlock()
9191
wi = nodes[0].getwalletinfo()
@@ -131,7 +131,7 @@ def run_test(self):
131131
nodes[0].getnewaddress()
132132
assert_raises_rpc_error(-12, "Keypool ran out", nodes[0].getnewaddress)
133133

134-
nodes[0].walletpassphrase('test', 100)
134+
nodes[0].walletpassphrase('test', 0)
135135
nodes[0].keypoolrefill(100)
136136
wi = nodes[0].getwalletinfo()
137137
if self.options.descriptors:
@@ -170,7 +170,7 @@ def run_test(self):
170170
else:
171171
res = w2.importmulti([{'desc': desc, 'timestamp': 'now'}])
172172
assert_equal(res[0]['success'], True)
173-
w1.walletpassphrase('test', 100)
173+
w1.walletpassphrase('test', 0)
174174

175175
res = w1.sendtoaddress(address=address, amount=0.00010000)
176176
self.generate(nodes[0], 1)

0 commit comments

Comments
 (0)