Skip to content

Commit

Permalink
Remove dead code from fork_database
Browse files Browse the repository at this point in the history
Remove following dead code from fork_database

- fork_database::add( const header_confirmation& c )
- fork_database::set_bft_irreversible( block_id_type id )

Closes EOSIO#7100

Signed-off-by: Hyung-Kyu Choi <[email protected]>
  • Loading branch information
hqueue committed Apr 10, 2019
1 parent dc5852c commit 17e9e03
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
58 changes: 0 additions & 58 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,62 +297,4 @@ namespace eosio { namespace chain {
return *nitr;
}

void fork_database::add( const header_confirmation& c ) {
auto b = get_block( c.block_id );
EOS_ASSERT( b, fork_db_block_not_found, "unable to find block id ${id}", ("id",c.block_id));
b->add_confirmation( c );

if( b->bft_irreversible_blocknum < b->block_num &&
b->confirmations.size() >= ((b->active_schedule.producers.size() * 2) / 3 + 1) ) {
set_bft_irreversible( c.block_id );
}
}

/**
* This method will set this block as being BFT irreversible and will update
* all blocks which build off of it to have the same bft_irb if their existing
* bft irb is less than this block num.
*
* This will require a search over all forks
*/
void fork_database::set_bft_irreversible( block_id_type id ) {
auto& idx = my->index.get<by_block_id>();
auto itr = idx.find(id);
uint32_t block_num = (*itr)->block_num;
idx.modify( itr, [&]( auto& bsp ) {
bsp->bft_irreversible_blocknum = bsp->block_num;
});

/** to prevent stack-overflow, we perform a bredth-first traversal of the
* fork database. At each stage we iterate over the leafs from the prior stage
* and find all nodes that link their previous. If we update the bft lib then we
* add it to a queue for the next layer. This lambda takes one layer and returns
* all block ids that need to be iterated over for next layer.
*/
auto update = [&]( const vector<block_id_type>& in ) {
vector<block_id_type> updated;

for( const auto& i : in ) {
auto& pidx = my->index.get<by_prev>();
auto pitr = pidx.lower_bound( i );
auto epitr = pidx.upper_bound( i );
while( pitr != epitr ) {
pidx.modify( pitr, [&]( auto& bsp ) {
if( bsp->bft_irreversible_blocknum < block_num ) {
bsp->bft_irreversible_blocknum = block_num;
updated.push_back( bsp->id );
}
});
++pitr;
}
}
return updated;
};

vector<block_id_type> queue{id};
while( queue.size() ) {
queue = update( queue );
}
}

} } /// eosio::chain
3 changes: 0 additions & 3 deletions libraries/chain/include/eosio/chain/fork_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace eosio { namespace chain {
block_state_ptr add( const block_state_ptr& next_block, bool skip_validate_previous );
void remove( const block_id_type& id );

void add( const header_confirmation& c );

const block_state_ptr& head()const;

/**
Expand All @@ -71,7 +69,6 @@ namespace eosio { namespace chain {
signal<void(block_state_ptr)> irreversible;

private:
void set_bft_irreversible( block_id_type id );
unique_ptr<fork_database_impl> my;
};

Expand Down

0 comments on commit 17e9e03

Please sign in to comment.