Merge pull request #5742 from nuttycom/fix/sapling_ivk_load

Restore legacy default Sapling addresses to the keystore.
This commit is contained in:
Kris Nuttycombe 2022-03-24 20:00:04 -06:00 committed by GitHub
commit 56f7bce865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

View File

@ -1136,6 +1136,32 @@ bool CWallet::LoadCaches()
}
}
// Sapling legacy addresses were not directly added to the keystore; instead,
// the default address for each key was automatically added to the in-memory
// keystore, but not persisted. Following the addition of unified addresses,
// all addresses must be written to the wallet database explicitly.
auto legacySeed = GetLegacyHDSeed();
if (legacySeed.has_value()) {
for (const auto& [saplingIvk, keyMeta] : mapSaplingZKeyMetadata) {
// This condition only applies for keys derived from the legacy seed
if (keyMeta.seedFp == legacySeed.value().Fingerprint()) {
SaplingExtendedFullViewingKey extfvk;
if (GetSaplingFullViewingKey(saplingIvk, extfvk)) {
auto defaultAddress = extfvk.DefaultAddress();
if (!HaveSaplingIncomingViewingKey(defaultAddress)) {
// restore the address to the keystore and persist it so that
// the database state is consistent.
if (!AddSaplingPaymentAddress(saplingIvk, defaultAddress)) {
LogPrintf("%s: Error: Failed to write legacy Sapling payment address to the wallet database.\n",
__func__);
return false;
}
}
}
}
}
}
// Restore decrypted Orchard notes.
for (const auto& [_, walletTx] : mapWallet) {
if (!walletTx.orchardTxMeta.empty()) {