Skip to content

Commit 6e6b859

Browse files
committed
Merge #15263: Descriptor expansions only need pubkey entries for PKH/WPKH
11e0fd8 Descriptor expansions only need pubkey entries for PKH/WPKH (Pieter Wuille) Pull request description: Currently, calling `Expand` on a `Descriptor` object will populate the output FlatSigningProvider with all public keys involved in the descriptor. This is overkill, as pubkey entries are only needed when the lookup of a public key based on its hash is desired (which is the case for `pkh`, `wpkh`, and `combo` descriptors). Fix this by pushing the population of pubkey entries down into the individual descriptor implementation's `MakeScript` function, instead of doing it generically. This should make it easier to implement #14491 without importing P2PKH outputs for the individual public keys listed inside a multisig. Tree-SHA512: 5bc7e9bd29f1b3bc63514803e9489b3bf126bfc177d46313aa9eeb98770ec61a97b55bd8ad4e2384154799f24b1bc4183bfdb4708b2ffa6e37ed2601a451cabc
2 parents b3a7153 + 11e0fd8 commit 6e6b859

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/script/descriptor.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class DescriptorImpl : public Descriptor
226226
* @param pubkeys The evaluations of the m_pubkey_args field.
227227
* @param script The evaluation of m_script_arg (or nullptr when m_script_arg is nullptr).
228228
* @param out A FlatSigningProvider to put scripts or public keys in that are necessary to the solver.
229-
* The script and pubkeys argument to this function are automatically added.
229+
* The script arguments to this function are automatically added, as is the origin info of the provided pubkeys.
230230
* @return A vector with scriptPubKeys for this descriptor.
231231
*/
232232
virtual std::vector<CScript> MakeScripts(const std::vector<CPubKey>& pubkeys, const CScript* script, FlatSigningProvider& out) const = 0;
@@ -322,7 +322,6 @@ class DescriptorImpl : public Descriptor
322322
for (auto& entry : entries) {
323323
pubkeys.push_back(entry.first);
324324
out.origins.emplace(entry.first.GetID(), std::move(entry.second));
325-
out.pubkeys.emplace(entry.first.GetID(), entry.first);
326325
}
327326
if (m_script_arg) {
328327
for (const auto& subscript : subscripts) {
@@ -396,7 +395,12 @@ class PKDescriptor final : public DescriptorImpl
396395
class PKHDescriptor final : public DescriptorImpl
397396
{
398397
protected:
399-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(keys[0].GetID())); }
398+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider& out) const override
399+
{
400+
CKeyID id = keys[0].GetID();
401+
out.pubkeys.emplace(id, keys[0]);
402+
return Singleton(GetScriptForDestination(id));
403+
}
400404
public:
401405
PKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton(std::move(prov)), {}, "pkh") {}
402406
};
@@ -405,7 +409,12 @@ class PKHDescriptor final : public DescriptorImpl
405409
class WPKHDescriptor final : public DescriptorImpl
406410
{
407411
protected:
408-
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider&) const override { return Singleton(GetScriptForDestination(WitnessV0KeyHash(keys[0].GetID()))); }
412+
std::vector<CScript> MakeScripts(const std::vector<CPubKey>& keys, const CScript*, FlatSigningProvider& out) const override
413+
{
414+
CKeyID id = keys[0].GetID();
415+
out.pubkeys.emplace(id, keys[0]);
416+
return Singleton(GetScriptForDestination(WitnessV0KeyHash(id)));
417+
}
409418
public:
410419
WPKHDescriptor(std::unique_ptr<PubkeyProvider> prov) : DescriptorImpl(Singleton(std::move(prov)), {}, "wpkh") {}
411420
};
@@ -418,6 +427,7 @@ class ComboDescriptor final : public DescriptorImpl
418427
{
419428
std::vector<CScript> ret;
420429
CKeyID id = keys[0].GetID();
430+
out.pubkeys.emplace(id, keys[0]);
421431
ret.emplace_back(GetScriptForRawPubKey(keys[0])); // P2PK
422432
ret.emplace_back(GetScriptForDestination(id)); // P2PKH
423433
if (keys[0].IsCompressed()) {

0 commit comments

Comments
 (0)