Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::state_history_plugin_impl Struct Reference
Inheritance diagram for sysio::state_history_plugin_impl:
Collaboration diagram for sysio::state_history_plugin_impl:

Classes

struct  session
 

Public Member Functions

void get_log_entry (state_history_log &log, uint32_t block_num, std::optional< bytes > &result)
 
void get_block (uint32_t block_num, const block_state_ptr &block_state, std::optional< bytes > &result)
 
std::optional< chain::block_id_typeget_block_id (uint32_t block_num)
 
void listen ()
 
void do_accept ()
 
void on_applied_transaction (const transaction_trace_ptr &p, const packed_transaction_ptr &t)
 
void on_accepted_block (const block_state_ptr &block_state)
 
void on_block_start (uint32_t block_num)
 
void clear_caches ()
 
void store_traces (const block_state_ptr &block_state)
 
void store_chain_state (const block_state_ptr &block_state)
 

Public Attributes

chain_pluginchain_plug = nullptr
 
std::optional< state_history_logtrace_log
 
std::optional< state_history_logchain_state_log
 
bool trace_debug_mode = false
 
bool stopping = false
 
std::optional< scoped_connection > applied_transaction_connection
 
std::optional< scoped_connection > block_start_connection
 
std::optional< scoped_connection > accepted_block_connection
 
string endpoint_address = "0.0.0.0"
 
uint16_t endpoint_port = 8080
 
std::unique_ptr< tcp::acceptor > acceptor
 
state_history::trace_converter trace_converter
 
std::map< session *, std::shared_ptr< session > > sessions
 

Detailed Description

Definition at line 43 of file state_history_plugin.cpp.

Member Function Documentation

◆ clear_caches()

void sysio::state_history_plugin_impl::clear_caches ( )
inline

Definition at line 387 of file state_history_plugin.cpp.

387 {
390 }
std::optional< augmented_transaction_trace > onblock_trace
std::map< transaction_id_type, augmented_transaction_trace > cached_traces
state_history::trace_converter trace_converter
Here is the caller graph for this function:

◆ do_accept()

void sysio::state_history_plugin_impl::do_accept ( )
inline

Definition at line 335 of file state_history_plugin.cpp.

335 {
336 auto socket = std::make_shared<tcp::socket>(app().get_io_service());
337 acceptor->async_accept(*socket, [self = shared_from_this(), socket, this](const boost::system::error_code& ec) {
338 if (stopping)
339 return;
340 if (ec) {
341 if (ec == boost::system::errc::too_many_files_open)
342 catch_and_log([&] { do_accept(); });
343 return;
344 }
345 catch_and_log([&] {
346 auto s = std::make_shared<session>(self);
347 sessions[s.get()] = s;
348 s->start(std::move(*socket));
349 });
350 catch_and_log([&] { do_accept(); });
351 });
352 }
application & app()
auto catch_and_log(F f)
@ self
the connection is to itself
Definition protocol.hpp:48
std::unique_ptr< tcp::acceptor > acceptor
std::map< session *, std::shared_ptr< session > > sessions
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block()

void sysio::state_history_plugin_impl::get_block ( uint32_t block_num,
const block_state_ptr & block_state,
std::optional< bytes > & result )
inline

Definition at line 74 of file state_history_plugin.cpp.

74 {
76 try {
77 if( block_state && block_num == block_state->block_num ) {
78 p = block_state->block;
79 } else {
80 p = chain_plug->chain().fetch_block_by_number( block_num );
81 }
82 } catch (...) {
83 return;
84 }
85 if (p)
86 result = fc::raw::pack(*p);
87 }
const mie::Vuint & p
Definition bn.cpp:27
signed_block_ptr fetch_block_by_number(uint32_t block_num) const
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
std::shared_ptr< signed_block > signed_block_ptr
Definition block.hpp:105
Here is the call graph for this function:

◆ get_block_id()

std::optional< chain::block_id_type > sysio::state_history_plugin_impl::get_block_id ( uint32_t block_num)
inline

Definition at line 89 of file state_history_plugin.cpp.

89 {
90 if (trace_log && block_num >= trace_log->begin_block() && block_num < trace_log->end_block())
91 return trace_log->get_block_id(block_num);
92 if (chain_state_log && block_num >= chain_state_log->begin_block() && block_num < chain_state_log->end_block())
93 return chain_state_log->get_block_id(block_num);
94 try {
95 return chain_plug->chain().get_block_id_for_num(block_num);
96 } catch (...) {}
97 return {};
98 }
block_id_type get_block_id_for_num(uint32_t block_num) const
std::optional< state_history_log > trace_log
std::optional< state_history_log > chain_state_log
Here is the call graph for this function:

