wallet: don't copy every encrypted Sapling key on each lookup
CCryptoKeyStore::HaveSaplingSpendingKey and GetSaplingSpendingKey scan mapCryptedSaplingSpendingKeys with `for (auto entry : ...)`. That copies each entry (an extended full viewing key plus its encrypted-secret vector) for every key visited, on every call. GetFilteredNotes' requireSpendingKey check makes one such call per note, and the history RPCs make one per output per address: ~22ns per key per call, measured (11us per note on a 1024-key wallet). Iterate by const reference. The equivalence test gains a locked, encrypted-keystore variant, LockedWalletMatchesLegacy, so spendability coming from the encrypted map is covered too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -591,7 +591,7 @@ bool CCryptoKeyStore::GetSaplingSpendingKey(const libzcash::SaplingFullViewingKe
|
||||
if (!IsCrypted())
|
||||
return CBasicKeyStore::GetSaplingSpendingKey(fvk, skOut);
|
||||
|
||||
for (auto entry : mapCryptedSaplingSpendingKeys) {
|
||||
for (const auto& entry : mapCryptedSaplingSpendingKeys) {
|
||||
if (entry.first.fvk == fvk) {
|
||||
const std::vector<unsigned char> &vchCryptedSecret = entry.second;
|
||||
return DecryptSaplingSpendingKey(vMasterKey, vchCryptedSecret, entry.first, skOut);
|
||||
|
||||
Reference in New Issue
Block a user