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

Commit

Permalink
fix plugins #6897
Browse files Browse the repository at this point in the history
Now compiles, but the tests fail due to bugs.
  • Loading branch information
arhag committed Mar 30, 2019
1 parent 50635a6 commit ed8b7b4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
48 changes: 22 additions & 26 deletions plugins/history_plugin/history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,34 +148,34 @@ namespace eosio {
if (bypass_filter) {
pass_on = true;
}
if (filter_on.find({ act.receipt.receiver, 0, 0 }) != filter_on.end()) {
if (filter_on.find({ act.receiver, 0, 0 }) != filter_on.end()) {
pass_on = true;
}
if (filter_on.find({ act.receipt.receiver, act.act.name, 0 }) != filter_on.end()) {
if (filter_on.find({ act.receiver, act.act.name, 0 }) != filter_on.end()) {
pass_on = true;
}
for (const auto& a : act.act.authorization) {
if (filter_on.find({ act.receipt.receiver, 0, a.actor }) != filter_on.end()) {
if (filter_on.find({ act.receiver, 0, a.actor }) != filter_on.end()) {
pass_on = true;
}
if (filter_on.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_on.end()) {
if (filter_on.find({ act.receiver, act.act.name, a.actor }) != filter_on.end()) {
pass_on = true;
}
}

if (!pass_on) { return false; }

if (filter_out.find({ act.receipt.receiver, 0, 0 }) != filter_out.end()) {
if (filter_out.find({ act.receiver, 0, 0 }) != filter_out.end()) {
return false;
}
if (filter_out.find({ act.receipt.receiver, act.act.name, 0 }) != filter_out.end()) {
if (filter_out.find({ act.receiver, act.act.name, 0 }) != filter_out.end()) {
return false;
}
for (const auto& a : act.act.authorization) {
if (filter_out.find({ act.receipt.receiver, 0, a.actor }) != filter_out.end()) {
if (filter_out.find({ act.receiver, 0, a.actor }) != filter_out.end()) {
return false;
}
if (filter_out.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_out.end()) {
if (filter_out.find({ act.receiver, act.act.name, a.actor }) != filter_out.end()) {
return false;
}
}
Expand All @@ -186,25 +186,25 @@ namespace eosio {
set<account_name> account_set( const action_trace& act ) {
set<account_name> result;

result.insert( act.receipt.receiver );
result.insert( act.receiver );
for( const auto& a : act.act.authorization ) {
if( bypass_filter ||
filter_on.find({ act.receipt.receiver, 0, 0}) != filter_on.end() ||
filter_on.find({ act.receipt.receiver, 0, a.actor}) != filter_on.end() ||
filter_on.find({ act.receipt.receiver, act.act.name, 0}) != filter_on.end() ||
filter_on.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_on.end() ) {
if ((filter_out.find({ act.receipt.receiver, 0, 0 }) == filter_out.end()) &&
(filter_out.find({ act.receipt.receiver, 0, a.actor }) == filter_out.end()) &&
(filter_out.find({ act.receipt.receiver, act.act.name, 0 }) == filter_out.end()) &&
(filter_out.find({ act.receipt.receiver, act.act.name, a.actor }) == filter_out.end())) {
filter_on.find({ act.receiver, 0, 0}) != filter_on.end() ||
filter_on.find({ act.receiver, 0, a.actor}) != filter_on.end() ||
filter_on.find({ act.receiver, act.act.name, 0}) != filter_on.end() ||
filter_on.find({ act.receiver, act.act.name, a.actor }) != filter_on.end() ) {
if ((filter_out.find({ act.receiver, 0, 0 }) == filter_out.end()) &&
(filter_out.find({ act.receiver, 0, a.actor }) == filter_out.end()) &&
(filter_out.find({ act.receiver, act.act.name, 0 }) == filter_out.end()) &&
(filter_out.find({ act.receiver, act.act.name, a.actor }) == filter_out.end())) {
result.insert( a.actor );
}
}
}
return result;
}

void record_account_action( account_name n, const base_action_trace& act ) {
void record_account_action( account_name n, const action_trace& act ) {
auto& chain = chain_plug->chain();
chainbase::database& db = const_cast<chainbase::database&>( chain.db() ); // Override read-only access to state DB (highly unrecommended practice!)

Expand All @@ -216,13 +216,11 @@ namespace eosio {
if( itr->account == n )
asn = itr->account_sequence_num + 1;

//idump((n)(act.receipt.global_sequence)(asn));
const auto& a = db.create<account_history_object>( [&]( auto& aho ) {
aho.account = n;
aho.action_sequence_num = act.receipt.global_sequence;
aho.action_sequence_num = act.receipt->global_sequence;
aho.account_sequence_num = asn;
});
//idump((a.account)(a.action_sequence_num)(a.action_sequence_num));
}

void on_system_action( const action_trace& at ) {
Expand Down Expand Up @@ -263,7 +261,7 @@ namespace eosio {
aho.packed_action_trace.resize(ps);
datastream<char*> ds( aho.packed_action_trace.data(), ps );
fc::raw::pack( ds, at );
aho.action_sequence_num = at.receipt.global_sequence;
aho.action_sequence_num = at.receipt->global_sequence;
aho.block_num = chain.head_block_num() + 1;
aho.block_time = chain.pending_block_time();
aho.trx_id = at.trx_id;
Expand All @@ -274,18 +272,16 @@ namespace eosio {
record_account_action( a, at );
}
}
if( at.receipt.receiver == chain::config::system_account_name )
if( at.receiver == chain::config::system_account_name )
on_system_action( at );
for( const auto& iline : at.inline_traces ) {
on_action_trace( iline );
}
}

void on_applied_transaction( const transaction_trace_ptr& trace ) {
if( !trace->receipt || (trace->receipt->status != transaction_receipt_header::executed &&
trace->receipt->status != transaction_receipt_header::soft_fail) )
return;
for( const auto& atrace : trace->action_traces ) {
if( !atrace.receipt ) continue;
on_action_trace( atrace );
}
}
Expand Down
14 changes: 4 additions & 10 deletions plugins/mongo_db_plugin/mongo_db_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void mongo_db_plugin_impl::_process_accepted_transaction( const chain::transacti
const signed_transaction& trx = t->packed_trx->get_signed_transaction();

if( !filter_include( trx ) ) return;

auto trans_doc = bsoncxx::builder::basic::document{};

auto now = std::chrono::duration_cast<std::chrono::milliseconds>(
Expand Down Expand Up @@ -830,22 +830,20 @@ mongo_db_plugin_impl::add_action_trace( mongocxx::bulk_write& bulk_action_traces
using namespace bsoncxx::types;
using bsoncxx::builder::basic::kvp;

if( executed && atrace.receipt.receiver == chain::config::system_account_name ) {
if( executed && atrace.receiver == chain::config::system_account_name ) {
update_account( atrace.act );
}

bool added = false;
const bool in_filter = (store_action_traces || store_transaction_traces) && start_block_reached &&
filter_include( atrace.receipt.receiver, atrace.act.name, atrace.act.authorization );
filter_include( atrace.receiver, atrace.act.name, atrace.act.authorization );
write_ttrace |= in_filter;
if( start_block_reached && store_action_traces && in_filter ) {
auto action_traces_doc = bsoncxx::builder::basic::document{};
const chain::base_action_trace& base = atrace; // without inline action traces

// improve data distributivity when using mongodb sharding
action_traces_doc.append( kvp( "_id", make_custom_oid() ) );

auto v = to_variant_with_abi( base );
auto v = to_variant_with_abi( atrace );
string json = fc::json::to_string( v );
try {
const auto& value = bsoncxx::from_json( json );
Expand All @@ -871,10 +869,6 @@ mongo_db_plugin_impl::add_action_trace( mongocxx::bulk_write& bulk_action_traces
added = true;
}

for( const auto& iline_atrace : atrace.inline_traces ) {
added |= add_action_trace( bulk_action_traces, iline_atrace, t, executed, now, write_ttrace );
}

return added;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,14 @@ 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::action_trace>& obj) {
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, make_history_serial_wrapper(obj.db, as_type<eosio::chain::action_receipt>(obj.obj.receipt)));
fc::raw::pack(ds, as_type<int32_t>(obj.obj.action_ordinal));
fc::raw::pack(ds, as_type<int32_t>(obj.obj.creator_action_ordinal));
fc::raw::pack(ds, as_type<int32_t>(obj.obj.parent_action_ordinal));
fc::raw::pack(ds, bool(obj.obj.receipt));
if (obj.obj.receipt) {
fc::raw::pack(ds, make_history_serial_wrapper(obj.db, as_type<eosio::chain::action_receipt>(*obj.obj.receipt)));
}
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()));
Expand All @@ -492,7 +499,6 @@ 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_container(ds, obj.db, as_type<std::vector<eosio::chain::action_trace>>(obj.obj.inline_traces));
return ds;
}

Expand All @@ -519,6 +525,11 @@ datastream<ST>& operator<<(datastream<ST>&
fc::raw::pack(ds, as_type<bool>(obj.obj.scheduled));
history_serialize_container(ds, obj.db, as_type<std::vector<eosio::chain::action_trace>>(obj.obj.action_traces));

fc::raw::pack(ds, bool(obj.obj.account_ram_delta));
if (obj.obj.account_ram_delta) {
fc::raw::pack(ds, make_history_serial_wrapper(obj.db, as_type<eosio::chain::account_delta>(*obj.obj.account_ram_delta)));
}

fc::optional<std::string> e;
if (obj.obj.except)
e = obj.obj.except->to_string();
Expand Down
7 changes: 6 additions & 1 deletion plugins/state_history_plugin/state_history_plugin_abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ extern const char* const state_history_plugin_abi = R"({
},
{
"name": "action_trace_v0", "fields": [
{ "name": "receipt", "type": "action_receipt" },
{ "name": "action_ordinal", "type": "int32" },
{ "name": "creator_action_ordinal", "type": "int32" },
{ "name": "parent_action_ordinal", "type": "int32" },
{ "name": "receipt", "type": "action_receipt?" },
{ "name": "receiver", "type": "name" },
{ "name": "act", "type": "action" },
{ "name": "context_free", "type": "bool" },
{ "name": "elapsed", "type": "int64" },
Expand All @@ -113,6 +117,7 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "net_usage", "type": "uint64" },
{ "name": "scheduled", "type": "bool" },
{ "name": "action_traces", "type": "action_trace[]" },
{ "name": "account_ram_delta", "type": "account_delta?" },
{ "name": "except", "type": "string?" },
{ "name": "failed_dtrx_trace", "type": "transaction_trace?" }
]
Expand Down

0 comments on commit ed8b7b4

Please sign in to comment.