]>
Commit | Line | Data |
---|---|---|
8fc4030c MT |
1 | /******************************************************************** |
2 | * (C) 2018 Michael Toutonghi | |
3 | * | |
4 | * Distributed under the MIT software license, see the accompanying | |
5 | * file COPYING or http://www.opensource.org/licenses/mit-license.php. | |
6 | * | |
16ef4f1e | 7 | * This supports code to catch nothing at stake cheaters who stake |
8 | * on multiple forks. | |
8fc4030c MT |
9 | * |
10 | */ | |
11 | ||
12 | #ifndef CHEATCATCHER_H | |
13 | #define CHEATCATCHER_H | |
14 | ||
15 | #include <vector> | |
16 | ||
17 | #include "streams.h" | |
8c3a9bc7 | 18 | #include "primitives/transaction.h" |
8fc4030c MT |
19 | #include "script/script.h" |
20 | #include "uint256.h" | |
21 | ||
22 | #include <vector> | |
23 | #include <map> | |
24 | ||
25 | class CTxHolder | |
26 | { | |
27 | public: | |
28 | uint256 utxo; | |
29 | uint32_t height; | |
30 | CTransaction tx; | |
31 | CTxHolder(const CTransaction &_tx, uint32_t _height) : height(_height), tx(_tx) { | |
32 | CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); | |
33 | ||
34 | hw << tx.vin[0].prevout.hash; | |
35 | hw << tx.vin[0].prevout.n; | |
36 | utxo = hw.GetHash(); | |
37 | } | |
8c3a9bc7 | 38 | |
39 | CTxHolder& operator=(const CTxHolder& txh) | |
40 | { | |
41 | utxo = txh.utxo; | |
42 | height = txh.height; | |
43 | tx = txh.tx; | |
c6f45c52 | 44 | return *this; |
8c3a9bc7 | 45 | } |
8fc4030c MT |
46 | }; |
47 | ||
48 | ||
49 | class CCheatList | |
50 | { | |
51 | private: | |
52 | std::multimap<const int32_t, CTxHolder> orderedCheatCandidates; | |
53 | std::multimap<const uint256, CTxHolder *> indexedCheatCandidates; | |
54 | CCriticalSection cs_cheat; | |
55 | ||
56 | public: | |
57 | CCheatList() {} | |
58 | ||
59 | // prune all transactions in the list below height | |
60 | uint32_t Prune(uint32_t height); | |
61 | ||
62 | // check to see if a transaction that could be a cheat for the passed transaction is in our list | |
63 | bool IsCheatInList(const CTransaction &tx, CTransaction *pcheatTx); | |
64 | ||
b276e368 | 65 | // checks if the out point is in the list |
66 | bool IsUTXOInList(COutPoint _utxo, uint32_t height); | |
67 | ||
8fc4030c | 68 | // check to see if there are cheat candidates of the same or greater block height in list |
1ca4abe4 | 69 | bool IsHeightOrGreaterInList(uint32_t height); |
8fc4030c MT |
70 | |
71 | // add a potential cheat transaction to the list. we do this for all stake transactions from orphaned stakes | |
7d8624ff | 72 | void Add(const CTxHolder &txh); |
8fc4030c MT |
73 | |
74 | // remove a transaction from the the list | |
75 | void Remove(const CTxHolder &txh); | |
76 | }; | |
77 | ||
78 | ||
79 | extern CCheatList cheatList; | |
6e62f837 | 80 | extern boost::optional<libzcash::SaplingPaymentAddress> defaultSaplingDest; |
8fc4030c MT |
81 | |
82 | #endif |