Locking: Lock cs_KeyStore instead of cs_wallet in legacy keyman
This commit only affects locking behavior and doesn't have other changes.
This commit is contained in:
1 parent
f5be479694
commit
fadc08ad94
13 files changed
+112
-116
No files matched your search
@@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2PK compressed
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
|
||||
|
||||
// Keystore does not have key
|
||||
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2PK uncompressed
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
|
||||
|
||||
// Keystore does not have key
|
||||
@@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2PKH compressed
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
|
||||
// Keystore does not have key
|
||||
@@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2PKH uncompressed
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
|
||||
|
||||
// Keystore does not have key
|
||||
@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2SH
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
@@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// (P2PKH inside) P2SH inside P2SH (invalid)
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
CScript redeemscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
CScript redeemscript = GetScriptForDestination(ScriptHash(redeemscript_inner));
|
||||
@@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// (P2PKH inside) P2SH inside P2WSH (invalid)
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
CScript redeemscript = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
CScript witnessscript = GetScriptForDestination(ScriptHash(redeemscript));
|
||||
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2WPKH inside P2WSH (invalid)
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
|
||||
@@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// (P2PKH inside) P2WSH inside P2WSH (invalid)
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
CScript witnessscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
CScript witnessscript = GetScriptForDestination(WitnessV0ScriptHash(witnessscript_inner));
|
||||
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2WPKH compressed
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
||||
@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2WPKH uncompressed
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
||||
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(uncompressedPubkey)));
|
||||
@@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// scriptPubKey multisig
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
scriptPubKey = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
|
||||
|
||||
@@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2SH multisig
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
|
||||
|
||||
@@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2WSH multisig with compressed keys
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
|
||||
|
||||
@@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2WSH multisig with uncompressed key
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey));
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1]));
|
||||
|
||||
@@ -321,7 +321,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// P2WSH multisig wrapped in P2SH
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
|
||||
CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
|
||||
CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
||||
@@ -347,7 +347,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// OP_RETURN
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||
|
||||
scriptPubKey.clear();
|
||||
@@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// witness unspendable
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||
|
||||
scriptPubKey.clear();
|
||||
@@ -373,7 +373,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// witness unknown
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||
|
||||
scriptPubKey.clear();
|
||||
@@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
// Nonstandard
|
||||
{
|
||||
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
LOCK(keystore.cs_wallet);
|
||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore);
|
||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||
|
||||
scriptPubKey.clear();
|
||||
|
||||
@@ -17,7 +17,7 @@ BOOST_FIXTURE_TEST_SUITE(psbt_wallet_tests, WalletTestingSetup)
|
||||
BOOST_AUTO_TEST_CASE(psbt_updater_test)
|
||||
{
|
||||
auto spk_man = m_wallet.GetLegacyScriptPubKeyMan();
|
||||
LOCK(m_wallet.cs_wallet);
|
||||
LOCK2(m_wallet.cs_wallet, spk_man->cs_KeyStore);
|
||||
|
||||
// Create prevtxs and add to wallet
|
||||
CDataStream s_prev_tx1(ParseHex("0200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f7965000000"), SER_NETWORK, PROTOCOL_VERSION);
|
||||
|
||||
@@ -29,8 +29,7 @@ BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
|
||||
static void AddKey(CWallet& wallet, const CKey& key)
|
||||
{
|
||||
auto spk_man = wallet.GetLegacyScriptPubKeyMan();
|
||||
LOCK(wallet.cs_wallet);
|
||||
AssertLockHeld(spk_man->cs_wallet);
|
||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
|
||||
spk_man->AddKeyPubKey(key, key.GetPubKey());
|
||||
}
|
||||
|
||||
@@ -217,8 +216,7 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
{
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||
auto spk_man = wallet->GetLegacyScriptPubKeyMan();
|
||||
LOCK(wallet->cs_wallet);
|
||||
AssertLockHeld(spk_man->cs_wallet);
|
||||
LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore);
|
||||
spk_man->mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = KEY_TIME;
|
||||
spk_man->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey());
|
||||
|
||||
@@ -272,8 +270,7 @@ BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
|
||||
|
||||
auto locked_chain = chain->lock();
|
||||
LockAssertion lock(::cs_main);
|
||||
LOCK(wallet.cs_wallet);
|
||||
AssertLockHeld(spk_man->cs_wallet);
|
||||
LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
|
||||
wallet.SetLastBlockProcessed(::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash());
|
||||
|
||||
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, ::ChainActive().Height(), ::ChainActive().Tip()->GetBlockHash(), 0);
|
||||
@@ -377,7 +374,7 @@ static void TestWatchOnlyPubKey(LegacyScriptPubKeyMan* spk_man, const CPubKey& a
|
||||
CScript p2pk = GetScriptForRawPubKey(add_pubkey);
|
||||
CKeyID add_address = add_pubkey.GetID();
|
||||
CPubKey found_pubkey;
|
||||
LOCK(spk_man->cs_wallet);
|
||||
LOCK(spk_man->cs_KeyStore);
|
||||
|
||||
// all Scripts (i.e. also all PubKeys) are added to the general watch-only set
|
||||
BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
|
||||
@@ -394,7 +391,6 @@ static void TestWatchOnlyPubKey(LegacyScriptPubKeyMan* spk_man, const CPubKey& a
|
||||
BOOST_CHECK(found_pubkey == CPubKey()); // passed key is unchanged
|
||||
}
|
||||
|
||||
AssertLockHeld(spk_man->cs_wallet);
|
||||
spk_man->RemoveWatchOnly(p2pk);
|
||||
BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
|
||||
|
||||
|
||||
Reference in new issue
Block a user