Skip to content

Commit

Permalink
Merge pull request #733 from eosnetworkfoundation/detailed_except_inf…
Browse files Browse the repository at this point in the history
…o_trx_trace

[3.2] return the error from the contract itself in the transaction trace log message for asserts
  • Loading branch information
linh2931 authored Aug 16, 2022
2 parents 1f1243d + 900b2a2 commit 98dc651
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,30 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
});
}

// Returns contract name, action name, and exception text
// of an exception occured in a contract
std::string get_detailed_contract_exception_info(const fc::exception_ptr& except_ptr,
const std::variant<fc::exception_ptr, transaction_trace_ptr>& response) {
account_name contract_name;
action_name act_name;
std::string details;

if (std::holds_alternative<transaction_trace_ptr>(response)) {
auto resp_ptr = std::get<transaction_trace_ptr>(response);
if (resp_ptr && !resp_ptr->action_traces.empty()) {
auto last_action_ordinal = resp_ptr->action_traces.size() - 1;
contract_name = resp_ptr->action_traces[last_action_ordinal].receiver;
act_name = resp_ptr->action_traces[last_action_ordinal].act.name;
}
}

if (except_ptr) {
details = fc::format_string("${d}", fc::mutable_variant_object() ("d", except_ptr->top_message()), true); // true for limitting the formatted string size
}

return "action:" + contract_name.to_string() + ":" + act_name.to_string() + ":" + details;
}

bool process_incoming_transaction_async(const transaction_metadata_ptr& trx,
bool persist_until_expired,
bool return_failure_traces,
Expand Down Expand Up @@ -548,23 +572,23 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin

if (except_ptr) {
if (_pending_block_mode == pending_block_mode::producing) {
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${txid}, auth: ${a} : ${why} ",
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${txid}, auth: ${a}, ${details}",
("block_num", chain.head_block_num() + 1)
("prod", get_pending_block_producer())
("txid", trx->id())
("a", trx->packed_trx()->get_transaction().first_authorizer())
("why", except_ptr->what()));
("details", get_detailed_contract_exception_info(except_ptr, response)));
fc_dlog(_trx_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${trx}",
("block_num", chain.head_block_num() + 1)("prod", get_pending_block_producer())
("trx", chain_plug->get_log_trx(trx->packed_trx()->get_transaction())));
fc_dlog(_trx_trace_failure_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING tx: ${entire_trace}",
("block_num", chain.head_block_num() + 1)("prod", get_pending_block_producer())
("entire_trace", get_trace(response)));
} else {
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid}, auth: ${a} : ${why} ",
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid}, auth: ${a} : ${details}",
("txid", trx->id())
("a", trx->packed_trx()->get_transaction().first_authorizer())
("why", except_ptr->what()));
("details", get_detailed_contract_exception_info(except_ptr, response)));
fc_dlog(_trx_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${trx} ",
("trx", chain_plug->get_log_trx(trx->packed_trx()->get_transaction())));
fc_dlog(_trx_trace_failure_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${entire_trace} ",
Expand Down Expand Up @@ -2085,10 +2109,10 @@ void producer_plugin_impl::process_scheduled_and_incoming_trxs( const fc::time_p
}
} else {
fc_dlog(_trx_failed_trace_log,
"[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING scheduled tx: ${txid}, time: ${r}, auth: ${a} : ${why} ",
"[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING scheduled tx: ${txid}, time: ${r}, auth: ${a} : ${details}",
("block_num", chain.head_block_num() + 1)("prod", get_pending_block_producer())
("txid", trx_id)("r", fc::time_point::now() - start)("a", get_first_authorizer(trace))
("why", trace->except->what()));
("details", get_detailed_contract_exception_info(trace->except->dynamic_copy_exception(), trace)));
fc_dlog(_trx_trace_failure_log, "[TRX_TRACE] Block ${block_num} for producer ${prod} is REJECTING scheduled tx: ${entire_trace}",
("block_num", chain.head_block_num() + 1)("prod", get_pending_block_producer())
("entire_trace", chain_plug->get_log_trx_trace(trace)));
Expand Down

0 comments on commit 98dc651

Please sign in to comment.