Use u64 weights to avoid size_t mismatch across platforms

This commit is contained in:
Doyle 2019-02-25 18:33:06 +11:00
parent a8b1db4f8c
commit 53794c7658
5 changed files with 10 additions and 10 deletions

View File

@ -1200,7 +1200,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
}
uint64_t height = cryptonote::get_block_height(b);
std::vector<size_t> last_blocks_weights;
std::vector<uint64_t> last_blocks_weights;
get_last_n_blocks_weights(last_blocks_weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
loki_block_reward_context block_reward_context = {};
@ -1265,7 +1265,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
}
//------------------------------------------------------------------
// get the block weights of the last <count> blocks, and return by reference <sz>.
void Blockchain::get_last_n_blocks_weights(std::vector<size_t>& weights, size_t count) const
void Blockchain::get_last_n_blocks_weights(std::vector<uint64_t>& weights, size_t count) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
@ -3199,7 +3199,7 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
grace_blocks = CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1;
const uint64_t min_block_weight = get_min_block_weight(version);
std::vector<size_t> weights;
std::vector<uint64_t> weights;
get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW - grace_blocks);
weights.reserve(grace_blocks);
for (size_t i = 0; i < grace_blocks; ++i)
@ -3836,7 +3836,7 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti
if (hf_version < HF_VERSION_LONG_TERM_BLOCK_WEIGHT)
{
std::vector<size_t> weights;
std::vector<uint64_t> weights;
get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
m_current_block_cumul_weight_median = epee::misc_utils::median(weights);
long_term_block_weight = weights.back();

View File

@ -1347,7 +1347,7 @@ namespace cryptonote
* @param sz return-by-reference the list of weights
* @param count the number of blocks to get weights for
*/
void get_last_n_blocks_weights(std::vector<size_t>& weights, size_t count) const;
void get_last_n_blocks_weights(std::vector<uint64_t>& weights, size_t count) const;
/**
* @brief checks if a transaction is unlocked (its outputs spendable)

View File

@ -74,7 +74,7 @@ namespace
bool construct_max_weight_block(test_generator& generator, block& blk, const block& blk_prev, const account_base& miner_account,
size_t median_block_count = CRYPTONOTE_REWARD_BLOCKS_WINDOW)
{
std::vector<size_t> block_weights;
std::vector<uint64_t> block_weights;
generator.get_last_n_block_weights(block_weights, get_block_hash(blk_prev), median_block_count);
size_t median = misc_utils::median(block_weights);
@ -190,7 +190,7 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
size_t txs_1_weight = get_transaction_weight(tx_1) + get_transaction_weight(tx_2);
uint64_t txs_fee = get_tx_fee(tx_1) + get_tx_fee(tx_2);
std::vector<size_t> block_weights;
std::vector<uint64_t> block_weights;
generator.get_last_n_block_weights(block_weights, get_block_hash(blk_7), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
size_t median = misc_utils::median(block_weights);

View File

@ -382,7 +382,7 @@ void test_generator::get_block_chain(std::vector<cryptonote::block>& blockchain,
std::reverse(blockchain.begin(), blockchain.end());
}
void test_generator::get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const
void test_generator::get_last_n_block_weights(std::vector<uint64_t>& block_weights, const crypto::hash& head, size_t n) const
{
std::vector<block_info> blockchain;
get_block_chain(blockchain, head, n);
@ -582,7 +582,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
size_t height = get_block_height(prev_block) + 1;
uint64_t already_generated_coins = get_already_generated_coins(prev_block);
std::vector<size_t> block_weights;
std::vector<uint64_t> block_weights;
get_last_n_block_weights(block_weights, get_block_hash(prev_block), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (actual_params & bf_miner_tx)
{

View File

@ -204,7 +204,7 @@ public:
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
void get_block_chain(std::vector<cryptonote::block>& blockchain, const crypto::hash& head, size_t n) const;
void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
void get_last_n_block_weights(std::vector<uint64_t>& block_weights, const crypto::hash& head, size_t n) const;
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
uint64_t get_already_generated_coins(const cryptonote::block& blk) const;