Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to stop processing blocks at specific block height #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/blockchain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@ class blockchain_plugin_impl : std::enable_shared_from_this<blockchain_plugin_im
public:
blockchain_plugin_impl() = default;

inline void init() {
inline void init(uint64_t _stop_at_block) {
SILK_DEBUG << "blockchain_plugin_impl INIT";
db_env = appbase::app().get_plugin<engine_plugin>().get_db();
node_settings = appbase::app().get_plugin<engine_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<channels::evm_blocks>().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<silkworm::stagedsync::ExecutionEngine>(appbase::app().get_io_context(), *node_settings, silkworm::db::RWAccess{*db_env});
exec_engine->open();
Expand Down Expand Up @@ -52,7 +60,7 @@ class blockchain_plugin_impl : std::enable_shared_from_this<blockchain_plugin_im
}

using txn_t = std::unique_ptr<silkworm::db::RWTxn>;

uint64_t stop_at_block;
silkworm::NodeSettings* node_settings;
mdbx::env* db_env;
channels::evm_blocks::channel_type::handle evm_blocks_subscription;
Expand All @@ -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<std::uint64_t>()->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<std::uint64_t>();
my->init(stop_at_block);
SILK_INFO << "Initialized Blockchain Plugin";
}

Expand Down