Monero
tx_pool.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 
46 {
49 
50 public:
51  txpool_base();
52 
53  bool increase_broadcasted_tx_count(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& events);
54  bool increase_all_tx_count(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& events);
55  bool check_txpool_spent_keys(cryptonote::core& c, size_t /*ev_index*/, const std::vector<test_event_entry>& events);
56 };
57 
59 {
61  {}
62 
63  bool generate(std::vector<test_event_entry>& events) const;
64 };
65 
67 {
69  {}
70 
71  bool generate(std::vector<test_event_entry>& events);
72 };
73 
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;
83 
84  bool check_changed(cryptonote::core& c, size_t ev_index, relay_test condition);
85 
86 public:
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 
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& /*tx*/);
102 };
103 
105 {
108  {}
109 
110  bool generate(std::vector<test_event_entry>& events) const;
111 };
112 
114 {
117  {}
118 
119  bool generate(std::vector<test_event_entry>& events) const;
120 };
121 
123 {
126  {}
127 
128  bool generate(std::vector<test_event_entry>& events) const;
129 };
130 
132 {
135  {}
136 
137  bool generate(std::vector<test_event_entry>& events) const;
138 };
Definition: tx_pool.h:45
size_t m_no_new_index
Definition: tx_pool.h:79
std::unordered_set< crypto::hash > m_no_relay_hashes
Definition: tx_pool.h:77
txpool_stem_loop()
Definition: tx_pool.h:133
bool generate(std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:109
std::unordered_map< crypto::hash, uint64_t > m_all_hashes
Definition: tx_pool.h:78
txpool_base()
Definition: tx_pool.cpp:45
Definition: tx_pool.h:131
relay_test
Definition: tx_pool.h:37
bool generate(std::vector< test_event_entry > &events) const
Definition: tx_pool.cpp:534
bool generate(std::vector< test_event_entry > &events) const
Definition: tx_pool.cpp:568
bool mark_timestamp_change(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:154
Definition: tx_pool.h:122
bool check_unchanged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:467
txpool_spend_key_all()
Definition: tx_pool.h:68
bool check_new_no_relay(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:481
bool check_changed(cryptonote::core &c, size_t ev_index, relay_test condition)
Definition: tx_pool.cpp:166
crypto::hash m_last_tx
Definition: tx_pool.h:82
Definition: tx_pool.h:74
A new block or fluff/flood tx is expected in txpool.
size_t m_failed_index
Definition: tx_pool.h:80
txpool_double_spend_norelay()
Definition: tx_pool.h:106
bool check_txpool_spent_keys(cryptonote::core &c, size_t, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:67
Definition: verification_context.h:40
Definition: tx_pool.h:58
size_t m_new_timestamp_index
Definition: tx_pool.h:81
bool timestamp_change_pause(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Pause for 1 second, so that receive_time for tx meta changes (tx hidden from public rpc being updated...
Definition: tx_pool.cpp:160
handles core cryptonote functionality
Definition: cryptonote_core.h:86
bool increase_all_tx_count(cryptonote::core &c, size_t, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:61
bool check_tx_verification_context(const cryptonote::tx_verification_context &tvc, bool tx_added, size_t event_idx, const cryptonote::transaction &)
Definition: tx_pool.cpp:486
bool check_new_hidden(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:477
txpool_double_spend_keyimage()
Definition: tx_pool.h:124
size_t m_broadcasted_tx_count
Definition: tx_pool.h:47
bool generate(std::vector< test_event_entry > &events) const
Definition: tx_pool.cpp:96
std::unordered_set< crypto::hash > m_broadcasted_hashes
Definition: tx_pool.h:76
txpool_double_spend_base()
Definition: tx_pool.cpp:122
A new no relay is expected in txpool.
txpool_spend_key_public()
Definition: tx_pool.h:60
bool generate(std::vector< test_event_entry > &events) const
Definition: tx_pool.cpp:497
bool generate(std::vector< test_event_entry > &events) const
Definition: tx_pool.cpp:611
bool mark_failed(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:148
Definition: tx_pool.h:66
POD_CLASS hash
Definition: hash.h:49
Definition: chaingen.h:165
Definition: tx_pool.h:113
bool increase_broadcasted_tx_count(cryptonote::core &c, size_t, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:55
A new stem or local tx is expected in txpool.
Definition: cryptonote_basic.h:204
No expected changes to the txpool.
Definition: tx_pool.h:104
c
Definition: pymoduletest.py:79
bool mark_no_new(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:142
size_t m_all_tx_count
Definition: tx_pool.h:48
txpool_double_spend_local()
Definition: tx_pool.h:115
bool check_new_broadcasted(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: tx_pool.cpp:472