Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
create_deltas.cpp
Go to the documentation of this file.
3
4namespace sysio {
5namespace state_history {
6
7template <typename T>
8bool include_delta(const T& old, const T& curr) {
9 return true;
10}
11
13 return old.payer != curr.payer;
14}
15
18 return //
19 old.net_weight != curr.net_weight || //
20 old.cpu_weight != curr.cpu_weight || //
21 old.ram_bytes != curr.ram_bytes;
22}
23
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}
39
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}
49
50bool include_delta(const chain::code_object& old, const chain::code_object& curr) { //
51 return false;
52}
53
57
58std::vector<table_delta> create_deltas(const chainbase::database& db, bool full_snapshot) {
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}
136
137} // namespace state_history
138} // namespace sysio
std::string name
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
const generic_index< MultiIndexType > & get_index() const
Maintains global state information about consensus protocol rules.
shared_vector< activated_protocol_feature > activated_protocol_features
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< resource_usage_object, indexed_by< ordered_unique< tag< by_id >, member< resource_usage_object, resource_usage_object::id_type, &resource_usage_object::id > >, ordered_unique< tag< by_owner >, member< resource_usage_object, account_name, &resource_usage_object::owner > > > > resource_usage_index
chainbase::shared_multi_index_container< resource_limits_object, indexed_by< ordered_unique< tag< by_id >, member< resource_limits_object, resource_limits_object::id_type, &resource_limits_object::id > >, ordered_unique< tag< by_owner >, composite_key< resource_limits_object, BOOST_MULTI_INDEX_MEMBER(resource_limits_object, bool, pending), > > > > resource_limits_index
chainbase::shared_multi_index_container< resource_limits_state_object, indexed_by< ordered_unique< tag< by_id >, member< resource_limits_state_object, resource_limits_state_object::id_type, &resource_limits_state_object::id > > > > resource_limits_state_index
chainbase::shared_multi_index_container< resource_limits_config_object, indexed_by< ordered_unique< tag< by_id >, member< resource_limits_config_object, resource_limits_config_object::id_type, &resource_limits_config_object::id > > > > resource_limits_config_index
chainbase::shared_multi_index_container< global_property_object, indexed_by< ordered_unique< tag< by_id >, > > > global_property_multi_index
chainbase::shared_multi_index_container< code_object, indexed_by< ordered_unique< tag< by_id >, member< code_object, code_object::id_type, &code_object::id > >, ordered_unique< tag< by_code_hash >, composite_key< code_object, member< code_object, digest_type, &code_object::code_hash >, member< code_object, uint8_t, &code_object::vm_type >, member< code_object, uint8_t, &code_object::vm_version > > > > > code_index
chainbase::shared_multi_index_container< account_object, indexed_by< ordered_unique< tag< by_id >, member< account_object, account_object::id_type, &account_object::id > >, ordered_unique< tag< by_name >, member< account_object, account_name, &account_object::name > > > > account_index
chainbase::shared_multi_index_container< permission_link_object, indexed_by< ordered_unique< tag< by_id >, >, ordered_unique< tag< by_action_name >, composite_key< permission_link_object, BOOST_MULTI_INDEX_MEMBER(permission_link_object, account_name, account), BOOST_MULTI_INDEX_MEMBER(permission_link_object, account_name, code), > >, ordered_unique< tag< by_permission_name >, composite_key< permission_link_object, BOOST_MULTI_INDEX_MEMBER(permission_link_object, account_name, account), BOOST_MULTI_INDEX_MEMBER(permission_link_object, permission_name, required_permission), > > > > permission_link_index
secondary_index< uint128_t, index128_object_type >::index_index index128_index
chainbase::shared_multi_index_container< permission_object, indexed_by< ordered_unique< tag< by_id >, member< permission_object, permission_object::id_type, &permission_object::id > >, ordered_unique< tag< by_parent >, composite_key< permission_object, member< permission_object, permission_object::id_type, &permission_object::parent >, member< permission_object, permission_object::id_type, &permission_object::id > > >, ordered_unique< tag< by_owner >, composite_key< permission_object, member< permission_object, account_name, &permission_object::owner >, member< permission_object, permission_name, &permission_object::name > > >, ordered_unique< tag< by_name >, composite_key< permission_object, member< permission_object, permission_name, &permission_object::name >, member< permission_object, permission_object::id_type, &permission_object::id > > > > > permission_index
secondary_index< float64_t, index_double_object_type, soft_double_less >::index_index index_double_index
secondary_index< uint64_t, index64_object_type >::index_index index64_index
secondary_index< key256_t, index256_object_type >::index_index index256_index
chainbase::shared_multi_index_container< generated_transaction_object, indexed_by< ordered_unique< tag< by_id >, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, generated_transaction_object::id_type, id)>, ordered_unique< tag< by_trx_id >, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, transaction_id_type, trx_id)>, ordered_unique< tag< by_expiration >, composite_key< generated_transaction_object, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, time_point, expiration), > >, ordered_unique< tag< by_delay >, composite_key< generated_transaction_object, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, time_point, delay_until), > >, ordered_unique< tag< by_sender_id >, composite_key< generated_transaction_object, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, account_name, sender), > > > > generated_transaction_multi_index
chainbase::shared_multi_index_container< key_value_object, indexed_by< ordered_unique< tag< by_id >, member< key_value_object, key_value_object::id_type, &key_value_object::id > >, ordered_unique< tag< by_scope_primary >, composite_key< key_value_object, member< key_value_object, table_id, &key_value_object::t_id >, member< key_value_object, uint64_t, &key_value_object::primary_key > >, composite_key_compare< std::less< table_id >, std::less< uint64_t > > > > > key_value_index
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
chainbase::shared_multi_index_container< protocol_state_object, indexed_by< ordered_unique< tag< by_id >, > > > protocol_state_multi_index
chainbase::shared_multi_index_container< account_metadata_object, indexed_by< ordered_unique< tag< by_id >, member< account_metadata_object, account_metadata_object::id_type, &account_metadata_object::id > >, ordered_unique< tag< by_name >, member< account_metadata_object, account_name, &account_metadata_object::name > > > > account_metadata_index
secondary_index< float128_t, index_long_double_object_type, soft_long_double_less >::index_index index_long_double_index
std::vector< table_delta > create_deltas(const chainbase::database &db, bool full_snapshot)
bool include_delta(const T &old, const T &curr)
#define T(meth, val, expected)
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
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.