Skip to content

Commit b9cf505

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23338: tests: speed up coinselector_tests
a52f1d1 walletdb: Use SQLiteDatabase for mock wallet databases (Andrew Chow) a78c229 tests: Place into mapWallet in coinselector_tests (Andrew Chow) Pull request description: #23288 changed coinselector_tests to use `DescriptorScriptPubKeyMan`, but it also ended up significantly slowing down the test, from 4 seconds to over 1 minute. It appears that the source of this slow down is with `CWallet::AddToWallet`, and primarily due to writing data to the mock wallet database. Because the only thing that is actually needed is for the created transaction to be placed into `CWallet::mapWallet`, this PR removes the call to `AddToWallet` and just places the transaction into `mapWallet` directly. This reduces the test time to 5 seconds. To speed things up further, `CreateMockWalletDatabase` is changed to make a `SQLiteDatabase` instead of a `BerkeleyDatabase`. This is safe because there are no tests that require a specific mock database type. ACKs for top commit: brunoerg: tACK a52f1d1 lsilva01: tACK a52f1d1. Performed 74.36% better on Ubuntu 20.04 (VM, 12 MB, 8vCPU). glozow: utACK a52f1d1 Tree-SHA512: da77936bfd2e816d2e71703567b9389d0ee79f3a4a690802ffe3469df5bed371b296cb822b897f625654dab9436d91fd6bc02364a518a47d746e487d70a72595
2 parents 04437ee + a52f1d1 commit b9cf505

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/wallet/test/coinselector_tests.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
7171
// so stop vin being empty, and cache a non-zero Debit to fake out IsFromMe()
7272
tx.vin.resize(1);
7373
}
74-
CWalletTx* wtx = wallet.AddToWallet(MakeTransactionRef(std::move(tx)), /* confirm= */ {});
74+
uint256 txid = tx.GetHash();
75+
76+
LOCK(wallet.cs_wallet);
77+
auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx))));
78+
assert(ret.second);
79+
CWalletTx& wtx = (*ret.first).second;
7580
if (fIsFromMe)
7681
{
77-
wtx->m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1);
78-
wtx->m_is_cache_empty = false;
82+
wtx.m_amounts[CWalletTx::DEBIT].Set(ISMINE_SPENDABLE, 1);
83+
wtx.m_is_cache_empty = false;
7984
}
80-
COutput output(wallet, *wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
85+
COutput output(wallet, wtx, nInput, nAge, true /* spendable */, true /* solvable */, true /* safe */);
8186
coins.push_back(output);
8287
}
8388

src/wallet/walletdb.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,9 +1188,9 @@ std::unique_ptr<WalletDatabase> CreateDummyWalletDatabase()
11881188
/** Return object for accessing temporary in-memory database. */
11891189
std::unique_ptr<WalletDatabase> CreateMockWalletDatabase()
11901190
{
1191-
#ifdef USE_BDB
1192-
return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
1193-
#elif USE_SQLITE
1191+
#ifdef USE_SQLITE
11941192
return std::make_unique<SQLiteDatabase>("", "", true);
1193+
#elif USE_BDB
1194+
return std::make_unique<BerkeleyDatabase>(std::make_shared<BerkeleyEnvironment>(), "");
11951195
#endif
11961196
}

0 commit comments

Comments
 (0)