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

Commit

Permalink
Merge pull request #7309 from EOSIO/ship-debug-mode-develop
Browse files Browse the repository at this point in the history
add debug_mode to state history plugin - develop
  • Loading branch information
arhag authored May 8, 2019
2 parents be76897 + 8b21822 commit 1feae7e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 33 deletions.
17 changes: 17 additions & 0 deletions libraries/chain/include/eosio/chain/resource_limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ namespace eosio { namespace chain { namespace resource_limits {
static_assert(std::is_integral<T>::value, "ratios must have integral types");
T numerator;
T denominator;

friend inline bool operator ==( const ratio& lhs, const ratio& rhs ) {
return std::tie(lhs.numerator, lhs.denominator) == std::tie(rhs.numerator, rhs.denominator);
}

friend inline bool operator !=( const ratio& lhs, const ratio& rhs ) {
return !(lhs == rhs);
}
};
}

Expand All @@ -27,6 +35,15 @@ namespace eosio { namespace chain { namespace resource_limits {
ratio expand_rate; // the rate at which an uncongested resource expands its limits

void validate()const; // throws if the parameters do not satisfy basic sanity checks

friend inline bool operator ==( const elastic_limit_parameters& lhs, const elastic_limit_parameters& rhs ) {
return std::tie(lhs.target, lhs.max, lhs.periods, lhs.max_multiplier, lhs.contract_rate, lhs.expand_rate)
== std::tie(rhs.target, rhs.max, rhs.periods, rhs.max_multiplier, rhs.contract_rate, rhs.expand_rate);
}

friend inline bool operator !=( const elastic_limit_parameters& lhs, const elastic_limit_parameters& rhs ) {
return !(lhs == rhs);
}
};

struct account_resource_limit {
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/resource_limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void resource_limits_manager::set_block_parameters(const elastic_limit_parameter
cpu_limit_parameters.validate();
net_limit_parameters.validate();
const auto& config = _db.get<resource_limits_config_object>();
if( config.cpu_limit_parameters == cpu_limit_parameters && config.net_limit_parameters == net_limit_parameters )
return;
_db.modify(config, [&](resource_limits_config_object& c){
c.cpu_limit_parameters = cpu_limit_parameters;
c.net_limit_parameters = net_limit_parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
#include <eosio/chain_plugin/chain_plugin.hpp>
#include <eosio/state_history_plugin/state_history_plugin.hpp>

#include <type_traits>

template <typename T>
struct history_serial_wrapper {
const chainbase::database& db;
const T& obj;
};

template <typename T>
history_serial_wrapper<T> make_history_serial_wrapper(const chainbase::database& db, const T& obj) {
history_serial_wrapper<std::decay_t<T>> make_history_serial_wrapper(const chainbase::database& db, const T& obj) {
return {db, obj};
}

Expand All @@ -37,7 +39,8 @@ struct history_context_wrapper {
};

template <typename P, typename T>
history_context_wrapper<P, T> make_history_context_wrapper(const chainbase::database& db, P& context, const T& obj) {
history_context_wrapper<std::decay_t<P>, std::decay_t<T>>
make_history_context_wrapper(const chainbase::database& db, const P& context, const T& obj) {
return {db, context, obj};
}

Expand Down Expand Up @@ -67,6 +70,16 @@ datastream<ST>& history_serialize_container(datastream<ST>& ds, const chainbase:
return ds;
}

template <typename ST, typename P, typename T>
datastream<ST>& history_context_serialize_container(datastream<ST>& ds, const chainbase::database& db, const P& context,
const std::vector<T>& v) {
fc::raw::pack(ds, unsigned_int(v.size()));
for (const auto& x : v) {
ds << make_history_context_wrapper(db, context, x);
}
return ds;
}

template <typename ST, typename T>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_big_vector_wrapper<T>& obj) {
FC_ASSERT(obj.obj.size() <= 1024 * 1024 * 1024);
Expand Down Expand Up @@ -96,6 +109,11 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<std:
return history_serialize_container(ds, obj.db, obj.obj);
}

template <typename ST, typename P, typename T>
datastream<ST>& operator<<(datastream<ST>& ds, const history_context_wrapper<P, std::vector<T>>& obj) {
return history_context_serialize_container(ds, obj.db, obj.context, obj.obj);
}

template <typename ST, typename First, typename Second>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<std::pair<First, Second>>& obj) {
fc::raw::pack(ds, obj.obj.first);
Expand Down Expand Up @@ -151,8 +169,8 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi

template <typename ST>
datastream<ST>&
operator<<(datastream<ST>& ds,
const history_context_wrapper<const eosio::chain::table_id_object, eosio::chain::key_value_object>& obj) {
operator<<(datastream<ST>& ds,
const history_context_wrapper<eosio::chain::table_id_object, eosio::chain::key_value_object>& obj) {
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, as_type<uint64_t>(obj.context.code.value));
fc::raw::pack(ds, as_type<uint64_t>(obj.context.scope.value));
Expand Down Expand Up @@ -208,36 +226,36 @@ datastream<ST>& serialize_secondary_index(datastream<ST>& ds, const eosio::chain

template <typename ST>
datastream<ST>&
operator<<(datastream<ST>& ds,
const history_context_wrapper<const eosio::chain::table_id_object, eosio::chain::index64_object>& obj) {
operator<<(datastream<ST>& ds,
const history_context_wrapper<eosio::chain::table_id_object, eosio::chain::index64_object>& obj) {
return serialize_secondary_index(ds, obj.context, obj.obj);
}

template <typename ST>
datastream<ST>&
operator<<(datastream<ST>& ds,
const history_context_wrapper<const eosio::chain::table_id_object, eosio::chain::index128_object>& obj) {
operator<<(datastream<ST>& ds,
const history_context_wrapper<eosio::chain::table_id_object, eosio::chain::index128_object>& obj) {
return serialize_secondary_index(ds, obj.context, obj.obj);
}

template <typename ST>
datastream<ST>&
operator<<(datastream<ST>& ds,
const history_context_wrapper<const eosio::chain::table_id_object, eosio::chain::index256_object>& obj) {
operator<<(datastream<ST>& ds,
const history_context_wrapper<eosio::chain::table_id_object, eosio::chain::index256_object>& obj) {
return serialize_secondary_index(ds, obj.context, obj.obj);
}

template <typename ST>
datastream<ST>&
operator<<(datastream<ST>& ds,
const history_context_wrapper<const eosio::chain::table_id_object, eosio::chain::index_double_object>& obj) {
operator<<(datastream<ST>& ds,
const history_context_wrapper<eosio::chain::table_id_object, eosio::chain::index_double_object>& obj) {
return serialize_secondary_index(ds, obj.context, obj.obj);
}

template <typename ST>
datastream<ST>& operator<<(
datastream<ST>& ds,
const history_context_wrapper<const eosio::chain::table_id_object, eosio::chain::index_long_double_object>& obj) {
datastream<ST>& ds,
const history_context_wrapper<eosio::chain::table_id_object, eosio::chain::index_long_double_object>& obj) {
return serialize_secondary_index(ds, obj.context, obj.obj);
}

Expand Down Expand Up @@ -516,8 +534,25 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi
return ds;
}

inline fc::optional<uint64_t> cap_error_code( const fc::optional<uint64_t>& error_code ) {
fc::optional<uint64_t> result;

if (!error_code) return result;

const uint64_t upper_limit = static_cast<uint64_t>(eosio::chain::system_error_code::generic_system_error);

if (*error_code >= upper_limit) {
result = upper_limit;
return result;
}

result = error_code;
return result;
}

template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosio::chain::action_trace>& obj) {
datastream<ST>& operator<<(datastream<ST>& ds, const history_context_wrapper<bool, eosio::chain::action_trace>& obj) {
bool debug_mode = obj.context;
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, as_type<fc::unsigned_int>(obj.obj.action_ordinal));
fc::raw::pack(ds, as_type<fc::unsigned_int>(obj.obj.creator_action_ordinal));
Expand All @@ -528,23 +563,33 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi
fc::raw::pack(ds, as_type<uint64_t>(obj.obj.receiver.value));
fc::raw::pack(ds, make_history_serial_wrapper(obj.db, as_type<eosio::chain::action>(obj.obj.act)));
fc::raw::pack(ds, as_type<bool>(obj.obj.context_free));
fc::raw::pack(ds, as_type<int64_t>(obj.obj.elapsed.count()));
fc::raw::pack(ds, as_type<std::string>(obj.obj.console));
fc::raw::pack(ds, as_type<int64_t>(debug_mode ? obj.obj.elapsed.count() : 0));
if (debug_mode)
fc::raw::pack(ds, as_type<std::string>(obj.obj.console));
else
fc::raw::pack(ds, std::string{});
history_serialize_container(ds, obj.db, as_type<flat_set<eosio::chain::account_delta>>(obj.obj.account_ram_deltas));

fc::optional<std::string> e;
if (obj.obj.except)
e = obj.obj.except->to_string();
if (obj.obj.except) {
if (debug_mode)
e = obj.obj.except->to_string();
else
e = "Y";
}
fc::raw::pack(ds, as_type<fc::optional<std::string>>(e));
fc::raw::pack(ds, as_type<fc::optional<uint64_t>>(obj.obj.error_code));
fc::raw::pack(ds, as_type<fc::optional<uint64_t>>(debug_mode ? obj.obj.error_code
: cap_error_code(obj.obj.error_code)));

return ds;
}

template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds,
const history_context_wrapper<uint8_t, eosio::augmented_transaction_trace>& obj) {
datastream<ST>& operator<<(datastream<ST>& ds,
const history_context_wrapper<std::pair<uint8_t, bool>,
eosio::augmented_transaction_trace>& obj) {
auto& trace = *obj.obj.trace;
bool debug_mode = obj.context.second;
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, as_type<eosio::chain::transaction_id_type>(trace.id));
if (trace.receipt) {
Expand All @@ -555,14 +600,15 @@ datastream<ST>& operator<<(datastream<ST>&
fc::raw::pack(ds, as_type<uint32_t>(trace.receipt->cpu_usage_us));
fc::raw::pack(ds, as_type<fc::unsigned_int>(trace.receipt->net_usage_words));
} else {
fc::raw::pack(ds, uint8_t(obj.context));
fc::raw::pack(ds, uint8_t(obj.context.first));
fc::raw::pack(ds, uint32_t(0));
fc::raw::pack(ds, fc::unsigned_int(0));
}
fc::raw::pack(ds, as_type<int64_t>(trace.elapsed.count()));
fc::raw::pack(ds, as_type<int64_t>(debug_mode ? trace.elapsed.count() : 0));
fc::raw::pack(ds, as_type<uint64_t>(trace.net_usage));
fc::raw::pack(ds, as_type<bool>(trace.scheduled));
history_serialize_container(ds, obj.db, as_type<std::vector<eosio::chain::action_trace>>(trace.action_traces));
history_context_serialize_container(ds, obj.db, debug_mode,
as_type<std::vector<eosio::chain::action_trace>>(trace.action_traces));

fc::raw::pack(ds, bool(trace.account_ram_delta));
if (trace.account_ram_delta) {
Expand All @@ -571,19 +617,25 @@ datastream<ST>& operator<<(datastream<ST>&
}

fc::optional<std::string> e;
if (trace.except)
e = trace.except->to_string();
if (trace.except) {
if (debug_mode)
e = trace.except->to_string();
else
e = "Y";
}
fc::raw::pack(ds, as_type<fc::optional<std::string>>(e));
fc::raw::pack(ds, as_type<fc::optional<uint64_t>>(trace.error_code));
fc::raw::pack(ds, as_type<fc::optional<uint64_t>>(debug_mode ? trace.error_code
: cap_error_code(trace.error_code)));

fc::raw::pack(ds, bool(trace.failed_dtrx_trace));
if (trace.failed_dtrx_trace) {
uint8_t stat = eosio::chain::transaction_receipt_header::hard_fail;
if (trace.receipt && trace.receipt->status.value == eosio::chain::transaction_receipt_header::soft_fail)
stat = eosio::chain::transaction_receipt_header::soft_fail;
std::pair<uint8_t, bool> context = std::make_pair(stat, debug_mode);
fc::raw::pack( //
ds, make_history_context_wrapper(
obj.db, stat, eosio::augmented_transaction_trace{trace.failed_dtrx_trace, obj.obj.partial}));
obj.db, context, eosio::augmented_transaction_trace{trace.failed_dtrx_trace, obj.obj.partial}));
}

bool include_partial = obj.obj.partial && !trace.failed_dtrx_trace;
Expand All @@ -606,9 +658,10 @@ datastream<ST>& operator<<(datastream<ST>&
}

template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosio::augmented_transaction_trace>& obj) {
uint8_t stat = eosio::chain::transaction_receipt_header::hard_fail;
ds << make_history_context_wrapper(obj.db, stat, obj.obj);
datastream<ST>& operator<<(datastream<ST>& ds,
const history_context_wrapper<bool, eosio::augmented_transaction_trace>& obj) {
std::pair<uint8_t, bool> context = std::make_pair(eosio::chain::transaction_receipt_header::hard_fail, obj.context);
ds << make_history_context_wrapper(obj.db, context, obj.obj);
return ds;
}

Expand Down
9 changes: 8 additions & 1 deletion plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
chain_plugin* chain_plug = nullptr;
fc::optional<state_history_log> trace_log;
fc::optional<state_history_log> chain_state_log;
bool trace_debug_mode = false;
bool stopping = false;
fc::optional<scoped_connection> applied_transaction_connection;
fc::optional<scoped_connection> accepted_block_connection;
Expand Down Expand Up @@ -441,7 +442,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
onblock_trace.reset();

auto& db = chain_plug->chain().db();
auto traces_bin = zlib_compress_bytes(fc::raw::pack(make_history_serial_wrapper(db, traces)));
auto traces_bin = zlib_compress_bytes(fc::raw::pack(make_history_context_wrapper(db, trace_debug_mode, traces)));
EOS_ASSERT(traces_bin.size() == (uint32_t)traces_bin.size(), plugin_exception, "traces is too big");

state_history_log_header header{.magic = ship_magic(ship_current_version),
Expand Down Expand Up @@ -570,6 +571,8 @@ void state_history_plugin::set_program_options(options_description& cli, options
options("state-history-endpoint", bpo::value<string>()->default_value("127.0.0.1:8080"),
"the endpoint upon which to listen for incoming connections. Caution: only expose this port to "
"your internal network.");
options("trace-history-debug-mode", bpo::bool_switch()->default_value(false),
"enable debug mode for trace history");
}

void state_history_plugin::plugin_initialize(const variables_map& options) {
Expand Down Expand Up @@ -607,6 +610,10 @@ void state_history_plugin::plugin_initialize(const variables_map& options) {
}
boost::filesystem::create_directories(state_history_dir);

if (options.at("trace-history-debug-mode").as<bool>()) {
my->trace_debug_mode = true;
}

if (options.at("trace-history").as<bool>())
my->trace_log.emplace("trace_history", (state_history_dir / "trace_history.log").string(),
(state_history_dir / "trace_history.index").string());
Expand Down

0 comments on commit 1feae7e

Please sign in to comment.