Golos
Разработчикам Статистика Баунти Документация Партнеры Github
Public Types | Public Member Functions | Static Public Attributes | List of all members
golos::chain::fork_database Class Reference

#include <fork_database.hpp>

Public Types

typedef vector< item_ptrbranch_type
 
typedef multi_index_container< item_ptr, indexed_by< hashed_unique< tag< block_id >, member< fork_item, block_id_type, &fork_item::id >, std::hash< fc::ripemd160 > >, hashed_non_unique< tag< by_previous >, const_mem_fun< fork_item, block_id_type, &fork_item::previous_id >, std::hash< fc::ripemd160 > >, ordered_non_unique< tag< block_num >, member< fork_item, uint32_t, &fork_item::num > > > > fork_multi_index_type
 

Public Member Functions

 fork_database ()
 
void reset ()
 
void start_block (signed_block b)
 
void remove (block_id_type b)
 
void set_head (shared_ptr< fork_item > h)
 
bool is_known_block (const block_id_type &id) const
 
shared_ptr< fork_itemfetch_block (const block_id_type &id) const
 
vector< item_ptrfetch_block_by_number (uint32_t n) const
 
shared_ptr< fork_itempush_block (const signed_block &b)
 
shared_ptr< fork_itemhead () const
 
void pop_block ()
 
pair< branch_type, branch_typefetch_branch_from (block_id_type first, block_id_type second) const
 
shared_ptr< fork_itemwalk_main_branch_to_num (uint32_t block_num) const
 
shared_ptr< fork_itemfetch_block_on_main_branch_by_number (uint32_t block_num) const
 
void set_max_size (uint32_t s)
 

Static Public Attributes

static const int MAX_BLOCK_REORDERING = 1024
 The maximum number of blocks that may be skipped in an out-of-order push. More...
 

Detailed Description

As long as blocks are pushed in order the fork database will maintain a linked tree of all blocks that branch from the start_block. The tree will have a maximum depth of 1024 blocks after which the database will start lopping off forks.

Every time a block is pushed into the fork DB the block with the highest block_num will be returned.

Definition at line 53 of file fork_database.hpp.

Member Typedef Documentation

◆ branch_type

Definition at line 55 of file fork_database.hpp.

◆ fork_multi_index_type

typedef multi_index_container< item_ptr, indexed_by< hashed_unique<tag<block_id>, member<fork_item, block_id_type, &fork_item::id>, std::hash<fc::ripemd160> >, hashed_non_unique<tag<by_previous>, const_mem_fun<fork_item, block_id_type, &fork_item::previous_id>, std::hash<fc::ripemd160> >, ordered_non_unique<tag<block_num>, member<fork_item, uint32_t, &fork_item::num> > > > golos::chain::fork_database::fork_multi_index_type

Definition at line 99 of file fork_database.hpp.

Constructor & Destructor Documentation

◆ fork_database()

golos::chain::fork_database::fork_database ( )

Definition at line 8 of file fork_database.cpp.

Member Function Documentation

◆ fetch_block()

item_ptr golos::chain::fork_database::fetch_block ( const block_id_type &  id) const

Definition at line 135 of file fork_database.cpp.

◆ fetch_block_by_number()

vector< item_ptr > golos::chain::fork_database::fetch_block_by_number ( uint32_t  n) const

Definition at line 149 of file fork_database.cpp.

◆ fetch_block_on_main_branch_by_number()

shared_ptr< fork_item > golos::chain::fork_database::fetch_block_on_main_branch_by_number ( uint32_t  block_num) const

Definition at line 222 of file fork_database.cpp.

◆ fetch_branch_from()

pair< fork_database::branch_type, fork_database::branch_type > golos::chain::fork_database::fetch_branch_from ( block_id_type  first,
block_id_type  second 
) const

Given two head blocks, return two branches of the fork graph that end with a common ancestor (same prior block)

Definition at line 167 of file fork_database.cpp.

◆ head()

shared_ptr<fork_item> golos::chain::fork_database::head ( ) const
inline

Definition at line 80 of file fork_database.hpp.

◆ is_known_block()

bool golos::chain::fork_database::is_known_block ( const block_id_type &  id) const

Definition at line 124 of file fork_database.cpp.

◆ pop_block()

void golos::chain::fork_database::pop_block ( )

Definition at line 16 of file fork_database.cpp.

◆ push_block()

shared_ptr< fork_item > golos::chain::fork_database::push_block ( const signed_block &  b)
Returns
the new head block ( the longest fork )

Pushes the block into the fork database and caches it if it doesn't link

Definition at line 33 of file fork_database.cpp.

◆ remove()

void golos::chain::fork_database::remove ( block_id_type  b)

Definition at line 237 of file fork_database.cpp.

◆ reset()

void golos::chain::fork_database::reset ( )

Definition at line 11 of file fork_database.cpp.

◆ set_head()

void golos::chain::fork_database::set_head ( shared_ptr< fork_item h)

Definition at line 233 of file fork_database.cpp.

◆ set_max_size()

void golos::chain::fork_database::set_max_size ( uint32_t  s)

index

unlinked_index

Definition at line 90 of file fork_database.cpp.

◆ start_block()

void golos::chain::fork_database::start_block ( signed_block  b)

Definition at line 23 of file fork_database.cpp.

◆ walk_main_branch_to_num()

shared_ptr< fork_item > golos::chain::fork_database::walk_main_branch_to_num ( uint32_t  block_num) const

Definition at line 210 of file fork_database.cpp.

Member Data Documentation

◆ MAX_BLOCK_REORDERING

const int golos::chain::fork_database::MAX_BLOCK_REORDERING = 1024
static

The maximum number of blocks that may be skipped in an out-of-order push.

Definition at line 57 of file fork_database.hpp.


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