@@ -166,7 +166,7 @@ struct PubkeyProvider
166166 * write_cache is the cache to write keys to (if not nullptr)
167167 * Caches are not exclusive but this is not tested. Currently we use them exclusively
168168 */
169- virtual bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) = 0;
169+ virtual bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const = 0;
170170
171171 /* * Whether this represent multiple public keys at different positions. */
172172 virtual bool IsRange () const = 0;
@@ -199,7 +199,7 @@ class OriginPubkeyProvider final : public PubkeyProvider
199199
200200public:
201201 OriginPubkeyProvider (uint32_t exp_index, KeyOriginInfo info, std::unique_ptr<PubkeyProvider> provider) : PubkeyProvider(exp_index), m_origin(std::move(info)), m_provider(std::move(provider)) {}
202- bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) override
202+ bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const override
203203 {
204204 if (!m_provider->GetPubKey (pos, arg, key, info, read_cache, write_cache)) return false ;
205205 std::copy (std::begin (m_origin.fingerprint ), std::end (m_origin.fingerprint ), info.fingerprint );
@@ -245,7 +245,7 @@ class ConstPubkeyProvider final : public PubkeyProvider
245245
246246public:
247247 ConstPubkeyProvider (uint32_t exp_index, const CPubKey& pubkey, bool xonly) : PubkeyProvider(exp_index), m_pubkey(pubkey), m_xonly(xonly) {}
248- bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) override
248+ bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key, KeyOriginInfo& info, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const override
249249 {
250250 key = m_pubkey;
251251 info.path .clear ();
@@ -288,9 +288,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
288288 CExtPubKey m_root_extkey;
289289 KeyPath m_path;
290290 DeriveType m_derive;
291- // Cache of the parent of the final derived pubkeys.
292- // Primarily useful for situations when no read_cache is provided
293- CExtPubKey m_cached_xpub;
294291
295292 bool GetExtKey (const SigningProvider& arg, CExtKey& ret) const
296293 {
@@ -327,7 +324,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
327324 BIP32PubkeyProvider (uint32_t exp_index, const CExtPubKey& extkey, KeyPath path, DeriveType derive) : PubkeyProvider(exp_index), m_root_extkey(extkey), m_path(std::move(path)), m_derive(derive) {}
328325 bool IsRange () const override { return m_derive != DeriveType::NO; }
329326 size_t GetSize () const override { return 33 ; }
330- bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key_out, KeyOriginInfo& final_info_out, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) override
327+ bool GetPubKey (int pos, const SigningProvider& arg, CPubKey& key_out, KeyOriginInfo& final_info_out, const DescriptorCache* read_cache = nullptr , DescriptorCache* write_cache = nullptr ) const override
331328 {
332329 // Info of parent of the to be derived pubkey
333330 KeyOriginInfo parent_info;
@@ -352,9 +349,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
352349 final_extkey = parent_extkey;
353350 if (m_derive == DeriveType::UNHARDENED) der = parent_extkey.Derive (final_extkey, pos);
354351 }
355- } else if (m_cached_xpub.pubkey .IsValid () && m_derive != DeriveType::HARDENED) {
356- parent_extkey = final_extkey = m_cached_xpub;
357- if (m_derive == DeriveType::UNHARDENED) der = parent_extkey.Derive (final_extkey, pos);
358352 } else if (IsHardened ()) {
359353 CExtKey xprv;
360354 if (!GetDerivedExtKey (arg, xprv)) return false ;
@@ -376,11 +370,6 @@ class BIP32PubkeyProvider final : public PubkeyProvider
376370 final_info_out = final_info_out_tmp;
377371 key_out = final_extkey.pubkey ;
378372
379- // We rely on the consumer to check that m_derive isn't HARDENED as above
380- // But we can't have already cached something in case we read something from the cache
381- // and parent_extkey isn't actually the parent.
382- if (!m_cached_xpub.pubkey .IsValid ()) m_cached_xpub = parent_extkey;
383-
384373 if (write_cache) {
385374 // Only cache parent if there is any unhardened derivation
386375 if (m_derive != DeriveType::HARDENED) {
0 commit comments