Electroneum
gen_block_invalid_binary_format Struct Reference

#include <block_validation.h>

Inheritance diagram for gen_block_invalid_binary_format:
Collaboration diagram for gen_block_invalid_binary_format:

Public Member Functions

 gen_block_invalid_binary_format ()
 
bool generate (std::vector< test_event_entry > &events) const
 
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
 
bool check_all_blocks_purged (cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
 
bool corrupt_blocks_boundary (cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
 
- Public Member Functions inherited from test_chain_unit_base
void register_callback (const std::string &cb_name, verify_callback cb)
 
bool verify (const std::string &cb_name, cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
 
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
 
bool check_tx_verification_context (const cryptonote::tx_verification_context &tvc, bool, size_t, const cryptonote::transaction &)
 
bool check_tx_verification_context_array (const std::vector< cryptonote::tx_verification_context > &tvcs, size_t, size_t, const std::vector< cryptonote::transaction > &)
 

Additional Inherited Members

- Public Types inherited from test_chain_unit_base
typedef boost::function< bool(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)> verify_callback
 
typedef std::map< std::string, verify_callbackcallbacks_map
 

Detailed Description

Definition at line 199 of file block_validation.h.

Constructor & Destructor Documentation

◆ gen_block_invalid_binary_format()

gen_block_invalid_binary_format::gen_block_invalid_binary_format ( )

Definition at line 545 of file block_validation.cpp.

546  : m_corrupt_blocks_begin_idx(0)
547 {
550 }
bool corrupt_blocks_boundary(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
bool check_all_blocks_purged(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
#define REGISTER_CALLBACK(CB_NAME, CLBACK)
Definition: chaingen.h:827
Here is the call graph for this function:

Member Function Documentation

◆ check_all_blocks_purged()

bool gen_block_invalid_binary_format::check_all_blocks_purged ( cryptonote::core c,
size_t  ev_index,
const std::vector< test_event_entry > &  events 
)

Definition at line 635 of file block_validation.cpp.

636 {
637  DEFINE_TESTS_ERROR_CONTEXT("gen_block_invalid_binary_format::check_all_blocks_purged");
638 
640  CHECK_EQ(m_corrupt_blocks_begin_idx - 2, c.get_current_blockchain_height());
641 
642  return true;
643 }
uint64_t get_current_blockchain_height() const
get the current height of the blockchain
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
#define CHECK_EQ(v1, v2)
Definition: chaingen.h:1058
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition: chaingen.h:1056
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_block_verification_context()

bool gen_block_invalid_binary_format::check_block_verification_context ( const cryptonote::block_verification_context bvc,
size_t  event_idx,
const cryptonote::block blk 
)

Definition at line 615 of file block_validation.cpp.

617 {
618  if (0 == m_corrupt_blocks_begin_idx || event_idx < m_corrupt_blocks_begin_idx)
619  {
620  return bvc.m_added_to_main_chain;
621  }
622  else
623  {
626  }
627 }

◆ corrupt_blocks_boundary()

bool gen_block_invalid_binary_format::corrupt_blocks_boundary ( cryptonote::core c,
size_t  ev_index,
const std::vector< test_event_entry > &  events 
)

Definition at line 629 of file block_validation.cpp.

630 {
631  m_corrupt_blocks_begin_idx = ev_index + 1;
632  return true;
633 }
Here is the caller graph for this function:

◆ generate()

bool gen_block_invalid_binary_format::generate ( std::vector< test_event_entry > &  events) const

Definition at line 552 of file block_validation.cpp.

553 {
555 
556  std::vector<uint64_t> timestamps;
557  std::vector<difficulty_type> cummulative_difficulties;
558  difficulty_type cummulative_diff = 1;
559 
560  // Unlock blk_0 outputs
561  block blk_last = blk_0;
563  for (size_t i = 0; i < CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW; ++i)
564  {
565  MAKE_NEXT_BLOCK(events, blk_curr, blk_last, miner_account);
566  timestamps.push_back(blk_curr.timestamp);
567  cummulative_difficulties.push_back(++cummulative_diff);
568  blk_last = blk_curr;
569  }
570 
571  // Lifting up takes a while
572  difficulty_type diffic;
573  do
574  {
575  blk_last = boost::get<block>(events.back());
576  diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET);
577  if (!lift_up_difficulty(events, timestamps, cummulative_difficulties, generator, 1, blk_last, miner_account))
578  return false;
579  std::cout << "Block #" << events.size() << ", difficulty: " << diffic << std::endl;
580  }
581  while (diffic < 1500);
582 
583  blk_last = boost::get<block>(events.back());
584  MAKE_TX(events, tx_0, miner_account, miner_account, MK_COINS(30), boost::get<block>(events[1]));
585  DO_CALLBACK(events, "corrupt_blocks_boundary");
586 
587  block blk_test;
588  std::vector<crypto::hash> tx_hashes;
589  tx_hashes.push_back(get_transaction_hash(tx_0));
590  size_t txs_weight = get_transaction_weight(tx_0);
591  diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET);
592  if (!generator.construct_block_manually(blk_test, blk_last, miner_account,
594  crypto::hash(), diffic, transaction(), tx_hashes, txs_weight))
595  return false;
596 
597  blobdata blob = t_serializable_object_to_blob(blk_test);
598  for (size_t i = 0; i < blob.size(); ++i)
599  {
600  for (size_t bit_idx = 0; bit_idx < sizeof(blobdata::value_type) * 8; ++bit_idx)
601  {
602  serialized_block sr_block(blob);
603  blobdata::value_type& ch = sr_block.data[i];
604  ch ^= 1 << bit_idx;
605 
606  events.push_back(sr_block);
607  }
608  }
609 
610  DO_CALLBACK(events, "check_all_blocks_purged");
611 
612  return true;
613 }
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
difficulty_type next_difficulty(std::vector< uint64_t > timestamps, std::vector< difficulty_type > cumulative_difficulties, size_t target_seconds, uint8_t version)
Definition: difficulty.cpp:210
#define MAKE_NEXT_BLOCK(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC)
Definition: chaingen.h:839
uint64_t get_transaction_weight(const transaction &tx, size_t blob_size)
#define DIFFICULTY_WINDOW
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
std::string blobdata
Definition: blobdatatype.h:39
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
crypto::hash get_transaction_hash(const transaction &t)
#define MAKE_TX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, HEAD)
Definition: chaingen.h:903
#define DIFFICULTY_TARGET
POD_CLASS hash
Definition: hash.h:50
#define BLOCK_VALIDATION_INIT_GENERATE()
#define MK_COINS(amount)
Definition: chaingen.h:1060
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition: chaingen.h:820
Here is the call graph for this function:

The documentation for this struct was generated from the following files: