Skip to content

Commit 23c998d

Browse files
committed
Merge pull request #5511
e9c3215 [Wallet] sort pending wallet transactions before reaccepting (dexX7)
2 parents 948beaf + e9c3215 commit 23c998d

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,9 @@ void CWallet::ReacceptWalletTransactions()
11011101
if (!fBroadcastTransactions)
11021102
return;
11031103
LOCK2(cs_main, cs_wallet);
1104+
std::map<int64_t, CWalletTx*> mapSorted;
1105+
1106+
// Sort pending wallet transactions based on their initial wallet insertion order
11041107
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
11051108
{
11061109
const uint256& wtxid = item.first;
@@ -1109,13 +1112,19 @@ void CWallet::ReacceptWalletTransactions()
11091112

11101113
int nDepth = wtx.GetDepthInMainChain();
11111114

1112-
if (!wtx.IsCoinBase() && nDepth < 0)
1113-
{
1114-
// Try to add to memory pool
1115-
LOCK(mempool.cs);
1116-
wtx.AcceptToMemoryPool(false);
1115+
if (!wtx.IsCoinBase() && nDepth < 0) {
1116+
mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx));
11171117
}
11181118
}
1119+
1120+
// Try to add wallet transactions to memory pool
1121+
BOOST_FOREACH(PAIRTYPE(const int64_t, CWalletTx*)& item, mapSorted)
1122+
{
1123+
CWalletTx& wtx = *(item.second);
1124+
1125+
LOCK(mempool.cs);
1126+
wtx.AcceptToMemoryPool(false);
1127+
}
11191128
}
11201129

11211130
bool CWalletTx::RelayWalletTransaction()

0 commit comments

Comments
 (0)