Skip to content

Commit 7562b63

Browse files
committed
[BUG][GUI] Fix random double/triple transaction record issue
This bug is caused by the fact that, if at startup the wallet has more than 4000 (SINGLE_THREAD_MAX_TXES_SIZE) transaction records, then chachedWallet is loaded not properly ordered, therfore the binary search (used later in updateWallet, to check whether a tx is already in the model) is unreliable. When the wallet has more than 4000 records, in fact, the list of records in TransactionTablePriv::refreshWallet() is split in batches, each one processed in a separate thread, processing the last batch in the main thread at the beginning, thus without preserving the original order (by hash) of walletTxes. Further, if the wallet has more than 200k records (MAX_AMOUNT_LOADED_RECORDS), then the list is also sorted by date before being trimmed and split in batches. Fix this by re-sorting the cachedWallet list by hash at the end of the multi-threaded update. x
1 parent 129446a commit 7562b63

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class TransactionTablePriv
104104

105105
// First check if the amount of txs exceeds the UI limit
106106
if (txesSize > MAX_AMOUNT_LOADED_RECORDS) {
107-
// Sort the txs by date just to be really really sure that them are ordered.
108-
// (this extra calculation should be removed in the future if can ensure that
109-
// txs are stored in order in the db, which is what should be happening)
107+
// Sort the txs by date
110108
sort(walletTxes.begin(), walletTxes.end(),
111109
[](const CWalletTx & a, const CWalletTx & b) -> bool {
112110
return a.GetTxTime() > b.GetTxTime();
@@ -153,6 +151,10 @@ class TransactionTablePriv
153151
nFirstLoadedTxTime = convertRes.nFirstLoadedTxTime;
154152
}
155153
}
154+
155+
// Now that all records have been cached, sort them by tx hash
156+
std::sort(cachedWallet.begin(), cachedWallet.end(), TxLessThan());
157+
156158
} else {
157159
// Single thread flow
158160
ConvertTxToVectorResult convertRes = convertTxToRecords(wallet, walletTxes);

0 commit comments

Comments
 (0)