Fix #492 - database corruption when closing
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.
This commit is contained in:
parent
e46af9f372
commit
89fbb11bb6
2 changed files with 7 additions and 3 deletions
|
|
@ -417,9 +417,10 @@ void database::pop_block()
|
||||||
auto head_id = head_block_id();
|
auto head_id = head_block_id();
|
||||||
optional<signed_block> head_block = fetch_block_by_id( head_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" );
|
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();
|
_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() );
|
_popped_tx.insert( _popped_tx.begin(), head_block->transactions.begin(), head_block->transactions.end() );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,10 @@ void fork_database::reset()
|
||||||
|
|
||||||
void fork_database::pop_block()
|
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)
|
void fork_database::start_block(signed_block b)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue