Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::state_history Namespace Reference

Classes

struct  augmented_transaction_trace
 
struct  big_vector_wrapper
 
struct  block_position
 
struct  get_blocks_ack_request_v0
 
struct  get_blocks_request_v0
 
struct  get_blocks_result_v0
 
struct  get_status_request_v0
 
struct  get_status_result_v0
 
struct  partial_transaction
 
struct  table_delta
 
struct  trace_converter
 

Typedefs

using state_request = std::variant<get_status_request_v0, get_blocks_request_v0, get_blocks_ack_request_v0>
 
using state_result = std::variant<get_status_result_v0, get_blocks_result_v0>
 

Functions

bytes zlib_compress_bytes (const bytes &in)
 
bytes zlib_decompress (const bytes &in)
 
template<typename T >
bool include_delta (const T &old, const T &curr)
 
bool include_delta (const chain::table_id_object &old, const chain::table_id_object &curr)
 
bool include_delta (const chain::resource_limits::resource_limits_object &old, const chain::resource_limits::resource_limits_object &curr)
 
bool include_delta (const chain::resource_limits::resource_limits_state_object &old, const chain::resource_limits::resource_limits_state_object &curr)
 
bool include_delta (const chain::account_metadata_object &old, const chain::account_metadata_object &curr)
 
bool include_delta (const chain::code_object &old, const chain::code_object &curr)
 
bool include_delta (const chain::protocol_state_object &old, const chain::protocol_state_object &curr)
 
std::vector< table_deltacreate_deltas (const chainbase::database &db, bool full_snapshot)
 

Typedef Documentation

◆ state_request

◆ state_result

Function Documentation

◆ create_deltas()

std::vector< table_delta > sysio::state_history::create_deltas ( const chainbase::database & db,
bool full_snapshot )

Definition at line 58 of file create_deltas.cpp.

58 {
59 std::vector<table_delta> deltas;
60 const auto& table_id_index = db.get_index<chain::table_id_multi_index>();
61 std::map<uint64_t, const chain::table_id_object*> removed_table_id;
62 for (auto& rem : table_id_index.last_undo_session().removed_values)
63 removed_table_id[rem.id._id] = &rem;
64
65 auto get_table_id = [&](uint64_t tid) -> const chain::table_id_object& {
66 auto obj = table_id_index.find(tid);
67 if (obj)
68 return *obj;
69 auto it = removed_table_id.find(tid);
70 SYS_ASSERT(it != removed_table_id.end(), chain::plugin_exception, "can not found table id ${tid}", ("tid", tid));
71 return *it->second;
72 };
73
74 auto pack_row = [&](auto& row) { return fc::raw::pack(make_history_serial_wrapper(db, row)); };
75 auto pack_contract_row = [&](auto& row) {
76 return fc::raw::pack(make_history_context_wrapper(db, get_table_id(row.t_id._id), row));
77 };
78
79 auto process_table = [&](auto* name, auto& index, auto& pack_row) {
80 if (full_snapshot) {
81 if (index.indices().empty())
82 return;
83 deltas.push_back({});
84 auto& delta = deltas.back();
85 delta.name = name;
86 for (auto& row : index.indices())
87 delta.rows.obj.emplace_back(true, pack_row(row));
88 } else {
89 auto undo = index.last_undo_session();
90 if (undo.old_values.empty() && undo.new_values.empty() && undo.removed_values.empty())
91 return;
92 deltas.push_back({});
93 auto& delta = deltas.back();
94 delta.name = name;
95 for (auto& old : undo.old_values) {
96 auto& row = index.get(old.id);
97 if (include_delta(old, row))
98 delta.rows.obj.emplace_back(true, pack_row(row));
99 }
100 for (auto& old : undo.removed_values)
101 delta.rows.obj.emplace_back(false, pack_row(old));
102 for (auto& row : undo.new_values) {
103 delta.rows.obj.emplace_back(true, pack_row(row));
104 }
105 }
106 };
107
108 process_table("account", db.get_index<chain::account_index>(), pack_row);
109 process_table("account_metadata", db.get_index<chain::account_metadata_index>(), pack_row);
110 process_table("code", db.get_index<chain::code_index>(), pack_row);
111
112 process_table("contract_table", db.get_index<chain::table_id_multi_index>(), pack_row);
113 process_table("contract_row", db.get_index<chain::key_value_index>(), pack_contract_row);
114 process_table("contract_index64", db.get_index<chain::index64_index>(), pack_contract_row);
115 process_table("contract_index128", db.get_index<chain::index128_index>(), pack_contract_row);
116 process_table("contract_index256", db.get_index<chain::index256_index>(), pack_contract_row);
117 process_table("contract_index_double", db.get_index<chain::index_double_index>(), pack_contract_row);
118 process_table("contract_index_long_double", db.get_index<chain::index_long_double_index>(), pack_contract_row);
119
120 process_table("global_property", db.get_index<chain::global_property_multi_index>(), pack_row);
121 process_table("generated_transaction", db.get_index<chain::generated_transaction_multi_index>(), pack_row);
122 process_table("protocol_state", db.get_index<chain::protocol_state_multi_index>(), pack_row);
123
124 process_table("permission", db.get_index<chain::permission_index>(), pack_row);
125 process_table("permission_link", db.get_index<chain::permission_link_index>(), pack_row);
126
127 process_table("resource_limits", db.get_index<chain::resource_limits::resource_limits_index>(), pack_row);
128 process_table("resource_usage", db.get_index<chain::resource_limits::resource_usage_index>(), pack_row);
129 process_table("resource_limits_state", db.get_index<chain::resource_limits::resource_limits_state_index>(),
130 pack_row);
131 process_table("resource_limits_config", db.get_index<chain::resource_limits::resource_limits_config_index>(),
132 pack_row);
133
134 return deltas;
135}
std::string name
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
const generic_index< MultiIndexType > & get_index() const
The table_id_object class tracks the mapping of (scope, code, table) to an opaque identifier.
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
chainbase::shared_multi_index_container< table_id_object, indexed_by< ordered_unique< tag< by_id >, member< table_id_object, table_id_object::id_type, &table_id_object::id > >, ordered_unique< tag< by_code_scope_table >, composite_key< table_id_object, member< table_id_object, account_name, &table_id_object::code >, member< table_id_object, scope_name, &table_id_object::scope >, member< table_id_object, table_name, &table_id_object::table > > > > > table_id_multi_index
bool include_delta(const T &old, const T &curr)
history_context_wrapper< std::decay_t< P >, std::decay_t< T > > make_history_context_wrapper(const chainbase::database &db, const P &context, const T &obj)
history_serial_wrapper< std::decay_t< T > > make_history_serial_wrapper(const chainbase::database &db, const T &obj)
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ include_delta() [1/7]

