Skip to content

Commit 6f6f7bb

Browse files
committed
Make legacy wallet upgrades from non-HD to HD always flush the keypool
1 parent 2434b10 commit 6f6f7bb

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual
489489
}
490490
// Regenerate the keypool if upgraded to HD
491491
if (hd_upgrade) {
492-
if (!TopUp()) {
492+
if (!NewKeyPool()) {
493493
error = _("Unable to generate keys");
494494
return false;
495495
}

test/functional/wallet_upgradewallet.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,7 @@ def copy_split_hd():
235235
seed_id = bytearray(seed_id)
236236
seed_id.reverse()
237237
old_kvs = new_kvs
238-
# First 2 keys should still be non-HD
239-
for i in range(0, 2):
240-
info = wallet.getaddressinfo(wallet.getnewaddress())
241-
assert 'hdkeypath' not in info
242-
assert 'hdseedid' not in info
243-
# Next key should be HD
238+
# New keys should be HD (the two old keys have been flushed)
244239
info = wallet.getaddressinfo(wallet.getnewaddress())
245240
assert_equal(seed_id.hex(), info['hdseedid'])
246241
assert_equal('m/0\'/0\'/0\'', info['hdkeypath'])
@@ -291,14 +286,7 @@ def copy_split_hd():
291286
hd_chain_version, external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain)
292287
assert_equal(2, hd_chain_version)
293288
assert_equal(2, internal_counter)
294-
# Drain the keypool by fetching one external key and one change key. Should still be the same keypool
295-
info = wallet.getaddressinfo(wallet.getnewaddress())
296-
assert 'hdseedid' not in info
297-
assert 'hdkeypath' not in info
298-
info = wallet.getaddressinfo(wallet.getrawchangeaddress())
299-
assert 'hdseedid' not in info
300-
assert 'hdkeypath' not in info
301-
# The next addresses are HD and should be on different HD chains
289+
# The next addresses are HD and should be on different HD chains (the one remaining key in each pool should have been flushed)
302290
info = wallet.getaddressinfo(wallet.getnewaddress())
303291
ext_id = info['hdseedid']
304292
assert_equal('m/0\'/0\'/0\'', info['hdkeypath'])

0 commit comments

Comments
 (0)