Electroneum
Public Member Functions | Private Attributes | List of all members
cryptonote::checkpoints Class Reference

A container for blockchain checkpoints. More...

#include <checkpoints.h>

Public Member Functions

 checkpoints ()
 default constructor More...
 
bool add_checkpoint (uint64_t height, const std::string &hash_str)
 adds a checkpoint to the container More...
 
bool is_in_checkpoint_zone (uint64_t height) const
 checks if there is a checkpoint in the future More...
 
bool check_block (uint64_t height, const crypto::hash &h, bool &is_a_checkpoint) const
 checks if the given height and hash agree with the checkpoints More...
 
bool check_block (uint64_t height, const crypto::hash &h) const
 
bool is_alternative_block_allowed (uint64_t blockchain_height, uint64_t block_height) const
 checks if alternate chain blocks should be kept for a given height More...
 
uint64_t get_max_height () const
 gets the highest checkpoint height More...
 
const std::map< uint64_t, crypto::hash > & get_points () const
 gets the checkpoints container More...
 
bool check_for_conflicts (const checkpoints &other) const
 checks if our checkpoints container conflicts with another More...
 
bool init_default_checkpoints (network_type nettype)
 loads the default main chain checkpoints More...
 
bool load_new_checkpoints (const std::string &json_hashfile_fullpath, network_type nettype=MAINNET, bool dns=true)
 load new checkpoints More...
 
bool load_checkpoints_from_json (const std::string &json_hashfile_fullpath)
 load new checkpoints from json More...
 
bool load_checkpoints_from_dns (network_type nettype=MAINNET)
 load new checkpoints from DNS More...
 

Private Attributes

std::map< uint64_t, crypto::hashm_points
 the checkpoints container More...
 

Detailed Description

A container for blockchain checkpoints.

A checkpoint is a pre-defined hash for the block at a given height. Some of these are compiled-in, while others can be loaded at runtime either from a json file or via DNS from a checkpoint-hosting server.

Constructor & Destructor Documentation

◆ checkpoints()

cryptonote::checkpoints::checkpoints ( )

default constructor

Member Function Documentation

◆ add_checkpoint()

bool cryptonote::checkpoints::add_checkpoint ( uint64_t  height,
const std::string &  hash_str 
)

adds a checkpoint to the container

Parameters
heightthe height of the block the checkpoint is for
hash_strthe hash of the block, as a string
Returns
false if parsing the hash fails, or if the height is a duplicate AND the existing checkpoint hash does not match the new one, otherwise returns true

◆ check_block() [1/2]

bool cryptonote::checkpoints::check_block ( uint64_t  height,
const crypto::hash h 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ check_block() [2/2]

bool cryptonote::checkpoints::check_block ( uint64_t  height,
const crypto::hash h,
bool is_a_checkpoint 
) const

checks if the given height and hash agree with the checkpoints

This function checks if the given height and hash exist in the checkpoints container. If so, it returns whether or not the passed parameters match the stored values.

Parameters
heightthe height to be checked
hthe hash to be checked
is_a_checkpointreturn-by-reference if there is a checkpoint at the given height
Returns
true if there is no checkpoint at the given height, true if the passed parameters match the stored checkpoint, false otherwise

◆ check_for_conflicts()

bool cryptonote::checkpoints::check_for_conflicts ( const checkpoints other) const

checks if our checkpoints container conflicts with another

A conflict refers to a case where both checkpoint sets have a checkpoint for a specific height but their hashes for that height do not match.

Parameters
otherthe other checkpoints instance to check against
Returns
false if any conflict is found, otherwise true

◆ get_max_height()

uint64_t cryptonote::checkpoints::get_max_height ( ) const

gets the highest checkpoint height

Returns
the height of the highest checkpoint

◆ get_points()

const std::map< uint64_t, crypto::hash > & cryptonote::checkpoints::get_points ( ) const

gets the checkpoints container

Returns
a const reference to the checkpoints container

◆ init_default_checkpoints()

bool cryptonote::checkpoints::init_default_checkpoints ( network_type  nettype)

loads the default main chain checkpoints

Parameters
nettypenetwork type
Returns
true unless adding a checkpoint fails

◆ is_alternative_block_allowed()

bool cryptonote::checkpoints::is_alternative_block_allowed ( uint64_t  blockchain_height,
uint64_t  block_height 
) const

checks if alternate chain blocks should be kept for a given height

this basically says if the blockchain is smaller than the first checkpoint then alternate blocks are allowed. Alternatively, if the last checkpoint before the end of the current chain is also before the block to be added, then this is fine.

Parameters
blockchain_heightthe current blockchain height
block_heightthe height of the block to be added as alternate
Returns
true if alternate blocks are allowed given the parameters, otherwise false

◆ is_in_checkpoint_zone()

bool cryptonote::checkpoints::is_in_checkpoint_zone ( uint64_t  height) const

checks if there is a checkpoint in the future

This function checks if the height passed is lower than the highest checkpoint.

Parameters
heightthe height to check against
Returns
false if no checkpoints, otherwise returns whether or not the height passed is lower than the highest checkpoint.

◆ load_checkpoints_from_dns()

bool cryptonote::checkpoints::load_checkpoints_from_dns ( network_type  nettype = MAINNET)

load new checkpoints from DNS

Parameters
nettypenetwork type
Returns
true if loading successful and no conflicts

◆ load_checkpoints_from_json()

bool cryptonote::checkpoints::load_checkpoints_from_json ( const std::string &  json_hashfile_fullpath)

load new checkpoints from json

Parameters
json_hashfile_fullpathpath to the json checkpoints file
Returns
true if loading successful and no conflicts

◆ load_new_checkpoints()

bool cryptonote::checkpoints::load_new_checkpoints ( const std::string &  json_hashfile_fullpath,
network_type  nettype = MAINNET,
bool  dns = true 
)

load new checkpoints

Loads new checkpoints from the specified json file, as well as (optionally) from DNS.

Parameters
json_hashfile_fullpathpath to the json checkpoints file
nettypenetwork type
dnswhether or not to load DNS checkpoints
Returns
true if loading successful and no conflicts

Member Data Documentation

◆ m_points

std::map<uint64_t, crypto::hash> cryptonote::checkpoints::m_points
private

the checkpoints container


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