Electroneum
Loading...
Searching...
No Matches
block_tracker Class Reference

#include <chaingen.h>

Collaboration diagram for block_tracker:

Public Member Functions

 block_tracker ()=default
 block_tracker (const block_tracker &bt)
map_txid_output_t::iterator find_out (const crypto::hash &txid, size_t out)
map_txid_output_t::iterator find_out (const output_hasher &id)
void process (const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
void process (const std::vector< const cryptonote::block * > &blockchain, const map_hash2tx_t &mtx)
void process (const cryptonote::block *blk, const cryptonote::transaction *tx, size_t i)
void global_indices (const cryptonote::transaction *tx, std::vector< uint64_t > &indices)
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)
std::string dump_data ()
void dump_data (const std::string &fname)

Public Attributes

map_output_idx_t m_outs
map_txid_output_t m_map_outs
map_block_t m_blocks

Friends

class boost::serialization::access

Detailed Description

Definition at line 370 of file chaingen.h.

Constructor & Destructor Documentation

◆ block_tracker() [1/2]

block_tracker::block_tracker ( )
default
Here is the caller graph for this function:

◆ block_tracker() [2/2]

block_tracker::block_tracker ( const block_tracker & bt)
inline

Definition at line 378 of file chaingen.h.

map_output_idx_t m_outs
Definition chaingen.h:373
map_block_t m_blocks
Definition chaingen.h:375
map_txid_output_t m_map_outs
Definition chaingen.h:374
Here is the call graph for this function:

Member Function Documentation

◆ dump_data() [1/2]

std::string block_tracker::dump_data ( )

Definition at line 584 of file chaingen.cpp.

585{
586 ostringstream ss;
587 for (auto &m_out : m_outs)
588 {
589 auto & vct = m_out.second;
590 ss << m_out.first << " => |vector| = " << vct.size() << '\n';
591
592 for (const auto & oi : vct)
593 {
594 auto out = boost::get<txout_to_key>(oi.out);
595
596 ss << " idx: " << oi.idx
597 << ", rct: " << oi.rct
598 << ", etn: " << oi.amount
599 << ", key: " << dump_keys(out.key.data)
600 << ", msk: " << dump_keys(oi.comm.bytes)
601 << ", txid: " << dump_keys(oi.p_tx->hash.data)
602 << '\n';
603 }
604 }
605
606 return ss.str();
607}
std::string dump_keys(T *buff32)
Definition chaingen.h:271
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump_data() [2/2]

void block_tracker::dump_data ( const std::string & fname)

Definition at line 609 of file chaingen.cpp.

610{
611 ofstream myfile;
612 myfile.open (fname);
613 myfile << dump_data();
614 myfile.close();
615}
std::string dump_data()
Definition chaingen.cpp:584
Here is the call graph for this function:

◆ find_out() [1/2]

map_txid_output_t::iterator block_tracker::find_out ( const crypto::hash & txid,
size_t out )

Definition at line 462 of file chaingen.cpp.

463{
464 return find_out(std::make_pair(txid, out));
465}
map_txid_output_t::iterator find_out(const crypto::hash &txid, size_t out)
Definition chaingen.cpp:462
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_out() [2/2]

map_txid_output_t::iterator block_tracker::find_out ( const output_hasher & id)

Definition at line 467 of file chaingen.cpp.

468{
469 return m_map_outs.find(id);
470}

◆ get_fake_outs()

void block_tracker::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 at line 547 of file chaingen.cpp.

547 {
548 auto & vct = m_outs[amount];
549 const size_t n_outs = vct.size();
550
551 std::set<size_t> used;
552 std::vector<size_t> choices;
553 choices.resize(n_outs);
554 for(size_t i=0; i < n_outs; ++i) choices[i] = i;
555 shuffle(choices.begin(), choices.end(), std::default_random_engine(crypto::rand<unsigned>()));
556
557 size_t n_iters = 0;
558 ssize_t idx = -1;
559 outs.reserve(num_outs);
560 while(outs.size() < num_outs){
561 n_iters += 1;
562 idx = (idx + 1) % n_outs;
563 size_t oi_idx = choices[(size_t)idx];
564 CHECK_AND_ASSERT_THROW_MES((n_iters / n_outs) <= outs.size(), "Fake out pick selection problem");
565
566 auto & oi = vct[oi_idx];
567 if (oi.idx == global_index)
568 continue;
569 if (oi.out.type() != typeid(cryptonote::txout_to_key))
570 continue;
571 if (oi.unlock_time > cur_height)
572 continue;
573 if (used.find(oi_idx) != used.end())
574 continue;
575
576 rct::key comm = oi.commitment();
577 auto out = boost::get<txout_to_key>(oi.out);
578 auto item = std::make_tuple(oi.idx, out.key, comm);
579 outs.push_back(item);
580 used.insert(oi_idx);
581 }
582}
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
std::enable_if< std::is_pod< T >::value, T >::type rand()
Definition crypto.h:216
Here is the call graph for this function:
Here is the caller graph for this function:

◆ global_indices()

void block_tracker::global_indices ( const cryptonote::transaction * tx,
std::vector< uint64_t > & indices )

Definition at line 535 of file chaingen.cpp.

536{
537 indices.clear();
538
539 for(size_t j=0; j < tx->vout.size(); ++j){
540 auto it = find_out(tx->hash, j);
541 if (it != m_map_outs.end()){
542 indices.push_back(it->second.idx);
543 }
544 }
545}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process() [1/3]

void block_tracker::process ( const cryptonote::block * blk,
const cryptonote::transaction * tx,
size_t i )

Definition at line 508 of file chaingen.cpp.

509{
510 for (size_t j = 0; j < tx->vout.size(); ++j) {
511 const tx_out &out = tx->vout[j];
512
513 if (typeid(cryptonote::txout_to_key) != out.target.type()) { // out_to_key
514 continue;
515 }
516
517 const uint64_t rct_amount = tx->version == 2 ? 0 : out.amount;
518 const output_hasher hid = std::make_pair(tx->hash, j);
519 auto it = find_out(hid);
520 if (it != m_map_outs.end()){
521 continue;
522 }
523
524 output_index oi(out.target, out.amount, boost::get<txin_gen>(blk->miner_tx.vin.front()).height, i, j, blk, tx);
525 oi.set_rct(tx->version == 2);
526 oi.idx = m_outs[rct_amount].size();
527 oi.unlock_time = tx->unlock_time;
528 oi.is_coin_base = tx->vin.size() == 1 && tx->vin.back().type() == typeid(cryptonote::txin_gen);
529
530 m_outs[rct_amount].push_back(oi);
531 m_map_outs.insert({hid, oi});
532 }
533}
std::pair< crypto::hash, size_t > output_hasher
Definition chaingen.h:353
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ process() [2/3]

void block_tracker::process ( const std::vector< const cryptonote::block * > & blockchain,
const map_hash2tx_t & mtx )

Definition at line 490 of file chaingen.cpp.

491{
492 BOOST_FOREACH (const block* blk, blockchain) {
493 vector<const transaction*> vtx;
494 vtx.push_back(&(blk->miner_tx));
495
496 BOOST_FOREACH(const crypto::hash &h, blk->tx_hashes) {
497 const map_hash2tx_t::const_iterator cit = mtx.find(h);
498 CHECK_AND_ASSERT_THROW_MES(mtx.end() != cit, "block contains an unknown tx hash");
499 vtx.push_back(cit->second);
500 }
501
502 for (size_t i = 0; i < vtx.size(); i++) {
503 process(blk, vtx[i], i);
504 }
505 }
506}
void process(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
Definition chaingen.cpp:472
POD_CLASS hash
Definition hash.h:50
std::vector< crypto::hash > tx_hashes
Here is the call graph for this function:

◆ process() [3/3]

void block_tracker::process ( const std::vector< cryptonote::block > & blockchain,
const map_hash2tx_t & mtx )

Definition at line 472 of file chaingen.cpp.

473{
474 std::vector<const cryptonote::block*> blks;
475 blks.reserve(blockchain.size());
476
477 BOOST_FOREACH (const block& blk, blockchain) {
478 auto hsh = get_block_hash(blk);
479 auto it = m_blocks.find(hsh);
480 if (it == m_blocks.end()){
481 m_blocks[hsh] = blk;
482 }
483
484 blks.push_back(&m_blocks[hsh]);
485 }
486
487 process(blks, mtx);
488}
crypto::hash get_block_hash(uint64_t height)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 391 of file chaingen.h.

Member Data Documentation

◆ m_blocks

map_block_t block_tracker::m_blocks

Definition at line 375 of file chaingen.h.

◆ m_map_outs

map_txid_output_t block_tracker::m_map_outs

Definition at line 374 of file chaingen.h.

◆ m_outs

map_output_idx_t block_tracker::m_outs

Definition at line 373 of file chaingen.h.


The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/chaingen.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/chaingen.cpp