diff options
author | dexX7 <ugithub@bitwatch.co> | 2014-12-19 06:59:16 +0100 |
---|---|---|
committer | dexX7 <dexx@bitwatch.co> | 2015-03-21 13:03:23 +0100 |
commit | e9c3215b776b07faeb5184249fc0e43876f26723 (patch) | |
tree | 65d5b22750d3eef2d405134e6a7d5ce1c797e04f | |
parent | f3948a30cd27928fdf9dffbbf90ea6430c869edf (diff) | |
download | bitcoin-e9c3215b776b07faeb5184249fc0e43876f26723.tar.xz |
[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.
-rw-r--r-- | src/wallet/wallet.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 44b416d496..207bb8c97a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1028,6 +1028,9 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) void CWallet::ReacceptWalletTransactions() { 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) { const uint256& wtxid = item.first; @@ -1036,13 +1039,19 @@ void CWallet::ReacceptWalletTransactions() int nDepth = wtx.GetDepthInMainChain(); - if (!wtx.IsCoinBase() && nDepth < 0) - { - // Try to add to memory pool - LOCK(mempool.cs); - wtx.AcceptToMemoryPool(false); + 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) + { + CWalletTx& wtx = *(item.second); + + LOCK(mempool.cs); + wtx.AcceptToMemoryPool(false); + } } void CWalletTx::RelayWalletTransaction() |