| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#pragma once |
| 30 |
|
| 31 |
#include <unordered_map> |
| 32 |
#include <unordered_set> |
| 33 |
|
| 34 |
#include "chaingen.h" |
| 35 |
#include "crypto/crypto.h" |
| 36 |
|
| 37 |
enum class relay_test |
| 38 |
{ |
| 39 |
no_change = 0, |
| 40 |
broadcasted, |
| 41 |
hidden, |
| 42 |
no_relay |
| 43 |
}; |
| 44 |
|
| 45 |
class txpool_base : public test_chain_unit_base |
| 46 |
{ |
| 47 |
size_t m_broadcasted_tx_count; |
| 48 |
size_t m_all_tx_count; |
| 49 |
|
| 50 |
public: |
| 51 |
txpool_base(); |
| 52 |
|
| 53 |
bool increase_broadcasted_tx_count(cryptonote::core& c, size_t , const std::vector<test_event_entry>& events); |
| 54 |
bool increase_all_tx_count(cryptonote::core& c, size_t , const std::vector<test_event_entry>& events); |
| 55 |
bool check_txpool_spent_keys(cryptonote::core& c, size_t , const std::vector<test_event_entry>& events); |
| 56 |
}; |
| 57 |
|
| 58 |
struct txpool_spend_key_public : txpool_base |
| 59 |
{ |
| 60 |
txpool_spend_key_public() : txpool_base() |
| 61 |
{} |
| 62 |
|
| 63 |
bool generate(std::vector<test_event_entry>& events) const; |
| 64 |
}; |
| 65 |
|
| 66 |
struct txpool_spend_key_all : txpool_base |
| 67 |
{ |
| 68 |
txpool_spend_key_all() : txpool_base() |
| 69 |
{} |
| 70 |
|
| 71 |
bool generate(std::vector<test_event_entry>& events); |
| 72 |
}; |
| 73 |
|
| 74 |
class txpool_double_spend_base : public txpool_base |
| 75 |
{ |
| 76 |
std::unordered_set<crypto::hash> m_broadcasted_hashes; |
| 77 |
std::unordered_set<crypto::hash> m_no_relay_hashes; |
| 78 |
std::unordered_map<crypto::hash, uint64_t> m_all_hashes; |
| 79 |
size_t m_no_new_index; |
| 80 |
size_t m_failed_index; |
| 81 |
size_t m_new_timestamp_index; |
| 82 |
crypto::hash m_last_tx; |
| 83 |
|
| 84 |
bool check_changed(cryptonote::core& c, size_t ev_index, relay_test condition); |
| 85 |
|
| 86 |
public: |
| 87 |
txpool_double_spend_base(); |
| 88 |
|
| 89 |
bool mark_no_new(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 90 |
bool mark_failed(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 91 |
bool mark_timestamp_change(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 92 |
|
| 93 |
|
| 94 |
bool timestamp_change_pause(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 95 |
|
| 96 |
bool check_unchanged(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 97 |
bool check_new_broadcasted(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 98 |
bool check_new_hidden(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 99 |
bool check_new_no_relay(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events); |
| 100 |
|
| 101 |
bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_idx, const cryptonote::transaction& ); |
| 102 |
}; |
| 103 |
|
| 104 |
struct txpool_double_spend_norelay : txpool_double_spend_base |
| 105 |
{ |
| 106 |
txpool_double_spend_norelay() |
| 107 |
: txpool_double_spend_base() |
| 108 |
{} |
| 109 |
|
| 110 |
bool generate(std::vector<test_event_entry>& events) const; |
| 111 |
}; |
| 112 |
|
| 113 |
struct txpool_double_spend_local : txpool_double_spend_base |
| 114 |
{ |
| 115 |
txpool_double_spend_local() |
| 116 |
: txpool_double_spend_base() |
| 117 |
{} |
| 118 |
|
| 119 |
bool generate(std::vector<test_event_entry>& events) const; |
| 120 |
}; |
| 121 |
|
| 122 |
struct txpool_double_spend_keyimage : txpool_double_spend_base |
| 123 |
{ |
| 124 |
txpool_double_spend_keyimage() |
| 125 |
: txpool_double_spend_base() |
| 126 |
{} |
| 127 |
|
| 128 |
bool generate(std::vector<test_event_entry>& events) const; |
| 129 |
}; |
| 130 |
|
| 131 |
struct txpool_stem_loop : txpool_double_spend_base |
| 132 |
{ |
| 133 |
txpool_stem_loop() |
| 134 |
: txpool_double_spend_base() |
| 135 |
{} |
| 136 |
|
| 137 |
bool generate(std::vector<test_event_entry>& events) const; |
| 138 |
}; |