Enable undo + fork database for final blocks in a replay
Dont remove blocks from block db when popping blocks, handle edge case in replay wrt fork_db, adapted unit tests
This commit is contained in:
parent
cefd1de512
commit
d75d003a63
3 changed files with 29 additions and 18 deletions
|
|
@ -506,7 +506,6 @@ void database::pop_block()
|
||||||
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" );
|
||||||
|
|
||||||
_fork_db.pop_block();
|
_fork_db.pop_block();
|
||||||
_block_id_to_block.remove( head_id );
|
|
||||||
pop_undo();
|
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() );
|
||||||
|
|
|
||||||
|
|
@ -64,11 +64,16 @@ void database::reindex( fc::path data_dir )
|
||||||
uint32_t undo_point = last_block_num - 50;
|
uint32_t undo_point = last_block_num - 50;
|
||||||
|
|
||||||
ilog( "Replaying blocks..." );
|
ilog( "Replaying blocks..." );
|
||||||
// Right now, we leave undo_db enabled when replaying when the bookie plugin is
|
if( head_block_num() >= undo_point )
|
||||||
// enabled. It depends on new/changed/removed object notifications, and those are
|
_fork_db.start_block( *fetch_block_by_number( head_block_num() ) );
|
||||||
// only fired when the undo_db is enabled
|
else
|
||||||
if (!_slow_replays)
|
{
|
||||||
_undo_db.disable();
|
// Right now, we leave undo_db enabled when replaying when the bookie plugin is
|
||||||
|
// enabled. It depends on new/changed/removed object notifications, and those are
|
||||||
|
// only fired when the undo_db is enabled
|
||||||
|
if (!_slow_replays)
|
||||||
|
_undo_db.disable();
|
||||||
|
}
|
||||||
for( uint32_t i = head_block_num() + 1; i <= last_block_num; ++i )
|
for( uint32_t i = head_block_num() + 1; i <= last_block_num; ++i )
|
||||||
{
|
{
|
||||||
if( i % 10000 == 0 ) std::cerr << " " << double(i*100)/last_block_num << "% "<<i << " of " <<last_block_num<<" \n";
|
if( i % 10000 == 0 ) std::cerr << " " << double(i*100)/last_block_num << "% "<<i << " of " <<last_block_num<<" \n";
|
||||||
|
|
@ -78,8 +83,6 @@ void database::reindex( fc::path data_dir )
|
||||||
flush();
|
flush();
|
||||||
ilog( "Done" );
|
ilog( "Done" );
|
||||||
}
|
}
|
||||||
if( i == undo_point )
|
|
||||||
_undo_db.enable();
|
|
||||||
fc::optional< signed_block > block = _block_id_to_block.fetch_by_number(i);
|
fc::optional< signed_block > block = _block_id_to_block.fetch_by_number(i);
|
||||||
if( !block.valid() )
|
if( !block.valid() )
|
||||||
{
|
{
|
||||||
|
|
@ -100,21 +103,26 @@ void database::reindex( fc::path data_dir )
|
||||||
wlog( "Dropped ${n} blocks from after the gap", ("n", dropped_count) );
|
wlog( "Dropped ${n} blocks from after the gap", ("n", dropped_count) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (_slow_replays)
|
if( i < undo_point && !_slow_replays)
|
||||||
push_block(*block, skip_fork_db |
|
{
|
||||||
skip_witness_signature |
|
|
||||||
skip_transaction_signatures |
|
|
||||||
skip_transaction_dupe_check |
|
|
||||||
skip_tapos_check |
|
|
||||||
skip_witness_schedule_check |
|
|
||||||
skip_authority_check);
|
|
||||||
else
|
|
||||||
apply_block(*block, skip_witness_signature |
|
apply_block(*block, skip_witness_signature |
|
||||||
skip_transaction_signatures |
|
skip_transaction_signatures |
|
||||||
skip_transaction_dupe_check |
|
skip_transaction_dupe_check |
|
||||||
skip_tapos_check |
|
skip_tapos_check |
|
||||||
skip_witness_schedule_check |
|
skip_witness_schedule_check |
|
||||||
skip_authority_check);
|
skip_authority_check);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!_slow_replays)
|
||||||
|
_undo_db.enable();
|
||||||
|
push_block(*block, skip_witness_signature |
|
||||||
|
skip_transaction_signatures |
|
||||||
|
skip_transaction_dupe_check |
|
||||||
|
skip_tapos_check |
|
||||||
|
skip_witness_schedule_check |
|
||||||
|
skip_authority_check);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!_slow_replays)
|
if (!_slow_replays)
|
||||||
_undo_db.enable();
|
_undo_db.enable();
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks )
|
||||||
// TODO: Don't generate this here
|
// TODO: Don't generate this here
|
||||||
auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) );
|
||||||
signed_block cutoff_block;
|
signed_block cutoff_block;
|
||||||
|
uint32_t last_block;
|
||||||
{
|
{
|
||||||
database db;
|
database db;
|
||||||
db.open(data_dir.path(), make_genesis, "TEST" );
|
db.open(data_dir.path(), make_genesis, "TEST" );
|
||||||
|
|
@ -156,6 +157,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks )
|
||||||
if( cutoff_height >= 200 )
|
if( cutoff_height >= 200 )
|
||||||
{
|
{
|
||||||
cutoff_block = *(db.fetch_block_by_number( cutoff_height ));
|
cutoff_block = *(db.fetch_block_by_number( cutoff_height ));
|
||||||
|
last_block = db.head_block_num();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +166,9 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks )
|
||||||
{
|
{
|
||||||
database db;
|
database db;
|
||||||
db.open(data_dir.path(), []{return genesis_state_type();}, "TEST");
|
db.open(data_dir.path(), []{return genesis_state_type();}, "TEST");
|
||||||
BOOST_CHECK_EQUAL( db.head_block_num(), cutoff_block.block_num() );
|
BOOST_CHECK_EQUAL( db.head_block_num(), last_block );
|
||||||
|
while( db.head_block_num() > cutoff_block.block_num() )
|
||||||
|
db.pop_block();
|
||||||
b = cutoff_block;
|
b = cutoff_block;
|
||||||
for( uint32_t i = 0; i < 200; ++i )
|
for( uint32_t i = 0; i < 200; ++i )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue