@@ -1805,33 +1805,18 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
1805
1805
}
1806
1806
m_map_pubkeys[pubkey] = i;
1807
1807
}
1808
- // Write the cache
1809
- for (const auto & parent_xpub_pair : temp_cache.GetCachedParentExtPubKeys ()) {
1810
- CExtPubKey xpub;
1811
- if (m_wallet_descriptor.cache .GetCachedParentExtPubKey (parent_xpub_pair.first , xpub)) {
1812
- if (xpub != parent_xpub_pair.second ) {
1813
- throw std::runtime_error (std::string (__func__) + " : New cached parent xpub does not match already cached parent xpub" );
1814
- }
1815
- continue ;
1816
- }
1808
+ // Merge and write the cache
1809
+ DescriptorCache new_items = m_wallet_descriptor.cache .MergeAndDiff (temp_cache);
1810
+ for (const auto & parent_xpub_pair : new_items.GetCachedParentExtPubKeys ()) {
1817
1811
if (!batch.WriteDescriptorParentCache (parent_xpub_pair.second , id, parent_xpub_pair.first )) {
1818
1812
throw std::runtime_error (std::string (__func__) + " : writing cache item failed" );
1819
1813
}
1820
- m_wallet_descriptor.cache .CacheParentExtPubKey (parent_xpub_pair.first , parent_xpub_pair.second );
1821
1814
}
1822
- for (const auto & derived_xpub_map_pair : temp_cache .GetCachedDerivedExtPubKeys ()) {
1815
+ for (const auto & derived_xpub_map_pair : new_items .GetCachedDerivedExtPubKeys ()) {
1823
1816
for (const auto & derived_xpub_pair : derived_xpub_map_pair.second ) {
1824
- CExtPubKey xpub;
1825
- if (m_wallet_descriptor.cache .GetCachedDerivedExtPubKey (derived_xpub_map_pair.first , derived_xpub_pair.first , xpub)) {
1826
- if (xpub != derived_xpub_pair.second ) {
1827
- throw std::runtime_error (std::string (__func__) + " : New cached derived xpub does not match already cached derived xpub" );
1828
- }
1829
- continue ;
1830
- }
1831
1817
if (!batch.WriteDescriptorDerivedCache (derived_xpub_pair.second , id, derived_xpub_map_pair.first , derived_xpub_pair.first )) {
1832
1818
throw std::runtime_error (std::string (__func__) + " : writing cache item failed" );
1833
1819
}
1834
- m_wallet_descriptor.cache .CacheDerivedExtPubKey (derived_xpub_map_pair.first , derived_xpub_pair.first , derived_xpub_pair.second );
1835
1820
}
1836
1821
}
1837
1822
m_max_cached_index++;
0 commit comments