Debian Codegraph @

monero/src/cryptonote_core/tx_pool.h

raw symbols SCIP
1 // Copyright (c) 2014-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 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31 #pragma once
32 #include "include_base_utils.h"
33
34 #include <atomic>
35 #include <set>
36 #include <tuple>
37 #include <unordered_map>
38 #include <unordered_set>
39 #include <queue>
40 #include <boost/serialization/version.hpp>
41 #include <boost/utility.hpp>
42
43 #include "span.h"
44 #include "string_tools.h"
45 #include "syncobj.h"
46 #include "math_helper.h"
47 #include "cryptonote_basic/cryptonote_basic_impl.h"
48 #include "cryptonote_basic/verification_context.h"
49 #include "cryptonote_protocol/enums.h"
50 #include "blockchain_db/blockchain_db.h"
51 #include "crypto/hash.h"
52 #include "rpc/core_rpc_server_commands_defs.h"
53 #include "rpc/message_data_structs.h"
54
55 namespace cryptonote
56 {
57 class Blockchain;
58 /************************************************************************/
59 /* */
60 /************************************************************************/
61
62 //! pair of <transaction fee, transaction hash> for organization
63 typedef std::pair<std::pair<double, std::time_t>, crypto::hash> tx_by_fee_and_receive_time_entry;
64
65 class txCompare
66 {
67 public:
68 bool operator()(const tx_by_fee_and_receive_time_entry& a, const tx_by_fee_and_receive_time_entry& b) const
69 {
70 // sort by greatest first, not least
71 if (a.first.first > b.first.first) return true;
72 if (a.first.first < b.first.first) return false;
73
74 if (a.first.second < b.first.second) return true;
75 if (a.first.second > b.first.second) return false;
76
77 return memcmp(a.second.data, b.second.data, sizeof(crypto::hash)) < 0;
78 }
79 };
80
81 //! container for sorting transactions by fee per unit size
82 typedef std::set<tx_by_fee_and_receive_time_entry, txCompare> sorted_tx_container;
83
84 /**
85 * @brief Transaction pool, handles transactions which are not part of a block
86 *
87 * This class handles all transactions which have been received, but not as
88 * part of a block.
89 *
90 * This handling includes:
91 * storing the transactions
92 * organizing the transactions by fee per weight unit
93 * taking/giving transactions to and from various other components
94 * saving the transactions to disk on shutdown
95 * helping create a new block template by choosing transactions for it
96 *
97 */
98 class tx_memory_pool: boost::noncopyable
99 {
100 public:
101 /**
102 * @brief Constructor
103 *
104 * @param bchs a Blockchain class instance, for getting chain info
105 */
106 tx_memory_pool(Blockchain& bchs);
107
108
109 /**
110 * @copydoc add_tx(transaction&, tx_verification_context&, bool, bool, uint8_t)
111 *
112 * @param id the transaction's hash
113 * @tx_relay how the transaction was received
114 * @param tx_weight the transaction's weight
115 */
116 bool add_tx(transaction &tx, const crypto::hash &id, const cryptonote::blobdata &blob,
117 size_t tx_weight, tx_verification_context& tvc, relay_method tx_relay, bool relayed,
118 uint8_t version, uint8_t nic_verified_hf_version = 0);
119
120 /**
121 * @brief add a transaction to the transaction pool
122 *
123 * Most likely the transaction will come from the network, but it is
124 * also possible for transactions to come from popped blocks during
125 * a reorg, or from local clients creating a transaction and
126 * submitting it to the network
127 *
128 * @param tx the transaction to be added
129 * @param tvc return-by-reference status about the transaction verification
130 * @tx_relay how the transaction was received
131 * @param relayed was this transaction from the network or a local client?
132 * @param version the version used to create the transaction
133 * @param nic_verified_hf_version hard fork which "tx" is known to pass non-input consensus test
134 *
135 * If "nic_verified_hf_version" parameter is equal to "version" parameter, then we skip the
136 * asserting `ver_non_input_consensus(tx)`, which greatly speeds up block popping and returning
137 * txs to mempool for txs which we know will pass the test. If nothing is known about how "tx"
138 * passes the non-input consensus tests (e.g. for newly received relayed txs), then leave
139 * "nic_verified_hf_version" as its default value of 0 (there is no v0 fork).
140 *
141 * @return true if the transaction passes validations, otherwise false
142 */
143 bool add_tx(transaction &tx, tx_verification_context& tvc, relay_method tx_relay, bool relayed,
144 uint8_t version, uint8_t nic_verified_hf_version = 0);
145
146 /**
147 * @brief takes a transaction with the given hash from the pool
148 *
149 * @param id the hash of the transaction
150 * @param tx return-by-reference the transaction taken
151 * @param txblob return-by-reference the transaction as a blob
152 * @param tx_weight return-by-reference the transaction's weight
153 * @param fee the transaction fee
154 * @param relayed return-by-reference was transaction relayed to us by the network?
155 * @param do_not_relay return-by-reference is transaction not to be relayed to the network?
156 * @param double_spend_seen return-by-reference was a double spend seen for that transaction?
157 * @param pruned return-by-reference is the tx pruned
158 * @param suppress_missing_msgs suppress warning msgs when txid is missing (optional, defaults to `false`)
159 *
160 * @return true unless the transaction cannot be found in the pool
161 */
162 bool take_tx(const crypto::hash &id, transaction &tx, cryptonote::blobdata &txblob, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen, bool &pruned, bool suppress_missing_msgs = false);
163
164 /**
165 * @brief checks if the pool has a transaction with the given hash
166 *
167 * @param id the hash to look for
168 * @param tx_category a filter for txes
169 *
170 * @return true if the transaction is in the pool and meets tx_category requirements
171 */
172 bool have_tx(const crypto::hash &id, relay_category tx_category) const;
173
174 /**
175 * @brief action to take when notified of a block added to the blockchain
176 *
177 * Currently does nothing
178 *
179 * @param new_block_height the height of the blockchain after the change
180 * @param top_block_id the hash of the new top block
181 *
182 * @return true
183 */
184 bool on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id);
185
186 /**
187 * @brief action to take when notified of a block removed from the blockchain
188 *
189 * Currently does nothing
190 *
191 * @param new_block_height the height of the blockchain after the change
192 * @param top_block_id the hash of the new top block
193 *
194 * @return true
195 */
196 bool on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id);
197
198 /**
199 * @brief action to take periodically
200 *
201 * Currently checks transaction pool for stale ("stuck") transactions
202 */
203 void on_idle();
204
205 /**
206 * @brief locks the transaction pool
207 */
208 void lock() const;
209
210 /**
211 * @brief unlocks the transaction pool
212 */
213 void unlock() const;
214
215 // load/store operations
216
217 /**
218 * @brief loads pool state (if any) from disk, and initializes pool
219 *
220 * @param max_txpool_weight the max weight in bytes
221 * @param mine_stem_txes whether to mine txes in stem relay mode
222 *
223 * @return true
224 */
225 bool init(size_t max_txpool_weight = 0, bool mine_stem_txes = false);
226
227 /**
228 * @brief attempts to save the transaction pool state to disk
229 *
230 * Currently fails (returns false) if the data directory from init()
231 * does not exist and cannot be created, but returns true even if
232 * saving to disk is unsuccessful.
233 *
234 * @return true in most cases (see above)
235 */
236 bool deinit();
237
238 /**
239 * @brief Chooses transactions for a block to include
240 *
241 * @param bl return-by-reference the block to fill in with transactions
242 * @param median_weight the current median block weight
243 * @param already_generated_coins the current total number of coins "minted"
244 * @param total_weight return-by-reference the total weight of the new block
245 * @param fee return-by-reference the total of fees from the included transactions
246 * @param expected_reward return-by-reference the total reward awarded to the miner finding this block, including transaction fees
247 * @param version hard fork version to use for consensus rules
248 *
249 * @return true
250 */
251 bool fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version);
252
253 /**
254 * @brief get a list of all transactions in the pool
255 *
256 * @param txs return-by-reference the list of transactions
257 * @param include_sensitive return stempool, anonymity-pool, and unrelayed txes
258 *
259 */
260 void get_transactions(std::vector<transaction>& txs, bool include_sensitive = false) const;
261
262 /**
263 * @brief get a list of all transaction hashes in the pool
264 *
265 * @param txs return-by-reference the list of transactions
266 * @param include_sensitive return stempool, anonymity-pool, and unrelayed txes
267 *
268 */
269 void get_transaction_hashes(std::vector<crypto::hash>& txs, bool include_sensitive = false) const;
270
271 /**
272 * @brief get (weight, fee, receive time) for all transaction in the pool
273 *
274 * @param txs return-by-reference that data
275 * @param include_sensitive return stempool, anonymity-pool, and unrelayed txes
276 *
277 */
278 void get_transaction_backlog(std::vector<tx_backlog_entry>& backlog, bool include_sensitive = false) const;
279
280 /**
281 * @brief get (hash, weight, fee) for transactions in the pool - the minimum required information to create a block template
282 *
283 * Not all transactions in the pool will be returned for performance reasons
284 * If there are too many transactions in the pool, only the highest-paying transactions
285 * will be returned - but enough for the miner to create a full block
286 *
287 * @param backlog return-by-reference that data
288 * @param include_sensitive return stempool, anonymity-pool, and unrelayed txes
289 *
290 */
291 void get_block_template_backlog(std::vector<tx_block_template_backlog_entry>& backlog, bool include_sensitive = false) const;
292
293 /**
294 * @brief get a summary statistics of all transaction hashes in the pool
295 *
296 * @param stats return-by-reference the pool statistics
297 * @param include_sensitive return stempool, anonymity-pool, and unrelayed txes
298 *
299 */
300 void get_transaction_stats(struct txpool_stats& stats, bool include_sensitive = false) const;
301
302 /**
303 * @brief get information about all transactions and key images in the pool
304 *
305 * see documentation on tx_info and spent_key_image_info for more details
306 *
307 * @param tx_infos return-by-reference the transactions' information
308 * @param key_image_infos return-by-reference the spent key images' information
309 * @param include_sensitive_data return stempool, anonymity-pool, and unrelayed
310 * txes and fields that are sensitive to the node privacy
311 *
312 * @return true
313 */
314 bool get_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos, bool include_sensitive_data = false) const;
315
316 /**
317 * @brief get information about all transactions and key images in the pool
318 *
319 * see documentation on tx_in_pool and key_images_with_tx_hashes for more details
320 *
321 * @param tx_infos [out] the transactions' information
322 * @param key_image_infos [out] the spent key images' information
323 *
324 * @return true
325 */
326 bool get_pool_for_rpc(std::vector<cryptonote::rpc::tx_in_pool>& tx_infos, cryptonote::rpc::key_images_with_tx_hashes& key_image_infos) const;
327
328 /**
329 * @brief check for presence of key images in the pool
330 *
331 * @param key_images [in] vector of key images to check
332 * @param spent [out] vector of bool to return
333 *
334 * @return true
335 */
336 bool check_for_key_images(const std::vector<crypto::key_image>& key_images, std::vector<bool>& spent) const;
337
338 /**
339 * @brief get a specific transaction from the pool
340 *
341 * @param h the hash of the transaction to get
342 * @param tx return-by-reference the transaction blob requested
343 * @param tx_relay last relay method us
344 *
345 * @return true if the transaction is found, otherwise false
346 */
347 bool get_transaction(const crypto::hash& h, cryptonote::blobdata& txblob, relay_category tx_category) const;
348
349 /**
350 * @brief get a list of all relayable transactions and their hashes
351 *
352 * "relayable" in this case means:
353 * nonzero fee
354 * hasn't been relayed too recently
355 * isn't old enough that relaying it is considered harmful
356 * Note a transaction can be "relayable" even if do_not_relay is true
357 *
358 * This function will skip all DB checks if an insufficient amount of
359 * time since the last call.
360 *
361 * @param txs return-by-reference the transactions and their hashes
362 *
363 * @return True if DB was checked, false if DB checks skipped.
364 */
365 bool get_relayable_transactions(std::vector<std::tuple<crypto::hash, cryptonote::blobdata, relay_method>>& txs);
366
367 /**
368 * @brief tell the pool that certain transactions were just relayed
369 *
370 * @param hashes list of tx hashes that are about to be relayed
371 * @param tx_relay update how the tx left this node
372 * @param just_broadcasted true if a tx was just broadcasted
373 *
374 */
375 void set_relayed(epee::span<const crypto::hash> hashes, relay_method tx_relay, std::vector<bool> &just_broadcasted);
376
377 /**
378 * @brief get the total number of transactions in the pool
379 *
380 * @return the number of transactions in the pool
381 */
382 size_t get_transactions_count(bool include_sensitive = false) const;
383
384 /**
385 * @brief get a string containing human-readable pool information
386 *
387 * @param short_format whether to use a shortened format for the info
388 *
389 * @return the string
390 */
391 std::string print_pool(bool short_format) const;
392
393 /**
394 * @brief remove transactions from the pool which are no longer valid
395 *
396 * With new versions of the currency, what conditions render a transaction
397 * invalid may change. This function clears those which were received
398 * before a version change and no longer conform to requirements.
399 *
400 * @param version the version the transactions must conform to
401 *
402 * @return the number of transactions removed
403 */
404 size_t validate(uint8_t version);
405
406 /**
407 * @brief return the cookie
408 *
409 * @return the cookie
410 */
411 uint64_t cookie() const { return m_cookie; }
412
413 /**
414 * @brief get the cumulative txpool weight in bytes
415 *
416 * @return the cumulative txpool weight in bytes
417 */
418 size_t get_txpool_weight() const;
419
420 /**
421 * @brief set the max cumulative txpool weight in bytes
422 *
423 * @param bytes the max cumulative txpool weight in bytes
424 */
425 void set_txpool_max_weight(size_t bytes);
426
427 /**
428 * @brief reduce the cumulative txpool weight by the weight provided
429 *
430 * @param weight the weight to reduce the total txpool weight by
431 */
432 void reduce_txpool_weight(size_t weight);
433
434 #define CURRENT_MEMPOOL_ARCHIVE_VER 11
435 #define CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER 13
436
437 /**
438 * @brief information about a single transaction
439 */
440 struct tx_details
441 {
442 transaction tx; //!< the transaction
443 cryptonote::blobdata tx_blob; //!< the transaction's binary blob
444 size_t blob_size; //!< the transaction's size
445 size_t weight; //!< the transaction's weight
446 uint64_t fee; //!< the transaction's fee amount
447 crypto::hash max_used_block_id; //!< the hash of the highest block referenced by an input
448 uint64_t max_used_block_height; //!< the height of the highest block referenced by an input
449
450 //! whether or not the transaction has been in a block before
451 /*! if the transaction was returned to the pool from the blockchain
452 * due to a reorg, then this will be true
453 */
454 bool kept_by_block;
455
456 //! the highest block the transaction referenced when last checking it failed
457 /*! if verifying a transaction's inputs fails, it's possible this is due
458 * to a reorg since it was created (if it used recently created outputs
459 * as inputs).
460 */
461 uint64_t last_failed_height;
462
463 //! the hash of the highest block the transaction referenced when last checking it failed
464 /*! if verifying a transaction's inputs fails, it's possible this is due
465 * to a reorg since it was created (if it used recently created outputs
466 * as inputs).
467 */
468 crypto::hash last_failed_id;
469
470 time_t receive_time; //!< the time when the transaction entered the pool
471
472 time_t last_relayed_time; //!< the last time the transaction was relayed to the network
473 bool relayed; //!< whether or not the transaction has been relayed to the network
474 bool do_not_relay; //!< to avoid relay this transaction to the network
475
476 bool double_spend_seen; //!< true iff another tx was seen double spending this one
477 };
478
479 /**
480 * @brief get infornation about a single transaction
481 */
482 bool get_transaction_info(const crypto::hash &txid, tx_details &td, bool include_sensitive_data, bool include_blob = false) const;
483
484 /**
485 * @brief get information about multiple transactions
486 */
487 bool get_transactions_info(const std::vector<crypto::hash>& txids, std::vector<std::pair<crypto::hash, tx_details>>& txs, bool include_sensitive_data = false) const;
488
489 /**
490 * @brief get transactions not in the passed set
491 */
492 bool get_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes) const;
493
494 /**
495 * @brief get info necessary for update of pool-related info in a wallet, preferably incremental
496 *
497 * @return true on success, false on error
498 */
499 bool get_pool_info(time_t start_time, bool include_sensitive, size_t max_tx_count, std::vector<std::pair<crypto::hash, tx_details>>& added_txs, std::vector<crypto::hash>& remaining_added_txids, std::vector<crypto::hash>& removed_txs, bool& incremental) const;
500
501 private:
502
503 /**
504 * @brief insert key images into m_spent_key_images
505 *
506 * @return true on success, false on error
507 */
508 bool insert_key_images(const transaction_prefix &tx, const crypto::hash &txid, relay_method tx_relay);
509
510 /**
511 * @brief remove old transactions from the pool
512 *
513 * After a certain time, it is assumed that a transaction which has not
514 * yet been mined will likely not be mined. These transactions are removed
515 * from the pool to avoid buildup.
516 *
517 * @return true
518 */
519 bool remove_stuck_transactions();
520
521 /**
522 * @brief check if a transaction in the pool has a given spent key image
523 *
524 * @param key_im the spent key image to look for
525 * @param txid hash of the new transaction where `key_im` was seen.
526 *
527 * @return true if the spent key image is present, otherwise false
528 */
529 bool have_tx_keyimg_as_spent(const crypto::key_image& key_im, const crypto::hash& txid) const;
530
531 /**
532 * @brief check if any spent key image in a transaction is in the pool
533 *
534 * Checks if any of the spent key images in a given transaction are present
535 * in any of the transactions in the transaction pool.
536 *
537 * @note see tx_pool::have_tx_keyimg_as_spent
538 *
539 * @param tx the transaction to check spent key images of
540 * @param txid hash of `tx`.
541 *
542 * @return true if any spent key images are present in the pool, otherwise false
543 */
544 bool have_tx_keyimges_as_spent(const transaction& tx, const crypto::hash& txid) const;
545
546 /**
547 * @brief forget a transaction's spent key images
548 *
549 * Spent key images are stored separately from transactions for
550 * convenience/speed, so this is part of the process of removing
551 * a transaction from the pool.
552 *
553 * @param tx the transaction
554 * @param txid the transaction's hash
555 *
556 * @return false if any key images to be removed cannot be found, otherwise true
557 */
558 bool remove_transaction_keyimages(const transaction_prefix& tx, const crypto::hash &txid);
559
560 /**
561 * @brief check if any of a transaction's spent key images are present in a given set
562 *
563 * @param kic the set of key images to check against
564 * @param tx the transaction to check
565 *
566 * @return true if any key images present in the set, otherwise false
567 */
568 static bool have_key_images(const std::unordered_set<crypto::key_image>& kic, const transaction_prefix& tx);
569
570 /**
571 * @brief append the key images from a transaction to the given set
572 *
573 * @param kic the set of key images to append to
574 * @param tx the transaction
575 *
576 * @return false if any append fails, otherwise true
577 */
578 static bool append_key_images(std::unordered_set<crypto::key_image>& kic, const transaction_prefix& tx);
579
580 /**
581 * @brief check if a transaction is a valid candidate for inclusion in a block
582 *
583 * @param txd the transaction to check (and info about it)
584 * @param txid the txid of the transaction to check
585 * @param txblob the transaction blob to check
586 * @param tx the parsed transaction, if successful
587 *
588 * @return true if the transaction is good to go, otherwise false
589 */
590 bool is_transaction_ready_to_go(txpool_tx_meta_t& txd, const crypto::hash &txid, const cryptonote::blobdata_ref &txblob, transaction&tx) const;
591 bool is_transaction_ready_to_go(txpool_tx_meta_t& txd, const crypto::hash &txid, const cryptonote::blobdata &txblob, transaction&tx) const;
592
593 /**
594 * @brief mark all transactions double spending the one passed
595 */
596 void mark_double_spend(const transaction &tx);
597
598 /**
599 * @brief prune lowest fee/byte txes till we're not above bytes
600 *
601 * if bytes is 0, use m_txpool_max_weight
602 */
603 void prune(size_t bytes = 0);
604
605 void add_tx_to_transient_lists(const crypto::hash& txid, double fee, time_t receive_time);
606 void remove_tx_from_transient_lists(const cryptonote::sorted_tx_container::iterator& sorted_it, const crypto::hash& txid, bool sensitive);
607 void track_removed_tx(const crypto::hash& txid, bool sensitive);
608
609 //TODO: confirm the below comments and investigate whether or not this
610 // is the desired behavior
611 //! map key images to transactions which spent them
612 /*! this seems odd, but it seems that multiple transactions can exist
613 * in the pool which both have the same spent key. This would happen
614 * in the event of a reorg where someone creates a new/different
615 * transaction on the assumption that the original will not be in a
616 * block again.
617 */
618 typedef std::unordered_map<crypto::key_image, std::unordered_set<crypto::hash>> key_images_container;
619
620 #if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
621 public:
622 #endif
623 mutable epee::critical_section m_transactions_lock; //!< lock for the pool
624 #if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
625 private:
626 #endif
627
628 //! container for spent key images from the transactions in the pool
629 key_images_container m_spent_key_images;
630
631 //TODO: this time should be a named constant somewhere, not hard-coded
632 //! interval on which to check for stale/"stuck" transactions
633 epee::math_helper::once_a_time_seconds<30> m_remove_stuck_tx_interval;
634
635 //TODO: look into doing this better
636 //!< container for transactions organized by fee per size and receive time
637 sorted_tx_container m_txs_by_fee_and_receive_time;
638
639 std::atomic<uint64_t> m_cookie; //!< incremented at each change
640
641 // Info when transactions entered the pool, accessible by txid
642 std::unordered_map<crypto::hash, time_t> m_added_txs_by_id;
643
644 // Info at what time the pool started to track the adding of transactions
645 time_t m_added_txs_start_time;
646
647 struct removed_tx_info
648 {
649 crypto::hash txid;
650 bool sensitive;
651 };
652
653 // Info about transactions that were removed from the pool, ordered by the time
654 // of deletion
655 std::multimap<time_t, removed_tx_info> m_removed_txs_by_time;
656
657 // Info how far back in time the list of removed tx ids currently reaches
658 // (it gets shorted periodically to prevent overflow)
659 time_t m_removed_txs_start_time;
660
661 /**
662 * @brief get an iterator to a transaction in the sorted container
663 *
664 * @param id the hash of the transaction to look for
665 *
666 * @return an iterator, possibly to the end of the container if not found
667 */
668 sorted_tx_container::iterator find_tx_in_sorted_container(const crypto::hash& id) const;
669
670 //! cache/call Blockchain::check_tx_inputs results
671 bool check_tx_inputs(const std::function<cryptonote::transaction&(void)> &get_tx, const crypto::hash &txid, uint64_t &max_used_block_height, crypto::hash &max_used_block_id, tx_verification_context &tvc, bool kept_by_block = false) const;
672
673 //! transactions which are unlikely to be included in blocks
674 /*! These transactions are kept in RAM in case they *are* included
675 * in a block eventually, but this container is not saved to disk.
676 */
677 std::unordered_set<crypto::hash> m_timed_out_transactions;
678
679 Blockchain& m_blockchain; //!< reference to the Blockchain object
680
681 size_t m_txpool_max_weight;
682 size_t m_txpool_weight;
683 bool m_mine_stem_txes;
684
685 mutable std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>> m_input_cache;
686
687 std::unordered_map<crypto::hash, transaction> m_parsed_tx_cache;
688
689 //! Next timestamp that a DB check for relayable txes is allowed
690 std::atomic<time_t> m_next_check;
691 };
692 }
693
694 namespace boost
695 {
696 namespace serialization
697 {
698 template<class archive_t>
699 void serialize(archive_t & ar, cryptonote::tx_memory_pool::tx_details& td, const unsigned int version)
700 {
701 ar & td.blob_size;
702 ar & td.fee;
703 ar & td.tx;
704 ar & td.max_used_block_height;
705 ar & td.max_used_block_id;
706 ar & td.last_failed_height;
707 ar & td.last_failed_id;
708 ar & td.receive_time;
709 ar & td.last_relayed_time;
710 ar & td.relayed;
711 if (version < 11)
712 return;
713 ar & td.kept_by_block;
714 if (version < 12)
715 return;
716 ar & td.do_not_relay;
717 if (version < 13)
718 return;
719 ar & td.weight;
720 }
721 }
722 }
723 BOOST_CLASS_VERSION(cryptonote::tx_memory_pool, CURRENT_MEMPOOL_ARCHIVE_VER)
724 BOOST_CLASS_VERSION(cryptonote::tx_memory_pool::tx_details, CURRENT_MEMPOOL_TX_DETAILS_ARCHIVE_VER)
725
726
727