Electroneum
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 {
71 
72 private:
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 
82 template<typename T>
84 {
86 
88  : data(a_data)
89  {
90  }
91 
94  FIELD(data)
96 
97 private:
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 
115  enum settings
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 
126 private:
128 
129  template<class Archive>
130  void serialize(Archive & ar, const unsigned int /*version*/)
131  {
132  ar & valid_mask;
133  ar & txs_keeped_by_block;
134  }
135 };
136 
137 typedef std::vector<std::pair<uint8_t, uint64_t>> v_hardforks_t;
139 {
140  boost::optional<v_hardforks_t> hard_forks;
141 
142  event_replay_settings() = default;
143 
144 private:
146 
147  template<class Archive>
148  void serialize(Archive & ar, const unsigned int /*version*/)
149  {
150  ar & hard_forks;
151  }
152 };
153 
154 
161 
162 typedef 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;
163 typedef std::unordered_map<crypto::hash, const cryptonote::transaction*> map_hash2tx_t;
164 
166 {
167 public:
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 
177 private:
178  callbacks_map m_callbacks;
179 };
180 
181 
183 {
184 public:
185  struct block_info
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 
203  size_t block_weight;
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  {
219  bf_none = 0,
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);
240  bool construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
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 
249  bool construct_block_manually(cryptonote::block& blk, const cryptonote::block& prev_block,
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(),
252  const cryptonote::difficulty_type& diffic = 1, const cryptonote::transaction& miner_tx = cryptonote::transaction(),
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 
258 private:
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 
270 template<typename T>
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 
288 struct output_index {
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),
305  is_coin_base(false), spent(false), rct(false), p_blk(_pb), p_tx(_pt)
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)
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 
352 typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
353 typedef std::pair<crypto::hash, size_t> output_hasher;
354 typedef boost::hash<output_hasher> output_hasher_hasher;
355 typedef std::map<uint64_t, std::vector<size_t> > map_output_t;
356 typedef std::map<uint64_t, std::vector<output_index> > map_output_idx_t;
357 typedef std::unordered_map<crypto::hash, cryptonote::block> map_block_t;
358 typedef std::unordered_map<output_hasher, output_index, output_hasher_hasher> map_txid_output_t;
359 typedef std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses_t;
360 typedef std::pair<uint64_t, size_t> outloc_t;
361 
362 typedef boost::variant<cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry> var_addr_t;
363 typedef struct {
368 
369 // Daemon functionality
371 {
372 public:
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 
388  void dump_data(const std::string & fname);
389 
390 private:
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 
408 
409 inline cryptonote::difficulty_type get_test_difficulty(const boost::optional<uint8_t>& hf_ver=boost::none) {return !hf_ver || hf_ver.get() <= 1 ? 1 : 2;}
410 inline 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 
413 cryptonote::tx_destination_entry build_dst(const var_addr_t& to, bool is_subaddr=false, uint64_t amount=0);
414 std::vector<cryptonote::tx_destination_entry> build_dsts(const var_addr_t& to1, bool sub1=false, uint64_t am1=0);
415 std::vector<cryptonote::tx_destination_entry> build_dsts(std::initializer_list<dest_wrapper_t> inps);
416 uint64_t sum_amount(const std::vector<cryptonote::tx_destination_entry>& destinations);
417 uint64_t sum_amount(const std::vector<cryptonote::tx_source_entry>& sources);
418 
419 bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins,
421  uint64_t fee, cryptonote::keypair* p_txkey = nullptr);
422 
423 bool 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 
427 bool 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 
435 bool 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 
439 cryptonote::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 
443 bool 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 
451 uint64_t num_blocks(const std::vector<test_event_entry>& events);
452 cryptonote::block get_head_block(const std::vector<test_event_entry>& events);
453 
454 void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs);
455 bool trim_block_chain(std::vector<cryptonote::block>& blockchain, const crypto::hash& tail);
456 bool trim_block_chain(std::vector<const cryptonote::block*>& blockchain, const crypto::hash& tail);
457 bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<cryptonote::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
458 bool 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 
465 void 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 
479 void 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 
485 void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
486  const cryptonote::account_base& from, const cryptonote::account_base& to,
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 
491 uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
492 
493 bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks);
494 
495 /************************************************************************/
496 /* */
497 /************************************************************************/
498 template<class t_test_class>
499 struct push_core_event_visitor: public boost::static_visitor<bool>
500 {
501 private:
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 
509 public:
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 
542  bool operator()(const cryptonote::transaction& tx) const
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 
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 
600  bool operator()(const cryptonote::account_base& ab) const
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 
620  cryptonote::block blk;
621  std::stringstream ss;
622  ss << sr_block.data;
623  binary_archive<false> ba(ss);
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;
646  binary_archive<false> ba(ss);
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 
658 private:
659  void log_event(const std::string& event_type) const
660  {
661  MGINFO_YELLOW("=== EVENT # " << m_ev_index << ": " << event_type);
662  }
663 };
664 //--------------------------------------------------------------------------
665 template<class t_test_class>
666 inline 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 //--------------------------------------------------------------------------
671 template<class t_test_class>
672 inline 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 //--------------------------------------------------------------------------
696 template<typename t_test_class>
698  const std::pair<uint8_t, uint64_t> hard_forks[2];
700  hard_forks, 0
701  };
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 //--------------------------------------------------------------------------
705 template<class t_test_class>
706 inline 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 //--------------------------------------------------------------------------
758 template<class t_test_class>
759 inline 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 //--------------------------------------------------------------------------
773 template<class t_test_class>
774 inline 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 //--------------------------------------------------------------------------
782 template<class t_test_class>
783 inline 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)
friend class boost::serialization::access
Definition: chaingen.h:145
std::map< uint64_t, std::vector< output_index > > map_output_idx_t
Definition: chaingen.h:356
block_tracker()=default
#define MERROR(x)
Definition: misc_log_ex.h:73
bool operator()(const cryptonote::account_base &ab) const
Definition: chaingen.h:600
size_t tx_no
Definition: chaingen.h:292
std::vector< cryptonote::tx_destination_entry > build_dsts(const var_addr_t &to1, bool sub1=false, uint64_t am1=0)
Definition: chaingen.cpp:813
bool find_block_chain(const std::vector< test_event_entry > &events, std::vector< cryptonote::block > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)
Definition: chaingen.cpp:1072
const uint32_t T[512]
size_t idx
Definition: chaingen.h:294
test_generator(const test_generator &other)
Definition: chaingen.h:232
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
void global_indices(const cryptonote::transaction *tx, std::vector< uint64_t > &indices)
Definition: chaingen.cpp:535
bool deinit()
performs safe shutdown steps for core and core components
const char * inp
Definition: hmac_keccak.cpp:40
push_core_event_visitor(cryptonote::core &c, const std::vector< test_event_entry > &events, t_test_class &validator)
Definition: chaingen.h:510
bool check_tx_verification_context(const cryptonote::tx_verification_context &tvc, bool, size_t, const cryptonote::transaction &)
Definition: chaingen.cpp:1158
bool check_block_verification_context(const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
Definition: chaingen.cpp:1153
bool extract_hard_forks(const std::vector< test_event_entry > &events, v_hardforks_t &hard_forks)
uint64_t current_difficulty_window(const boost::optional< uint8_t > &hf_ver=boost::none)
Definition: chaingen.h:410
uint64_t sum_amount(const std::vector< cryptonote::tx_destination_entry > &destinations)
Definition: chaingen.cpp:700
std::string callback_name
Definition: chaingen.h:67
std::pair< uint64_t, size_t > outloc_t
Definition: chaingen.h:360
boost::optional< v_hardforks_t > hard_forks
Definition: chaingen.h:140
event_replay_settings()=default
::std::string string
Definition: gtest-port.h:1097
std::map< std::string, verify_callback > callbacks_map
Definition: chaingen.h:169
bool is_coin_base
Definition: chaingen.h:296
void serialize(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
bool operator()(const std::vector< cryptonote::transaction > &txs) const
Definition: chaingen.h:555
key commit(etn_amount amount, const key &mask)
Definition: rctOps.cpp:336
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool operator()(const callback_entry &cb) const
Definition: chaingen.h:594
bool handle_incoming_txs(const std::vector< blobdata > &tx_blobs, std::vector< tx_verification_context > &tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
handles a list of incoming transactions
map_output_idx_t m_outs
Definition: chaingen.h:373
std::unordered_map< crypto::public_key, cryptonote::subaddress_index > subaddresses_t
Definition: chaingen.h:359
uint64_t height
Definition: blockchain.cpp:91
const cryptonote::txout_target_v out
Definition: chaingen.h:289
cryptonote::blobdata data
Definition: chaingen.h:92
bool operator()(const cryptonote::transaction &tx) const
Definition: chaingen.h:542
#define CHECK_AND_NO_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:189
uint64_t amount
Definition: chaingen.h:366
std::map< uint64_t, std::vector< size_t > > map_output_t
Definition: chaingen.h:355
void event_index(size_t ev_index)
Definition: chaingen.h:519
friend class boost::serialization::access
Definition: chaingen.h:206
bool do_replay_events(std::vector< test_event_entry > &events)
Definition: chaingen.h:774
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
Definition: chaingen.h:65
boost::variant< txout_to_script, txout_to_scripthash, txout_to_key, txout_to_key_public > txout_target_v
bool operator()(const serialized_block &sr_block) const
Definition: chaingen.h:606
boost::function< bool(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)> verify_callback
Definition: chaingen.h:168
boost::variant< cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry > var_addr_t
Definition: chaingen.h:362
unsigned char uint8_t
Definition: stdint.h:124
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
bool check_tx_verification_context_array(const std::vector< cryptonote::tx_verification_context > &tvcs, size_t, size_t, const std::vector< cryptonote::transaction > &)
Definition: chaingen.cpp:1163
std::unordered_map< crypto::hash, cryptonote::block > map_block_t
Definition: chaingen.h:357
uint64_t amount
Definition: chaingen.h:290
bool prepare_handle_incoming_blocks(const std::vector< block_complete_entry > &blocks_entry, std::vector< block > &blocks)
performs some preprocessing on a group of incoming blocks to speed up verification ...
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
map_txid_output_t::iterator find_out(const crypto::hash &txid, size_t out)
Definition: chaingen.cpp:462
bool operator()(const cryptonote::block &b) const
Definition: chaingen.h:575
#define END_SERIALIZE()
self-explanatory
bool is_subaddr
Definition: chaingen.h:365
bool trim_block_chain(std::vector< cryptonote::block > &blockchain, const crypto::hash &tail)
Definition: chaingen.cpp:1004
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)
Definition: chaingen.cpp:872
event_visitor_settings(int a_valid_mask=0, bool a_txs_keeped_by_block=false)
Definition: chaingen.h:120
bool do_replay_file(const std::string &filename)
Definition: chaingen.h:783
rct::key comm
Definition: chaingen.h:299
bool flush_txes_from_pool(const std::vector< crypto::hash > &txids)
remove transactions from the transaction pool (if present)
bool handle_incoming_tx(const blobdata &tx_blob, tx_verification_context &tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
handles an incoming transaction
bool spent
Definition: chaingen.h:297
bool cleanup_handle_incoming_blocks(bool force_sync=false)
incoming blocks post-processing, cleanup, and disk sync
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 set_rct(bool arct)
Definition: chaingen.h:315
uint64_t unlock_time
Definition: chaingen.h:295
std::unordered_map< output_hasher, output_index, output_hasher_hasher > map_txid_output_t
Definition: chaingen.h:358
std::unordered_map< crypto::hash, const cryptonote::transaction * > map_hash2tx_t
Definition: chaingen.h:163
bool unserialize_obj_from_file(t_object &obj, const std::string &file_path)
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
Definition: command_line.h:237
#define TRY_ENTRY()
Definition: misc_log_ex.h:151
#define DIFFICULTY_TARGET_V6
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
const std::pair< uint8_t, uint64_t > hard_forks[2]
Definition: chaingen.h:698
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
VARIANT_TAG(binary_archive, callback_entry, 0xcb)
const cryptonote::transaction * p_tx
Definition: chaingen.h:301
output_index & operator=(const output_index &other)
Definition: chaingen.h:345
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
handles core cryptonote functionality
cryptonote::block get_head_block(const std::vector< test_event_entry > &events)
Definition: chaingen.cpp:1058
map_block_t m_blocks
Definition: chaingen.h:375
unsigned __int64 uint64_t
Definition: stdint.h:136
#define MGINFO_YELLOW(x)
Definition: misc_log_ex.h:83
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL for described the serialization of an object
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
Definition: chaingen.h:194
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
static void init_options(boost::program_options::options_description &desc)
adds command line options to the given options set
const var_addr_t addr
Definition: chaingen.h:364
friend class boost::serialization::access
Definition: chaingen.h:127
#define false
Definition: stdbool.h:38
uint64_t already_generated_coins
Definition: chaingen.h:202
bool operator()(const serialized_transaction &sr_tx) const
Definition: chaingen.h:634
friend class boost::serialization::access
Definition: chaingen.h:391
cryptonote::account_public_address get_address(const var_addr_t &inp)
Definition: chaingen.cpp:665
bool operator()(const event_replay_settings &settings)
Definition: chaingen.h:524
bool set_genesis_block(const block &b)
clears the blockchain and starts a new one
map_txid_output_t m_map_outs
Definition: chaingen.h:374
const cryptonote::block * p_blk
Definition: chaingen.h:300
const std::string toString() const
Definition: chaingen.h:327
bool handle_incoming_block(const blobdata &block_blob, const block *b, block_verification_context &bvc, bool update_miner_blocktemplate=true)
handles an incoming block
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
std::tuple< uint64_t, crypto::public_key, rct::key > get_outs_entry
Definition: chaingen.h:352
void register_callback(const std::string &cb_name, verify_callback cb)
Definition: chaingen.cpp:1138
std::string blobdata
Definition: blobdatatype.h:39
serialized_object(const cryptonote::blobdata &a_data)
Definition: chaingen.h:87
size_t out_no
Definition: chaingen.h:293
void fill_nonce(cryptonote::block &blk, const cryptonote::difficulty_type &diffic, uint64_t height)
Definition: chaingen.cpp:797
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)
unsigned char bytes[32]
Definition: rctTypes.h:86
key identity()
Definition: rctOps.h:73
Blockchain & get_blockchain_storage()
gets the Blockchain instance
std::pair< crypto::hash, size_t > output_hasher
Definition: chaingen.h:353
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
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(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
ctkeyV outPk
Definition: rctTypes.h:247
bool verify(const std::string &cb_name, cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
Definition: chaingen.cpp:1142
uint64_t get_already_generated_coins(const crypto::hash &blk_id) const
Definition: chaingen.cpp:88
bool replay_events_through_core(cryptonote::core &cr, const std::vector< test_event_entry > &events, t_test_class &validator)
Definition: chaingen.h:666
std::string dump_data(const cryptonote::transaction &tx)
Definition: chaingen.cpp:617
struct rule_list head
void process(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
Definition: chaingen.cpp:472
void get_confirmed_txs(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, map_hash2tx_t &confirmed_txs)
Definition: chaingen.cpp:984
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
const cryptonote::test_options test_options
Definition: chaingen.h:699
bool replay_events_through_core_validate(std::vector< test_event_entry > &events, cryptonote::core &c)
Definition: chaingen.h:759
serialized_object< cryptonote::transaction > serialized_transaction
Definition: chaingen.h:108
boost::hash< output_hasher > output_hasher_hasher
Definition: chaingen.h:354
#define DIFFICULTY_TARGET
output_index(const output_index &other)
Definition: chaingen.h:310
POD_CLASS hash
Definition: hash.h:50
uint64_t num_blocks(const std::vector< test_event_entry > &events)
Definition: chaingen.cpp:1044
friend class boost::serialization::access
Definition: chaingen.h:261
cryptonote::difficulty_type get_test_difficulty(const boost::optional< uint8_t > &hf_ver=boost::none)
Definition: chaingen.h:409
cryptonote::tx_destination_entry build_dst(const var_addr_t &to, bool is_subaddr=false, uint64_t amount=0)
Definition: chaingen.cpp:804
bool operator()(const event_visitor_settings &settings)
Definition: chaingen.h:530
RangeProofType
Definition: rctTypes.h:235
size_t blk_height
Definition: chaingen.h:291
std::string dump_keys(T *buff32)
Definition: chaingen.h:271
#define FIELD(f)
tags the field with the variable name and then serializes it
serialized_object< cryptonote::block > serialized_block
Definition: chaingen.h:107
std::string dump_data()
Definition: chaingen.cpp:584
const std::pair< uint8_t, uint64_t > * hard_forks
block_tracker(const block_tracker &bt)
Definition: chaingen.h:378
#define CATCH_ENTRY_L0(lacation, return_val)
Definition: misc_log_ex.h:165
void get_last_n_block_weights(std::vector< size_t > &block_weights, const crypto::hash &head, size_t n) const
Definition: chaingen.cpp:78
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
void get_block_chain(std::vector< block_info > &blockchain, const crypto::hash &head, size_t n) const
Definition: chaingen.cpp:60
std::vector< std::pair< uint8_t, uint64_t > > v_hardforks_t
Definition: chaingen.h:137
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)
Definition: chaingen.cpp:766
bool do_replay_events_get_core(std::vector< test_event_entry > &events, cryptonote::core *core)
Definition: chaingen.h:706
rct::key commitment() const
Definition: chaingen.h:323
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