Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::state_history_plugin Class Reference

#include <state_history_plugin.hpp>

Inheritance diagram for sysio::state_history_plugin:
Collaboration diagram for sysio::state_history_plugin:

Public Member Functions

 state_history_plugin ()
 
virtual ~state_history_plugin ()
 
virtual void set_program_options (options_description &cli, options_description &cfg) override
 
void plugin_initialize (const variables_map &options)
 
void plugin_startup ()
 
void plugin_shutdown ()
 
- Public Member Functions inherited from appbase::plugin< state_history_plugin >
 plugin ()
 
virtual ~plugin ()
 
virtual state get_state () const override
 
virtual const std::string & name () const override
 
virtual void register_dependencies ()
 
virtual void initialize (const variables_map &options) override
 
virtual void handle_sighup () override
 
virtual void startup () override
 
virtual void shutdown () override
 
- Public Member Functions inherited from appbase::abstract_plugin
virtual ~abstract_plugin ()
 

Additional Inherited Members

- Public Types inherited from appbase::abstract_plugin
enum  state { registered , initialized , started , stopped }
 
- Protected Member Functions inherited from appbase::plugin< state_history_plugin >
 plugin (const string &name)
 

Detailed Description

Definition at line 17 of file state_history_plugin.hpp.

Constructor & Destructor Documentation

◆ state_history_plugin()

sysio::state_history_plugin::state_history_plugin ( )

Definition at line 438 of file state_history_plugin.cpp.

439 : my(std::make_shared<state_history_plugin_impl>()) {}

◆ ~state_history_plugin()

sysio::state_history_plugin::~state_history_plugin ( )
virtual

Definition at line 441 of file state_history_plugin.cpp.

441{}

Member Function Documentation

◆ plugin_initialize()

void sysio::state_history_plugin::plugin_initialize ( const variables_map & options)

Definition at line 459 of file state_history_plugin.cpp.

459 {
460 try {
461 SYS_ASSERT(options.at("disable-replay-opts").as<bool>(), plugin_exception,
462 "state_history_plugin requires --disable-replay-opts");
463
464 my->chain_plug = app().find_plugin<chain_plugin>();
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())
479 state_history_dir = app().data_dir() / dir_option;
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 //the arbitrary limit of 1000 here is mainly so that there is enough buffer for newly applied forks to be delivered to clients
507 // before getting pruned out. ideally pruning would have been smart enough to know not to prune reversible blocks
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} // state_history_plugin::plugin_initialize
const mie::Vuint & p
Definition bn.cpp:27
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
abstract_plugin * find_plugin(const string &name) const
bfs::path data_dir() const
Get data directory.
#define FC_LOG_AND_RETHROW()
#define ilog(FORMAT,...)
Definition logger.hpp:118
#define idump(SEQ)
Definition logger.hpp:158
application & app()
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
unsigned int uint32_t
Definition stdint.h:126
Here is the call graph for this function:

◆ plugin_shutdown()

void sysio::state_history_plugin::plugin_shutdown ( )

Definition at line 523 of file state_history_plugin.cpp.

523 {
524 my->applied_transaction_connection.reset();
525 my->accepted_block_connection.reset();
526 my->block_start_connection.reset();
527 while (!my->sessions.empty())
528 my->sessions.begin()->second->close();
529 my->stopping = true;
530}

◆ plugin_startup()

void sysio::state_history_plugin::plugin_startup ( )

Definition at line 521 of file state_history_plugin.cpp.

521{ my->listen(); }

◆ set_program_options()

void sysio::state_history_plugin::set_program_options ( options_description & cli,
options_description & cfg )
overridevirtual

Implements appbase::abstract_plugin.

Definition at line 443 of file state_history_plugin.cpp.

443 {
444 auto options = cfg.add_options();
445 options("state-history-dir", bpo::value<bfs::path>()->default_value("state-history"),
446 "the location of the state-history directory (absolute path or relative to application data dir)");
447 cli.add_options()("delete-state-history", bpo::bool_switch()->default_value(false), "clear state history files");
448 options("trace-history", bpo::bool_switch()->default_value(false), "enable trace history");
449 options("chain-state-history", bpo::bool_switch()->default_value(false), "enable chain state history");
450 options("state-history-endpoint", bpo::value<string>()->default_value("127.0.0.1:8080"),
451 "the endpoint upon which to listen for incoming connections. Caution: only expose this port to "
452 "your internal network.");
453 options("trace-history-debug-mode", bpo::bool_switch()->default_value(false), "enable debug mode for trace history");
454
456 options("state-history-log-retain-blocks", bpo::value<uint32_t>(), "if set, periodically prune the state history files to store only configured number of most recent blocks");
457}
static bool supports_hole_punching()
Definition cfile.hpp:182
void cli()
Here is the call graph for this function:

The documentation for this class was generated from the following files: