Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
deep_mind.cpp
Go to the documentation of this file.
10#include <fc/crypto/hex.hpp>
11
12namespace {
13
14 void set_trace_elapsed_to_zero(sysio::chain::action_trace& trace) {
15 trace.elapsed = fc::microseconds{};
16 }
17
18 void set_trace_elapsed_to_zero(sysio::chain::transaction_trace& trace) {
19 trace.elapsed = fc::microseconds{};
20 for (auto& act_trace : trace.action_traces) {
21 set_trace_elapsed_to_zero(act_trace);
22 }
23 }
24
25}
26
27namespace sysio::chain {
28
30 {
31 _config = std::move(config);
32 }
33
35 {
37 }
38
39 static const char* prefix(deep_mind_handler::operation_qualifier q) {
40 switch(q)
41 {
45 }
46 }
47
49 {
50 // FIXME: We should probably feed that from CMake directly somehow ...
51 fc_dlog(_logger, "DEEP_MIND_VERSION wire_sysio 13 0");
52
53 fc_dlog(_logger, "ABIDUMP START ${block_num} ${global_sequence_num}",
54 ("block_num", head_block_num)
55 ("global_sequence_num", db.get<dynamic_global_property_object>().global_action_sequence)
56 );
57 const auto& idx = db.get_index<account_index>();
58 for (auto& row : idx.indices()) {
59 if (row.abi.size() != 0) {
60 fc_dlog(_logger, "ABIDUMP ABI ${contract} ${abi}",
61 ("contract", row.name)
62 ("abi", row.abi)
63 );
64 }
65 }
66 fc_dlog(_logger, "ABIDUMP END");
67 }
68
70 {
71 fc_dlog(_logger, "START_BLOCK ${block_num}", ("block_num", block_num));
72 }
73
74 void deep_mind_handler::on_accepted_block(const std::shared_ptr<block_state>& bsp)
75 {
76 auto packed_blk = fc::raw::pack(*bsp);
77
78 fc_dlog(_logger, "ACCEPTED_BLOCK ${num} ${blk}",
79 ("num", bsp->block_num)
80 ("blk", fc::to_hex(packed_blk))
81 );
82 }
83
84 void deep_mind_handler::on_switch_forks(const block_id_type& old_head, const block_id_type& new_head)
85 {
86 fc_dlog(_logger, "SWITCH_FORK ${from_id} ${to_id}",
87 ("from_id", old_head)
88 ("to_id", new_head)
89 );
90 }
91
93 {
94 auto packed_trx = fc::raw::pack(etrx);
95
96 fc_dlog(_logger, "TRX_OP CREATE onerror ${id} ${trx}",
97 ("id", etrx.id())
98 ("trx", fc::to_hex(packed_trx))
99 );
100 }
101
103 {
104 auto packed_trx = fc::raw::pack(trx);
105
106 fc_dlog(_logger, "TRX_OP CREATE onblock ${id} ${trx}",
107 ("id", trx.id())
108 ("trx", fc::to_hex(packed_trx))
109 );
110 }
111
113 {
114 _action_id = 0;
115 }
116
118 {
119 _action_id = 0;
120 }
121
123 {
124 std::vector<char> packed_trace;
125
126 if (_config.zero_elapsed) {
127 transaction_trace trace_copy = *trace;
128 set_trace_elapsed_to_zero(trace_copy);
129 packed_trace = fc::raw::pack(trace_copy);
130
131 } else {
132 packed_trace = fc::raw::pack(*trace);
133 }
134
135 fc_dlog(_logger, "APPLIED_TRANSACTION ${block} ${traces}",
136 ("block", block_num)
137 ("traces", fc::to_hex(packed_trace))
138 );
139 }
140
142 {
143 fc_dlog(_logger, "RAM_CORRECTION_OP ${action_id} ${correction_id} ${event_id} ${payer} ${delta}",
144 ("action_id", _action_id)
145 ("correction_id", rco.id._id)
146 ("event_id", _ram_trace.event_id)
147 ("payer", rco.name)
148 ("delta", delta)
149 );
150 _ram_trace = ram_trace();
151 }
152
154 {
155 fc_dlog(_logger, "FEATURE_OP PRE_ACTIVATE ${action_id} ${feature_digest} ${feature}",
156 ("action_id", _action_id)
157 ("feature_digest", feature.feature_digest)
158 ("feature", feature.to_variant())
159 );
160 }
161
163 {
164 fc_dlog(_logger, "FEATURE_OP ACTIVATE ${feature_digest} ${feature}",
165 ("feature_digest", feature.feature_digest)
166 ("feature", feature.to_variant())
167 );
168 }
169
171 {
172 fc_dlog(_logger, "CREATION_OP ROOT ${action_id}",
173 ("action_id", _action_id)
174 );
175 }
177 {
178 ++_action_id;
179 }
181 {
182 fc_dlog(_logger, "CREATION_OP NOTIFY ${action_id}",
183 ("action_id", _action_id)
184 );
185 }
187 {
188 fc_dlog(_logger, "CREATION_OP INLINE ${action_id}",
189 ("action_id", _action_id)
190 );
191 }
193 {
194 fc_dlog(_logger, "CREATION_OP CFA_INLINE ${action_id}",
195 ("action_id", _action_id)
196 );
197 }
199 {
200 fc_dlog(_logger, "DTRX_OP ${qual}CANCEL ${action_id} ${sender} ${sender_id} ${payer} ${published} ${delay} ${expiration} ${trx_id} ${trx}",
201 ("qual", prefix(qual))
202 ("action_id", _action_id)
203 ("sender", gto.sender)
204 ("sender_id", gto.sender_id)
205 ("payer", gto.payer)
206 ("published", gto.published)
207 ("delay", gto.delay_until)
208 ("expiration", gto.expiration)
209 ("trx_id", gto.trx_id)
210 ("trx", fc::to_hex(gto.packed_trx.data(), gto.packed_trx.size()))
211 );
212 }
214 {
215 fc_dlog(_logger, "DTRX_OP ${qual}CREATE ${action_id} ${sender} ${sender_id} ${payer} ${published} ${delay} ${expiration} ${trx_id} ${trx}",
216 ("qual", prefix(qual))
217 ("action_id", _action_id)
218 ("sender", gto.sender)
219 ("sender_id", gto.sender_id)
220 ("payer", gto.payer)
221 ("published", gto.published)
222 ("delay", gto.delay_until)
223 ("expiration", gto.expiration)
224 ("trx_id", gto.trx_id)
225 ("trx", fc::to_hex(gto.packed_trx.data(), gto.packed_trx.size()))
226 );
227 }
229 {
230 auto packed_signed_trx = fc::raw::pack(packed_trx.get_signed_transaction());
231
232 fc_dlog(_logger, "DTRX_OP ${qual}CREATE ${action_id} ${sender} ${sender_id} ${payer} ${published} ${delay} ${expiration} ${trx_id} ${trx}",
233 ("qual", prefix(qual))
234 ("action_id", _action_id)
235 ("sender", gto.sender)
236 ("sender_id", gto.sender_id)
237 ("payer", gto.payer)
238 ("published", gto.published)
239 ("delay", gto.delay_until)
240 ("expiration", gto.expiration)
241 ("trx_id", gto.trx_id)
242 ("trx", fc::to_hex(packed_signed_trx.data(), packed_signed_trx.size()))
243 );
244 }
246 {
247 fc_dlog(_logger, "DTRX_OP FAILED ${action_id}",
248 ("action_id", _action_id)
249 );
250 }
252 {
253 fc_dlog(_logger, "TBL_OP INS ${action_id} ${code} ${scope} ${table} ${payer}",
254 ("action_id", _action_id)
255 ("code", tid.code)
256 ("scope", tid.scope)
257 ("table", tid.table)
258 ("payer", tid.payer)
259 );
260 }
262 {
263 fc_dlog(_logger, "TBL_OP REM ${action_id} ${code} ${scope} ${table} ${payer}",
264 ("action_id", _action_id)
265 ("code", tid.code)
266 ("scope", tid.scope)
267 ("table", tid.table)
268 ("payer", tid.payer)
269 );
270 }
272 {
273 fc_dlog(_logger, "DB_OP INS ${action_id} ${payer} ${table_code} ${scope} ${table_name} ${primkey} ${ndata}",
274 ("action_id", _action_id)
275 ("payer", kvo.payer)
276 ("table_code", tid.code)
277 ("scope", tid.scope)
278 ("table_name", tid.table)
279 ("primkey", name(kvo.primary_key))
280 ("ndata", fc::to_hex(kvo.value.data(), kvo.value.size()))
281 );
282 }
283 void deep_mind_handler::on_db_update_i64(const table_id_object& tid, const key_value_object& kvo, account_name payer, const char* buffer, std::size_t buffer_size)
284 {
285 fc_dlog(_logger, "DB_OP UPD ${action_id} ${opayer}:${npayer} ${table_code} ${scope} ${table_name} ${primkey} ${odata}:${ndata}",
286 ("action_id", _action_id)
287 ("opayer", kvo.payer)
288 ("npayer", payer)
289 ("table_code", tid.code)
290 ("scope", tid.scope)
291 ("table_name", tid.table)
292 ("primkey", name(kvo.primary_key))
293 ("odata", fc::to_hex(kvo.value.data(),kvo.value.size()))
294 ("ndata", fc::to_hex(buffer, buffer_size))
295 );
296 }
298 {
299 fc_dlog(_logger, "DB_OP REM ${action_id} ${payer} ${table_code} ${scope} ${table_name} ${primkey} ${odata}",
300 ("action_id", _action_id)
301 ("payer", kvo.payer)
302 ("table_code", tid.code)
303 ("scope", tid.scope)
304 ("table_name", tid.table)
305 ("primkey", name(kvo.primary_key))
306 ("odata", fc::to_hex(kvo.value.data(), kvo.value.size()))
307 );
308 }
310 {
311 fc_dlog(_logger, "RLIMIT_OP CONFIG INS ${data}",
312 ("data", config)
313 );
314 fc_dlog(_logger, "RLIMIT_OP STATE INS ${data}",
315 ("data", state)
316 );
317 }
319 {
320 fc_dlog(_logger, "RLIMIT_OP CONFIG UPD ${data}",
321 ("data", config)
322 );
323 }
325 {
326 fc_dlog(_logger, "RLIMIT_OP STATE UPD ${data}",
327 ("data", state)
328 );
329 }
331 {
332 fc_dlog(_logger, "RLIMIT_OP ACCOUNT_LIMITS INS ${data}",
333 ("data", limits)
334 );
335 fc_dlog(_logger, "RLIMIT_OP ACCOUNT_USAGE INS ${data}",
336 ("data", usage)
337 );
338 }
340 {
341 fc_dlog(_logger, "RLIMIT_OP ACCOUNT_USAGE UPD ${data}",
342 ("data", usage)
343 );
344 }
346 {
347 fc_dlog(_logger, "RLIMIT_OP ACCOUNT_LIMITS UPD ${data}",
348 ("data", limits)
349 );
350 }
351 void deep_mind_handler::on_ram_trace(std::string&& event_id, const char* family, const char* operation, const char* legacy_tag)
352 {
353 _ram_trace = ram_trace(std::move(event_id), family, operation, legacy_tag);
354 }
356 {
357 fc_dlog(_logger, "RAM_OP ${action_id} ${event_id} ${family} ${operation} ${legacy_tag} ${payer} ${new_usage} ${delta}",
358 ("action_id", _action_id)
359 ("event_id", _ram_trace.event_id)
360 ("family", _ram_trace.family)
361 ("operation", _ram_trace.operation)
362 ("legacy_tag", _ram_trace.legacy_tag)
363 ("payer", account)
364 ("new_usage", new_usage)
365 ("delta", delta)
366 );
367 _ram_trace = ram_trace();
368 }
369
371 {
372 fc_dlog(_logger, "PERM_OP INS ${action_id} ${permission_id} ${data}",
373 ("action_id", _action_id)
374 ("permission_id", p.id)
375 ("data", p)
376 );
377 }
378 void deep_mind_handler::on_modify_permission(const permission_object& old_permission, const permission_object& new_permission)
379 {
380 fc_dlog(_logger, "PERM_OP UPD ${action_id} ${permission_id} ${data}",
381 ("action_id", _action_id)
382 ("permission_id", new_permission.id)
384 ("old", old_permission)
385 ("new", new_permission)
386 )
387 );
388 }
390 {
391 fc_dlog(_logger, "PERM_OP REM ${action_id} ${permission_id} ${data}",
392 ("action_id", _action_id)
393 ("permission_id", permission.id)
394 ("data", permission)
395 );
396 }
397
398}
const mie::Vuint & p
Definition bn.cpp:27
const generic_index< MultiIndexType > & get_index() const
const ObjectType & get(CompatibleKey &&key) const
static void update(const fc::string &name, logger &log)
Definition logger.cpp:92
An order-preserving dictionary of variants.
void on_cancel_deferred(operation_qualifier qual, const generated_transaction_object &gto)
void on_activate_feature(const protocol_feature &feature)
void on_modify_permission(const permission_object &old_permission, const permission_object &new_permission)
void on_newaccount_resource_limits(const resource_limits::resource_limits_object &limits, const resource_limits::resource_usage_object &usage)
void on_startup(chainbase::database &db, uint32_t head_block_num)
Definition deep_mind.cpp:48
void on_preactivate_feature(const protocol_feature &feature)
void on_create_deferred(operation_qualifier qual, const generated_transaction_object &gto, const packed_transaction &packed_trx)
void on_db_remove_i64(const table_id_object &tid, const key_value_object &kvo)
void on_update_resource_limits_state(const resource_limits::resource_limits_state_object &state)
void on_accepted_block(const std::shared_ptr< block_state > &bsp)
Definition deep_mind.cpp:74
void on_update_resource_limits_config(const resource_limits::resource_limits_config_object &config)
void update_config(deep_mind_config config)
Definition deep_mind.cpp:29
void on_onerror(const signed_transaction &etrx)
Definition deep_mind.cpp:92
void on_db_store_i64(const table_id_object &tid, const key_value_object &kvo)
void on_switch_forks(const block_id_type &old_head, const block_id_type &new_head)
Definition deep_mind.cpp:84
void on_remove_table(const table_id_object &tid)
void on_update_account_usage(const resource_limits::resource_usage_object &usage)
void on_start_block(uint32_t block_num)
Definition deep_mind.cpp:69
void on_send_deferred(operation_qualifier qual, const generated_transaction_object &gto)
void on_db_update_i64(const table_id_object &tid, const key_value_object &kvo, account_name payer, const char *buffer, std::size_t buffer_size)
void update_logger(const std::string &logger_name)
Definition deep_mind.cpp:34
void on_create_permission(const permission_object &p)
void on_add_ram_correction(const account_ram_correction_object &rco, uint64_t delta)
void on_set_account_limits(const resource_limits::resource_limits_object &limits)
void on_create_table(const table_id_object &tid)
void on_onblock(const signed_transaction &trx)
void on_remove_permission(const permission_object &permission)
void on_ram_event(account_name account, uint64_t new_usage, int64_t delta)
void on_ram_trace(std::string &&event_id, const char *family, const char *operation, const char *legacy_tag)
void on_init_resource_limits(const resource_limits::resource_limits_config_object &config, const resource_limits::resource_limits_state_object &state)
void on_applied_transaction(uint32_t block_num, const std::shared_ptr< transaction_trace > &trace)
Maintains global state information that frequently change.
The table_id_object class tracks the mapping of (scope, code, table) to an opaque identifier.
#define fc_dlog(LOGGER, FORMAT,...)
Definition logger.hpp:77
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
fc::string to_hex(const char *d, uint32_t s)
Definition hex.cpp:17
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
std::shared_ptr< transaction_trace > transaction_trace_ptr
Definition trace.hpp:20
const fc::string logger_name("net_plugin_impl")
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
fc::microseconds elapsed
Definition trace.hpp:38
Immutable except for fc::from_variant.
Definition name.hpp:43
const signed_transaction & get_signed_transaction() const
const char * legacy_tag
Definition deep_mind.hpp:39
fc::microseconds elapsed
Definition trace.hpp:56
vector< action_trace > action_traces
Definition trace.hpp:59
transaction_id_type id() const