Electroneum
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
cryptonote::HardFork Class Reference

#include <hardfork.h>

Collaboration diagram for cryptonote::HardFork:
Collaboration graph
[legend]

Classes

struct  Params
 

Public Types

enum  State { LikelyForked , UpdateNeeded , Ready }
 

Public Member Functions

 HardFork (cryptonote::BlockchainDB &db, uint8_t original_version=1, uint64_t original_version_till_height=DEFAULT_ORIGINAL_VERSION_TILL_HEIGHT, time_t forked_time=DEFAULT_FORKED_TIME, time_t update_time=DEFAULT_UPDATE_TIME, uint64_t window_size=DEFAULT_WINDOW_SIZE, uint8_t default_threshold_percent=DEFAULT_THRESHOLD_PERCENT)
 creates a new HardFork object More...
 
bool add_fork (uint8_t version, uint64_t height, uint8_t threshold, time_t time)
 add a new hardfork height More...
 
bool add_fork (uint8_t version, uint64_t height, time_t time)
 add a new hardfork height More...
 
void init ()
 initialize the object More...
 
bool check (const cryptonote::block &block) const
 check whether a new block would be accepted More...
 
bool check_for_height (const cryptonote::block &block, uint64_t height) const
 same as check, but for a particular height, rather than the top More...
 
bool add (const cryptonote::block &block, uint64_t height)
 add a new block More...
 
bool reorganize_from_block_height (uint64_t height)
 called when the blockchain is reorganized More...
 
bool reorganize_from_chain_height (uint64_t height)
 
void on_block_popped (uint64_t new_chain_height)
 called when one or more blocks are popped from the blockchain More...
 
State get_state (time_t t) const
 returns current state at the given time More...
 
State get_state () const
 
uint8_t get (uint64_t height) const
 returns the hard fork version for the given block height More...
 
uint8_t get_ideal_version () const
 returns the latest "ideal" version More...
 
uint8_t get_ideal_version (uint64_t height) const
 returns the "ideal" version for a given height More...
 
uint8_t get_next_version () const
 returns the next version More...
 
uint8_t get_current_version () const
 returns the current version More...
 
uint64_t get_earliest_ideal_height_for_version (uint8_t version) const
 returns the earliest block a given version may activate More...
 
