diff --git a/doc/developer-notes.md b/doc/developer-notes.md --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -419,7 +419,7 @@ Re-architecting the core code so there are better-defined interfaces between the various components is a goal, with any necessary locking -done by the components (e.g. see the self-contained `CBasicKeyStore` class +done by the components (e.g. see the self-contained `FillableSigningProvider` class and its `cs_KeyStore` lock for example). Threads diff --git a/src/bench/ccoins_caching.cpp b/src/bench/ccoins_caching.cpp --- a/src/bench/ccoins_caching.cpp +++ b/src/bench/ccoins_caching.cpp @@ -17,7 +17,8 @@ // paid to a TX_PUBKEYHASH. // static std::vector -SetupDummyInputs(CBasicKeyStore &keystoreRet, CCoinsViewCache &coinsRet) { +SetupDummyInputs(FillableSigningProvider &keystoreRet, + CCoinsViewCache &coinsRet) { std::vector dummyTransactions; dummyTransactions.resize(2); @@ -57,7 +58,7 @@ // every benchmark." // (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484) static void CCoinsCaching(benchmark::State &state) { - CBasicKeyStore keystore; + FillableSigningProvider keystore; CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); std::vector dummyTransactions = diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -599,7 +599,7 @@ throw std::runtime_error("privatekeys register variable must be set."); } - CBasicKeyStore tempKeystore; + FillableSigningProvider tempKeystore; UniValue keysObj = registers["privatekeys"]; for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) { @@ -684,7 +684,7 @@ } } - const CBasicKeyStore &keystore = tempKeystore; + const FillableSigningProvider &keystore = tempKeystore; // Sign what we can: for (size_t i = 0; i < mergedTx.vin.size(); i++) { diff --git a/src/keystore.h b/src/keystore.h --- a/src/keystore.h +++ b/src/keystore.h @@ -16,7 +16,7 @@ #include /** Basic key store, that keeps keys in an address->secret map */ -class CBasicKeyStore : public SigningProvider { +class FillableSigningProvider : public SigningProvider { protected: mutable RecursiveMutex cs_KeyStore; @@ -58,7 +58,7 @@ /** * Return the CKeyID of the key involved in a script (if there is a unique one). */ -CKeyID GetKeyForDestination(const CBasicKeyStore &store, +CKeyID GetKeyForDestination(const FillableSigningProvider &store, const CTxDestination &dest); #endif // BITCOIN_KEYSTORE_H diff --git a/src/keystore.cpp b/src/keystore.cpp --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -9,7 +9,8 @@ #include #include -void CBasicKeyStore::ImplicitlyLearnRelatedKeyScripts(const CPubKey &pubkey) { +void FillableSigningProvider::ImplicitlyLearnRelatedKeyScripts( + const CPubKey &pubkey) { AssertLockHeld(cs_KeyStore); CKeyID key_id = pubkey.GetID(); // We must actually know about this key already. @@ -25,8 +26,8 @@ // Right now there are none so do nothing. } -bool CBasicKeyStore::GetPubKey(const CKeyID &address, - CPubKey &vchPubKeyOut) const { +bool FillableSigningProvider::GetPubKey(const CKeyID &address, + CPubKey &vchPubKeyOut) const { CKey key; if (!GetKey(address, key)) { LOCK(cs_KeyStore); @@ -41,19 +42,20 @@ return true; } -bool CBasicKeyStore::AddKeyPubKey(const CKey &key, const CPubKey &pubkey) { +bool FillableSigningProvider::AddKeyPubKey(const CKey &key, + const CPubKey &pubkey) { LOCK(cs_KeyStore); mapKeys[pubkey.GetID()] = key; ImplicitlyLearnRelatedKeyScripts(pubkey); return true; } -bool CBasicKeyStore::HaveKey(const CKeyID &address) const { +bool FillableSigningProvider::HaveKey(const CKeyID &address) const { LOCK(cs_KeyStore); return mapKeys.count(address) > 0; } -std::set CBasicKeyStore::GetKeys() const { +std::set FillableSigningProvider::GetKeys() const { LOCK(cs_KeyStore); std::set set_address; for (const auto &mi : mapKeys) { @@ -62,7 +64,8 @@ return set_address; } -bool CBasicKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const { +bool FillableSigningProvider::GetKey(const CKeyID &address, + CKey &keyOut) const { LOCK(cs_KeyStore); KeyMap::const_iterator mi = mapKeys.find(address); if (mi != mapKeys.end()) { @@ -72,11 +75,12 @@ return false; } -bool CBasicKeyStore::AddCScript(const CScript &redeemScript) { +bool FillableSigningProvider::AddCScript(const CScript &redeemScript) { if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { - return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes " - "are invalid", - MAX_SCRIPT_ELEMENT_SIZE); + return error( + "FillableSigningProvider::AddCScript(): redeemScripts > %i bytes " + "are invalid", + MAX_SCRIPT_ELEMENT_SIZE); } LOCK(cs_KeyStore); @@ -84,12 +88,12 @@ return true; } -bool CBasicKeyStore::HaveCScript(const CScriptID &hash) const { +bool FillableSigningProvider::HaveCScript(const CScriptID &hash) const { LOCK(cs_KeyStore); return mapScripts.count(hash) > 0; } -std::set CBasicKeyStore::GetCScripts() const { +std::set FillableSigningProvider::GetCScripts() const { LOCK(cs_KeyStore); std::set set_script; for (const auto &mi : mapScripts) { @@ -98,8 +102,8 @@ return set_script; } -bool CBasicKeyStore::GetCScript(const CScriptID &hash, - CScript &redeemScriptOut) const { +bool FillableSigningProvider::GetCScript(const CScriptID &hash, + CScript &redeemScriptOut) const { LOCK(cs_KeyStore); ScriptMap::const_iterator mi = mapScripts.find(hash); if (mi != mapScripts.end()) { @@ -128,7 +132,7 @@ return true; } -bool CBasicKeyStore::AddWatchOnly(const CScript &dest) { +bool FillableSigningProvider::AddWatchOnly(const CScript &dest) { LOCK(cs_KeyStore); setWatchOnly.insert(dest); CPubKey pubKey; @@ -139,7 +143,7 @@ return true; } -bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest) { +bool FillableSigningProvider::RemoveWatchOnly(const CScript &dest) { LOCK(cs_KeyStore); setWatchOnly.erase(dest); CPubKey pubKey; @@ -151,17 +155,17 @@ return true; } -bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const { +bool FillableSigningProvider::HaveWatchOnly(const CScript &dest) const { LOCK(cs_KeyStore); return setWatchOnly.count(dest) > 0; } -bool CBasicKeyStore::HaveWatchOnly() const { +bool FillableSigningProvider::HaveWatchOnly() const { LOCK(cs_KeyStore); return (!setWatchOnly.empty()); } -CKeyID GetKeyForDestination(const CBasicKeyStore &store, +CKeyID GetKeyForDestination(const FillableSigningProvider &store, const CTxDestination &dest) { // Only supports destinations which map to single public keys, i.e. P2PKH. if (auto id = boost::get(&dest)) { diff --git a/src/outputtype.h b/src/outputtype.h --- a/src/outputtype.h +++ b/src/outputtype.h @@ -42,7 +42,7 @@ * script. This function will automatically add the script (and any other * necessary scripts) to the keystore. */ -CTxDestination AddAndGetDestinationForScript(CBasicKeyStore &keystore, +CTxDestination AddAndGetDestinationForScript(FillableSigningProvider &keystore, const CScript &script, OutputType); #endif // BITCOIN_OUTPUTTYPE_H diff --git a/src/outputtype.cpp b/src/outputtype.cpp --- a/src/outputtype.cpp +++ b/src/outputtype.cpp @@ -46,7 +46,7 @@ return std::vector{std::move(keyid)}; } -CTxDestination AddAndGetDestinationForScript(CBasicKeyStore &keystore, +CTxDestination AddAndGetDestinationForScript(FillableSigningProvider &keystore, const CScript &script, OutputType type) { // Add script to keystore diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -155,7 +155,7 @@ OutputType output_type = OutputType::LEGACY; // Construct using pay-to-script-hash: - CBasicKeyStore keystore; + FillableSigningProvider keystore; CScript inner; const CTxDestination dest = AddAndGetMultisigDestination( required, pubkeys, output_type, keystore, inner); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -884,7 +884,7 @@ throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); } - CBasicKeyStore keystore; + FillableSigningProvider keystore; const UniValue &keys = request.params[1].get_array(); for (size_t idx = 0; idx < keys.size(); ++idx) { UniValue k = keys[idx]; diff --git a/src/rpc/rawtransaction_util.h b/src/rpc/rawtransaction_util.h --- a/src/rpc/rawtransaction_util.h +++ b/src/rpc/rawtransaction_util.h @@ -7,7 +7,7 @@ #include -class CBasicKeyStore; +class FillableSigningProvider; class CChainParams; class CMutableTransaction; @@ -29,7 +29,7 @@ * @returns JSON object with details of signed transaction */ UniValue SignTransaction(CMutableTransaction &mtx, const UniValue &prevTxs, - CBasicKeyStore *keystore, + FillableSigningProvider *keystore, std::map &coins, bool tempKeystore, const UniValue &hashType); diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp --- a/src/rpc/rawtransaction_util.cpp +++ b/src/rpc/rawtransaction_util.cpp @@ -158,7 +158,7 @@ UniValue SignTransaction(CMutableTransaction &mtx, const UniValue &prevTxsUnival, - CBasicKeyStore *keystore, + FillableSigningProvider *keystore, std::map &coins, bool is_temp_keystore, const UniValue &hashType) { // Add previous txouts given in the RPC call: diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -19,7 +19,7 @@ #include class CChainParams; -class CBasicKeyStore; +class FillableSigningProvider; class CPubKey; class CScript; class UniValue; @@ -73,12 +73,12 @@ CPubKey HexToPubKey(const std::string &hex_in); CPubKey AddrToPubKey(const CChainParams &chainparams, - CBasicKeyStore *const keystore, + FillableSigningProvider *const keystore, const std::string &addr_in); CTxDestination AddAndGetMultisigDestination(const int required, const std::vector &pubkeys, OutputType type, - CBasicKeyStore &keystore, + FillableSigningProvider &keystore, CScript &script_out); UniValue DescribeAddress(const CTxDestination &dest); diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -156,9 +156,9 @@ return vchPubKey; } -// Retrieves a public key for an address from the given CBasicKeyStore +// Retrieves a public key for an address from the given FillableSigningProvider CPubKey AddrToPubKey(const CChainParams &chainparams, - CBasicKeyStore *const keystore, + FillableSigningProvider *const keystore, const std::string &addr_in) { CTxDestination dest = DecodeDestination(addr_in, chainparams); if (!IsValidDestination(dest)) { @@ -188,7 +188,7 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vector &pubkeys, OutputType type, - CBasicKeyStore &keystore, + FillableSigningProvider &keystore, CScript &script_out) { // Gather public keys if (required < 1) { diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) { CKey key; key.MakeNewKey(true); - CBasicKeyStore keystore; + FillableSigningProvider keystore; keystore.AddKey(key); // 50 orphan transactions: diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(multisig_Sign) { // Test SignSignature() (and therefore the version of Solver() that signs // transactions) - CBasicKeyStore keystore; + FillableSigningProvider keystore; CKey key[4]; for (int i = 0; i < 4; i++) { key[i].MakeNewKey(true); diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -57,7 +57,7 @@ // Test SignSignature() (and therefore the version of Solver() that signs // transactions) - CBasicKeyStore keystore; + FillableSigningProvider keystore; CKey key[4]; for (int i = 0; i < 4; i++) { key[i].MakeNewKey(true); @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(set) { LOCK(cs_main); // Test the CScript::Set* methods - CBasicKeyStore keystore; + FillableSigningProvider keystore; CKey key[4]; std::vector keys; for (int i = 0; i < 4; i++) { @@ -314,7 +314,7 @@ LOCK(cs_main); CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); - CBasicKeyStore keystore; + FillableSigningProvider keystore; CKey key[6]; std::vector keys; for (int i = 0; i < 6; i++) { diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -2718,7 +2718,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs) { // Test the ProduceSignature's ability to combine signatures function - CBasicKeyStore keystore; + FillableSigningProvider keystore; std::vector keys; std::vector pubkeys; for (int i = 0; i < 3; i++) { diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -282,7 +282,8 @@ // paid to a TX_PUBKEYHASH. // static std::vector -SetupDummyInputs(CBasicKeyStore &keystoreRet, CCoinsViewCache &coinsRet) { +SetupDummyInputs(FillableSigningProvider &keystoreRet, + CCoinsViewCache &coinsRet) { std::vector dummyTransactions; dummyTransactions.resize(2); @@ -316,7 +317,7 @@ } BOOST_AUTO_TEST_CASE(test_Get) { - CBasicKeyStore keystore; + FillableSigningProvider keystore; CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); std::vector dummyTransactions = @@ -342,7 +343,7 @@ (50 + 21 + 22) * CENT); } -static void CreateCreditAndSpend(const CBasicKeyStore &keystore, +static void CreateCreditAndSpend(const FillableSigningProvider &keystore, const CScript &outscript, CTransactionRef &output, CMutableTransaction &input, @@ -421,7 +422,7 @@ BOOST_AUTO_TEST_CASE(test_big_transaction) { CKey key; key.MakeNewKey(false); - CBasicKeyStore keystore; + FillableSigningProvider keystore; keystore.AddKeyPubKey(key, key.GetPubKey()); CScript scriptPubKey = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; @@ -516,7 +517,7 @@ } BOOST_AUTO_TEST_CASE(test_witness) { - CBasicKeyStore keystore, keystore2; + FillableSigningProvider keystore, keystore2; CKey key1, key2, key3, key1L, key2L; CPubKey pubkey1, pubkey2, pubkey3, pubkey1L, pubkey2L; key1.MakeNewKey(true); @@ -632,7 +633,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) { LOCK(cs_main); - CBasicKeyStore keystore; + FillableSigningProvider keystore; CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); std::vector dummyTransactions = diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp --- a/src/test/txvalidationcache_tests.cpp +++ b/src/test/txvalidationcache_tests.cpp @@ -204,7 +204,7 @@ CScript p2pkh_scriptPubKey = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey())); - CBasicKeyStore keystore; + FillableSigningProvider keystore; keystore.AddKey(coinbaseKey); keystore.AddCScript(p2pk_scriptPubKey); diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -114,7 +114,7 @@ * It derives from the basic key store, which is used if no encryption is * active. */ -class CCryptoKeyStore : public CBasicKeyStore { +class CCryptoKeyStore : public FillableSigningProvider { private: CKeyingMaterial vMasterKey GUARDED_BY(cs_KeyStore); diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp --- a/src/wallet/crypter.cpp +++ b/src/wallet/crypter.cpp @@ -242,7 +242,7 @@ bool CCryptoKeyStore::AddKeyPubKey(const CKey &key, const CPubKey &pubkey) { LOCK(cs_KeyStore); if (!IsCrypted()) { - return CBasicKeyStore::AddKeyPubKey(key, pubkey); + return FillableSigningProvider::AddKeyPubKey(key, pubkey); } if (IsLocked()) { @@ -277,7 +277,7 @@ bool CCryptoKeyStore::HaveKey(const CKeyID &address) const { LOCK(cs_KeyStore); if (!IsCrypted()) { - return CBasicKeyStore::HaveKey(address); + return FillableSigningProvider::HaveKey(address); } return mapCryptedKeys.count(address) > 0; } @@ -285,7 +285,7 @@ bool CCryptoKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const { LOCK(cs_KeyStore); if (!IsCrypted()) { - return CBasicKeyStore::GetKey(address, keyOut); + return FillableSigningProvider::GetKey(address, keyOut); } CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address); @@ -301,7 +301,7 @@ CPubKey &vchPubKeyOut) const { LOCK(cs_KeyStore); if (!IsCrypted()) { - return CBasicKeyStore::GetPubKey(address, vchPubKeyOut); + return FillableSigningProvider::GetPubKey(address, vchPubKeyOut); } CryptedKeyMap::const_iterator mi = mapCryptedKeys.find(address); @@ -311,13 +311,13 @@ } // Check for watch-only pubkeys - return CBasicKeyStore::GetPubKey(address, vchPubKeyOut); + return FillableSigningProvider::GetPubKey(address, vchPubKeyOut); } std::set CCryptoKeyStore::GetKeys() const { LOCK(cs_KeyStore); if (!IsCrypted()) { - return CBasicKeyStore::GetKeys(); + return FillableSigningProvider::GetKeys(); } std::set set_address; for (const auto &mi : mapCryptedKeys) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1537,8 +1537,8 @@ /** * Explicitly make the wallet learn the related scripts for outputs to the * given key. This is purely to make the wallet file compatible with older - * software, as CBasicKeyStore automatically does this implicitly for all - * keys now. + * software, as FillableSigningProvider automatically does this implicitly + * for all keys now. */ void LearnRelatedScripts(const CPubKey &key, OutputType);