]>
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" | |
18 | #include "script/script.h" | |
19 | #include "uint256.h" | |
20 | ||
21 | #include <vector> | |
22 | #include <map> | |
23 | ||
24 | class CTxHolder | |
25 | { | |
26 | public: | |
27 | uint256 utxo; | |
28 | uint32_t height; | |
29 | CTransaction tx; | |
30 | CTxHolder(const CTransaction &_tx, uint32_t _height) : height(_height), tx(_tx) { | |
31 | CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); | |
32 | ||
33 | hw << tx.vin[0].prevout.hash; | |
34 | hw << tx.vin[0].prevout.n; | |
35 | utxo = hw.GetHash(); | |
36 | } | |
37 | }; | |
38 | ||
39 | ||
40 | class CCheatList | |
41 | { | |
42 | private: | |
43 | std::multimap<const int32_t, CTxHolder> orderedCheatCandidates; | |
44 | std::multimap<const uint256, CTxHolder *> indexedCheatCandidates; | |
45 | CCriticalSection cs_cheat; | |
46 | ||
47 | public: | |
48 | CCheatList() {} | |
49 | ||
50 | // prune all transactions in the list below height | |
51 | uint32_t Prune(uint32_t height); | |
52 | ||
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); | |
55 | ||
56 | // check to see if there are cheat candidates of the same or greater block height in list | |
57 | bool IsHeightOrGreaterInList(uint32_t height) | |
58 | { | |
59 | auto range = orderedCheatCandidates.equal_range(height); | |
60 | return (range.first == orderedCheatCandidates.end()); | |
61 | } | |
62 | ||
63 | // add a potential cheat transaction to the list. we do this for all stake transactions from orphaned stakes | |
64 | bool Add(CTxHolder &txh); | |
65 | ||
66 | // remove a transaction from the the list | |
67 | void Remove(const CTxHolder &txh); | |
68 | }; | |
69 | ||
70 | ||
71 | extern CCheatList cheatList; | |
72 | extern boost::optional<libzcash::SaplingPaymentAddress> cheatCatcher; | |
73 | ||
74 | #endif |