Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::fork_database Class Reference

manages light-weight state for all potential unconfirmed forks More...

#include <fork_database.hpp>

Public Member Functions

 fork_database (const fc::path &data_dir)
 
 ~fork_database ()
 
void open (const std::function< void(block_timestamp_type, const flat_set< digest_type > &, const vector< digest_type > &)> &validator)
 
void close ()
 
block_header_state_ptr get_block_header (const block_id_type &id) const
 
block_state_ptr get_block (const block_id_type &id) const
 
void reset (const block_header_state &root_bhs)
 
void rollback_head_to_root ()
 
void advance_root (const block_id_type &id)
 
void add (const block_state_ptr &next_block, bool ignore_duplicate=false)
 
void remove (const block_id_type &id)
 fetch_branch_from_impl
 
block_state_ptr root () const
 
block_state_ptr head () const
 
block_state_ptr pending_head () const
 
branch_type fetch_branch (const block_id_type &h, uint32_t trim_after_block_num=std::numeric_limits< uint32_t >::max()) const
 
block_state_ptr search_on_branch (const block_id_type &h, uint32_t block_num) const
 
pair< branch_type, branch_typefetch_branch_from (const block_id_type &first, const block_id_type &second) const
 
void mark_valid (const block_state_ptr &h)
 

Static Public Attributes

static const uint32_t magic_number = 0x30510FDB
 
static const uint32_t min_supported_version = 1
 
static const uint32_t max_supported_version = 1
 

Detailed Description

As new blocks are received, they are pushed into the fork database. The fork database tracks the longest chain and the last irreversible block number. All blocks older than the last irreversible block are freed after emitting the irreversible signal.

An internal mutex is used to provide thread-safety.

Definition at line 22 of file fork_database.hpp.

Constructor & Destructor Documentation

◆ fork_database()

sysio::chain::fork_database::fork_database ( const fc::path & data_dir)
explicit

Definition at line 100 of file fork_database.cpp.

101 :my( new fork_database_impl( data_dir ) )
102 {}

◆ ~fork_database()

sysio::chain::fork_database::~fork_database ( )

Definition at line 259 of file fork_database.cpp.

259 {
260 my->close_impl();
261 }

Member Function Documentation

◆ add()

void sysio::chain::fork_database::add ( const block_state_ptr & next_block,
bool ignore_duplicate = false )

Add block state to fork database. Must link to existing block in fork database or the root.

Definition at line 385 of file fork_database.cpp.

385 {
386 std::lock_guard g( my->mtx );
387 my->add_impl( n, ignore_duplicate, false,
388 []( block_timestamp_type timestamp,
389 const flat_set<digest_type>& cur_features,
390 const vector<digest_type>& new_features )
391 {}
392 );
393 }
block_timestamp< config::block_interval_ms, config::block_timestamp_epoch > block_timestamp_type
Here is the caller graph for this function:

◆ advance_root()

void sysio::chain::fork_database::advance_root ( const block_id_type & id)

Advance root block forward to some other block in the tree.

Definition at line 293 of file fork_database.cpp.

293 {
294 std::lock_guard g( my->mtx );
295 my->advance_root_impl( id );
296 }
Here is the caller graph for this function:

◆ close()

void sysio::chain::fork_database::close ( )

Definition at line 191 of file fork_database.cpp.

191 {
192 std::lock_guard g( my->mtx );
193 my->close_impl();
194 }

◆ fetch_branch()

branch_type sysio::chain::fork_database::fetch_branch ( const block_id_type & h,
uint32_t trim_after_block_num = std::numeric_limits<uint32_t>::max() ) const

Returns the sequence of block states resulting from trimming the branch from the root block (exclusive) to the block with an id of h (inclusive) by removing any block states corresponding to block numbers greater than trim_after_block_num.

The order of the sequence is in descending block number order. A block with an id of h must exist in the fork database otherwise this method will throw an exception.

Definition at line 418 of file fork_database.cpp.

418 {
419 std::shared_lock g( my->mtx );
420 return my->fetch_branch_impl( h, trim_after_block_num );
421 }
Here is the caller graph for this function:

◆ fetch_branch_from()

