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

Commit

Permalink
Add formatter for trx and trx trace
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjjzhao committed Mar 14, 2022
1 parent 6c68328 commit 72bae5c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
5 changes: 4 additions & 1 deletion libraries/chain/include/eosio/chain/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ namespace eosio { namespace chain {

struct action : public action_base {
bytes data;
size_t size;
fc::sha256 code_hash;
bytes trimmed_hex;

action() = default;

Expand Down Expand Up @@ -135,4 +138,4 @@ namespace eosio { namespace chain {

FC_REFLECT( eosio::chain::permission_level, (actor)(permission) )
FC_REFLECT( eosio::chain::action_base, (account)(name)(authorization) )
FC_REFLECT_DERIVED( eosio::chain::action, (eosio::chain::action_base), (data) )
FC_REFLECT_DERIVED( eosio::chain::action, (eosio::chain::action_base), (data)/*(size)(code_hash)(trimmed_hex)*/ )
29 changes: 29 additions & 0 deletions libraries/chain/include/eosio/chain/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <eosio/chain/action.hpp>
#include <eosio/chain/action_receipt.hpp>
#include <eosio/chain/block.hpp>
#include <eosio/chain/contract_types.hpp>

namespace eosio { namespace chain {

Expand Down Expand Up @@ -157,6 +158,34 @@ namespace fmt {
return format_to( ctx.out(), "{}", p.to_detail_string());
}
};
template<typename T>
struct formatter<std::vector<T>> {
template<typename ParseContext>
constexpr auto parse( ParseContext& ctx ) { return ctx.begin(); }

template<typename FormatContext>
auto format( const std::vector<T>& p, FormatContext& ctx ) {
auto f = fmt::formatter<T>();
for( auto& i : p ) {
if constexpr (std::is_same_v<T, eosio::chain::action>){
if( i.account == eosio::chain::config::system_account_name && i.name.to_string() == "setcode" ) {
auto setcode_act = i.template data_as<eosio::chain::setcode>();
if( setcode_act.code.size() > 0 ) {
fc::sha256 code_hash = fc::sha256::hash(setcode_act.code.data(), (uint32_t) setcode_act.code.size());
std::memcpy(i.code_hash.data(), code_hash.data(), code_hash.data_size());
}
}

if (i.data.size() > 64){
i.size = i.data.size();
std::memcpy(i.trimmed_hex.data(), i.data.data(), 64);
}
}
f.format( i, ctx );
}
return format_to( ctx.out(), "");
}
};
}

FC_REFLECT( eosio::chain::account_delta,
Expand Down
35 changes: 11 additions & 24 deletions libraries/chain/include/eosio/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,30 +356,17 @@ namespace eosio { namespace chain {
} } /// namespace eosio::chain

namespace fmt {
template<typename T>
struct formatter<std::vector<T>> {
template<typename ParseContext>
constexpr auto parse( ParseContext& ctx ) { return ctx.begin(); }

template<typename FormatContext>
auto format( const std::vector<T>& p, FormatContext& ctx ) {
auto f = fmt::formatter<T>();
for( const auto& i : p ) { f.format( i, ctx ); }
return format_to( ctx.out(), "");
}
};

template<typename K, typename V>
struct formatter<std::pair<K, V>>{
template<typename ParseContext>
constexpr auto parse( ParseContext& ctx ) { return ctx.begin(); }

template<typename FormatContext>
auto format( const std::pair<K, V>& p, FormatContext& ctx ) {
fmt::formatter<V>().format(p.second, ctx);
return format_to( ctx.out(), "");
}
};
template<typename K, typename V>
struct formatter<std::pair<K, V>> {
template<typename ParseContext>
constexpr auto parse( ParseContext& ctx ) { return ctx.begin(); }

template<typename FormatContext>
auto format( const std::pair<K, V>& p, FormatContext& ctx ) {
fmt::formatter<V>().format(p.second, ctx);
return format_to( ctx.out(), "");
}
};
}

FC_REFLECT(eosio::chain::deferred_transaction_generation_context, (sender_trx_id)(sender_id)(sender) )
Expand Down
28 changes: 15 additions & 13 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
next(ex);

// fc_dlog(_trx_trace_failure_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${entire_trx}",
// ("entire_trx", self->chain_plug->get_log_trx(trx->get_transaction()).as_string()));
// ("entire_trx", self->chain_plug->get_log_trx(trx->get_transaction())));
// fc_dlog(_trx_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${trx}",
// ("trx", self->chain_plug->get_log_trx(trx->get_transaction()).as_string()));
// ("trx", self->chain_plug->get_log_trx(trx->get_transaction())));
};
try {
auto result = future.get();
Expand Down Expand Up @@ -436,11 +436,16 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin

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().to_string())
//("trx", chain_plug->get_log_trx(trx->packed_trx()->get_transaction()).as_string()));
("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().to_string())
// ("entire_trace", get_trace(response).as_string()));
if (std::holds_alternative<fc::exception_ptr>(response)){
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().to_string())
("entire_trace", *std::get<fc::exception_ptr>(response)));
} else {
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().to_string())
("entire_trace", *std::get<transaction_trace_ptr>(response)));
}
} else {
fc_dlog(_trx_failed_trace_log, "[TRX_TRACE] Speculative execution is REJECTING tx: ${txid}, auth: ${a} : ${why} ",
("txid", trx->id())
Expand Down Expand Up @@ -1478,8 +1483,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
} else if( _producers.find(scheduled_producer.producer_name) == _producers.end()) {
_pending_block_mode = pending_block_mode::speculating;
} else if (num_relevant_signatures == 0) {
//TODO: add formatter for custom type block_signing_authority_v0
// elog("Not producing block because I don't have any private keys relevant to authority: ${authority}", ("authority", scheduled_producer.authority));
elog("Not producing block because I don't have any private keys relevant to authority: ${authority}", ("authority", scheduled_producer.authority));
_pending_block_mode = pending_block_mode::speculating;
} else if ( _pause_production ) {
elog("Not producing block because production is explicitly paused");
Expand Down Expand Up @@ -1595,9 +1599,8 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
}
std::swap( features_to_activate, protocol_features_to_activate );
_protocol_features_signaled = true;
//TODO: add formatter for custom type `vector<digest_type>`
// ilog( "signaling activation of the following protocol features in block ${num}: ${features_to_activate}",
// ("num", hbs->block_num + 1)("features_to_activate", features_to_activate) );
ilog( "signaling activation of the following protocol features in block ${num}: ${features_to_activate}",
("num", hbs->block_num + 1)("features_to_activate", features_to_activate) );
}
}

Expand All @@ -1609,8 +1612,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
const fc::time_point preprocess_deadline = calculate_block_deadline(block_time);

if (_pending_block_mode == pending_block_mode::producing && pending_block_signing_authority != scheduled_producer.authority) {
//TODO: add formatter for custom type block_signing_authority_v0
// elog("Unexpected block signing authority, reverting to speculative mode! [expected: \"${expected}\", actual: \"${actual\"", ("expected", scheduled_producer.authority)("actual", pending_block_signing_authority));
elog("Unexpected block signing authority, reverting to speculative mode! [expected: \"${expected}\", actual: \"${actual\"", ("expected", scheduled_producer.authority)("actual", pending_block_signing_authority));
_pending_block_mode = pending_block_mode::speculating;
}

Expand Down

0 comments on commit 72bae5c

Please sign in to comment.