bool get_voting_info (uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
 returns information about current voting state More...
 
uint64_t get_window_size () const
 returns the size of the voting window in blocks More...
 

Static Public Attributes

static const uint64_t DEFAULT_ORIGINAL_VERSION_TILL_HEIGHT = 0
 
static const time_t DEFAULT_FORKED_TIME = 31557600
 
static const time_t DEFAULT_UPDATE_TIME = 31557600 / 2
 
static const uint64_t DEFAULT_WINDOW_SIZE = 10080
 
static const uint8_t DEFAULT_THRESHOLD_PERCENT = 80
 

Private Member Functions

uint8_t get_block_version (uint64_t height) const
 
bool do_check (uint8_t block_version, uint8_t voting_version) const
 
bool do_check_for_height (uint8_t block_version, uint8_t voting_version, uint64_t height) const
 
int get_voted_fork_index (uint64_t height) const
 
uint8_t get_effective_version (uint8_t voting_version) const
 
bool add (uint8_t block_version, uint8_t voting_version, uint64_t height)
 
bool rescan_from_block_height (uint64_t height)
 
bool rescan_from_chain_height (uint64_t height)
 

Private Attributes

BlockchainDBdb
 
time_t forked_time
 
time_t update_time
 
uint64_t window_size
 
uint8_t default_threshold_percent
 
uint8_t original_version
 
uint64_t original_version_till_height
 
std::vector< Paramsheights
 
std::deque< uint8_t > versions
 
unsigned int last_versions [256]
 
uint32_t current_fork_index
 
epee::critical_section lock
 

Member Enumeration Documentation

◆ State

Enumerator
LikelyForked 
UpdateNeeded 
Ready 

Constructor & Destructor Documentation

◆ HardFork()

HardFork::HardFork ( cryptonote::BlockchainDB db,
uint8_t  original_version = 1,
uint64_t  original_version_till_height = DEFAULT_ORIGINAL_VERSION_TILL_HEIGHT,
time_t  forked_time = DEFAULT_FORKED_TIME,
time_t  update_time = DEFAULT_UPDATE_TIME,
uint64_t  window_size = DEFAULT_WINDOW_SIZE,
uint8_t  default_threshold_percent = DEFAULT_THRESHOLD_PERCENT 
)

creates a new HardFork object

Parameters
original_versionthe block version for blocks 0 through to the first fork
forked_timethe time in seconds before thinking we're forked
update_timethe time in seconds before thinking we need to update
window_sizethe size of the window in blocks to consider for version voting
default_threshold_percentthe size of the majority in percents

Member Function Documentation

◆ add() [1/2]

bool HardFork::add ( const cryptonote::block block,
uint64_t  height 
)

add a new block

returns true if no error, false otherwise

Parameters
blockthe new block

◆ add() [2/2]

bool HardFork::add ( uint8_t  block_version,
uint8_t  voting_version,
uint64_t  height 
)
private

◆ add_fork() [1/2]

bool HardFork::add_fork ( uint8_t  version,
uint64_t  height,
time_t  time 
)

add a new hardfork height

returns true if no error, false otherwise

Parameters
versionthe major block version for the fork
heightThe height the hardfork takes effect
timeApproximate time of the hardfork (seconds since epoch)

◆ add_fork() [2/2]

bool HardFork::add_fork ( uint8_t  version,
uint64_t  height,
uint8_t  threshold,
time_t  time 
)

add a new hardfork height

returns true if no error, false otherwise

Parameters
versionthe major block version for the fork
heightThe height the hardfork takes effect
thresholdThe threshold of votes needed for this fork (0-100)
timeApproximate time of the hardfork (seconds since epoch)

◆ check()

bool HardFork::check ( const cryptonote::block block) const

check whether a new block would be accepted

returns true if the block is accepted, false otherwise

Parameters
blockthe new block

This check is made by add. It is exposed publicly to allow the caller to inexpensively check whether a block would be accepted or rejected by its version number. Indeed, if this check could only be done as part of add, the caller would either have to add the block to the blockchain first, then call add, then have to pop the block from the blockchain if its version did not satisfy the hard fork requirements, or call add first, then, if the hard fork requirements are met, add the block to the blockchain, upon which a failure (the block being invalid, double spending, etc) would cause the hardfork object to reorganize.

◆ check_for_height()

bool HardFork::check_for_height ( const cryptonote::block block,
uint64_t  height 
) const

same as check, but for a particular height, rather than the top

NOTE: this does not play well with voting, and relies on voting to be disabled (that is, forks happen on the scheduled date, whether or not enough blocks have voted for the fork).

returns true if no error, false otherwise

Parameters
blockthe new block
heightwhich height to check for

◆ do_check()

bool HardFork::do_check ( uint8_t  block_version,
uint8_t  voting_version 
) const
private

◆ do_check_for_height()

bool HardFork::do_check_for_height ( uint8_t  block_version,
uint8_t  voting_version,
uint64_t  height 
) const
private

◆ get()

uint8_t HardFork::get ( uint64_t  height) const

returns the hard fork version for the given block height

Parameters
heightheight of the block to check

◆ get_block_version()

uint8_t HardFork::get_block_version ( uint64_t  height) const
private

◆ get_current_version()

uint8_t HardFork::get_current_version ( ) const

returns the current version

This is the latest version that's past its trigger date and had enough votes at one point in the past.

◆ get_earliest_ideal_height_for_version()

uint64_t HardFork::get_earliest_ideal_height_for_version ( uint8_t  version) const

returns the earliest block a given version may activate

◆ get_effective_version()

uint8_t HardFork::get_effective_version ( uint8_t  voting_version) const
private

◆ get_ideal_version() [1/2]

uint8_t HardFork::get_ideal_version ( ) const

returns the latest "ideal" version

This is the latest version that's been scheduled

◆ get_ideal_version() [2/2]

uint8_t HardFork::get_ideal_version ( uint64_t  height) const

returns the "ideal" version for a given height

Parameters
heightheight of the block to check

◆ get_next_version()

uint8_t HardFork::get_next_version ( ) const

returns the next version

This is the version which will we fork to next

◆ get_state() [1/2]

HardFork::State HardFork::get_state ( ) const

◆ get_state() [2/2]

HardFork::State HardFork::get_state ( time_t  t) const

returns current state at the given time

Based on the approximate time of the last known hard fork, estimate whether we need to update, or if we're way behind

Parameters
tthe time to consider

◆ get_voted_fork_index()

int HardFork::get_voted_fork_index ( uint64_t  height) const
private

◆ get_voting_info()

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

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

Parameters
versionthe version to check voting for
windowthe number of blocks considered in voting
votesnumber of votes for next version
thresholdnumber of votes needed to switch to next version
earliest_heightearliest height at which the version can take effect

◆ get_window_size()

uint64_t cryptonote::HardFork::get_window_size ( ) const
inline

returns the size of the voting window in blocks

◆ init()

void HardFork::init ( )

initialize the object

Must be done after adding all the required hardforks via add above

◆ on_block_popped()

void HardFork::on_block_popped ( uint64_t  new_chain_height)

called when one or more blocks are popped from the blockchain

The current fork will be updated by looking up the db, which is much cheaper than recomputing everything

Parameters
new_chain_heightthe height of the chain after popping

◆ reorganize_from_block_height()

bool HardFork::reorganize_from_block_height ( uint64_t  height)

called when the blockchain is reorganized

This will rescan the blockchain to determine which hard forks have been triggered

returns true if no error, false otherwise

Parameters
blockchainthe blockchain
heightof the last block kept from the previous blockchain

◆ reorganize_from_chain_height()

bool HardFork::reorganize_from_chain_height ( uint64_t  height)

◆ rescan_from_block_height()

bool HardFork::rescan_from_block_height ( uint64_t  height)
private

◆ rescan_from_chain_height()

bool HardFork::rescan_from_chain_height ( uint64_t  height)
private

Member Data Documentation

◆ current_fork_index

uint32_t cryptonote::HardFork::current_fork_index
private

◆ db

BlockchainDB& cryptonote::HardFork::db
private

◆ DEFAULT_FORKED_TIME

const time_t cryptonote::HardFork::DEFAULT_FORKED_TIME = 31557600
static

◆ DEFAULT_ORIGINAL_VERSION_TILL_HEIGHT

const uint64_t cryptonote::HardFork::DEFAULT_ORIGINAL_VERSION_TILL_HEIGHT = 0
static

◆ DEFAULT_THRESHOLD_PERCENT

const uint8_t cryptonote::HardFork::DEFAULT_THRESHOLD_PERCENT = 80
static

◆ default_threshold_percent

uint8_t cryptonote::HardFork::default_threshold_percent
private

◆ DEFAULT_UPDATE_TIME

const time_t cryptonote::HardFork::DEFAULT_UPDATE_TIME = 31557600 / 2
static

◆ DEFAULT_WINDOW_SIZE

const uint64_t cryptonote::HardFork::DEFAULT_WINDOW_SIZE = 10080
static

◆ forked_time

time_t cryptonote::HardFork::forked_time
private

◆ heights

std::vector<Params> cryptonote::HardFork::heights
private

◆ last_versions

unsigned int cryptonote::HardFork::last_versions[256]
private

◆ lock

epee::critical_section cryptonote::HardFork::lock
mutableprivate

◆ original_version

uint8_t cryptonote::HardFork::original_version
private

◆ original_version_till_height

uint64_t cryptonote::HardFork::original_version_till_height
private

◆ update_time

time_t cryptonote::HardFork::update_time
private

◆ versions

std::deque<uint8_t> cryptonote::HardFork::versions
private

◆ window_size

uint64_t cryptonote::HardFork::window_size
private

The documentation for this class was generated from the following files: