Electroneum
Loading...
Searching...
No Matches
tools::gamma_picker Class Reference

#include <wallet2.h>

Public Member Functions

uint64_t pick ()
 gamma_picker (const std::vector< uint64_t > &rct_offsets)
 gamma_picker (const std::vector< uint64_t > &rct_offsets, double shape, double scale)

Detailed Description

Definition at line 87 of file wallet2.h.

Constructor & Destructor Documentation

◆ gamma_picker() [1/2]

tools::gamma_picker::gamma_picker ( const std::vector< uint64_t > & rct_offsets)

Definition at line 1011 of file wallet2.cpp.

1011: gamma_picker(rct_offsets, GAMMA_SHAPE, GAMMA_SCALE) {}
gamma_picker(const std::vector< uint64_t > &rct_offsets)
Definition wallet2.cpp:1011
#define GAMMA_SCALE
Definition wallet2.cpp:135
#define GAMMA_SHAPE
Definition wallet2.cpp:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gamma_picker() [2/2]

tools::gamma_picker::gamma_picker ( const std::vector< uint64_t > & rct_offsets,
double shape,
double scale )

Definition at line 996 of file wallet2.cpp.

996 :
997 rct_offsets(rct_offsets)
998{
999 gamma = std::gamma_distribution<double>(shape, scale);
1000 THROW_WALLET_EXCEPTION_IF(rct_offsets.size() <= ETN_DEFAULT_TX_SPENDABLE_AGE_V8, error::wallet_internal_error, "Bad offset calculation");
1001 const size_t blocks_in_a_year = 86400 * 365 / DIFFICULTY_TARGET_V6;
1002 const size_t blocks_to_consider = std::min<size_t>(rct_offsets.size(), blocks_in_a_year);
1003 const size_t outputs_to_consider = rct_offsets.back() - (blocks_to_consider < rct_offsets.size() ? rct_offsets[rct_offsets.size() - blocks_to_consider - 1] : 0);
1004 begin = rct_offsets.data();
1005 end = rct_offsets.data() + rct_offsets.size() - ETN_DEFAULT_TX_SPENDABLE_AGE_V8;
1006 num_rct_outputs = *(end - 1);
1007 THROW_WALLET_EXCEPTION_IF(num_rct_outputs == 0, error::wallet_internal_error, "No rct outputs");
1008 average_output_time = DIFFICULTY_TARGET_V6 * blocks_to_consider / outputs_to_consider; // this assumes constant target over the whole rct range
1009};
#define ETN_DEFAULT_TX_SPENDABLE_AGE_V8
#define DIFFICULTY_TARGET_V6
#define THROW_WALLET_EXCEPTION_IF(cond, err_type,...)

Member Function Documentation

◆ pick()

uint64_t tools::gamma_picker::pick ( )

Definition at line 1013 of file wallet2.cpp.

1014{
1015 double x = gamma(engine);
1016 x = exp(x);
1017 uint64_t output_index = x / average_output_time;
1018 if (output_index >= num_rct_outputs)
1019 return std::numeric_limits<uint64_t>::max(); // bad pick
1020 output_index = num_rct_outputs - 1 - output_index;
1021
1022 const uint64_t *it = std::lower_bound(begin, end, output_index);
1023 THROW_WALLET_EXCEPTION_IF(it == end, error::wallet_internal_error, "output_index not found");
1024 uint64_t index = std::distance(begin, it);
1025
1026 const uint64_t first_rct = index == 0 ? 0 : rct_offsets[index - 1];
1027 const uint64_t n_rct = rct_offsets[index] - first_rct;
1028 if (n_rct == 0)
1029 return std::numeric_limits<uint64_t>::max(); // bad pick
1030 MTRACE("Picking 1/" << n_rct << " in block " << index);
1031 return first_rct + crypto::rand_idx(n_rct);
1032};
#define MTRACE(x)
Definition misc_log_ex.h:77
std::enable_if< std::is_unsigned< T >::value, T >::type rand_idx(T sz)
Definition crypto.h:244
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

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/src/wallet/wallet2.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/wallet/wallet2.cpp