Merge bitcoin/bitcoin#35955: wallet: remove orphaned GetAffectedKeys and LegacyScriptPubKeyMan declarations
What changed, and why it matters
This commit is a routine code cleanup. It removes leftover declarations of functions and classes that no longer exist, renames one internal wallet setup function, and updates comments and log messages to use the current class name. There is no change to how the software behaves or to any security-sensitive logic.
No security action needed. This is a benign refactoring/cleanup change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes orphaned forward declarations of GetAffectedKeys and LegacyScriptPubKeyMan, renames CWallet::SetupLegacyScriptPubKeyMan() to SetupLegacyDataSPKM(), and updates comments/logging to refer to LegacyDataSPKM. The actual legacy-wallet loading and migration code remains unchanged; only naming and documentation are aligned with the class that already exists.
Changed components
src/wallet/scriptpubkeyman.hsrc/wallet/wallet.hsrc/wallet/wallet.cppsrc/wallet/walletdb.cppsrc/wallet/walletdb.hsrc/wallet/rpc/util.hsrc/script/signingprovider.hInspect captured patch +27 / −29
### src/script/signingprovider.h
@@ -301,7 +301,7 @@ class FillableSigningProvider : public SigningProvider
* payments.
*
* The FillableSigningProvider::mapScripts script map should not be confused
- * with LegacyScriptPubKeyMan::setWatchOnly script set. The two collections
+ * with the wallet::LegacyDataSPKM::setWatchOnly script set. The two collections
* can hold the same scripts, but they serve different purposes. The
* setWatchOnly script set is intended to expand the set of outputs the
* wallet considers payments. Every output with a script it contains is
### src/wallet/rpc/util.h
@@ -21,7 +21,6 @@ class UniValue;
struct bilingual_str;
namespace wallet {
-class LegacyScriptPubKeyMan;
enum class DatabaseStatus;
struct WalletContext;
### src/wallet/scriptpubkeyman.h
@@ -63,8 +63,6 @@ inline constexpr int64_t UNKNOWN_TIME = std::numeric_limits<int64_t>::max();
//! Default for -keypool
inline constexpr unsigned int DEFAULT_KEYPOOL_SIZE = 1000;
-std::vector<CKeyID> GetAffectedKeys(const CScript& spk, const SigningProvider& provider);
-
struct WalletDestination
{
CTxDestination dest;
@@ -160,7 +158,7 @@ class ScriptPubKeyMan
btcsignals::signal<void (const ScriptPubKeyMan* spkm, int64_t new_birth_time)> NotifyFirstKeyTimeChanged;
};
-/** OutputTypes supported by the LegacyScriptPubKeyMan */
+/** Output types associated with LegacyDataSPKM. */
inline const std::unordered_set<OutputType> LEGACY_OUTPUT_TYPES {
OutputType::LEGACY,
OutputType::P2SH_SEGWIT,
@@ -170,8 +168,7 @@ inline const std::unordered_set<OutputType> LEGACY_OUTPUT_TYPES {
using KeyMap = std::map<CKeyID, CKey>;
using CryptedKeyMap = std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char>>>;
-// Manages the data for a LegacyScriptPubKeyMan.
-// This is the minimum necessary to load a legacy wallet so that it can be migrated.
+// Manages the minimum data needed to load and migrate a legacy wallet.
class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider
{
private:
@@ -249,14 +246,14 @@ class LegacyDataSPKM : public ScriptPubKeyMan, public FillableSigningProvider
*/
std::unordered_set<CScript, SaltedSipHasher> GetNotMineScriptPubKeys() const;
- /** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyScriptPubKeyMan.
- * Does not modify this ScriptPubKeyMan. */
+ /** Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyDataSPKM.
+ * Does not modify this LegacyDataSPKM. */
std::optional<MigrationData> MigrateToDescriptor();
- /** Delete all the records of this LegacyScriptPubKeyMan from disk*/
+ /** Delete the legacy wallet records from disk. */
bool DeleteRecordsWithDB(WalletBatch& batch);
};
-/** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr. Does not provide privkeys */
+/** SigningProvider wrapper for LegacyDataSPKM that does not provide private keys. */
class LegacySigningProvider : public SigningProvider
{
private:
@@ -362,8 +359,8 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
void ReturnDestination(int64_t index, bool internal, const CTxDestination& addr) override;
// Tops up the descriptor cache and m_map_script_pub_keys. The cache is stored in the wallet file
- // and is used to expand the descriptor in GetNewDestination. DescriptorScriptPubKeyMan relies
- // more on ephemeral data than LegacyScriptPubKeyMan. For wallets using unhardened derivation
+ // and is used to expand the descriptor in GetNewDestination. Descriptor wallets rely more on
+ // ephemeral data than legacy wallets. For wallets using unhardened derivation
// (with or without private keys), the "keypool" is a single xpub.
bool TopUp(unsigned int size = 0) override;
### src/wallet/wallet.cpp
@@ -3536,11 +3536,11 @@ void CWallet::AddScriptPubKeyMan(const uint256& id, std::unique_ptr<ScriptPubKey
LegacyDataSPKM* CWallet::GetOrCreateLegacyDataSPKM()
{
- SetupLegacyScriptPubKeyMan();
+ SetupLegacyDataSPKM();
return GetLegacyDataSPKM();
}
-void CWallet::SetupLegacyScriptPubKeyMan()
+void CWallet::SetupLegacyDataSPKM()
{
if (!m_internal_spk_managers.empty() || !m_external_spk_managers.empty() || !m_spk_managers.empty() || IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
return;
@@ -3967,12 +3967,12 @@ util::Result<void> CWallet::ApplyMigrationData(WalletBatch& local_wallet_batch,
AddScriptPubKeyMan(id, std::move(desc_spkm));
}
- // Remove the LegacyScriptPubKeyMan from disk
+ // Remove the LegacyDataSPKM's records from disk
if (!legacy_spkm->DeleteRecordsWithDB(local_wallet_batch)) {
return util::Error{_("Error: cannot remove legacy wallet records")};
}
- // Remove the LegacyScriptPubKeyMan from memory
+ // Remove the LegacyDataSPKM from memory
m_spk_managers.erase(legacy_spkm->GetID());
m_external_spk_managers.clear();
m_internal_spk_managers.clear();
@@ -4208,8 +4208,9 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
FlatSigningProvider keys;
std::string parse_err;
std::vector<std::unique_ptr<Descriptor>> descs = Parse(desc_str, keys, parse_err, /*require_checksum=*/ true);
- assert(descs.size() == 1); // It shouldn't be possible to have the LegacyScriptPubKeyMan make an invalid descriptor or a multipath descriptors
- assert(!descs.at(0)->IsRange()); // It shouldn't be possible to have LegacyScriptPubKeyMan make a ranged watchonly descriptor
+ // LegacyDataSPKM should not produce invalid, multipath, or ranged watch-only descriptors.
+ assert(descs.size() == 1);
+ assert(!descs.at(0)->IsRange());
// Add to the wallet
WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0);
@@ -4247,8 +4248,9 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
FlatSigningProvider keys;
std::string parse_err;
std::vector<std::unique_ptr<Descriptor>> descs = Parse(desc_str, keys, parse_err, /*require_checksum=*/ true);
- assert(descs.size() == 1); // It shouldn't be possible to have the LegacyScriptPubKeyMan make an invalid descriptor or a multipath descriptors
- assert(!descs.at(0)->IsRange()); // It shouldn't be possible to have LegacyScriptPubKeyMan make a ranged watchonly descriptor
+ // LegacyDataSPKM should not produce invalid, multipath, or ranged watch-only descriptors.
+ assert(descs.size() == 1);
+ assert(!descs.at(0)->IsRange());
// Add to the wallet
WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0);
@@ -4262,7 +4264,7 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
}
}
- // Add the descriptors to wallet, remove LegacyScriptPubKeyMan, and cleanup txs and address book data
+ // Add the descriptors to the wallet, remove the LegacyDataSPKM, and clean up transactions and address book data
return RunWithinTxn(wallet.GetDatabase(), /*process_desc=*/"apply migration process", [&](WalletBatch& batch) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet){
if (auto res_migration = wallet.ApplyMigrationData(batch, *data); !res_migration) {
error = util::ErrorString(res_migration);
### src/wallet/wallet.h
@@ -979,12 +979,12 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
//! Get the wallet descriptors for a script.
std::vector<WalletDescriptor> GetWalletDescriptors(const CScript& script) const;
- //! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
+ //! Get the LegacyDataSPKM used for all legacy output types and both internal and external chains.
LegacyDataSPKM* GetLegacyDataSPKM() const;
LegacyDataSPKM* GetOrCreateLegacyDataSPKM();
- //! Make a Legacy(Data)SPKM and set it for all types, internal, and external.
- void SetupLegacyScriptPubKeyMan();
+ //! Create a LegacyDataSPKM and set it for all legacy output types and both internal and external chains.
+ void SetupLegacyDataSPKM();
bool WithEncryptionKey(std::function<bool (const CKeyingMaterial&)> cb) const override;
@@ -1066,8 +1066,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
//! Get all of the descriptors from a legacy wallet
std::optional<MigrationData> GetDescriptorsForLegacy(bilingual_str& error) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
- //! Adds the ScriptPubKeyMans given in MigrationData to this wallet, removes LegacyScriptPubKeyMan,
- //! and where needed, moves tx and address book entries to watchonly_wallet or solvable_wallet
+ //! Adds the ScriptPubKeyMans from MigrationData to this wallet, removes the LegacyDataSPKM,
+ //! and moves transaction and address book entries to watchonly_wallet or solvable_wallet as needed.
util::Result<void> ApplyMigrationData(WalletBatch& local_wallet_batch, MigrationData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
//! Whether the (external) signer performs R-value signature grinding
### src/wallet/walletdb.cpp
@@ -672,7 +672,7 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
}
}
} else {
- pwallet->WalletLogPrintf("Inactive HD Chains found but no Legacy ScriptPubKeyMan\n");
+ pwallet->WalletLogPrintf("Inactive HD chains found but no LegacyDataSPKM\n");
result = DBErrors::CORRUPT;
}
}
### src/wallet/walletdb.h
@@ -88,7 +88,7 @@ extern const std::string WALLETDESCRIPTORKEY;
extern const std::string WATCHMETA;
extern const std::string WATCHS;
-// Keys in this set pertain only to the legacy wallet (LegacyScriptPubKeyMan) and are removed during migration from legacy to descriptors.
+// Keys in this set pertain only to legacy wallets and are removed during migration to descriptors.
extern const std::unordered_set<std::string> LEGACY_TYPES;
} // namespace DBKeys
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.