bool sysio::state_history::include_delta ( const chain::account_metadata_object & old,
const chain::account_metadata_object & curr )

Definition at line 40 of file create_deltas.cpp.

40 {
41 return //
42 old.name != curr.name || //
43 old.is_privileged() != curr.is_privileged() || //
44 old.last_code_update != curr.last_code_update || //
45 old.vm_type != curr.vm_type || //
46 old.vm_version != curr.vm_version || //
47 old.code_hash != curr.code_hash;
48}

◆ include_delta() [2/7]

bool sysio::state_history::include_delta ( const chain::code_object & old,
const chain::code_object & curr )

Definition at line 50 of file create_deltas.cpp.

50 { //
51 return false;
52}

◆ include_delta() [3/7]

bool sysio::state_history::include_delta ( const chain::protocol_state_object & old,
const chain::protocol_state_object & curr )

Definition at line 54 of file create_deltas.cpp.

54 {
56}
shared_vector< activated_protocol_feature > activated_protocol_features

◆ include_delta() [4/7]

◆ include_delta() [5/7]

bool sysio::state_history::include_delta ( const chain::resource_limits::resource_limits_state_object & old,
const chain::resource_limits::resource_limits_state_object & curr )

Definition at line 24 of file create_deltas.cpp.

25 {
26 return //
27 old.average_block_net_usage.last_ordinal != curr.average_block_net_usage.last_ordinal || //
28 old.average_block_net_usage.value_ex != curr.average_block_net_usage.value_ex || //
29 old.average_block_net_usage.consumed != curr.average_block_net_usage.consumed || //
30 old.average_block_cpu_usage.last_ordinal != curr.average_block_cpu_usage.last_ordinal || //
31 old.average_block_cpu_usage.value_ex != curr.average_block_cpu_usage.value_ex || //
32 old.average_block_cpu_usage.consumed != curr.average_block_cpu_usage.consumed || //
33 old.total_net_weight != curr.total_net_weight || //
34 old.total_cpu_weight != curr.total_cpu_weight || //
35 old.total_ram_bytes != curr.total_ram_bytes || //
36 old.virtual_net_limit != curr.virtual_net_limit || //
37 old.virtual_cpu_limit != curr.virtual_cpu_limit;
38}
uint64_t consumed
The last periods average + the current periods contribution so far.
uint32_t last_ordinal
The ordinal of the last period which has contributed to the average.

◆ include_delta() [6/7]

bool sysio::state_history::include_delta ( const chain::table_id_object & old,
const chain::table_id_object & curr )

Definition at line 12 of file create_deltas.cpp.

12 {
13 return old.payer != curr.payer;
14}

◆ include_delta() [7/7]

template<typename T >
bool sysio::state_history::include_delta ( const T & old,
const T & curr )

Definition at line 8 of file create_deltas.cpp.

8 {
9 return true;
10}
Here is the caller graph for this function:

◆ zlib_compress_bytes()

bytes sysio::state_history::zlib_compress_bytes ( const bytes & in)

Definition at line 11 of file compression.cpp.

11 {
12 bytes out;
13 bio::filtering_ostream comp;
14 comp.push(bio::zlib_compressor(bio::zlib::default_compression));
15 comp.push(bio::back_inserter(out));
16 bio::write(comp, in.data(), in.size());
17 bio::close(comp);
18 return out;
19}
Here is the caller graph for this function:

◆ zlib_decompress()

bytes sysio::state_history::zlib_decompress ( const bytes & in)

Definition at line 21 of file compression.cpp.

21 {
22 bytes out;
23 bio::filtering_ostream decomp;
24 decomp.push(bio::zlib_decompressor());
25 decomp.push(bio::back_inserter(out));
26 bio::write(decomp, in.data(), in.size());
27 bio::close(decomp);
28 return out;
29}
Here is the caller graph for this function: