diff --git a/src/omnicore/pending.cpp b/src/omnicore/pending.cpp index 2ccc3f97f061c..4e37d9272f8c2 100644 --- a/src/omnicore/pending.cpp +++ b/src/omnicore/pending.cpp @@ -7,7 +7,9 @@ #include "omnicore/mdex.h" #include "amount.h" +#include "main.h" #include "sync.h" +#include "txmempool.h" #include "uint256.h" #include "ui_interface.h" @@ -73,6 +75,28 @@ void PendingDelete(const uint256& txid) } } +/** + * Performs a check to ensure all pending transactions are still in the mempool. + * + * NOTE: Transactions no longer in the mempool (eg orphaned) are deleted from + * the pending map and credited back to the pending tally. + */ +void PendingCheck() +{ + LOCK(cs_pending); + + std::vector vecMemPoolTxids; + mempool.queryHashes(vecMemPoolTxids); + + for (PendingMap::iterator it = my_pending.begin(); it != my_pending.end(); ++it) { + const uint256& txid = it->first; + if (std::find(vecMemPoolTxids.begin(), vecMemPoolTxids.end(), txid) == vecMemPoolTxids.end()) { + PrintToLog("WARNING: Pending transaction %s is no longer in this nodes mempool and will be discarded\n", txid.GetHex()); + PendingDelete(txid); + } + } +} + } // namespace mastercore /** diff --git a/src/omnicore/pending.h b/src/omnicore/pending.h index 429da0952f8a0..1da2d816da2a2 100644 --- a/src/omnicore/pending.h +++ b/src/omnicore/pending.h @@ -24,6 +24,10 @@ void PendingAdd(const uint256& txid, const std::string& sendingAddress, uint16_t /** Deletes a transaction from the pending map and credits the amount back to the pending tally for the address. */ void PendingDelete(const uint256& txid); + +/** Performs a check to ensure all pending transactions are still in the mempool. */ +void PendingCheck(); + } /** Structure to hold information about pending transactions.