Make legacy wallet upgrades from non-HD to HD always flush the keypool

pull/826/head
Samuel Dobson 3 years ago
parent 2434b10781
commit 6f6f7bb36c

@ -489,7 +489,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual
} }
// Regenerate the keypool if upgraded to HD // Regenerate the keypool if upgraded to HD
if (hd_upgrade) { if (hd_upgrade) {
if (!TopUp()) { if (!NewKeyPool()) {
error = _("Unable to generate keys"); error = _("Unable to generate keys");
return false; return false;
} }

@ -235,12 +235,7 @@ class UpgradeWalletTest(BitcoinTestFramework):
seed_id = bytearray(seed_id) seed_id = bytearray(seed_id)
seed_id.reverse() seed_id.reverse()
old_kvs = new_kvs old_kvs = new_kvs
# First 2 keys should still be non-HD # New keys should be HD (the two old keys have been flushed)
for i in range(0, 2):
info = wallet.getaddressinfo(wallet.getnewaddress())
assert 'hdkeypath' not in info
assert 'hdseedid' not in info
# Next key should be HD
info = wallet.getaddressinfo(wallet.getnewaddress()) info = wallet.getaddressinfo(wallet.getnewaddress())
assert_equal(seed_id.hex(), info['hdseedid']) assert_equal(seed_id.hex(), info['hdseedid'])
assert_equal('m/0\'/0\'/0\'', info['hdkeypath']) assert_equal('m/0\'/0\'/0\'', info['hdkeypath'])
@ -291,14 +286,7 @@ class UpgradeWalletTest(BitcoinTestFramework):
hd_chain_version, external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain) hd_chain_version, external_counter, seed_id, internal_counter = struct.unpack('<iI20sI', hd_chain)
assert_equal(2, hd_chain_version) assert_equal(2, hd_chain_version)
assert_equal(2, internal_counter) assert_equal(2, internal_counter)
# Drain the keypool by fetching one external key and one change key. Should still be the same keypool # The next addresses are HD and should be on different HD chains (the one remaining key in each pool should have been flushed)
info = wallet.getaddressinfo(wallet.getnewaddress())
assert 'hdseedid' not in info
assert 'hdkeypath' not in info
info = wallet.getaddressinfo(wallet.getrawchangeaddress())
assert 'hdseedid' not in info
assert 'hdkeypath' not in info
# The next addresses are HD and should be on different HD chains
info = wallet.getaddressinfo(wallet.getnewaddress()) info = wallet.getaddressinfo(wallet.getnewaddress())
ext_id = info['hdseedid'] ext_id = info['hdseedid']
assert_equal('m/0\'/0\'/0\'', info['hdkeypath']) assert_equal('m/0\'/0\'/0\'', info['hdkeypath'])

Loading…
Cancel
Save