Skip to content

Commit

Permalink
Refer to block as a pointer. More defensive coding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Dec 19, 2016
1 parent 551062f commit b427211
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3532,21 +3532,24 @@ void database::update_last_irreversible_block()
{
while( log_head_num < dpo.last_irreversible_block_num )
{
signed_block b;
signed_block* block_ptr;
auto blocks = _fork_db.fetch_block_by_number( log_head_num + 1 );

if( blocks.size() == 1 )
b = blocks[0]->data;
block_ptr = &( blocks[0]->data );
else
{
ilog( "Encountered a block num collision due to a fork. Walking the current fork to determine the correct block. block_num:${n}", ("n", log_head_num + 1) ); // TODO: Delete when we know this code works as intended
auto next = _fork_db.head();
while( next->num > log_head_num + 1 )
while( next.get() != nullptr && next->num > log_head_num + 1 )
next = next->prev.lock();

b = next->data;
FC_ASSERT( next.get() != nullptr, "Current fork in the fork database does not contain the last_irreversible_block" );

block_ptr = &( next->data );
}

_block_log.append( b );
_block_log.append( *block_ptr );
log_head_num++;
}

Expand Down

0 comments on commit b427211

Please sign in to comment.