pair< branch_type, branch_type > sysio::chain::fork_database::fetch_branch_from ( const block_id_type & first,
const 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 451 of file fork_database.cpp.

452 {
453 std::shared_lock g( my->mtx );
454 return my->fetch_branch_from_impl( first, second );
455 }
Here is the caller graph for this function:

◆ get_block()

block_state_ptr sysio::chain::fork_database::get_block ( const block_id_type & id) const

Definition at line 568 of file fork_database.cpp.

568 {
569 std::shared_lock g( my->mtx );
570 return my->get_block_impl(id);
571 }
Here is the caller graph for this function:

◆ get_block_header()

block_header_state_ptr sysio::chain::fork_database::get_block_header ( const block_id_type & id) const

Definition at line 331 of file fork_database.cpp.

331 {
332 std::shared_lock g( my->mtx );
333 return my->get_block_header_impl( id );
334 }
Here is the caller graph for this function:

◆ head()

block_state_ptr sysio::chain::fork_database::head ( ) const

Definition at line 400 of file fork_database.cpp.

400 {
401 std::shared_lock g( my->mtx );
402 return my->head;
403 }
Here is the caller graph for this function:

◆ mark_valid()

void sysio::chain::fork_database::mark_valid ( const block_state_ptr & h)

Definition at line 543 of file fork_database.cpp.

543 {
544 std::lock_guard g( my->mtx );
545 my->mark_valid_impl( h );
546 }
Here is the caller graph for this function:

◆ open()

void sysio::chain::fork_database::open ( const std::function< void(block_timestamp_type, const flat_set< digest_type > &, const vector< digest_type > &)> & validator)

Definition at line 105 of file fork_database.cpp.

108 {
109 std::lock_guard g( my->mtx );
110 my->open_impl( validator );
111 }
Here is the caller graph for this function:

◆ pending_head()

block_state_ptr sysio::chain::fork_database::pending_head ( ) const

Definition at line 405 of file fork_database.cpp.

405 {
406 std::shared_lock g( my->mtx );
407 const auto& indx = my->index.get<by_lib_block_num>();
408
409 auto itr = indx.lower_bound( false );
410 if( itr != indx.end() && !(*itr)->is_valid() ) {
411 if( first_preferred( **itr, *my->head ) )
412 return *itr;
413 }
414
415 return my->head;
416 }
bool first_preferred(const block_header_state &lhs, const block_header_state &rhs)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove()

void sysio::chain::fork_database::remove ( const block_id_type & id)

remove all of the invalid forks built off of this id including this id

Definition at line 517 of file fork_database.cpp.

517 {
518 std::lock_guard g( my->mtx );
519 return my->remove_impl( id );
520 }
Here is the caller graph for this function:

◆ reset()

void sysio::chain::fork_database::reset ( const block_header_state & root_bhs)

Purges any existing blocks from the fork database and resets the root block_header_state to the provided value. The head will also be reset to point to the root.

Definition at line 263 of file fork_database.cpp.

263 {
264 std::lock_guard g( my->mtx );
265 my->reset_impl(root_bhs);
266 }
Here is the caller graph for this function:

◆ rollback_head_to_root()

void sysio::chain::fork_database::rollback_head_to_root ( )

Removes validated flag from all blocks in fork database and resets head to point to the root.

Definition at line 276 of file fork_database.cpp.

276 {
277 std::lock_guard g( my->mtx );
278 my->rollback_head_to_root_impl();
279 }
Here is the caller graph for this function:

◆ root()

block_state_ptr sysio::chain::fork_database::root ( ) const

Definition at line 395 of file fork_database.cpp.

395 {
396 std::shared_lock g( my->mtx );
397 return my->root;
398 }
Here is the caller graph for this function:

◆ search_on_branch()

block_state_ptr sysio::chain::fork_database::search_on_branch ( const block_id_type & h,
uint32_t block_num ) const

Returns the block state with a block number of block_num that is on the branch that contains a block with an id ofh, or the empty shared pointer if no such block can be found.

Definition at line 433 of file fork_database.cpp.

433 {
434 std::shared_lock g( my->mtx );
435 return my->search_on_branch_impl( h, block_num );
436 }
Here is the caller graph for this function:

Member Data Documentation

◆ magic_number

const uint32_t sysio::chain::fork_database::magic_number = 0x30510FDB
static

Definition at line 91 of file fork_database.hpp.

◆ max_supported_version

const uint32_t sysio::chain::fork_database::max_supported_version = 1
static

Definition at line 94 of file fork_database.hpp.

◆ min_supported_version

const uint32_t sysio::chain::fork_database::min_supported_version = 1
static

Definition at line 93 of file fork_database.hpp.


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