Skip to content

Commit 33eb907

Browse files
committed
Fix ComputeTimeSmart test failure with -DDEBUG_LOCKORDER
Failure looks like: Entering test case "ComputeTimeSmart" test_bitcoin: sync.cpp:100: void potential_deadlock_detected(const std::pair<void*, void*>&, const LockStack&, const LockStack&): Assertion `false' failed. unknown location(0): fatal error in "ComputeTimeSmart": signal: SIGABRT (application abort requested) wallet/test/wallet_tests.cpp(566): last checkpoint Reproducible with: ./configure --enable-debug make -C src test/test_bitcoin && src/test/test_bitcoin --log_level=test_suite --run_test=wallet_tests/ComputeTimeSmart Happens due to "92fabcd443 Add LookupBlockIndex function" which acquires cs_main from inside CWallet::ComputeTimeSmart.
1 parent d42a4fe commit 33eb907

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/wallet/test/wallet_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,10 @@ static int64_t AddTx(CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64
553553
if (block) {
554554
wtx.SetMerkleBranch(block, 0);
555555
}
556-
wallet.AddToWallet(wtx);
556+
{
557+
LOCK(cs_main);
558+
wallet.AddToWallet(wtx);
559+
}
557560
LOCK(wallet.cs_wallet);
558561
return wallet.mapWallet.at(wtx.GetHash()).nTimeSmart;
559562
}

src/wallet/wallet.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3813,12 +3813,7 @@ unsigned int CWallet::ComputeTimeSmart(const CWalletTx& wtx) const
38133813
{
38143814
unsigned int nTimeSmart = wtx.nTimeReceived;
38153815
if (!wtx.hashUnset()) {
3816-
const CBlockIndex* pindex = nullptr;
3817-
{
3818-
LOCK(cs_main);
3819-
pindex = LookupBlockIndex(wtx.hashBlock);
3820-
}
3821-
if (pindex) {
3816+
if (const CBlockIndex* pindex = LookupBlockIndex(wtx.hashBlock)) {
38223817
int64_t latestNow = wtx.nTimeReceived;
38233818
int64_t latestEntry = 0;
38243819

0 commit comments

Comments
 (0)