Skip to content

Commit

Permalink
Add check to verify pending transactions are still in the mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
zathras-crypto committed Mar 14, 2017
1 parent 0680230 commit 9d1e400
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/omnicore/pending.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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<uint256> 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

/**
Expand Down
4 changes: 4 additions & 0 deletions src/omnicore/pending.h
Expand Up @@ -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.
Expand Down

0 comments on commit 9d1e400

Please sign in to comment.