Skip to content

Commit 74df6eb

Browse files
committed
Improve wallet related and other LOCKs
1 parent 5586779 commit 74df6eb

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/qt/sendmpdialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ void SendMPDialog::setWalletModel(WalletModel *model)
9797

9898
void SendMPDialog::updatePropSelector()
9999
{
100+
LOCK(cs_tally);
101+
100102
uint32_t nextPropIdMainEco = GetNextPropertyId(true); // these allow us to end the for loop at the highest existing
101103
uint32_t nextPropIdTestEco = GetNextPropertyId(false); // property ID rather than a fixed value like 100000 (optimization)
102104
QString spId = ui->propertyComboBox->itemData(ui->propertyComboBox->currentIndex()).toString();
103105
ui->propertyComboBox->clear();
104106

105-
LOCK(cs_tally);
106-
107107
for (unsigned int propertyId = 1; propertyId < nextPropIdMainEco; propertyId++) {
108108
if ((global_balance_money[propertyId] > 0) || (global_balance_reserved[propertyId] > 0)) {
109109
std::string spName = getPropertyName(propertyId);

src/qt/tradehistorydialog.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void TradeHistoryDialog::UpdateTradeHistoryTable(bool forceUpdate)
161161
if (forceUpdate || newTXCount > 0) {
162162
ui->tradeHistoryTable->setSortingEnabled(false); // disable sorting while we update the table
163163
QAbstractItemModel* tradeHistoryAbstractModel = ui->tradeHistoryTable->model();
164-
int chainHeight = chainActive.Height();
164+
int chainHeight = GetHeight();
165165

166166
// Loop through tradeHistoryMap and search tradeHistoryTable for the transaction, adding it if not already there
167167
for (TradeHistoryMap::iterator it = tradeHistoryMap.begin(); it != tradeHistoryMap.end(); ++it) {
@@ -247,12 +247,11 @@ void TradeHistoryDialog::UpdateTradeHistoryTable(bool forceUpdate)
247247
// Used to cache trades so we don't need to reparse all our transactions on every update
248248
int TradeHistoryDialog::PopulateTradeHistoryMap()
249249
{
250-
// Attempt to obtain locks
251-
CWallet *wallet = pwalletMain;
252-
if (NULL == wallet) return -1;
250+
// TODO: locks may not be needed here -- looks like wallet lock can be removed
251+
if (NULL == pwalletMain) return -1;
253252
TRY_LOCK(cs_main,lckMain);
254253
if (!lckMain) return -1;
255-
TRY_LOCK(wallet->cs_wallet, lckWallet);
254+
TRY_LOCK(pwalletMain->cs_wallet, lckWallet);
256255
if (!lckWallet) return -1;
257256

258257
int64_t nProcessed = 0; // number of new entries, forms return code

src/qt/txhistorydialog.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ void TXHistoryDialog::setWalletModel(WalletModel *model)
181181

182182
int TXHistoryDialog::PopulateHistoryMap()
183183
{
184-
CWallet *wallet = pwalletMain;
185-
if (NULL == wallet) return 0;
184+
// TODO: locks may not be needed here -- looks like wallet lock can be removed
185+
if (NULL == pwalletMain) return 0;
186186
// try and fix intermittent freeze on startup and while running by only updating if we can get required locks
187187
TRY_LOCK(cs_main,lckMain);
188188
if (!lckMain) return 0;
189-
TRY_LOCK(wallet->cs_wallet, lckWallet);
189+
TRY_LOCK(pwalletMain->cs_wallet, lckWallet);
190190
if (!lckWallet) return 0;
191191

192192
int64_t nProcessed = 0; // counter for how many transactions we've added to history this time
@@ -195,7 +195,6 @@ int TXHistoryDialog::PopulateHistoryMap()
195195
std::map<std::string,uint256> walletTransactions = FetchWalletOmniTransactions(GetArg("-omniuiwalletscope", 1000));
196196

197197
// reverse iterate over (now ordered) transactions and populate history map for each one
198-
Array response;
199198
for (std::map<std::string,uint256>::reverse_iterator it = walletTransactions.rbegin(); it != walletTransactions.rend(); it++) {
200199
uint256 txHash = it->second;
201200

@@ -227,7 +226,6 @@ int TXHistoryDialog::PopulateHistoryMap()
227226
uint256 blockHash = 0;
228227
if (!GetTransaction(txHash, wtx, blockHash, true)) continue;
229228
if ((0 == blockHash) || (NULL == GetBlockIndex(blockHash))) {
230-
231229
// this transaction is unconfirmed, should be one of our pending transactions
232230
LOCK(cs_pending);
233231
PendingMap::iterator pending_it = my_pending.find(txHash);
@@ -269,12 +267,15 @@ int TXHistoryDialog::PopulateHistoryMap()
269267
uint64_t tmpPropertyId = 0;
270268
bool bIsBuy = false;
271269
int numberOfPurchases = 0;
272-
LOCK(cs_tally);
273-
p_txlistdb->getPurchaseDetails(txHash, 1, &tmpBuyer, &tmpSeller, &tmpVout, &tmpPropertyId, &tmpNValue);
270+
{
271+
LOCK(cs_tally);
272+
p_txlistdb->getPurchaseDetails(txHash, 1, &tmpBuyer, &tmpSeller, &tmpVout, &tmpPropertyId, &tmpNValue);
273+
}
274274
bIsBuy = IsMyAddress(tmpBuyer);
275275
numberOfPurchases = p_txlistdb->getNumberOfPurchases(txHash);
276276
if (0 >= numberOfPurchases) continue;
277277
for (int purchaseNumber = 1; purchaseNumber <= numberOfPurchases; purchaseNumber++) {
278+
LOCK(cs_tally);
278279
p_txlistdb->getPurchaseDetails(txHash, purchaseNumber, &tmpBuyer, &tmpSeller, &tmpVout, &tmpPropertyId, &tmpNValue);
279280
total += tmpNValue;
280281
}
@@ -340,7 +341,7 @@ int TXHistoryDialog::PopulateHistoryMap()
340341

341342
void TXHistoryDialog::UpdateConfirmations()
342343
{
343-
int chainHeight = chainActive.Height(); // get the chain height
344+
int chainHeight = GetHeight(); // get the chain height
344345
int rowCount = ui->txHistoryTable->rowCount();
345346
for (int row = 0; row < rowCount; row++) {
346347
int confirmations = 0;
@@ -400,6 +401,7 @@ void TXHistoryDialog::UpdateHistory()
400401
QDateTime txTime;
401402
QTableWidgetItem *dateCell = new QTableWidgetItem;
402403
if (htxo.blockHeight>0) {
404+
LOCK(cs_main);
403405
CBlockIndex* pBlkIdx = chainActive[htxo.blockHeight];
404406
if (NULL != pBlkIdx) txTime.setTime_t(pBlkIdx->GetBlockTime());
405407
dateCell->setData(Qt::DisplayRole, txTime);

0 commit comments

Comments
 (0)