Only do slow replays when the bookie plugin is loaded

This commit is contained in:
Eric Frias 2017-09-07 15:55:44 -04:00
parent ed0917ee03
commit 69b00293d9
3 changed files with 36 additions and 12 deletions

View file

@ -64,13 +64,16 @@ void database::reindex(fc::path data_dir, const genesis_state_type& initial_allo
const auto last_block_num = last_block->block_num();
ilog( "Replaying blocks..." );
// Right now, we leave undo_db enabled when replaying because the bookie plugin
// depends on new/changed/removed object notifications, and those are only fired
// when the undo_db is enabled
//_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 = 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 == 1 ||
i % 10000 == 0 )
std::cerr << " " << double(i*100)/last_block_num << "% "<< i << " of " <<last_block_num<<" \n";
fc::optional< signed_block > block = _block_id_to_block.fetch_by_number(i);
if( !block.valid() )
{
@ -91,14 +94,24 @@ void database::reindex(fc::path data_dir, const genesis_state_type& initial_allo
wlog( "Dropped ${n} blocks from after the gap", ("n", dropped_count) );
break;
}
apply_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)
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 |
skip_transaction_signatures |
skip_transaction_dupe_check |
skip_tapos_check |
skip_witness_schedule_check |
skip_authority_check);
}
//_undo_db.enable();
if (!_slow_replays)
_undo_db.enable();
auto end = fc::time_point::now();
ilog( "Done reindexing, elapsed time: ${t} sec", ("t",double((end-start).count())/1000000.0 ) );
} FC_CAPTURE_AND_RETHROW( (data_dir) ) }
@ -189,4 +202,10 @@ void database::close(bool rewind)
_fork_db.reset();
}
void database::force_slow_replays()
{
ilog("enabling slow replays");
_slow_replays = true;
}
} }

View file

@ -180,6 +180,9 @@ namespace graphene { namespace chain {
// history object so other plugins that evaluate later can reference it.
vector<optional< operation_history_object > >& get_applied_operations();
// the bookie plugin depends on change notifications that are skipped during normal replays
void force_slow_replays();
string to_pretty_string( const asset& a )const;
/**
@ -534,6 +537,7 @@ namespace graphene { namespace chain {
node_property_object _node_property_object;
fc::hash_ctr_rng<secret_hash_type, 20> _random_number_generator;
bool _slow_replays = false;
};
namespace detail

View file

@ -453,6 +453,7 @@ void bookie_plugin::plugin_set_program_options(boost::program_options::options_d
void bookie_plugin::plugin_initialize(const boost::program_options::variables_map& options)
{
ilog("bookie plugin: plugin_startup() begin");
database().force_slow_replays();
database().applied_block.connect( [&]( const signed_block& b){ my->on_block_applied(b); } );
database().changed_objects.connect([&](const vector<object_id_type>& changed_object_ids, const fc::flat_set<graphene::chain::account_id_type>& impacted_accounts){ my->on_objects_changed(changed_object_ids); });
database().new_objects.connect([this](const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) { my->on_objects_new(ids); });