Skip to content

Commit

Permalink
Merge pull request #9073 from dfuse-io/feature/offchain-abi-and-hex-o…
Browse files Browse the repository at this point in the history
…utput

Deep Mind off-chain ABI serializer & FC encoded hex output
  • Loading branch information
b1bart authored Dec 3, 2020
2 parents b6b6043 + 786832b commit f6f6c40
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
22 changes: 7 additions & 15 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,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 @@ -595,8 +591,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 @@ -627,7 +623,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 @@ -655,8 +651,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 @@ -679,10 +675,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 @@ -693,8 +685,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 @@ -2254,9 +2276,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 @@ -1281,9 +1281,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);

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

Expand All @@ -1306,9 +1308,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));

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

0 comments on commit f6f6c40

Please sign in to comment.