Merge pull request #181 from stoffu/diff-128-fix

Display 128bit network difficulty properly
This commit is contained in:
moneroexamples 2019-06-17 16:31:30 +08:00 committed by GitHub
commit 89e6b48c2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 12 deletions

View File

@ -275,8 +275,11 @@ MempoolStatus::read_network_info()
local_copy.height = rpc_network_info.height;
local_copy.target_height = rpc_network_info.target_height;
local_copy.difficulty = rpc_network_info.difficulty;
local_copy.difficulty_top64 = rpc_network_info.difficulty_top64;
local_copy.target = rpc_network_info.target;
local_copy.hash_rate = (rpc_network_info.difficulty/rpc_network_info.target);
cryptonote::difficulty_type hash_rate = cryptonote::difficulty_type(rpc_network_info.wide_difficulty) / rpc_network_info.target;
local_copy.hash_rate = (hash_rate & 0xFFFFFFFFFFFFFFFF).convert_to<uint64_t>();
local_copy.hash_rate_top64 = ((hash_rate >> 64) & 0xFFFFFFFFFFFFFFFF).convert_to<uint64_t>();
local_copy.tx_count = rpc_network_info.tx_count;
local_copy.tx_pool_size = rpc_network_info.tx_pool_size;
local_copy.alt_blocks_count = rpc_network_info.alt_blocks_count;
@ -286,6 +289,7 @@ MempoolStatus::read_network_info()
local_copy.nettype = rpc_network_info.testnet ? cryptonote::network_type::TESTNET :
rpc_network_info.stagenet ? cryptonote::network_type::STAGENET : cryptonote::network_type::MAINNET;
local_copy.cumulative_difficulty = rpc_network_info.cumulative_difficulty;
local_copy.cumulative_difficulty_top64 = rpc_network_info.cumulative_difficulty_top64;
local_copy.block_size_limit = rpc_network_info.block_size_limit;
local_copy.block_size_median = rpc_network_info.block_size_median;
local_copy.block_weight_limit = rpc_network_info.block_weight_limit;

View File

@ -61,6 +61,7 @@ struct MempoolStatus
uint64_t height {0};
uint64_t target_height {0};
uint64_t difficulty {0};
uint64_t difficulty_top64 {0};
uint64_t target {0};
uint64_t tx_count {0};
uint64_t tx_pool_size {0};
@ -72,6 +73,7 @@ struct MempoolStatus
cryptonote::network_type nettype {cryptonote::network_type::MAINNET};
crypto::hash top_block_hash;
uint64_t cumulative_difficulty {0};
uint64_t cumulative_difficulty_top64 {0};
uint64_t block_size_limit {0};
uint64_t block_size_median {0};
uint64_t block_weight_limit {0};
@ -81,6 +83,7 @@ struct MempoolStatus
uint64_t current_hf_version {0};
uint64_t hash_rate {0};
uint64_t hash_rate_top64 {0};
uint64_t fee_per_kb {0};
uint64_t info_timestamp {0};

View File

