Electroneum
Loading...
Searching...
No Matches
chaingen.h
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32#pragma once
33
34#include <vector>
35#include <iostream>
36#include <stdint.h>
37
38#include <boost/archive/binary_oarchive.hpp>
39#include <boost/archive/binary_iarchive.hpp>
40#include <boost/program_options.hpp>
41#include <boost/optional.hpp>
42#include <boost/serialization/vector.hpp>
43#include <boost/serialization/variant.hpp>
44#include <boost/serialization/optional.hpp>
45#include <boost/serialization/unordered_map.hpp>
46#include <boost/functional/hash.hpp>
47
48#include "include_base_utils.h"
50#include "common/command_line.h"
51
58#include "misc_language.h"
59
60#undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
61#define ELECTRONEUM_DEFAULT_LOG_CATEGORY "tests.core"
62
63
64
66{
67 std::string callback_name;
71
72private:
73 friend class boost::serialization::access;
74
75 template<class Archive>
76 void serialize(Archive & ar, const unsigned int /*version*/)
77 {
78 ar & callback_name;
79 }
80};
81
82template<typename T>
84{
86
88 : data(a_data)
89 {
90 }
91
94 FIELD(data)
96
97private:
98 friend class boost::serialization::access;
99
100 template<class Archive>
101 void serialize(Archive & ar, const unsigned int /*version*/)
102 {
103 ar & data;
104 }
105};
106
109
111{
114
116 {
118 };
119
120 event_visitor_settings(int a_valid_mask = 0, bool a_txs_keeped_by_block = false)
121 : valid_mask(a_valid_mask)
122 , txs_keeped_by_block(a_txs_keeped_by_block)
123 {
124 }
125
126private:
128
129 template<class Archive>
130 void serialize(Archive & ar, const unsigned int /*version*/)
131 {
132 ar & valid_mask;
134 }
135};
136
137typedef std::vector<std::pair<uint8_t, uint64_t>> v_hardforks_t;
139{
140 boost::optional<v_hardforks_t> hard_forks;
141
143
144private:
146
147 template<class Archive>
148 void serialize(Archive & ar, const unsigned int /*version*/)
149 {
150 ar & hard_forks;
151 }
152};
153
154
161
162typedef boost::variant<cryptonote::block, cryptonote::transaction, std::vector<cryptonote::transaction>, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings, event_replay_settings> test_event_entry;
163typedef std::unordered_map<crypto::hash, const cryptonote::transaction*> map_hash2tx_t;
164
166{
167public:
168 typedef boost::function<bool (cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events)> verify_callback;
169 typedef std::map<std::string, verify_callback> callbacks_map;
170
171 void register_callback(const std::string& cb_name, verify_callback cb);
172 bool verify(const std::string& cb_name, cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry> &events);
173 bool check_block_verification_context(const cryptonote::block_verification_context& bvc, size_t event_idx, const cryptonote::block& /*blk*/);
174 bool check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool /*tx_added*/, size_t /*event_index*/, const cryptonote::transaction& /*tx*/);
175 bool check_tx_verification_context_array(const std::vector<cryptonote::tx_verification_context>& tvcs, size_t /*tx_added*/, size_t /*event_index*/, const std::vector<cryptonote::transaction>& /*txs*/);
176
177private:
178 callbacks_map m_callbacks;
179};
180
181
183{
184public:
186 {
188 : prev_id()
190 , block_weight(0)
191 {
192 }
193
194 block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
195 : prev_id(a_prev_id)
196 , already_generated_coins(an_already_generated_coins)
197 , block_weight(a_block_weight)
198 {
199 }
200
204
205 private:
207
208 template<class Archive>
209 void serialize(Archive & ar, const unsigned int /*version*/)
210 {
211 ar & prev_id;
213 ar & block_weight;
214 }
215 };
216
218 {
220 bf_major_ver = 1 << 0,
221 bf_minor_ver = 1 << 1,
222 bf_timestamp = 1 << 2,
223 bf_prev_id = 1 << 3,
224 bf_miner_tx = 1 << 4,
225 bf_tx_hashes = 1 << 5,
226 bf_diffic = 1 << 6,
227 bf_max_outs = 1 << 7,
229 };
230
232 test_generator(const test_generator &other): m_blocks_info(other.m_blocks_info) {}
233 void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
234 void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
237
238 void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_weights, uint64_t already_generated_coins,
239 uint8_t hf_version = 1);
241 const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
242 std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list,
243 const boost::optional<uint8_t>& hf_ver = boost::none);
244 bool construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp);
245 bool construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev, const cryptonote::account_base& miner_acc,
246 const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>(),
247 const boost::optional<uint8_t>& hf_ver = boost::none);
248
250 const cryptonote::account_base& miner_acc, int actual_params = bf_none, uint8_t major_ver = 0,
251 uint8_t minor_ver = 0, uint64_t timestamp = 0, const crypto::hash& prev_id = crypto::hash(),
253 const std::vector<crypto::hash>& tx_hashes = std::vector<crypto::hash>(), size_t txs_sizes = 0, size_t max_outs = 999,
254 uint8_t hf_version = 1);
256 const cryptonote::account_base& miner_acc, const std::vector<crypto::hash>& tx_hashes, size_t txs_size);
257
258private:
259 std::unordered_map<crypto::hash, block_info> m_blocks_info;
260
262
263 template<class Archive>
264 void serialize(Archive & ar, const unsigned int /*version*/)
265 {
266 ar & m_blocks_info;
267 }
268};
269
270template<typename T>
271std::string dump_keys(T * buff32)
272{
273 std::ostringstream ss;
274 char buff[10];
275
276 ss << "[";
277 for(int i = 0; i < 32; i++)
278 {
279 snprintf(buff, 10, "0x%02x", ((uint8_t)buff32[i] & 0xff));
280 ss << buff;
281 if (i < 31)
282 ss << ",";
283 }
284 ss << "]";
285 return ss.str();
286}
287
291 size_t blk_height; // block height
292 size_t tx_no; // index of transaction in block
293 size_t out_no; // index of out in transaction
294 size_t idx;
297 bool spent;
298 bool rct;
302
303 output_index(const cryptonote::txout_target_v &_out, uint64_t _a, size_t _h, size_t tno, size_t ono, const cryptonote::block *_pb, const cryptonote::transaction *_pt)
304 : out(_out), amount(_a), blk_height(_h), tx_no(tno), out_no(ono), idx(0), unlock_time(0),
306 {
307
308 }
309
311 : out(other.out), amount(other.amount), blk_height(other.blk_height), tx_no(other.tx_no), rct(other.rct),
312 out_no(other.out_no), idx(other.idx), unlock_time(other.unlock_time), is_coin_base(other.is_coin_base),
313 spent(other.spent), comm(other.comm), p_blk(other.p_blk), p_tx(other.p_tx) { }
314
315 void set_rct(bool arct) {
316 rct = arct;
317 if (rct && p_tx->rct_signatures.outPk.size() > out_no)
318 comm = p_tx->rct_signatures.outPk[out_no].mask;
319 else
321 }
322
324 return comm;
325 }
326
327 const std::string toString() const {
328 std::stringstream ss;
329
330 ss << "output_index{blk_height=" << blk_height
331 << " tx_no=" << tx_no
332 << " out_no=" << out_no
333 << " amount=" << amount
334 << " idx=" << idx
335 << " unlock_time=" << unlock_time
336 << " spent=" << spent
337 << " is_coin_base=" << is_coin_base
338 << " rct=" << rct
339 << " comm=" << dump_keys(comm.bytes)
340 << "}";
341
342 return ss.str();
343 }
344
346 {
347 new(this) output_index(other);
348 return *this;
349 }
350};
351
352typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
353typedef std::pair<crypto::hash, size_t> output_hasher;
354typedef boost::hash<output_hasher> output_hasher_hasher;
355typedef std::map<uint64_t, std::vector<size_t> > map_output_t;
356typedef std::map<uint64_t, std::vector<output_index> > map_output_idx_t;
357typedef std::unordered_map<crypto::hash, cryptonote::block> map_block_t;
358typedef std::unordered_map<output_hasher, output_index, output_hasher_hasher> map_txid_output_t;
359typedef std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses_t;
360typedef std::pair<uint64_t, size_t> outloc_t;
361
362typedef boost::variant<cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry> var_addr_t;
368
369// Daemon functionality
371{
372public:
374 map_txid_output_t m_map_outs; // mapping (txid, out) -> output_index
376
377 block_tracker() = default;
379 map_txid_output_t::iterator find_out(const crypto::hash &txid, size_t out);
380 map_txid_output_t::iterator find_out(const output_hasher &id);
381 void process(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
382 void process(const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t& mtx);
383 void process(const cryptonote::block* blk, const cryptonote::transaction * tx, size_t i);
384 void global_indices(const cryptonote::transaction *tx, std::vector<uint64_t> &indices);
385 void get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector<get_outs_entry> &outs);
386
387 std::string dump_data();
388 void dump_data(const std::string & fname);
389
390private:
392
393 template<class Archive>
394 void serialize(Archive & ar, const unsigned int /*version*/)
395 {
396 ar & m_outs;
397 ar & m_map_outs;
398 ar & m_blocks;
399 }
400};
401
402std::string dump_data(const cryptonote::transaction &tx);
408
409inline cryptonote::difficulty_type get_test_difficulty(const boost::optional<uint8_t>& hf_ver=boost::none) {return !hf_ver || hf_ver.get() <= 1 ? 1 : 2;}
410inline uint64_t current_difficulty_window(const boost::optional<uint8_t>& hf_ver=boost::none){ return !hf_ver || hf_ver.get() <= 1 ? DIFFICULTY_TARGET : DIFFICULTY_TARGET_V6; }
412
413cryptonote::tx_destination_entry build_dst(const var_addr_t& to, bool is_subaddr=false, uint64_t amount=0);
414std::vector<cryptonote::tx_destination_entry> build_dsts(const var_addr_t& to1, bool sub1=false, uint64_t am1=0);
415std::vector<cryptonote::tx_destination_entry> build_dsts(std::initializer_list<dest_wrapper_t> inps);
416uint64_t sum_amount(const std::vector<cryptonote::tx_destination_entry>& destinations);
417uint64_t sum_amount(const std::vector<cryptonote::tx_source_entry>& sources);
418
419bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins,
421 uint64_t fee, cryptonote::keypair* p_txkey = nullptr);
422
423bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx,
424 const cryptonote::block& blk_head, const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
425 uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
426
427bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const cryptonote::block& blk_head,
428 const cryptonote::account_base& from, std::vector<cryptonote::tx_destination_entry> destinations,
429 uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
430
432 std::vector<cryptonote::tx_source_entry> &sources,
433 uint64_t fee, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
434
435bool construct_tx_to_key(cryptonote::transaction& tx, const cryptonote::account_base& from, const std::vector<cryptonote::tx_destination_entry>& destinations,
436 std::vector<cryptonote::tx_source_entry> &sources,
437 uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version = 0);
438
439cryptonote::transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
440 const cryptonote::account_base& acc_from, const var_addr_t& to,
441 uint64_t amount, uint64_t fee);
442
443bool construct_tx_rct(const cryptonote::account_keys& sender_account_keys,
444 std::vector<cryptonote::tx_source_entry>& sources,
445 const std::vector<cryptonote::tx_destination_entry>& destinations,
446 const boost::optional<cryptonote::account_public_address>& change_addr,
447 std::vector<uint8_t> extra, cryptonote::transaction& tx, uint64_t unlock_time,
448 bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
449
450
451uint64_t num_blocks(const std::vector<test_event_entry>& events);
452cryptonote::block get_head_block(const std::vector<test_event_entry>& events);
453
454void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs);
455bool trim_block_chain(std::vector<cryptonote::block>& blockchain, const crypto::hash& tail);
456bool trim_block_chain(std::vector<const cryptonote::block*>& blockchain, const crypto::hash& tail);
457bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<cryptonote::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
458bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<const cryptonote::block*>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
459
461 uint64_t amount, uint64_t fee,
462 const std::vector<cryptonote::tx_source_entry> &sources,
463 std::vector<cryptonote::tx_destination_entry>& destinations, bool always_change=false);
464
465void fill_tx_destinations(const var_addr_t& from, const std::vector<cryptonote::tx_destination_entry>& dests,
466 uint64_t fee,
467 const std::vector<cryptonote::tx_source_entry> &sources,
468 std::vector<cryptonote::tx_destination_entry>& destinations,
469 bool always_change);
470
472 uint64_t amount, uint64_t fee,
473 const std::vector<cryptonote::tx_source_entry> &sources,
474 std::vector<cryptonote::tx_destination_entry>& destinations,
475 std::vector<cryptonote::tx_destination_entry>& destinations_pure,
476 bool always_change=false);
477
478
479void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
481 uint64_t amount, uint64_t fee, size_t nmix,
482 std::vector<cryptonote::tx_source_entry>& sources,
483 std::vector<cryptonote::tx_destination_entry>& destinations);
484
485void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
487 uint64_t amount, uint64_t fee, size_t nmix,
488 std::vector<cryptonote::tx_source_entry>& sources,
489 std::vector<cryptonote::tx_destination_entry>& destinations);
490
491uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
492
493bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks);
494
495/************************************************************************/
496/* */
497/************************************************************************/
498template<class t_test_class>
499struct push_core_event_visitor: public boost::static_visitor<bool>
500{
501private:
502 cryptonote::core& m_c;
503 const std::vector<test_event_entry>& m_events;
504 t_test_class& m_validator;
505 size_t m_ev_index;
506
507 bool m_txs_keeped_by_block;
508
509public:
510 push_core_event_visitor(cryptonote::core& c, const std::vector<test_event_entry>& events, t_test_class& validator)
511 : m_c(c)
512 , m_events(events)
513 , m_validator(validator)
514 , m_ev_index(0)
515 , m_txs_keeped_by_block(false)
516 {
517 }
518
519 void event_index(size_t ev_index)
520 {
521 m_ev_index = ev_index;
522 }
523
524 bool operator()(const event_replay_settings& settings)
525 {
526 log_event("event_replay_settings");
527 return true;
528 }
529
530 bool operator()(const event_visitor_settings& settings)
531 {
532 log_event("event_visitor_settings");
533
535 {
536 m_txs_keeped_by_block = settings.txs_keeped_by_block;
537 }
538
539 return true;
540 }
541
543 {
544 log_event("cryptonote::transaction");
545
547 size_t pool_size = m_c.get_pool_transactions_count();
548 m_c.handle_incoming_tx(t_serializable_object_to_blob(tx), tvc, m_txs_keeped_by_block, false, false);
549 bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count();
550 bool r = m_validator.check_tx_verification_context(tvc, tx_added, m_ev_index, tx);
551 CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed");
552 return true;
553 }
554
555 bool operator()(const std::vector<cryptonote::transaction>& txs) const
556 {
557 log_event("cryptonote::transaction");
558
559 std::vector<cryptonote::blobdata> tx_blobs;
560 std::vector<cryptonote::tx_verification_context> tvcs;
562 for (const auto &tx: txs)
563 {
564 tx_blobs.push_back(t_serializable_object_to_blob(tx));
565 tvcs.push_back(tvc0);
566 }
567 size_t pool_size = m_c.get_pool_transactions_count();
568 m_c.handle_incoming_txs(tx_blobs, tvcs, m_txs_keeped_by_block, false, false);
569 size_t tx_added = m_c.get_pool_transactions_count() - pool_size;
570 bool r = m_validator.check_tx_verification_context_array(tvcs, tx_added, m_ev_index, txs);
571 CHECK_AND_NO_ASSERT_MES(r, false, "tx verification context check failed");
572 return true;
573 }
574
575 bool operator()(const cryptonote::block& b) const
576 {
577 log_event("cryptonote::block");
578
580 cryptonote::blobdata bd = t_serializable_object_to_blob(b);
581 std::vector<cryptonote::block> pblocks;
582 if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, {bd, {}}), pblocks))
583 {
584 m_c.handle_incoming_block(bd, &b, bvc);
586 }
587 else
588 bvc.m_verification_failed = true;
589 bool r = m_validator.check_block_verification_context(bvc, m_ev_index, b);
590 CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed");
591 return r;
592 }
593
594 bool operator()(const callback_entry& cb) const
595 {
596 log_event(std::string("callback_entry ") + cb.callback_name);
597 return m_validator.verify(cb.callback_name, m_c, m_ev_index, m_events);
598 }
599
601 {
602 log_event("cryptonote::account_base");
603 return true;
604 }
605
606 bool operator()(const serialized_block& sr_block) const
607 {
608 log_event("serialized_block");
609
611 std::vector<cryptonote::block> pblocks;
612 if (m_c.prepare_handle_incoming_blocks(std::vector<cryptonote::block_complete_entry>(1, {sr_block.data, {}}), pblocks))
613 {
614 m_c.handle_incoming_block(sr_block.data, NULL, bvc);
616 }
617 else
618 bvc.m_verification_failed = true;
619
621 std::stringstream ss;
622 ss << sr_block.data;
625 if (!ss.good())
626 {
627 blk = cryptonote::block();
628 }
629 bool r = m_validator.check_block_verification_context(bvc, m_ev_index, blk);
630 CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed");
631 return true;
632 }
633
634 bool operator()(const serialized_transaction& sr_tx) const
635 {
636 log_event("serialized_transaction");
637
639 size_t pool_size = m_c.get_pool_transactions_count();
640 m_c.handle_incoming_tx(sr_tx.data, tvc, m_txs_keeped_by_block, false, false);
641 bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count();
642
644 std::stringstream ss;
645 ss << sr_tx.data;
648 if (!ss.good())
649 {
651 }
652
653 bool r = m_validator.check_tx_verification_context(tvc, tx_added, m_ev_index, tx);
654 CHECK_AND_NO_ASSERT_MES(r, false, "transaction verification context check failed");
655 return true;
656 }
657
658private:
659 void log_event(const std::string& event_type) const
660 {
661 MGINFO_YELLOW("=== EVENT # " << m_ev_index << ": " << event_type);
662 }
663};
664//--------------------------------------------------------------------------
665template<class t_test_class>
666inline bool replay_events_through_core(cryptonote::core& cr, const std::vector<test_event_entry>& events, t_test_class& validator)
667{
668 return replay_events_through_core_plain(cr, events, validator, true);
669}
670//--------------------------------------------------------------------------
671template<class t_test_class>
672inline bool replay_events_through_core_plain(cryptonote::core& cr, const std::vector<test_event_entry>& events, t_test_class& validator, bool reinit=true)
673{
674 TRY_ENTRY();
675
676 //init core here
677 if (reinit) {
678 CHECK_AND_ASSERT_MES(typeid(cryptonote::block) == events[0].type(), false,
679 "First event must be genesis block creation");
680 cr.set_genesis_block(boost::get<cryptonote::block>(events[0]));
681 }
682
683 bool r = true;
684 push_core_event_visitor<t_test_class> visitor(cr, events, validator);
685 for(size_t i = 1; i < events.size() && r; ++i)
686 {
687 visitor.event_index(i);
688 r = boost::apply_visitor(visitor, events[i]);
689 }
690
691 return r;
692
693 CATCH_ENTRY_L0("replay_events_through_core", false);
694}
695//--------------------------------------------------------------------------
696template<typename t_test_class>
698 const std::pair<uint8_t, uint64_t> hard_forks[2];
702 get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{}
703};
704//--------------------------------------------------------------------------
705template<class t_test_class>
706inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cryptonote::core *core)
707{
708 boost::program_options::options_description desc("Allowed options");
710 boost::program_options::variables_map vm;
711 bool r = command_line::handle_error_helper(desc, [&]()
712 {
713 boost::program_options::store(boost::program_options::basic_parsed_options<char>(&desc), vm);
714 boost::program_options::notify(vm);
715 return true;
716 });
717 if (!r)
718 return false;
719
720 auto & c = *core;
721
722 // FIXME: make sure that vm has arg_testnet_on set to true or false if
723 // this test needs for it to be so.
725
726 // Hardforks can be specified in events.
727 v_hardforks_t hardforks;
728 cryptonote::test_options test_options_tmp{nullptr, 0};
729 const cryptonote::test_options * test_options_ = &gto.test_options;
730 if (extract_hard_forks(events, hardforks)){
731 hardforks.push_back(std::make_pair((uint8_t)0, (uint64_t)0)); // terminator
732 test_options_tmp.hard_forks = hardforks.data();
733 test_options_ = &test_options_tmp;
734 }
735
736 if (!c.init(vm, test_options_))
737 {
738 MERROR("Failed to init core");
739 return false;
740 }
741 c.get_blockchain_storage().get_db().set_batch_transactions(true);
742
743 // start with a clean pool
744 std::vector<crypto::hash> pool_txs;
745 if (!c.get_pool_transaction_hashes(pool_txs))
746 {
747 MERROR("Failed to flush txpool");
748 return false;
749 }
750 c.get_blockchain_storage().flush_txes_from_pool(pool_txs);
751
752 t_test_class validator;
753 bool ret = replay_events_through_core<t_test_class>(c, events, validator);
754// c.deinit();
755 return ret;
756}
757//--------------------------------------------------------------------------
758template<class t_test_class>
759inline bool replay_events_through_core_validate(std::vector<test_event_entry>& events, cryptonote::core & c)
760{
761 std::vector<crypto::hash> pool_txs;
762 if (!c.get_pool_transaction_hashes(pool_txs))
763 {
764 MERROR("Failed to flush txpool");
765 return false;
766 }
768
769 t_test_class validator;
770 return replay_events_through_core_plain<t_test_class>(c, events, validator, false);
771}
772//--------------------------------------------------------------------------
773template<class t_test_class>
774inline bool do_replay_events(std::vector<test_event_entry>& events)
775{
776 cryptonote::core core(nullptr);
777 bool ret = do_replay_events_get_core<t_test_class>(events, &core);
778 core.deinit();
779 return ret;
780}
781//--------------------------------------------------------------------------
782template<class t_test_class>
783inline bool do_replay_file(const std::string& filename)
784{
785 std::vector<test_event_entry> events;
786 if (!tools::unserialize_obj_from_file(events, filename))
787 {
788 MERROR("Failed to deserialize data from file: ");
789 return false;
790 }
791 return do_replay_events<t_test_class>(events);
792}
793
794//--------------------------------------------------------------------------
795#define DEFAULT_HARDFORKS(HARDFORKS) do { \
796 HARDFORKS.push_back(std::make_pair((uint8_t)1, (uint64_t)0)); \
797} while(0)
798
799#define ADD_HARDFORK(HARDFORKS, FORK, HEIGHT) HARDFORKS.push_back(std::make_pair((uint8_t)FORK, (uint64_t)HEIGHT))
800
801#define GENERATE_ACCOUNT(account) \
802 cryptonote::account_base account; \
803 account.generate();
804
805#define GENERATE_MULTISIG_ACCOUNT(account, threshold, total) \
806 CHECK_AND_ASSERT_MES(threshold >= 2 && threshold <= total, false, "Invalid multisig scheme"); \
807 std::vector<cryptonote::account_base> account(total); \
808 do \
809 { \
810 for (size_t msidx = 0; msidx < total; ++msidx) \
811 account[msidx].generate(); \
812 make_multisig_accounts(account, threshold); \
813 } while(0)
814
815#define MAKE_ACCOUNT(VEC_EVENTS, account) \
816 cryptonote::account_base account; \
817 account.generate(); \
818 VEC_EVENTS.push_back(account);
819
820#define DO_CALLBACK(VEC_EVENTS, CB_NAME) \
821{ \
822 callback_entry CALLBACK_ENTRY; \
823 CALLBACK_ENTRY.callback_name = CB_NAME; \
824 VEC_EVENTS.push_back(CALLBACK_ENTRY); \
825}
826
827#define REGISTER_CALLBACK(CB_NAME, CLBACK) \
828 register_callback(CB_NAME, std::bind(&CLBACK, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
829
830#define REGISTER_CALLBACK_METHOD(CLASS, METHOD) \
831 register_callback(#METHOD, std::bind(&CLASS::METHOD, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
832
833#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS) \
834 test_generator generator; \
835 cryptonote::block BLK_NAME; \
836 generator.construct_block(BLK_NAME, MINER_ACC, TS); \
837 VEC_EVENTS.push_back(BLK_NAME);
838
839#define MAKE_NEXT_BLOCK(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC) \
840 cryptonote::block BLK_NAME; \
841 generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC); \
842 VEC_EVENTS.push_back(BLK_NAME);
843
844#define MAKE_NEXT_BLOCK_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, HF) \
845 cryptonote::block BLK_NAME; \
846 generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, std::list<cryptonote::transaction>(), HF); \
847 VEC_EVENTS.push_back(BLK_NAME);
848
849#define MAKE_NEXT_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1) \
850 cryptonote::block BLK_NAME; \
851 { \
852 std::list<cryptonote::transaction> tx_list; \
853 tx_list.push_back(TX1); \
854 generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list); \
855 } \
856 VEC_EVENTS.push_back(BLK_NAME);
857
858#define MAKE_NEXT_BLOCK_TX1_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1, HF) \
859 cryptonote::block BLK_NAME; \
860 { \
861 std::list<cryptonote::transaction> tx_list; \
862 tx_list.push_back(TX1); \
863 generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list, HF); \
864 } \
865 VEC_EVENTS.push_back(BLK_NAME);
866
867#define MAKE_NEXT_BLOCK_TX_LIST(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST) \
868 cryptonote::block BLK_NAME; \
869 generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST); \
870 VEC_EVENTS.push_back(BLK_NAME);
871
872#define MAKE_NEXT_BLOCK_TX_LIST_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST, HF) \
873 cryptonote::block BLK_NAME; \
874 generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST, HF); \
875 VEC_EVENTS.push_back(BLK_NAME);
876
877#define REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT, HF) \
878 cryptonote::block BLK_NAME; \
879 { \
880 cryptonote::block blk_last = PREV_BLOCK; \
881 for (size_t i = 0; i < COUNT; ++i) \
882 { \
883 MAKE_NEXT_BLOCK_HF(VEC_EVENTS, blk, blk_last, MINER_ACC, HF); \
884 blk_last = blk; \
885 } \
886 BLK_NAME = blk_last; \
887 }
888
889#define REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT) REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT, boost::none)
890#define REWIND_BLOCKS(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC) REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW)
891#define REWIND_BLOCKS_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, HF) REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW, HF)
892
893#define MAKE_TX_MIX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
894 cryptonote::transaction TX_NAME; \
895 construct_tx_to_key(VEC_EVENTS, TX_NAME, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX); \
896 VEC_EVENTS.push_back(TX_NAME);
897
898#define MAKE_TX_MIX_RCT(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
899 cryptonote::transaction TX_NAME; \
900 construct_tx_to_key(VEC_EVENTS, TX_NAME, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX, true, rct::RangeProofPaddedBulletproof); \
901 VEC_EVENTS.push_back(TX_NAME);
902
903#define MAKE_TX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, HEAD) MAKE_TX_MIX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, 0, HEAD)
904
905#define MAKE_TX_MIX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
906 { \
907 cryptonote::transaction t; \
908 construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX); \
909 SET_NAME.push_back(t); \
910 VEC_EVENTS.push_back(t); \
911 }
912
913#define MAKE_TX_MIX_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
914 MAKE_TX_MIX_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD, rct::RangeProofPaddedBulletproof, 1)
915#define MAKE_TX_MIX_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD, RCT_TYPE, BP_VER) \
916 { \
917 cryptonote::transaction t; \
918 construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX, true, RCT_TYPE, BP_VER); \
919 SET_NAME.push_back(t); \
920 VEC_EVENTS.push_back(t); \
921 }
922
923#define MAKE_TX_MIX_DEST_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD) \
924 MAKE_TX_MIX_DEST_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD, rct::RangeProofPaddedBulletproof, 1)
925#define MAKE_TX_MIX_DEST_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD, RCT_TYPE, BP_VER) \
926 { \
927 cryptonote::transaction t; \
928 construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, TESTS_DEFAULT_FEE, NMIX, true, RCT_TYPE, BP_VER); \
929 SET_NAME.push_back(t); \
930 VEC_EVENTS.push_back(t); \
931 }
932
933#define MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD) MAKE_TX_MIX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, 0, HEAD)
934
935#define MAKE_TX_LIST_START(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD) \
936 std::list<cryptonote::transaction> SET_NAME; \
937 MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD);
938
939#define MAKE_TX_LIST_START_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
940 std::list<cryptonote::transaction> SET_NAME; \
941 MAKE_TX_MIX_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD);
942
943#define MAKE_MINER_TX_AND_KEY_MANUALLY(TX, BLK, KEY) \
944 transaction TX; \
945 if (!construct_miner_tx_manually(get_block_height(BLK) + 1, generator.get_already_generated_coins(BLK), \
946 miner_account.get_keys().m_account_address, TX, 0, KEY)) \
947 return false;
948
949#define MAKE_MINER_TX_MANUALLY(TX, BLK) MAKE_MINER_TX_AND_KEY_MANUALLY(TX, BLK, 0)
950
951#define SET_EVENT_VISITOR_SETT(VEC_EVENTS, SETT, VAL) VEC_EVENTS.push_back(event_visitor_settings(SETT, VAL));
952
953#define GENERATE(filename, genclass) \
954 { \
955 std::vector<test_event_entry> events; \
956 genclass g; \
957 g.generate(events); \
958 if (!tools::serialize_obj_to_file(events, filename)) \
959 { \
960 MERROR("Failed to serialize data to file: " << filename); \
961 throw std::runtime_error("Failed to serialize data to file"); \
962 } \
963 }
964
965
966#define PLAY(filename, genclass) \
967 if(!do_replay_file<genclass>(filename)) \
968 { \
969 MERROR("Failed to pass test : " << #genclass); \
970 return 1; \
971 }
972
973#define CATCH_REPLAY(genclass) \
974 catch (const std::exception& ex) \
975 { \
976 MERROR(#genclass << " generation failed: what=" << ex.what()); \
977 } \
978 catch (...) \
979 { \
980 MERROR(#genclass << " generation failed: generic exception"); \
981 }
982
983#define REPLAY_CORE(genclass) \
984 if (generated && do_replay_events< genclass >(events)) \
985 { \
986 MGINFO_GREEN("#TEST# Succeeded " << #genclass); \
987 } \
988 else \
989 { \
990 MERROR("#TEST# Failed " << #genclass); \
991 failed_tests.push_back(#genclass); \
992 }
993
994#define REPLAY_WITH_CORE(genclass, CORE) \
995 if (generated && replay_events_through_core_validate< genclass >(events, CORE)) \
996 { \
997 MGINFO_GREEN("#TEST# Succeeded " << #genclass); \
998 } \
999 else \
1000 { \
1001 MERROR("#TEST# Failed " << #genclass); \
1002 failed_tests.push_back(#genclass); \
1003 }
1004
1005#define CATCH_GENERATE_REPLAY(genclass) \
1006 CATCH_REPLAY(genclass); \
1007 REPLAY_CORE(genclass);
1008
1009#define CATCH_GENERATE_REPLAY_CORE(genclass, CORE) \
1010 CATCH_REPLAY(genclass); \
1011 REPLAY_WITH_CORE(genclass, CORE);
1012
1013#define GENERATE_AND_PLAY(genclass) \
1014 if (list_tests) \
1015 std::cout << #genclass << std::endl; \
1016 else if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
1017 { \
1018 std::vector<test_event_entry> events; \
1019 ++tests_count; \
1020 bool generated = false; \
1021 try \
1022 { \
1023 genclass g; \
1024 generated = g.generate(events); \
1025 } \
1026 CATCH_GENERATE_REPLAY(genclass); \
1027 }
1028
1029#define GENERATE_AND_PLAY_INSTANCE(genclass, ins, CORE) \
1030 if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
1031 { \
1032 std::vector<test_event_entry> events; \
1033 ++tests_count; \
1034 bool generated = false; \
1035 try \
1036 { \
1037 generated = ins.generate(events); \
1038 } \
1039 CATCH_GENERATE_REPLAY_CORE(genclass, CORE); \
1040 }
1041
1042#define CALL_TEST(test_name, function) \
1043 { \
1044 if(!function()) \
1045 { \
1046 MERROR("#TEST# Failed " << test_name); \
1047 return 1; \
1048 } \
1049 else \
1050 { \
1051 MGINFO_GREEN("#TEST# Succeeded " << test_name); \
1052 } \
1053 }
1054
1055#define QUOTEME(x) #x
1056#define DEFINE_TESTS_ERROR_CONTEXT(text) const char* perr_context = text;
1057#define CHECK_TEST_CONDITION(cond) CHECK_AND_ASSERT_MES(cond, false, "[" << perr_context << "] failed: \"" << QUOTEME(cond) << "\"")
1058#define CHECK_EQ(v1, v2) CHECK_AND_ASSERT_MES(v1 == v2, false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " == " << QUOTEME(v2) << "\", " << v1 << " != " << v2)
1059#define CHECK_NOT_EQ(v1, v2) CHECK_AND_ASSERT_MES(!(v1 == v2), false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " != " << QUOTEME(v2) << "\", " << v1 << " == " << v2)
1060#define MK_COINS(amount) (UINT64_C(amount) * COIN)
1061#define TESTS_DEFAULT_FEE ((uint64_t)10) // pow(10, 1)
uint64_t height
boost::variant< cryptonote::block, cryptonote::transaction, std::vector< cryptonote::transaction >, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings, event_replay_settings > test_event_entry
Definition chaingen.h:162
cryptonote::block get_head_block(const std::vector< test_event_entry > &events)
std::vector< cryptonote::tx_destination_entry > build_dsts(const var_addr_t &to1, bool sub1=false, uint64_t am1=0)
bool replay_events_through_core_validate(std::vector< test_event_entry > &events, cryptonote::core &c)
Definition chaingen.h:759
void fill_tx_destinations(const var_addr_t &from, const cryptonote::account_public_address &to, uint64_t amount, uint64_t fee, const std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations, bool always_change=false)
void fill_tx_sources_and_destinations(const std::vector< test_event_entry > &events, const cryptonote::block &blk_head, const cryptonote::account_base &from, const cryptonote::account_public_address &to, uint64_t amount, uint64_t fee, size_t nmix, std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations)
Definition chaingen.cpp:775
std::unordered_map< crypto::hash, const cryptonote::transaction * > map_hash2tx_t
Definition chaingen.h:163
uint64_t current_difficulty_window(const boost::optional< uint8_t > &hf_ver=boost::none)
Definition chaingen.h:410
serialized_object< cryptonote::block > serialized_block
Definition chaingen.h:107
std::map< uint64_t, std::vector< output_index > > map_output_idx_t
Definition chaingen.h:356
boost::hash< output_hasher > output_hasher_hasher
Definition chaingen.h:354
std::vector< std::pair< uint8_t, uint64_t > > v_hardforks_t
Definition chaingen.h:137
serialized_object< cryptonote::transaction > serialized_transaction
Definition chaingen.h:108
uint64_t sum_amount(const std::vector< cryptonote::tx_destination_entry > &destinations)
Definition chaingen.cpp:700
bool find_block_chain(const std::vector< test_event_entry > &events, std::vector< cryptonote::block > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)
std::unordered_map< crypto::public_key, cryptonote::subaddress_index > subaddresses_t
Definition chaingen.h:359
cryptonote::transaction construct_tx_with_fee(std::vector< test_event_entry > &events, const cryptonote::block &blk_head, const cryptonote::account_base &acc_from, const var_addr_t &to, uint64_t amount, uint64_t fee)
Definition chaingen.cpp:931
uint64_t num_blocks(const std::vector< test_event_entry > &events)
bool construct_tx_to_key(const std::vector< test_event_entry > &events, cryptonote::transaction &tx, const cryptonote::block &blk_head, const cryptonote::account_base &from, const var_addr_t &to, uint64_t amount, uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version=0)
bool do_replay_events_get_core(std::vector< test_event_entry > &events, cryptonote::core *core)
Definition chaingen.h:706
std::unordered_map< output_hasher, output_index, output_hasher_hasher > map_txid_output_t
Definition chaingen.h:358
bool do_replay_events(std::vector< test_event_entry > &events)
Definition chaingen.h:774
cryptonote::account_public_address get_address(const var_addr_t &inp)
Definition chaingen.cpp:665
cryptonote::tx_destination_entry build_dst(const var_addr_t &to, bool is_subaddr=false, uint64_t amount=0)
bool construct_tx_rct(const cryptonote::account_keys &sender_account_keys, std::vector< cryptonote::tx_source_entry > &sources, const std::vector< cryptonote::tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, std::vector< uint8_t > extra, cryptonote::transaction &tx, uint64_t unlock_time, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version=0)
boost::variant< cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry > var_addr_t
Definition chaingen.h:362
std::pair< uint64_t, size_t > outloc_t
Definition chaingen.h:360
bool do_replay_file(const std::string &filename)
Definition chaingen.h:783
std::string dump_keys(T *buff32)
Definition chaingen.h:271
void fill_nonce(cryptonote::block &blk, const cryptonote::difficulty_type &diffic, uint64_t height)
Definition chaingen.cpp:797
cryptonote::difficulty_type get_test_difficulty(const boost::optional< uint8_t > &hf_ver=boost::none)
Definition chaingen.h:409
bool trim_block_chain(std::vector< cryptonote::block > &blockchain, const crypto::hash &tail)
std::tuple< uint64_t, crypto::public_key, rct::key > get_outs_entry
Definition chaingen.h:352
bool extract_hard_forks(const std::vector< test_event_entry > &events, v_hardforks_t &hard_forks)
Definition chaingen.cpp:966
bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins, const cryptonote::account_public_address &miner_address, cryptonote::transaction &tx, uint64_t fee, cryptonote::keypair *p_txkey=nullptr)
Definition chaingen.cpp:830
std::pair< crypto::hash, size_t > output_hasher
Definition chaingen.h:353
std::string dump_data(const cryptonote::transaction &tx)
Definition chaingen.cpp:617
uint64_t get_balance(const cryptonote::account_base &addr, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
Definition chaingen.cpp:940
bool replay_events_through_core_plain(cryptonote::core &cr, const std::vector< test_event_entry > &events, t_test_class &validator, bool reinit=true)
Definition chaingen.h:672
std::map< uint64_t, std::vector< size_t > > map_output_t
Definition chaingen.h:355
void get_confirmed_txs(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, map_hash2tx_t &confirmed_txs)
Definition chaingen.cpp:984
std::unordered_map< crypto::hash, cryptonote::block > map_block_t
Definition chaingen.h:357
bool replay_events_through_core(cryptonote::core &cr, const std::vector< test_event_entry > &events, t_test_class &validator)
Definition chaingen.h:666
block_tracker(const block_tracker &bt)
Definition chaingen.h:378
void process(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
Definition chaingen.cpp:472
void global_indices(const cryptonote::transaction *tx, std::vector< uint64_t > &indices)
Definition chaingen.cpp:535
void get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector< get_outs_entry > &outs)
Definition chaingen.cpp:547
map_output_idx_t m_outs
Definition chaingen.h:373
map_block_t m_blocks
Definition chaingen.h:375
std::string dump_data()
Definition chaingen.cpp:584
block_tracker()=default
map_txid_output_t m_map_outs
Definition chaingen.h:374
friend class boost::serialization::access
Definition chaingen.h:391
map_txid_output_t::iterator find_out(const crypto::hash &txid, size_t out)
Definition chaingen.cpp:462
bool flush_txes_from_pool(const std::vector< crypto::hash > &txids)
remove transactions from the transaction pool (if present)
handles core cryptonote functionality
static void init_options(boost::program_options::options_description &desc)
adds command line options to the given options set
bool set_genesis_block(const block &b)
clears the blockchain and starts a new one
bool cleanup_handle_incoming_blocks(bool force_sync=false)
incoming blocks post-processing, cleanup, and disk sync
bool get_pool_transaction_hashes(std::vector< crypto::hash > &txs, bool include_unrelayed_txes=true) const
get a list of all transactions in the pool
bool deinit()
performs safe shutdown steps for core and core components
bool handle_incoming_block(const blobdata &block_blob, const block *b, block_verification_context &bvc, bool update_miner_blocktemplate=true)
handles an incoming block
Blockchain & get_blockchain_storage()
gets the Blockchain instance
std::map< std::string, verify_callback > callbacks_map
Definition chaingen.h:169
bool check_tx_verification_context(const cryptonote::tx_verification_context &tvc, bool, size_t, const cryptonote::transaction &)
boost::function< bool(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)> verify_callback
Definition chaingen.h:168
void register_callback(const std::string &cb_name, verify_callback cb)
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool check_tx_verification_context_array(const std::vector< cryptonote::tx_verification_context > &tvcs, size_t, size_t, const std::vector< cryptonote::transaction > &)
bool verify(const std::string &cb_name, cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
uint64_t get_already_generated_coins(const crypto::hash &blk_id) const
Definition chaingen.cpp:88
bool construct_block_manually(cryptonote::block &blk, const cryptonote::block &prev_block, const cryptonote::account_base &miner_acc, int actual_params=bf_none, uint8_t major_ver=0, uint8_t minor_ver=0, uint64_t timestamp=0, const crypto::hash &prev_id=crypto::hash(), const cryptonote::difficulty_type &diffic=1, const cryptonote::transaction &miner_tx=cryptonote::transaction(), const std::vector< crypto::hash > &tx_hashes=std::vector< crypto::hash >(), size_t txs_sizes=0, size_t max_outs=999, uint8_t hf_version=1)
Definition chaingen.cpp:221
void get_last_n_block_weights(std::vector< size_t > &block_weights, const crypto::hash &head, size_t n) const
Definition chaingen.cpp:78
test_generator(const test_generator &other)
Definition chaingen.h:232
void get_block_chain(std::vector< block_info > &blockchain, const crypto::hash &head, size_t n) const
Definition chaingen.cpp:60
bool construct_block(cryptonote::block &blk, uint64_t height, const crypto::hash &prev_id, const cryptonote::account_base &miner_acc, uint64_t timestamp, uint64_t already_generated_coins, std::vector< size_t > &block_weights, const std::list< cryptonote::transaction > &tx_list, const boost::optional< uint8_t > &hf_ver=boost::none)
Definition chaingen.cpp:112
void add_block(const cryptonote::block &blk, size_t tsx_size, std::vector< size_t > &block_weights, uint64_t already_generated_coins, uint8_t hf_version=1)
Definition chaingen.cpp:104
bool construct_block_manually_tx(cryptonote::block &blk, const cryptonote::block &prev_block, const cryptonote::account_base &miner_acc, const std::vector< crypto::hash > &tx_hashes, size_t txs_size)
Definition chaingen.cpp:263
friend class boost::serialization::access
Definition chaingen.h:261
#define DIFFICULTY_TARGET
#define DIFFICULTY_TARGET_V6
const char * inp
#define AUTO_VAL_INIT(v)
#define MERROR(x)
Definition misc_log_ex.h:73
#define CHECK_AND_NO_ASSERT_MES(expr, fail_ret_val, message)
#define CATCH_ENTRY_L0(lacation, return_val)
#define MGINFO_YELLOW(x)
Definition misc_log_ex.h:83
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
#define TRY_ENTRY()
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
POD_CLASS hash
Definition hash.h:50
boost::multiprecision::uint128_t difficulty_type
Definition difficulty.h:43
std::string blobdata
boost::variant< txout_to_script, txout_to_scripthash, txout_to_key, txout_to_key_public > txout_target_v
RangeProofType
Definition rctTypes.h:235
@ RangeProofBorromean
Definition rctTypes.h:235
key commit(etn_amount amount, const key &mask)
Definition rctOps.cpp:336
key identity()
Definition rctOps.h:73
bool serialize(Archive &ar, T &v)
STL namespace.
bool unserialize_obj_from_file(t_object &obj, const std::string &file_path)
struct rule_list head
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
#define BEGIN_SERIALIZE_OBJECT()
#define FIELD(f)
#define false
#define END_SERIALIZE()
#define VARIANT_TAG(Archive, Type, Tag)
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
Definition chaingen.h:66
std::string callback_name
Definition chaingen.h:67
friend class boost::serialization::access
Definition chaingen.h:73
const std::pair< uint8_t, uint64_t > * hard_forks
const var_addr_t addr
Definition chaingen.h:364
uint64_t amount
Definition chaingen.h:366
boost::optional< v_hardforks_t > hard_forks
Definition chaingen.h:140
friend class boost::serialization::access
Definition chaingen.h:145
event_replay_settings()=default
event_visitor_settings(int a_valid_mask=0, bool a_txs_keeped_by_block=false)
Definition chaingen.h:120
friend class boost::serialization::access
Definition chaingen.h:127
const std::pair< uint8_t, uint64_t > hard_forks[2]
Definition chaingen.h:698
const cryptonote::test_options test_options
Definition chaingen.h:699
uint64_t amount
Definition chaingen.h:290
const cryptonote::transaction * p_tx
Definition chaingen.h:301
const std::string toString() const
Definition chaingen.h:327
size_t blk_height
Definition chaingen.h:291
size_t out_no
Definition chaingen.h:293
bool is_coin_base
Definition chaingen.h:296
const cryptonote::block * p_blk
Definition chaingen.h:300
size_t tx_no
Definition chaingen.h:292
output_index(const cryptonote::txout_target_v &_out, uint64_t _a, size_t _h, size_t tno, size_t ono, const cryptonote::block *_pb, const cryptonote::transaction *_pt)
Definition chaingen.h:303
rct::key commitment() const
Definition chaingen.h:323
const cryptonote::txout_target_v out
Definition chaingen.h:289
output_index & operator=(const output_index &other)
Definition chaingen.h:345
output_index(const output_index &other)
Definition chaingen.h:310
size_t idx
Definition chaingen.h:294
uint64_t unlock_time
Definition chaingen.h:295
rct::key comm
Definition chaingen.h:299
void set_rct(bool arct)
Definition chaingen.h:315
bool operator()(const callback_entry &cb) const
Definition chaingen.h:594
push_core_event_visitor(cryptonote::core &c, const std::vector< test_event_entry > &events, t_test_class &validator)
Definition chaingen.h:510
bool operator()(const cryptonote::block &b) const
Definition chaingen.h:575
bool operator()(const cryptonote::transaction &tx) const
Definition chaingen.h:542
bool operator()(const serialized_block &sr_block) const
Definition chaingen.h:606
bool operator()(const cryptonote::account_base &ab) const
Definition chaingen.h:600
bool operator()(const event_replay_settings &settings)
Definition chaingen.h:524
void event_index(size_t ev_index)
Definition chaingen.h:519
bool operator()(const std::vector< cryptonote::transaction > &txs) const
Definition chaingen.h:555
bool operator()(const serialized_transaction &sr_tx) const
Definition chaingen.h:634
bool operator()(const event_visitor_settings &settings)
Definition chaingen.h:530
serialized_object(const cryptonote::blobdata &a_data)
Definition chaingen.h:87
friend class boost::serialization::access
Definition chaingen.h:98
block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
Definition chaingen.h:194
friend class boost::serialization::access
Definition chaingen.h:206
#define T(x)