Merge pull request #959

7e4e002 daemon: print time to next fork (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2016-08-16 14:40:32 +02:00
commit 40e8c6c403
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
5 changed files with 50 additions and 2 deletions

View file

@ -666,6 +666,13 @@ namespace cryptonote
*/ */
uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); } uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); }
/**
* @brief returns the next hardfork version
*
* @return the version
*/
uint8_t get_next_hard_fork_version() const { return m_hardfork->get_next_version(); }
/** /**
* @brief returns the newest hardfork version voted to be enabled * @brief returns the newest hardfork version voted to be enabled
* as of a certain height * as of a certain height

View file

@ -369,6 +369,18 @@ uint64_t HardFork::get_earliest_ideal_height_for_version(uint8_t version) const
return 0; return 0;
} }
uint8_t HardFork::get_next_version() const
{
CRITICAL_REGION_LOCAL(lock);
uint64_t height = db.height();
for (unsigned int n = heights.size() - 1; n > 0; --n) {
if (height >= heights[n].height) {
return heights[n < heights.size() - 1 ? n + 1 : n].version;
}
}
return original_version;
}
bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
{ {
CRITICAL_REGION_LOCAL(lock); CRITICAL_REGION_LOCAL(lock);

View file

@ -168,6 +168,13 @@ namespace cryptonote
*/ */
uint8_t get_ideal_version(uint64_t height) const; uint8_t get_ideal_version(uint64_t height) const;
/**
* @brief returns the next version
*
* This is the version which will we fork to next
*/
uint8_t get_next_version() const;
/** /**
* @brief returns the current version * @brief returns the current version
* *

View file

@ -274,6 +274,27 @@ static std::string get_mining_speed(uint64_t hr)
return (boost::format("%.0f H/s") % hr).str(); return (boost::format("%.0f H/s") % hr).str();
} }
static std::string get_fork_extra_info(uint64_t t, uint64_t now, uint64_t block_time)
{
uint64_t blocks_per_day = 86400 / block_time;
if (t == now)
return " (forking now)";
if (t > now)
{
uint64_t dblocks = t - now;
if (dblocks <= 30)
return (boost::format(" (next fork in %u blocks)") % (unsigned)dblocks).str();
if (dblocks <= blocks_per_day / 2)
return (boost::format(" (next fork in %.1f hours)") % (dblocks / (float)(blocks_per_day / 24))).str();
if (dblocks <= blocks_per_day * 30)
return (boost::format(" (next fork in %.1f days)") % (dblocks / (float)blocks_per_day)).str();
return "";
}
return "";
}
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;
@ -331,7 +352,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, %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)) % (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height))
@ -339,6 +360,7 @@ bool t_rpc_command_executor::show_status() {
% (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)
% (unsigned)hfres.version % (unsigned)hfres.version
% get_fork_extra_info(hfres.earliest_height, ires.height, ires.target)
% (hfres.state == cryptonote::HardFork::Ready ? "up to date" : hfres.state == cryptonote::HardFork::UpdateNeeded ? "update needed" : "out of date, likely forked") % (hfres.state == cryptonote::HardFork::Ready ? "up to date" : hfres.state == cryptonote::HardFork::UpdateNeeded ? "update needed" : "out of date, likely forked")
% (unsigned)ires.outgoing_connections_count % (unsigned)ires.incoming_connections_count % (unsigned)ires.outgoing_connections_count % (unsigned)ires.incoming_connections_count
; ;

View file

@ -1025,7 +1025,7 @@ namespace cryptonote
#if BLOCKCHAIN_DB == DB_LMDB #if BLOCKCHAIN_DB == DB_LMDB
const Blockchain &blockchain = m_core.get_blockchain_storage(); const Blockchain &blockchain = m_core.get_blockchain_storage();
uint8_t version = req.version > 0 ? req.version : blockchain.get_ideal_hard_fork_version(); uint8_t version = req.version > 0 ? req.version : blockchain.get_next_hard_fork_version();
res.version = blockchain.get_current_hard_fork_version(); res.version = blockchain.get_current_hard_fork_version();
res.enabled = blockchain.get_hard_fork_voting_info(version, res.window, res.votes, res.threshold, res.earliest_height, res.voting); res.enabled = blockchain.get_hard_fork_voting_info(version, res.window, res.votes, res.threshold, res.earliest_height, res.voting);
res.state = blockchain.get_hard_fork_state(); res.state = blockchain.get_hard_fork_state();