◆ get_log_entry()

void sysio::state_history_plugin_impl::get_log_entry ( state_history_log & log,
uint32_t block_num,
std::optional< bytes > & result )
inline

Definition at line 57 of file state_history_plugin.cpp.

57 {
58 if (block_num < log.begin_block() || block_num >= log.end_block())
59 return;
60 state_history_log_header header;
61 auto& stream = log.get_entry(block_num, header);
62 uint32_t s;
63 // Compressed deltas now exceeds 4GB on one of the public chains. This length prefix
64 // was intended to support adding additional fields in the future after the
65 // packed deltas or packed traces. For now we're going to ignore on read.
66 stream.read((char*)&s, sizeof(s));
67 uint64_t s2 = header.payload_size - sizeof(s);
68 bytes compressed(s2);
69 if (s2)
70 stream.read(compressed.data(), s2);
71 result = state_history::zlib_decompress(compressed);
72 }
vector< char > bytes
Definition types.hpp:243
bytes zlib_decompress(const bytes &in)
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ listen()

void sysio::state_history_plugin_impl::listen ( )
inline

Definition at line 311 of file state_history_plugin.cpp.

311 {
312 boost::system::error_code ec;
313
314 auto address = boost::asio::ip::make_address(endpoint_address);
315 auto endpoint = tcp::endpoint{address, endpoint_port};
316 acceptor = std::make_unique<tcp::acceptor>(app().get_io_service());
317
318 auto check_ec = [&](const char* what) {
319 if (!ec)
320 return;
321 elog("${w}: ${m}", ("w", what)("m", ec.message()));
322 SYS_ASSERT(false, plugin_exception, "unable to open listen socket");
323 };
324
325 acceptor->open(endpoint.protocol(), ec);
326 check_ec("open");
327 acceptor->set_option(boost::asio::socket_base::reuse_address(true));
328 acceptor->bind(endpoint, ec);
329 check_ec("bind");
330 acceptor->listen(boost::asio::socket_base::max_listen_connections, ec);
331 check_ec("listen");
332 do_accept();
333 }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
void check_ec(T *c, websocketpp::lib::error_code ec, websocketpp::connection_hdl hdl)
#define elog(FORMAT,...)
Definition logger.hpp:130
Here is the call graph for this function:

◆ on_accepted_block()

void sysio::state_history_plugin_impl::on_accepted_block ( const block_state_ptr & block_state)
inline

Definition at line 359 of file state_history_plugin.cpp.

359 {
360 try {
361 store_traces(block_state);
362 store_chain_state(block_state);
363 } catch (const fc::exception& e) {
364 elog("fc::exception: ${details}", ("details", e.to_detail_string()));
365 // Both app().quit() and exception throwing are required. Without app().quit(),
366 // the exception would be caught and drop before reaching main(). The exception is
367 // to ensure the block won't be commited.
368 appbase::app().quit();
369 SYS_THROW(
370 chain::state_history_write_exception,
371 "State history encountered an Error which it cannot recover from. Please resolve the error and relaunch "
372 "the process");
373 }
374
375 for (auto& s : sessions) {
376 auto& p = s.second;
377 if (p) {
378 if (p->current_request && block_state->block_num < p->current_request->start_block_num)
379 p->current_request->start_block_num = block_state->block_num;
380 p->send_update(block_state);
381 }
382 }
383 }
#define SYS_THROW(exc_type, FORMAT,...)
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
std::string to_detail_string(log_level ll=log_level::all) const
void store_traces(const block_state_ptr &block_state)
void store_chain_state(const block_state_ptr &block_state)
Here is the call graph for this function:

◆ on_applied_transaction()

void sysio::state_history_plugin_impl::on_applied_transaction ( const transaction_trace_ptr & p,
const packed_transaction_ptr & t )
inline

Definition at line 354 of file state_history_plugin.cpp.

354 {
355 if (trace_log)
357 }
void add_transaction(const transaction_trace_ptr &trace, const chain::packed_transaction_ptr &transaction)
Here is the call graph for this function:

◆ on_block_start()

void sysio::state_history_plugin_impl::on_block_start ( uint32_t block_num)
inline

Definition at line 385 of file state_history_plugin.cpp.

Here is the call graph for this function:

◆ store_chain_state()

void sysio::state_history_plugin_impl::store_chain_state ( const block_state_ptr & block_state)
inline

Definition at line 411 of file state_history_plugin.cpp.

