Add an RPC call and daemon command to get info on hard fork voting

This commit is contained in:
moneromooo-monero 2015-09-19 16:34:29 +01:00
parent d06713199e
commit e546f3724a
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
13 changed files with 169 additions and 5 deletions

View file

@ -72,7 +72,7 @@ DISABLE_VS_WARNINGS(4267)
//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool) :
m_db(), m_tx_pool(tx_pool), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false),
m_is_blockchain_storing(false), m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_fast_sync(true)
m_is_blockchain_storing(false), m_enforce_dns_checkpoints(false), m_hardfork(), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_fast_sync(true)
{
LOG_PRINT_L3("Blockchain::" << __func__);
}
@ -3082,3 +3082,8 @@ HardFork::State Blockchain::get_hard_fork_state() const
{
return m_hardfork.get_state();
}
bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const
{
return m_hardfork.get_voting_info(version, window, votes, threshold, voting);
}

View file

@ -160,6 +160,9 @@ namespace cryptonote
void set_show_time_stats(bool stats) { m_show_time_stats = stats; }
HardFork::State get_hard_fork_state() const;
uint8_t get_current_hard_fork_version() const { return m_hardfork.get_current_version(); }
uint8_t get_ideal_hard_fork_version() const { return m_hardfork.get_ideal_version(); }
bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const;
BlockchainDB& get_db()
{

View file

@ -135,7 +135,7 @@ void HardFork::init()
starting[n] = 0;
checkpoints.clear();
current_fork_index = 0;
vote_threshold = (unsigned int)ceilf(max_history * threshold_percent / 100.0f);
vote_threshold = (uint32_t)ceilf(max_history * threshold_percent / 100.0f);
}
bool HardFork::reorganize_from_block_height(const cryptonote::BlockchainDB *db, uint64_t height)
@ -186,7 +186,7 @@ bool HardFork::reorganize_from_chain_height(const cryptonote::BlockchainDB *db,
int HardFork::get_voted_fork_index(uint64_t height) const
{
CRITICAL_REGION_LOCAL(lock);
unsigned int accumulated_votes = 0;
uint32_t accumulated_votes = 0;
for (unsigned int n = heights.size() - 1; n > current_fork_index; --n) {
uint8_t v = heights[n].version;
accumulated_votes += last_versions[v];
@ -247,6 +247,22 @@ uint8_t HardFork::get_ideal_version() const
return heights.back().version;
}
bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const
{
CRITICAL_REGION_LOCAL(lock);
const uint8_t current_version = heights[current_fork_index].version;
const bool enabled = current_version >= version;
window = versions.size();
votes = 0;
for (size_t n = version; n < 256; ++n)
votes += last_versions[n];
threshold = vote_threshold;
assert((votes >= threshold) == enabled);
voting = heights.back().version;
return enabled;
}
template<class archive_t>
void HardFork::serialize(archive_t & ar, const unsigned int version)
{

View file

@ -162,6 +162,24 @@ namespace cryptonote
*/
uint8_t get_current_version() const;
/**
* @brief returns information about current voting state
*
* returns true if the given version is enabled (ie, the current version
* is at least the passed version), false otherwise
*
* @param version the version to check voting for
* @param window the number of blocks considered in voting
* @param votes number of votes for next version
* @param threshold number of votes needed to switch to next version
*/
bool get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const;
/**
* @brief returns the size of the voting window in blocks
*/
uint64_t get_window_size() const { return max_history; }
template<class archive_t>
void serialize(archive_t & ar, const unsigned int version);
@ -189,10 +207,10 @@ namespace cryptonote
std::vector<Params> heights;
std::deque<uint8_t> versions; /* rolling window of the last N blocks' versions */
unsigned int last_versions[256]; /* count of the block versions in the lsat N blocks */
unsigned int last_versions[256]; /* count of the block versions in the last N blocks */
uint64_t starting[256]; /* block height at which each fork starts */
unsigned int current_fork_index;
unsigned int vote_threshold;
uint32_t vote_threshold;
uint64_t checkpoint_period;
std::vector<std::pair<uint64_t, int>> checkpoints;