Skip to content

Commit

Permalink
Fix #492 - database corruption when closing
Browse files Browse the repository at this point in the history
The database was attempting to pop blocks for which there was no undo
history. These changes make it impossible to pop blocks if there isn't
a fork db history.
  • Loading branch information
bytemaster committed Feb 15, 2016
1 parent c7f272d commit 1c1db75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ void database::pop_block()
auto head_id = head_block_id();
optional<signed_block> head_block = fetch_block_by_id( head_id );
GRAPHENE_ASSERT( head_block.valid(), pop_empty_chain, "there are no blocks to pop" );
pop_undo();
_block_id_to_block.remove( head_id );

_fork_db.pop_block();
_block_id_to_block.remove( head_id );
pop_undo();

_popped_tx.insert( _popped_tx.begin(), head_block->transactions.begin(), head_block->transactions.end() );

Expand Down
5 changes: 4 additions & 1 deletion libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ void fork_database::reset()

void fork_database::pop_block()
{
if( _head ) _head = _head->prev.lock();
FC_ASSERT( _head, "no blocks to pop" );
auto prev = _head->prev.lock();
FC_ASSERT( prev, "poping block would leave head block null" );
_head = prev;
}

void fork_database::start_block(signed_block b)
Expand Down

0 comments on commit 1c1db75

Please # to comment.