mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
[Wallet] sort pending wallet transactions before reaccepting
During startup, when adding pending wallet transactions, which spend outputs of other pending wallet transactions, back to the memory pool, and when they are added out of order, it appears as if they are orphans with missing inputs. Those transactions are then rejected and flagged as "conflicting" (= not in the memory pool, not in the block chain). To prevent this, transactions are explicitly sorted.
This commit is contained in:
parent
f3948a30cd
commit
e9c3215b77
@ -1028,6 +1028,9 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||||||
void CWallet::ReacceptWalletTransactions()
|
void CWallet::ReacceptWalletTransactions()
|
||||||
{
|
{
|
||||||
LOCK2(cs_main, cs_wallet);
|
LOCK2(cs_main, cs_wallet);
|
||||||
|
std::map<int64_t, CWalletTx*> mapSorted;
|
||||||
|
|
||||||
|
// Sort pending wallet transactions based on their initial wallet insertion order
|
||||||
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
|
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
|
||||||
{
|
{
|
||||||
const uint256& wtxid = item.first;
|
const uint256& wtxid = item.first;
|
||||||
@ -1036,13 +1039,19 @@ void CWallet::ReacceptWalletTransactions()
|
|||||||
|
|
||||||
int nDepth = wtx.GetDepthInMainChain();
|
int nDepth = wtx.GetDepthInMainChain();
|
||||||
|
|
||||||
if (!wtx.IsCoinBase() && nDepth < 0)
|
if (!wtx.IsCoinBase() && nDepth < 0) {
|
||||||
|
mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to add wallet transactions to memory pool
|
||||||
|
BOOST_FOREACH(PAIRTYPE(const int64_t, CWalletTx*)& item, mapSorted)
|
||||||
{
|
{
|
||||||
// Try to add to memory pool
|
CWalletTx& wtx = *(item.second);
|
||||||
|
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
wtx.AcceptToMemoryPool(false);
|
wtx.AcceptToMemoryPool(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWalletTx::RelayWalletTransaction()
|
void CWalletTx::RelayWalletTransaction()
|
||||||
|
Loading…
Reference in New Issue
Block a user