@ -929,13 +929,15 @@ index2(uint64_t page_no = 0, bool refresh_page = false)
// perapre network info mstch::map for the front page
string hash_rate;
double hr_d;
char metric_prefix;
cryptonote::difficulty_type hr = make_difficulty(current_network_info.hash_rate, current_network_info.hash_rate_top64);
get_metric_prefix(hr, hr_d, metric_prefix);
if (current_network_info.hash_rate > 1e6)
hash_rate = fmt::format("{:0.3f} MH/s", current_network_info.hash_rate/1.0e6);
else if (current_network_info.hash_rate > 1e3)
hash_rate = fmt::format("{:0.3f} kH/s", current_network_info.hash_rate/1.0e3);
if (metric_prefix != 0)
hash_rate = fmt::format("{:0.3f} {:c}H/s", hr_d, metric_prefix);
else
hash_rate = fmt::format("{:d} H/s", current_network_info.hash_rate);
hash_rate = fmt::format("{:s} H/s", hr.str());
pair<string, string> network_info_age = get_age(local_copy_server_timestamp,
current_network_info.info_timestamp);
@ -948,7 +950,7 @@ index2(uint64_t page_no = 0, bool refresh_page = false)
}
context["network_info"] = mstch::map {
{"difficulty" , current_network_info.difficulty},
{"difficulty" , make_difficulty(current_network_info.difficulty, current_network_info.difficulty_top64).str()},
{"hash_rate" , hash_rate},
{"fee_per_kb" , print_money(current_network_info.fee_per_kb)},
{"alt_blocks_no" , current_network_info.alt_blocks_count},
@ -1312,8 +1314,7 @@ show_block(uint64_t _blk_height)
{"delta_time" , delta_time},
{"blk_nonce" , blk.nonce},
{"blk_pow_hash" , blk_pow_hash_str},
{"blk_difficulty_lo" , (blk_difficulty << 64 >> 64).convert_to<uint64_t>()},
{"blk_difficulty_hi" , (blk_difficulty >> 64).convert_to<uint64_t>()},
{"blk_difficulty" , blk_difficulty.str()},
{"age_format" , age.second},
{"major_ver" , std::to_string(blk.major_version)},
{"minor_ver" , std::to_string(blk.minor_version)},
@ -6988,7 +6989,7 @@ get_monero_network_info(json& j_info)
{"current" , local_copy_network_info.current},
{"height" , local_copy_network_info.height},
{"target_height" , local_copy_network_info.target_height},
{"difficulty" , local_copy_network_info.difficulty},
{"difficulty" , make_difficulty(local_copy_network_info.difficulty, local_copy_network_info.difficulty_top64).str()},
{"target" , local_copy_network_info.target},
{"hash_rate" , local_copy_network_info.hash_rate},
{"tx_count" , local_copy_network_info.tx_count},
@ -7001,7 +7002,7 @@ get_monero_network_info(json& j_info)
{"testnet" , local_copy_network_info.nettype == cryptonote::network_type::TESTNET},
{"stagenet" , local_copy_network_info.nettype == cryptonote::network_type::STAGENET},
{"top_block_hash" , pod_to_hex(local_copy_network_info.top_block_hash)},
{"cumulative_difficulty" , local_copy_network_info.cumulative_difficulty},
{"cumulative_difficulty" , make_difficulty(local_copy_network_info.cumulative_difficulty, local_copy_network_info.cumulative_difficulty_top64).str()},
{"block_size_limit" , local_copy_network_info.block_size_limit},
{"block_size_median" , local_copy_network_info.block_size_median},
{"start_time" , local_copy_network_info.start_time},

View File

@ -32,7 +32,7 @@
</tr>
<tr>
<td>PoW hash:</td><td>{{blk_pow_hash}}</td>
<td>Difficulty (hi64, lo64):</td><td>{{blk_difficulty_hi}}, {{blk_difficulty_lo}}</td>
<td>Difficulty:</td><td>{{blk_difficulty}}</td>
<td></td>
</tr>
</table>

View File

@ -1272,4 +1272,31 @@ tx_to_hex(transaction const& tx)
return epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx));
}
void get_metric_prefix(cryptonote::difficulty_type hr, double& hr_d, char& prefix)
{
if (hr < 1000)
{
prefix = 0;
return;
}
static const char metric_prefixes[4] = { 'k', 'M', 'G', 'T' };
for (size_t i = 0; i < sizeof(metric_prefixes); ++i)
{
if (hr < 1000000)
{
hr_d = hr.convert_to<double>() / 1000;
prefix = metric_prefixes[i];
return;
}
hr /= 1000;
}
prefix = 0;
}
cryptonote::difficulty_type
make_difficulty(uint64_t low, uint64_t high)
{
return (cryptonote::difficulty_type(high) << 64) + low;
}
}

View File

@ -373,6 +373,12 @@ pause_execution(uint64_t no_seconds, const string& text = "now");
string
tx_to_hex(transaction const& tx);
void
get_metric_prefix(cryptonote::difficulty_type hr, double& hr_d, char& prefix);
cryptonote::difficulty_type
make_difficulty(uint64_t low, uint64_t high);
}
#endif //XMREG01_TOOLS_H