Merge pull request #1124

8b4e7c6 daemon: report status at 99.9% rather than 100% when not quite synced (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2016-09-29 22:17:51 +02:00
commit 8f94fcf6a3
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD

View File

@ -296,6 +296,16 @@ static std::string get_fork_extra_info(uint64_t t, uint64_t now, uint64_t block_
return ""; return "";
} }
static float get_sync_percentage(const cryptonote::COMMAND_RPC_GET_INFO::response &ires)
{
uint64_t height = ires.height;
uint64_t target_height = ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height;
float pc = 100.0f * height / target_height;
if (height < target_height && pc > 99.9f)
return 99.9f; // to avoid 100% when not fully synced
return pc;
}
bool t_rpc_command_executor::show_status() { bool t_rpc_command_executor::show_status() {
cryptonote::COMMAND_RPC_GET_INFO::request ireq; cryptonote::COMMAND_RPC_GET_INFO::request ireq;
cryptonote::COMMAND_RPC_GET_INFO::response ires; cryptonote::COMMAND_RPC_GET_INFO::response ires;
@ -356,7 +366,7 @@ bool t_rpc_command_executor::show_status() {
tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, %s, net hash %s, v%u%s, %s, %u+%u connections") tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, %s, net hash %s, v%u%s, %s, %u+%u connections")
% (unsigned long long)ires.height % (unsigned long long)ires.height
% (unsigned long long)(ires.target_height >= ires.height ? ires.target_height : ires.height) % (unsigned long long)(ires.target_height >= ires.height ? ires.target_height : ires.height)
% (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height)) % get_sync_percentage(ires)
% (ires.testnet ? "testnet" : "mainnet") % (ires.testnet ? "testnet" : "mainnet")
% (mining_busy ? "syncing" : mres.active ? "mining at " + get_mining_speed(mres.speed) : "not mining") % (mining_busy ? "syncing" : mres.active ? "mining at " + get_mining_speed(mres.speed) : "not mining")
% get_mining_speed(ires.difficulty / ires.target) % get_mining_speed(ires.difficulty / ires.target)