Skip to content

Commit

Permalink
state history plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tbfleming committed Oct 31, 2018
1 parent 413a73a commit d4764cb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ history_serial_wrapper<T> make_history_serial_wrapper(const chainbase::database&

template <typename P, typename T>
struct history_context_wrapper {
const P& context;
const T& obj;
const chainbase::database& db;
const P& context;
const T& obj;
};

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

namespace fc {
Expand All @@ -45,14 +46,6 @@ const T& as_type(const T& x) {
return x;
}

template <typename ST, typename T>
datastream<ST>& history_serialize_ptr(datastream<ST>& ds, const chainbase::database& db, const T* p) {
fc::raw::pack(ds, bool(p));
if (p)
fc::raw::pack(ds, make_history_serial_wrapper(db, *p));
return ds;
}

template <typename ST, typename T>
datastream<ST>& history_serialize_container(datastream<ST>& ds, const chainbase::database& db, const T& v) {
fc::raw::pack(ds, unsigned_int(v.size()));
Expand Down Expand Up @@ -469,12 +462,23 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi
}

template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosio::chain::transaction_trace>& obj) {
datastream<ST>& operator<<(datastream<ST>& ds,
const history_context_wrapper<uint8_t, eosio::chain::transaction_trace>& obj) {
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, as_type<eosio::chain::transaction_id_type>(obj.obj.id));
fc::raw::pack(ds, as_type<uint8_t>(obj.obj.receipt->status.value));
fc::raw::pack(ds, as_type<uint32_t>(obj.obj.receipt->cpu_usage_us));
fc::raw::pack(ds, as_type<fc::unsigned_int>(obj.obj.receipt->net_usage_words));
if (obj.obj.receipt) {
if (obj.obj.failed_dtrx_trace &&
obj.obj.receipt->status.value == eosio::chain::transaction_receipt_header::soft_fail)
fc::raw::pack(ds, uint8_t(eosio::chain::transaction_receipt_header::executed));
else
fc::raw::pack(ds, as_type<uint8_t>(obj.obj.receipt->status.value));
fc::raw::pack(ds, as_type<uint32_t>(obj.obj.receipt->cpu_usage_us));
fc::raw::pack(ds, as_type<fc::unsigned_int>(obj.obj.receipt->net_usage_words));
} else {
fc::raw::pack(ds, uint8_t(obj.context));
fc::raw::pack(ds, uint32_t(0));
fc::raw::pack(ds, fc::unsigned_int(0));
}
fc::raw::pack(ds, as_type<int64_t>(obj.obj.elapsed.count()));
fc::raw::pack(ds, as_type<uint64_t>(obj.obj.net_usage));
fc::raw::pack(ds, as_type<bool>(obj.obj.scheduled));
Expand All @@ -485,7 +489,21 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi
e = obj.obj.except->to_string();
fc::raw::pack(ds, as_type<fc::optional<std::string>>(e));

history_serialize_ptr(ds, obj.db, as_type<eosio::chain::transaction_trace*>(obj.obj.failed_dtrx_trace.get()));
fc::raw::pack(ds, bool(obj.obj.failed_dtrx_trace));
if (obj.obj.failed_dtrx_trace) {
uint8_t stat = eosio::chain::transaction_receipt_header::hard_fail;
if (obj.obj.receipt && obj.obj.receipt->status.value == eosio::chain::transaction_receipt_header::soft_fail)
stat = eosio::chain::transaction_receipt_header::soft_fail;
fc::raw::pack(ds, make_history_context_wrapper(obj.db, stat, *obj.obj.failed_dtrx_trace));
}

return ds;
}

template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosio::chain::transaction_trace>& obj) {
uint8_t stat = eosio::chain::transaction_receipt_header::hard_fail;
ds << make_history_context_wrapper(obj.db, stat, obj.obj);
return ds;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl

auto pack_row = [&](auto& row) { return fc::raw::pack(make_history_serial_wrapper(db, row)); };
auto pack_contract_row = [&](auto& row) {
return fc::raw::pack(make_history_context_wrapper(get_table_id(row.t_id._id), row));
return fc::raw::pack(make_history_context_wrapper(db, get_table_id(row.t_id._id), row));
};

auto process_table = [&](auto* name, auto& index, auto& pack_row) {
Expand Down

0 comments on commit d4764cb

Please sign in to comment.