1 /********************************************************************
2 * (C) 2018 Michael Toutonghi
4 * Distributed under the MIT software license, see the accompanying
5 * file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 * This crypto-condition eval solves the problem of nothing-at-stake
8 * in a proof of stake consensus system.
12 #ifndef CHEATCATCHER_H
13 #define CHEATCATCHER_H
18 #include "script/script.h"
30 CTxHolder(const CTransaction &_tx, uint32_t _height) : height(_height), tx(_tx) {
31 CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
33 hw << tx.vin[0].prevout.hash;
34 hw << tx.vin[0].prevout.n;
43 std::multimap<const int32_t, CTxHolder> orderedCheatCandidates;
44 std::multimap<const uint256, CTxHolder *> indexedCheatCandidates;
45 CCriticalSection cs_cheat;
50 // prune all transactions in the list below height
51 uint32_t Prune(uint32_t height);
53 // check to see if a transaction that could be a cheat for the passed transaction is in our list
54 bool IsCheatInList(const CTransaction &tx, CTransaction *pcheatTx);
56 // check to see if there are cheat candidates of the same or greater block height in list
57 bool IsHeightOrGreaterInList(uint32_t height)
59 auto range = orderedCheatCandidates.equal_range(height);
60 return (range.first == orderedCheatCandidates.end());
63 // add a potential cheat transaction to the list. we do this for all stake transactions from orphaned stakes
64 bool Add(CTxHolder &txh);
66 // remove a transaction from the the list
67 void Remove(const CTxHolder &txh);
71 extern CCheatList cheatList;
72 extern boost::optional<libzcash::SaplingPaymentAddress> cheatCatcher;