459 {
460 try {
461 SYS_ASSERT(options.at(
"disable-replay-opts").as<
bool>(), plugin_exception,
462 "state_history_plugin requires --disable-replay-opts");
463
465 SYS_ASSERT(my->chain_plug, chain::missing_chain_plugin_exception,
"");
466 auto& chain = my->chain_plug->chain();
467 my->applied_transaction_connection.emplace(
468 chain.applied_transaction.connect([&](std::tuple<const transaction_trace_ptr&, const packed_transaction_ptr&> t) {
469 my->on_applied_transaction(std::get<0>(t), std::get<1>(t));
470 }));
471 my->accepted_block_connection.emplace(
472 chain.accepted_block.connect([&](
const block_state_ptr&
p) { my->on_accepted_block(p); }));
473 my->block_start_connection.emplace(
474 chain.block_start.connect([&](
uint32_t block_num) { my->on_block_start(block_num); }));
475
476 auto dir_option = options.at("state-history-dir").as<bfs::path>();
477 boost::filesystem::path state_history_dir;
478 if (dir_option.is_relative())
480 else
481 state_history_dir = dir_option;
482 if (
auto resmon_plugin =
app().find_plugin<resource_monitor_plugin>())
483 resmon_plugin->monitor_directory(state_history_dir);
484
485 auto ip_port = options.at("state-history-endpoint").as<string>();
486 auto port = ip_port.substr(ip_port.find(':') + 1, ip_port.size());
487 auto host = ip_port.substr(0, ip_port.find(':'));
488 my->endpoint_address =
host;
489 my->endpoint_port = std::stoi(port);
490 idump((ip_port)(host)(port));
491
492 if (options.at("delete-state-history").as<bool>()) {
493 ilog(
"Deleting state history");
494 boost::filesystem::remove_all(state_history_dir);
495 }
496 boost::filesystem::create_directories(state_history_dir);
497
498 if (options.at("trace-history-debug-mode").as<bool>()) {
499 my->trace_debug_mode = true;
500 }
501
502 std::optional<state_history_log_prune_config> ship_log_prune_conf;
503 if (options.count("state-history-log-retain-blocks")) {
504 ship_log_prune_conf.emplace();
505 ship_log_prune_conf->prune_blocks = options.at(
"state-history-log-retain-blocks").as<
uint32_t>();
506
507
508 SYS_ASSERT(ship_log_prune_conf->prune_blocks >= 1000, plugin_exception,
"state-history-log-retain-blocks must be 1000 blocks or greater");
509 }
510
511 if (options.at("trace-history").as<bool>())
512 my->trace_log.emplace("trace_history", (state_history_dir / "trace_history.log").string(),
513 (state_history_dir / "trace_history.index").string(), ship_log_prune_conf);
514 if (options.at("chain-state-history").as<bool>())
515 my->chain_state_log.emplace("chain_state_history", (state_history_dir / "chain_state_history.log").string(),
516 (state_history_dir / "chain_state_history.index").string(), ship_log_prune_conf);
517 }
519}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
abstract_plugin * find_plugin(const string &name) const
bfs::path data_dir() const
Get data directory.
#define FC_LOG_AND_RETHROW()
std::shared_ptr< block_state > block_state_ptr
schedule config_dir_name data_dir_name p2p_port http_port file_size name host(p2p_endpoint)) FC_REFLECT(tn_node_def