From b0a4c74fede6868d2687c24499695a3715329d98 Mon Sep 17 00:00:00 2001 From: Scott Sallinen Date: Wed, 18 Jul 2018 15:33:12 -0700 Subject: [PATCH 1/2] Add filter-out history config option --- plugins/history_plugin/history_plugin.cpp | 69 ++++++++++++++++++----- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index d8af87408ec..49de13d29c7 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -139,29 +139,56 @@ namespace eosio { public: bool bypass_filter = false; std::set filter_on; + std::set filter_out; chain_plugin* chain_plug = nullptr; fc::optional applied_transaction_connection; - bool filter( const action_trace& act ) { - if( bypass_filter ) - return true; - if( filter_on.find({ act.receipt.receiver, act.act.name, 0 }) != filter_on.end() ) - return true; - for( const auto& a : act.act.authorization ) - if( filter_on.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_on.end() ) - return true; - return false; - } + bool filter(const action_trace& act) { + bool pass_on = false; + if (bypass_filter) { + pass_on = true; + } + if (filter_on.find({ act.receipt.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, 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()) { + return false; + } + if (filter_out.find({ act.receipt.receiver, act.act.name, 0 }) != filter_out.end()) { + return false; + } + for (const auto& a : act.act.authorization) { + if (filter_out.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_out.end()) { + return false; + } + } + + return true; + } set account_set( const action_trace& act ) { set result; result.insert( act.receipt.receiver ); - for( const auto& a : act.act.authorization ) + for( const auto& a : act.act.authorization ) { if( bypass_filter || 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() ) - result.insert( a.actor ); + 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, act.act.name, 0 }) == filter_out.end()) && + (filter_out.find({ act.receipt.receiver, act.act.name, a.actor }) == filter_out.end())) { + result.insert( a.actor ); + } + } + } return result; } @@ -263,6 +290,10 @@ namespace eosio { ("filter-on,f", bpo::value>()->composing(), "Track actions which match receiver:action:actor. Actor may be blank to include all. Receiver and Action may not be blank.") ; + cfg.add_options() + ("filter-out,f", bpo::value>()->composing(), + "Do not track actions which match receiver:action:actor. Action and Actor both blank excludes all from reciever. Actor blank excludes all from reciever:action. Receiver may not be blank.") + ; } void history_plugin::plugin_initialize(const variables_map& options) { @@ -284,6 +315,18 @@ namespace eosio { my->filter_on.insert( fe ); } } + if( options.count( "filter-out" )) { + auto fo = options.at( "filter-out" ).as>(); + for( auto& s : fo ) { + std::vector v; + boost::split( v, s, boost::is_any_of( ":" )); + EOS_ASSERT( v.size() == 3, fc::invalid_arg_exception, "Invalid value ${s} for --filter-out", ("s", s)); + filter_entry fe{v[0], v[1], v[2]}; + EOS_ASSERT( fe.receiver.value, fc::invalid_arg_exception, + "Invalid value ${s} for --filter-out", ("s", s)); + my->filter_out.insert( fe ); + } + } my->chain_plug = app().find_plugin(); auto& chain = my->chain_plug->chain(); From 28cc7b5e13ceaf2939b93c366a11d17c2b81768e Mon Sep 17 00:00:00 2001 From: Scott Sallinen Date: Sat, 28 Jul 2018 11:23:00 -0700 Subject: [PATCH 2/2] More filtering options --- plugins/history_plugin/history_plugin.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 49de13d29c7..673a6ec4580 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -148,10 +148,16 @@ namespace eosio { if (bypass_filter) { pass_on = true; } + if (filter_on.find({ act.receipt.receiver, 0, 0 }) != filter_on.end()) { + pass_on = true; + } if (filter_on.find({ act.receipt.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()) { + pass_on = true; + } if (filter_on.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_on.end()) { pass_on = true; } @@ -166,6 +172,9 @@ namespace eosio { return false; } for (const auto& a : act.act.authorization) { + if (filter_out.find({ act.receipt.receiver, 0, a.actor }) != filter_out.end()) { + return false; + } if (filter_out.find({ act.receipt.receiver, act.act.name, a.actor }) != filter_out.end()) { return false; } @@ -180,9 +189,12 @@ namespace eosio { result.insert( act.receipt.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())) { result.insert( a.actor ); @@ -288,11 +300,11 @@ namespace eosio { void history_plugin::set_program_options(options_description& cli, options_description& cfg) { cfg.add_options() ("filter-on,f", bpo::value>()->composing(), - "Track actions which match receiver:action:actor. Actor may be blank to include all. Receiver and Action may not be blank.") + "Track actions which match receiver:action:actor. Actor may be blank to include all. Action and Actor both blank allows all from Recieiver. Receiver may not be blank.") ; cfg.add_options() ("filter-out,f", bpo::value>()->composing(), - "Do not track actions which match receiver:action:actor. Action and Actor both blank excludes all from reciever. Actor blank excludes all from reciever:action. Receiver may not be blank.") + "Do not track actions which match receiver:action:actor. Action and Actor both blank excludes all from Reciever. Actor blank excludes all from reciever:action. Receiver may not be blank.") ; } @@ -310,7 +322,7 @@ namespace eosio { boost::split( v, s, boost::is_any_of( ":" )); EOS_ASSERT( v.size() == 3, fc::invalid_arg_exception, "Invalid value ${s} for --filter-on", ("s", s)); filter_entry fe{v[0], v[1], v[2]}; - EOS_ASSERT( fe.receiver.value && fe.action.value, fc::invalid_arg_exception, + EOS_ASSERT( fe.receiver.value, fc::invalid_arg_exception, "Invalid value ${s} for --filter-on", ("s", s)); my->filter_on.insert( fe ); }