411 {
412 if (!chain_state_log)
413 return;
414 bool fresh = chain_state_log->begin_block() == chain_state_log->end_block();
415 if (fresh)
416 ilog("Placing initial state in block ${n}", ("n", block_state->block->block_num()));
417
418 std::vector<table_delta> deltas = state_history::create_deltas(chain_plug->chain().db(), fresh);
419 auto deltas_bin = state_history::zlib_compress_bytes(fc::raw::pack(deltas));
420 state_history_log_header header{.magic = ship_magic(ship_current_version, 0),
421 .block_id = block_state->id,
422 .payload_size = sizeof(uint32_t) + deltas_bin.size()};
423 chain_state_log->write_entry(header, block_state->block->previous, [&](auto& stream) {
424 // Compressed deltas now exceeds 4GB on one of the public chains. This length prefix
425 // was intended to support adding additional fields in the future after the
426 // packed deltas. For now we're going to ignore on read. The 0 is an attempt to signal
427 // old versions that something's not quite right.
428 uint32_t s = (uint32_t)deltas_bin.size();
429 if (s != deltas_bin.size())
430 s = 0;
431 stream.write((char*)&s, sizeof(s));
432 if (!deltas_bin.empty())
433 stream.write(deltas_bin.data(), deltas_bin.size());
434 });
435 } // store_chain_state
const chainbase::database & db() const
#define ilog(FORMAT,...)
Definition logger.hpp:118
std::vector< table_delta > create_deltas(const chainbase::database &db, bool full_snapshot)
bytes zlib_compress_bytes(const bytes &in)
uint64_t ship_magic(uint16_t version, uint16_t features=0)
Definition log.hpp:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ store_traces()

void sysio::state_history_plugin_impl::store_traces ( const block_state_ptr & block_state)
inline

Definition at line 392 of file state_history_plugin.cpp.

392 {
393 if (!trace_log)
394 return;
395 auto traces_bin = state_history::zlib_compress_bytes(
397
398 SYS_ASSERT(traces_bin.size() == (uint32_t)traces_bin.size(), plugin_exception, "traces is too big");
399
400 state_history_log_header header{.magic = ship_magic(ship_current_version, 0),
401 .block_id = block_state->id,
402 .payload_size = sizeof(uint32_t) + traces_bin.size()};
403 trace_log->write_entry(header, block_state->block->previous, [&](auto& stream) {
404 uint32_t s = (uint32_t)traces_bin.size();
405 stream.write((char*)&s, sizeof(s));
406 if (!traces_bin.empty())
407 stream.write(traces_bin.data(), traces_bin.size());
408 });
409 }
bytes pack(const chainbase::database &db, bool trace_debug_mode, const block_state_ptr &block_state)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ accepted_block_connection

std::optional<scoped_connection> sysio::state_history_plugin_impl::accepted_block_connection

Definition at line 51 of file state_history_plugin.cpp.

◆ acceptor

std::unique_ptr<tcp::acceptor> sysio::state_history_plugin_impl::acceptor

Definition at line 54 of file state_history_plugin.cpp.

◆ applied_transaction_connection

std::optional<scoped_connection> sysio::state_history_plugin_impl::applied_transaction_connection

Definition at line 49 of file state_history_plugin.cpp.

◆ block_start_connection

std::optional<scoped_connection> sysio::state_history_plugin_impl::block_start_connection

Definition at line 50 of file state_history_plugin.cpp.

◆ chain_plug

chain_plugin* sysio::state_history_plugin_impl::chain_plug = nullptr

Definition at line 44 of file state_history_plugin.cpp.

◆ chain_state_log

std::optional<state_history_log> sysio::state_history_plugin_impl::chain_state_log

Definition at line 46 of file state_history_plugin.cpp.

◆ endpoint_address

string sysio::state_history_plugin_impl::endpoint_address = "0.0.0.0"

Definition at line 52 of file state_history_plugin.cpp.

◆ endpoint_port

uint16_t sysio::state_history_plugin_impl::endpoint_port = 8080

Definition at line 53 of file state_history_plugin.cpp.

◆ sessions

std::map<session*, std::shared_ptr<session> > sysio::state_history_plugin_impl::sessions

Definition at line 309 of file state_history_plugin.cpp.

◆ stopping

bool sysio::state_history_plugin_impl::stopping = false

Definition at line 48 of file state_history_plugin.cpp.

◆ trace_converter

state_history::trace_converter sysio::state_history_plugin_impl::trace_converter

Definition at line 55 of file state_history_plugin.cpp.

◆ trace_debug_mode

bool sysio::state_history_plugin_impl::trace_debug_mode = false

Definition at line 47 of file state_history_plugin.cpp.

◆ trace_log

std::optional<state_history_log> sysio::state_history_plugin_impl::trace_log

Definition at line 45 of file state_history_plugin.cpp.


The documentation for this struct was generated from the following file: