mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-10 15:46:48 -04:00
Add AssertLockHeld assertions in CWallet::ListCoins
This commit is contained in:
parent
3cf76c23fb
commit
545e85eccc
2 changed files with 15 additions and 13 deletions
|
@ -317,7 +317,11 @@ BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup)
|
||||||
|
|
||||||
// Confirm ListCoins initially returns 1 coin grouped under coinbaseKey
|
// Confirm ListCoins initially returns 1 coin grouped under coinbaseKey
|
||||||
// address.
|
// address.
|
||||||
auto list = wallet->ListCoins();
|
std::map<CTxDestination, std::vector<COutput>> list;
|
||||||
|
{
|
||||||
|
LOCK2(cs_main, wallet->cs_wallet);
|
||||||
|
list = wallet->ListCoins();
|
||||||
|
}
|
||||||
BOOST_CHECK_EQUAL(list.size(), 1U);
|
BOOST_CHECK_EQUAL(list.size(), 1U);
|
||||||
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), coinbaseAddress);
|
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), coinbaseAddress);
|
||||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 1U);
|
BOOST_CHECK_EQUAL(list.begin()->second.size(), 1U);
|
||||||
|
@ -330,7 +334,10 @@ BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup)
|
||||||
// coinbaseKey pubkey, even though the change address has a different
|
// coinbaseKey pubkey, even though the change address has a different
|
||||||
// pubkey.
|
// pubkey.
|
||||||
AddTx(CRecipient{GetScriptForRawPubKey({}), 1 * COIN, false /* subtract fee */});
|
AddTx(CRecipient{GetScriptForRawPubKey({}), 1 * COIN, false /* subtract fee */});
|
||||||
|
{
|
||||||
|
LOCK2(cs_main, wallet->cs_wallet);
|
||||||
list = wallet->ListCoins();
|
list = wallet->ListCoins();
|
||||||
|
}
|
||||||
BOOST_CHECK_EQUAL(list.size(), 1U);
|
BOOST_CHECK_EQUAL(list.size(), 1U);
|
||||||
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), coinbaseAddress);
|
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), coinbaseAddress);
|
||||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
|
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
|
||||||
|
@ -356,7 +363,10 @@ BOOST_FIXTURE_TEST_CASE(ListCoins, ListCoinsTestingSetup)
|
||||||
}
|
}
|
||||||
// Confirm ListCoins still returns same result as before, despite coins
|
// Confirm ListCoins still returns same result as before, despite coins
|
||||||
// being locked.
|
// being locked.
|
||||||
|
{
|
||||||
|
LOCK2(cs_main, wallet->cs_wallet);
|
||||||
list = wallet->ListCoins();
|
list = wallet->ListCoins();
|
||||||
|
}
|
||||||
BOOST_CHECK_EQUAL(list.size(), 1U);
|
BOOST_CHECK_EQUAL(list.size(), 1U);
|
||||||
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), coinbaseAddress);
|
BOOST_CHECK_EQUAL(boost::get<CKeyID>(list.begin()->first).ToString(), coinbaseAddress);
|
||||||
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
|
BOOST_CHECK_EQUAL(list.begin()->second.size(), 2U);
|
||||||
|
|
|
@ -2364,20 +2364,12 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
|
||||||
|
|
||||||
std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins() const
|
std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins() const
|
||||||
{
|
{
|
||||||
// TODO: Add AssertLockHeld(cs_wallet) here.
|
AssertLockHeld(cs_main);
|
||||||
//
|
AssertLockHeld(cs_wallet);
|
||||||
// Because the return value from this function contains pointers to
|
|
||||||
// CWalletTx objects, callers to this function really should acquire the
|
|
||||||
// cs_wallet lock before calling it. However, the current caller doesn't
|
|
||||||
// acquire this lock yet. There was an attempt to add the missing lock in
|
|
||||||
// https://github.com/bitcoin/bitcoin/pull/10340, but that change has been
|
|
||||||
// postponed until after https://github.com/bitcoin/bitcoin/pull/10244 to
|
|
||||||
// avoid adding some extra complexity to the Qt code.
|
|
||||||
|
|
||||||
std::map<CTxDestination, std::vector<COutput>> result;
|
std::map<CTxDestination, std::vector<COutput>> result;
|
||||||
std::vector<COutput> availableCoins;
|
std::vector<COutput> availableCoins;
|
||||||
|
|
||||||
LOCK2(cs_main, cs_wallet);
|
|
||||||
AvailableCoins(availableCoins);
|
AvailableCoins(availableCoins);
|
||||||
|
|
||||||
for (auto& coin : availableCoins) {
|
for (auto& coin : availableCoins) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue