From bd3f73d1950e9f46bf1a47660cc4a742029c0769 Mon Sep 17 00:00:00 2001 From: Cryptoforge Date: Wed, 12 May 2021 15:58:46 -0700 Subject: [PATCH] fix deadlock --- src/wallet/rpcpiratewallet.cpp | 73 +++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/src/wallet/rpcpiratewallet.cpp b/src/wallet/rpcpiratewallet.cpp index 28c5bce3a7..7fce7807df 100644 --- a/src/wallet/rpcpiratewallet.cpp +++ b/src/wallet/rpcpiratewallet.cpp @@ -34,28 +34,32 @@ void getTransparentSpends(RpcTx &tx, vector &vSpend, CAmount if (parentwtx != NULL) { parentOut = parentwtx->vout[txin.prevout.n]; } else { - CTransaction parentctx; - uint256 hashBlock; + map::iterator it = pwalletMain->mapArcTxs.find(txin.prevout.hash); + if (it != pwalletMain->mapArcTxs.end()){ - // Find the block it claims to be in - BlockMap::iterator mi = mapBlockIndex.find(txin.prevout.hash); - if (mi == mapBlockIndex.end()) { - return; - } - CBlockIndex* pindex = (*mi).second; - if (!pindex || !chainActive.Contains(pindex)) { - return; - } + CTransaction parentctx; + uint256 hashBlock; - //Get Tx from block - CBlock block; - ReadBlockFromDisk(block, pindex, 1); + // Find the block it claims to be in + BlockMap::iterator mi = mapBlockIndex.find(it->second.hashBlock); + if (mi == mapBlockIndex.end()) { + return; + } + CBlockIndex* pindex = (*mi).second; + if (!pindex || !chainActive.Contains(pindex)) { + return; + } + + //Get Tx from block + CBlock block; + ReadBlockFromDisk(block, pindex, 1); - //Get Tx - for (int j = 0; j < block.vtx.size(); j++) { - if (txin.prevout.hash == block.vtx[j].GetHash()) { - parentctx = block.vtx[j]; - parentOut = parentctx.vout[txin.prevout.n]; + //Get Tx + for (int j = 0; j < block.vtx.size(); j++) { + if (txin.prevout.hash == block.vtx[j].GetHash()) { + parentctx = block.vtx[j]; + parentOut = parentctx.vout[txin.prevout.n]; + } } } } @@ -244,10 +248,33 @@ void getSaplingSpends(RpcTx &tx, std::set &ivks, std::set &ivk if (parentwtx != NULL) { output = parentwtx->vShieldedOutput[op.n]; } else { - CTransaction parentctx; - uint256 hashBlock; - if (GetTransaction(op.hash, parentctx, hashBlock, true)) { - output = parentctx.vShieldedOutput[op.n]; + map::iterator it = pwalletMain->mapArcTxs.find(op.hash); + if (it != pwalletMain->mapArcTxs.end()){ + + CTransaction parentctx; + uint256 hashBlock; + + // Find the block it claims to be in + BlockMap::iterator mi = mapBlockIndex.find(it->second.hashBlock); + if (mi == mapBlockIndex.end()) { + return; + } + CBlockIndex* pindex = (*mi).second; + if (!pindex || !chainActive.Contains(pindex)) { + return; + } + + //Get Tx from block + CBlock block; + ReadBlockFromDisk(block, pindex, 1); + + //Get Tx + for (int j = 0; j < block.vtx.size(); j++) { + if (op.hash == block.vtx[j].GetHash()) { + parentctx = block.vtx[j]; + output = parentctx.vShieldedOutput[op.n]; + } + } } }