|
|
|
@ -249,15 +249,6 @@ CurrentBlockchainStatus::get_output_file_path()
|
|
|
|
|
CurrentBlockchainStatus::Emission
|
|
|
|
|
CurrentBlockchainStatus::get_emission()
|
|
|
|
|
{
|
|
|
|
|
// we store gap emission from last few blocks
|
|
|
|
|
// we use it together with last_block_hash, so that
|
|
|
|
|
// we can reuse gap emission if hash is same between
|
|
|
|
|
// requests. no need to always keep recalucalting
|
|
|
|
|
// it, if top block hash is same as last time.
|
|
|
|
|
static Emission total_emission_gap {0, 0, 0};
|
|
|
|
|
static crypto::hash last_block_hash {null_hash};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get current emission
|
|
|
|
|
Emission current_emission = total_emission_atomic;
|
|
|
|
|
|
|
|
|
@ -266,27 +257,6 @@ CurrentBlockchainStatus::get_emission()
|
|
|
|
|
// the emission from the top missing blocks, to have complete
|
|
|
|
|
// emission data.
|
|
|
|
|
|
|
|
|
|
Emission gap_emission_calculated {0, 0, 0};
|
|
|
|
|
|
|
|
|
|
crypto::hash top_block_id = core_storage->get_tail_id();
|
|
|
|
|
|
|
|
|
|
if (last_block_hash == top_block_id)
|
|
|
|
|
{
|
|
|
|
|
// if we already calclated gap for the same few blocks
|
|
|
|
|
// just reuse the emission calcualted for the gap.
|
|
|
|
|
|
|
|
|
|
//cout << "reusing total_emission_gap" << endl;
|
|
|
|
|
|
|
|
|
|
gap_emission_calculated = total_emission_gap;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// if top height has change for whatever reason, e.g, new block
|
|
|
|
|
// was added, blockchain reoraganization happened, then
|
|
|
|
|
// recaulate the gap emission
|
|
|
|
|
|
|
|
|
|
//cout << "recalculate total_emission_gap" << endl;
|
|
|
|
|
|
|
|
|
|
uint64_t current_blockchain_height = current_height;
|
|
|
|
|
|
|
|
|
|
uint64_t start_blk = current_emission.blk_no;
|
|
|
|
@ -296,22 +266,16 @@ CurrentBlockchainStatus::get_emission()
|
|
|
|
|
// height
|
|
|
|
|
uint64_t end_block = start_blk + blockchain_chunk_gap;
|
|
|
|
|
|
|
|
|
|
if (end_block >= current_blockchain_height && start_blk < current_blockchain_height)
|
|
|
|
|
if (end_block >= current_blockchain_height
|
|
|
|
|
&& start_blk < current_blockchain_height)
|
|
|
|
|
{
|
|
|
|
|
// make sure we are not over the blockchain height
|
|
|
|
|
end_block = end_block > current_blockchain_height
|
|
|
|
|
? current_blockchain_height : end_block;
|
|
|
|
|
|
|
|
|
|
// calculated emission for missing blocks
|
|
|
|
|
gap_emission_calculated = calculate_emission_in_blocks(start_blk, end_block);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// store calcualted gap emission for future use
|
|
|
|
|
total_emission_gap = gap_emission_calculated;
|
|
|
|
|
|
|
|
|
|
// update stored top block hash
|
|
|
|
|
last_block_hash = top_block_id;
|
|
|
|
|
}
|
|
|
|
|
Emission gap_emission_calculated
|
|
|
|
|
= calculate_emission_in_blocks(start_blk, end_block);
|
|
|
|
|
|
|
|
|
|
//cout << "gap_emission_calculated: " << std::string(gap_emission_calculated) << endl;
|
|
|
|
|
|
|
|
|
@ -320,6 +284,7 @@ CurrentBlockchainStatus::get_emission()
|
|
|
|
|
current_emission.blk_no = gap_emission_calculated.blk_no > 0
|
|
|
|
|
? gap_emission_calculated.blk_no
|
|
|
|
|
: current_emission.blk_no;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return current_emission;
|
|
|
|
|
}
|
|
|
|
|