Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Deep Mind off-chain ABI serializer & FC encoded hex output #9073

Merged
merged 7 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,6 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
}

if (auto dm_logger = control.get_deep_mind_logger()) {
fc::datastream<const char*> ds( ptr->packed_trx.data(), ptr->packed_trx.size() );
transaction dtrx;
fc::raw::unpack(ds, dtrx);

fc_dlog(*dm_logger, "DTRX_OP MODIFY_CANCEL ${action_id} ${sender} ${sender_id} ${payer} ${published} ${delay} ${expiration} ${trx_id} ${trx}",
("action_id", get_action_id())
("sender", receiver)
Expand All @@ -594,8 +590,8 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
("published", ptr->published)
("delay", ptr->delay_until)
("expiration", ptr->expiration)
("trx_id", dtrx.id())
("trx", control.maybe_to_variant_with_abi(dtrx, abi_serializer::create_yield_function(control.get_abi_serializer_max_time())))
("trx_id", ptr->trx_id)
("trx", fc::to_hex(ptr->packed_trx.data(), ptr->packed_trx.size()))
);
}

Expand Down Expand Up @@ -626,7 +622,7 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
("delay", gtx.delay_until)
("expiration", gtx.expiration)
("trx_id", trx.id())
("trx", control.maybe_to_variant_with_abi(trx, abi_serializer::create_yield_function(control.get_abi_serializer_max_time())))
("trx", fc::to_hex(gtx.packed_trx.data(), gtx.packed_trx.size()))
);
}
} );
Expand Down Expand Up @@ -654,8 +650,8 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
("published", gtx.published)
("delay", gtx.delay_until)
("expiration", gtx.expiration)
("trx_id", trx.id())
("trx", control.maybe_to_variant_with_abi(trx, abi_serializer::create_yield_function(control.get_abi_serializer_max_time())))
("trx_id", gtx.trx_id)
("trx", fc::to_hex(gtx.packed_trx.data(), gtx.packed_trx.size()))
);
}
} );
Expand All @@ -678,10 +674,6 @@ bool apply_context::cancel_deferred_transaction( const uint128_t& sender_id, acc
if ( gto ) {
std::string event_id;
if (auto dm_logger = control.get_deep_mind_logger()) {
fc::datastream<const char*> ds( gto->packed_trx.data(), gto->packed_trx.size() );
transaction dtrx;
fc::raw::unpack(ds, dtrx);

event_id = STORAGE_EVENT_ID("${id}", ("id", gto->id));

fc_dlog(*dm_logger, "DTRX_OP CANCEL ${action_id} ${sender} ${sender_id} ${payer} ${published} ${delay} ${expiration} ${trx_id} ${trx}",
Expand All @@ -692,8 +684,8 @@ bool apply_context::cancel_deferred_transaction( const uint128_t& sender_id, acc
("published", gto->published)
("delay", gto->delay_until)
("expiration", gto->expiration)
("trx_id", dtrx.id())
("trx", control.maybe_to_variant_with_abi(dtrx, abi_serializer::create_yield_function(control.get_abi_serializer_max_time())))
("trx_id", gto->trx_id)
("trx", fc::to_hex(gto->packed_trx.data(), gto->packed_trx.size()))
);
}

Expand Down
12 changes: 8 additions & 4 deletions libraries/chain/authorization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ namespace eosio { namespace chain {
p.auth = auth;

if (auto dm_logger = _control.get_deep_mind_logger()) {
fc_dlog(*dm_logger, "PERM_OP INS ${action_id} ${data}",
fc_dlog(*dm_logger, "PERM_OP INS ${action_id} ${permission_id} ${data}",
("action_id", action_id)
("permission_id", p.id)
("data", p)
);
}
Expand Down Expand Up @@ -198,8 +199,9 @@ namespace eosio { namespace chain {
p.auth = std::move(auth);

if (auto dm_logger = _control.get_deep_mind_logger()) {
fc_dlog(*dm_logger, "PERM_OP INS ${action_id} ${data}",
fc_dlog(*dm_logger, "PERM_OP INS ${action_id} ${permission_id} ${data}",
("action_id", action_id)
("permission_id", p.id)
("data", p)
);
}
Expand All @@ -224,8 +226,9 @@ namespace eosio { namespace chain {
po.last_updated = _control.pending_block_time();

if (auto dm_logger = _control.get_deep_mind_logger()) {
fc_dlog(*dm_logger, "PERM_OP UPD ${action_id} ${data}",
fc_dlog(*dm_logger, "PERM_OP UPD ${action_id} ${permission_id} ${data}",
("action_id", action_id)
("permission_id", po.id)
("data", fc::mutable_variant_object()
("old", old_permission)
("new", po)
Expand All @@ -244,8 +247,9 @@ namespace eosio { namespace chain {
_db.get_mutable_index<permission_usage_index>().remove_object( permission.usage_id._id );

if (auto dm_logger = _control.get_deep_mind_logger()) {
fc_dlog(*dm_logger, "PERM_OP REM ${action_id} ${data}",
fc_dlog(*dm_logger, "PERM_OP REM ${action_id} ${permission_id} ${data}",
("action_id", action_id)
("permission_id", permission.id)
("data", permission)
);
}
Expand Down
28 changes: 26 additions & 2 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,26 @@ struct controller_impl {
// else no checks needed since fork_db will be completely reset on replay anyway
}

if (auto dm_logger = get_deep_mind_logger()) {
// FIXME: We should probably feed that from CMake directly somehow ...
fc_dlog(*dm_logger, "DEEP_MIND_VERSION 13 0");

fc_dlog(*dm_logger, "ABIDUMP START ${block_num} ${global_sequence_num}",
("block_num", head->block_num)
("global_sequence_num", db.get<dynamic_global_property_object>().global_action_sequence)
);
const auto& idx = db.get_index<account_index>();
for (auto& row : idx.indices()) {
if (row.abi.size() != 0) {
fc_dlog(*dm_logger, "ABIDUMP ABI ${contract} ${abi}",
("contract", row.name)
("abi", row.abi)
);
}
}
fc_dlog(*dm_logger, "ABIDUMP END");
}

if( last_block_num > head->block_num ) {
replay( check_shutdown ); // replay any irreversible and reversible blocks ahead of current head
}
Expand Down Expand Up @@ -894,9 +914,11 @@ struct controller_impl {
}

if (auto dm_logger = get_deep_mind_logger()) {
auto packed_trx = fc::raw::pack(etrx);

fc_dlog(*dm_logger, "TRX_OP CREATE onerror ${id} ${trx}",
("id", etrx.id())
("trx", self.maybe_to_variant_with_abi(etrx, abi_serializer::create_yield_function(self.get_abi_serializer_max_time())))
("trx", fc::to_hex(packed_trx))
);
}

Expand Down Expand Up @@ -2253,9 +2275,11 @@ struct controller_impl {
}

if (auto dm_logger = get_deep_mind_logger()) {
auto packed_trx = fc::raw::pack(trx);

fc_dlog(*dm_logger, "TRX_OP CREATE onblock ${id} ${trx}",
("id", trx.id())
("trx", self.maybe_to_variant_with_abi(trx, abi_serializer::create_yield_function(self.get_abi_serializer_max_time())))
("trx", fc::to_hex(packed_trx))
);
}

Expand Down
5 changes: 3 additions & 2 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ namespace eosio { namespace chain {
if (auto dm_logger = control.get_deep_mind_logger()) {
event_id = STORAGE_EVENT_ID("${id}", ("id", gto.id));

auto packed_signed_trx = fc::raw::pack(packed_trx.to_packed_transaction_v0()->get_signed_transaction());
fc_dlog(*dm_logger, "DTRX_OP PUSH_CREATE ${action_id} ${sender} ${sender_id} ${payer} ${published} ${delay} ${expiration} ${trx_id} ${trx}",
("action_id", get_action_id())
("sender", gto.sender)
Expand All @@ -655,8 +656,8 @@ namespace eosio { namespace chain {
("published", gto.published)
("delay", gto.delay_until)
("expiration", gto.expiration)
("trx_id", trx.id())
("trx", control.maybe_to_variant_with_abi(trx, abi_serializer::create_yield_function(control.get_abi_serializer_max_time())))
("trx_id", gto.trx_id)
("trx", fc::to_hex(packed_signed_trx.data(), packed_signed_trx.size()))
);
}
});
Expand Down
8 changes: 6 additions & 2 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,9 +1266,11 @@ void chain_plugin::plugin_initialize(const variables_map& options) {

my->accepted_block_connection = my->chain->accepted_block.connect( [this]( const block_state_ptr& blk ) {
if (auto dm_logger = my->chain->get_deep_mind_logger()) {
auto packed_blk = fc::raw::pack(*blk);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a shared_ptr is used, it adds a first optionality byte to the binary data. So I had to use this here, but I'm wondering if this creates a copy of the structure prior packing it, I think it does.

Is there a way to avoid it if it's the case? Can I cast somehow to a const block_state& type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no copy of *blk before packing. Also, fc::raw::pack takes its argument as const T&.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's pointing to the shared_ptr gets cast as const ref, perfect thanks!


fc_dlog(*dm_logger, "ACCEPTED_BLOCK ${num} ${blk}",
("num", blk->block_num)
("blk", blk)
("blk", fc::to_hex(packed_blk))
);
}

Expand All @@ -1291,9 +1293,11 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
my->applied_transaction_connection = my->chain->applied_transaction.connect(
[this]( std::tuple<const transaction_trace_ptr&, const packed_transaction_ptr&> t ) {
if (auto dm_logger = my->chain->get_deep_mind_logger()) {
auto packed_trace = fc::raw::pack(*std::get<0>(t));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for the copy and const reference cast (for me when updating the PR).


fc_dlog(*dm_logger, "APPLIED_TRANSACTION ${block} ${traces}",
("block", my->chain->head_block_num() + 1)
("traces", my->chain->maybe_to_variant_with_abi(std::get<0>(t), abi_serializer::create_yield_function(my->chain->get_abi_serializer_max_time())))
("traces", fc::to_hex(packed_trace))
);
}

Expand Down