Skip to content

Commit

Permalink
[BUG] Missing cs_wallet lock in SaplingScriptPubKeyMan::GetNotes
Browse files Browse the repository at this point in the history
needed by CWalletTx::GetDepthInMainChain
  • Loading branch information
random-zebra authored and furszy committed Apr 22, 2021
1 parent b2d9061 commit 9bec9bc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/sapling/saplingscriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ void SaplingScriptPubKeyMan::GetNotes(const std::vector<SaplingOutPoint>& saplin
for (const auto& outpoint : saplingOutpoints) {
const auto* wtx = wallet->GetWalletTx(outpoint.hash);
if (!wtx) throw std::runtime_error("No transaction available for hash " + outpoint.hash.GetHex());
const int depth = WITH_LOCK(wallet->cs_wallet, return wtx->GetDepthInMainChain(); );
const auto& it = wtx->mapSaplingNoteData.find(outpoint);
if (it != wtx->mapSaplingNoteData.end()) {
const SaplingOutPoint& op = it->first;
Expand All @@ -414,7 +415,7 @@ void SaplingScriptPubKeyMan::GetNotes(const std::vector<SaplingOutPoint>& saplin
const libzcash::SaplingPaymentAddress& pa = optNotePtAndAddress->second;
auto note = notePt.note(ivk).get();

saplingEntriesRet.emplace_back(op, pa, note, notePt.memo(), wtx->GetDepthInMainChain());
saplingEntriesRet.emplace_back(op, pa, note, notePt.memo(), depth);
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/test/librust/sapling_wallet_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,6 @@ BOOST_AUTO_TEST_CASE(GetNotes)
BOOST_CHECK_EQUAL(entries[i].confirmations, 1);
}

/*
* !TODO: fix GetNotes.
* This test currently fails due to an assertion error (cs_wallet lock not held)
*/

// Check GetNotes
std::vector<SaplingNoteEntry> entries2;
wallet.GetSaplingScriptPubKeyMan()->GetNotes(saplingOutpoints, entries2);
Expand Down

0 comments on commit 9bec9bc

Please sign in to comment.