diff --git a/src/blockchain_plugin.cpp b/src/blockchain_plugin.cpp index 2129c26..dad8758 100644 --- a/src/blockchain_plugin.cpp +++ b/src/blockchain_plugin.cpp @@ -13,18 +13,26 @@ class blockchain_plugin_impl : std::enable_shared_from_this().get_db(); node_settings = appbase::app().get_plugin().get_node_settings(); SILK_INFO << "Using DB environment at location : " << node_settings->data_directory->chaindata().path().string(); - + stop_at_block = _stop_at_block; + if(stop_at_block != 0) { + SILK_INFO << "Stoping at block : " << stop_at_block; + } evm_blocks_subscription = appbase::app().get_channel().subscribe( [this](auto new_block) { try { static size_t block_count{0}; SILK_DEBUG << "EVM Block " << new_block->header.number; + if( stop_at_block != 0 && new_block->header.number >= stop_at_block ) { + if( new_block->header.number > stop_at_block ) return; + block_count = 5000-1; + } + if(!exec_engine) { exec_engine = std::make_unique(appbase::app().get_io_context(), *node_settings, silkworm::db::RWAccess{*db_env}); exec_engine->open(); @@ -52,7 +60,7 @@ class blockchain_plugin_impl : std::enable_shared_from_this; - + uint64_t stop_at_block; silkworm::NodeSettings* node_settings; mdbx::env* db_env; channels::evm_blocks::channel_type::handle evm_blocks_subscription; @@ -63,10 +71,15 @@ blockchain_plugin::blockchain_plugin() : my(new blockchain_plugin_impl()) {} blockchain_plugin::~blockchain_plugin() {} void blockchain_plugin::set_program_options( appbase::options_description& cli, appbase::options_description& cfg ) { + cfg.add_options() + ("stop-at-block", boost::program_options::value()->default_value(0), + "Stop processing once the block height exceeds the specified value."); + } void blockchain_plugin::plugin_initialize( const appbase::variables_map& options ) { - my->init(); + const auto stop_at_block = options.at("stop-at-block").as(); + my->init(stop_at_block); SILK_INFO << "Initialized Blockchain Plugin"; }