From a59f09c93a66248c98f27d56f0d6eb40f7cfaccd Mon Sep 17 00:00:00 2001 From: vlbos Date: Thu, 14 Mar 2019 19:35:24 +0800 Subject: [PATCH 01/12] blacklist --- .../include/eosio.system/eosio.system.hpp | 3 + contracts/eosio.system/src/eosio.system.cpp | 47 +- .../include/eosio.token/eosio.token.hpp | 14 + contracts/eosio.token/src/eosio.token.cpp | 39 +- tests/eosio.system_tester.hpp | 34 ++ tests/eosio.system_tests.cpp | 468 ++++++++++++++++++ tests/eosio.token_tests.cpp | 77 ++- 7 files changed, 678 insertions(+), 4 deletions(-) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index 43b2c353c..fbdd3dae2 100755 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -563,6 +563,9 @@ namespace eosiosystem { [[eosio::action]] void setparams( const eosio::blockchain_parameters& params ); + [[eosio::action]] + void namelist(std::string list, std::string action, const std::vector& names ); + // functions defined in producer_pay.cpp [[eosio::action]] void claimrewards( const name owner ); diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index b8c3bba39..4e5596933 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -7,7 +7,7 @@ #include "voting.cpp" #include "exchange_state.cpp" #include "rex.cpp" - +#include namespace eosiosystem { system_contract::system_contract( name s, name code, datastream ds ) @@ -120,6 +120,49 @@ namespace eosiosystem { check( 3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3" ); set_blockchain_parameters( params ); } + + void system_contract::namelist(std::string list, std::string action, const std::vector &names) + { + const int MAX_LIST_LENGTH = 30; + const int MAX_ACTION_LENGTH = 10; + enum class list_type:int64_t + { + actor_blacklist_type = 1, + contract_blacklist_type, + resource_greylist_type, + list_type_count + }; + enum class list_action_type:int64_t + { + insert_type = 1, + remove_type, + list_action_type_count + }; + + std::map list_type_string_to_enum = { + {"actor_blacklist", list_type::actor_blacklist_type}, + {"contract_blacklist", list_type::contract_blacklist_type}, + {"resource_greylist", list_type::resource_greylist_type}}; + + std::map list_action_type_string_to_enum = { + {"insert", list_action_type::insert_type}, + {"remove", list_action_type::remove_type}}; + + std::map::iterator itlt = list_type_string_to_enum.find(list); + std::map::iterator itlat = list_action_type_string_to_enum.find(action); + + require_auth(_self); + check(3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3"); + check(list.length() < MAX_LIST_LENGTH, "list string is greater than max length 30"); + check(action.length() < MAX_ACTION_LENGTH, " action string is greater than max length 10"); + check(itlt != list_type_string_to_enum.end(), " unknown list type string support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); + check(itlat != list_action_type_string_to_enum.end(), " unknown list type string support 'insert' or 'remove'"); + + auto packed_names = pack(names); + + set_name_list_packed(static_cast(itlt->second), static_cast(itlat->second), packed_names.data(), packed_names.size()); + } + void system_contract::setpriv( name account, uint8_t ispriv ) { require_auth( _self ); @@ -464,7 +507,7 @@ EOSIO_DISPATCH( eosiosystem::system_contract, (newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(canceldelay)(onerror)(setabi) // eosio.system.cpp (init)(setram)(setramrate)(setparams)(setpriv)(setalimits)(setacctram)(setacctnet)(setacctcpu) - (rmvproducer)(updtrevision)(bidname)(bidrefund) + (rmvproducer)(updtrevision)(bidname)(bidrefund)(namelist) // rex.cpp (deposit)(withdraw)(buyrex)(unstaketorex)(sellrex)(cnclrexorder)(rentcpu)(rentnet)(fundcpuloan)(fundnetloan) (defcpuloan)(defnetloan)(updaterex)(consolidate)(mvtosavings)(mvfrsavings)(setrex)(rexexec)(closerex) diff --git a/contracts/eosio.token/include/eosio.token/eosio.token.hpp b/contracts/eosio.token/include/eosio.token/eosio.token.hpp index 2463d1212..a8e81407e 100755 --- a/contracts/eosio.token/include/eosio.token/eosio.token.hpp +++ b/contracts/eosio.token/include/eosio.token/eosio.token.hpp @@ -43,6 +43,12 @@ namespace eosio { [[eosio::action]] void close( name owner, const symbol& symbol ); + [[eosio::action]] + void addblacklist(const std::vector& accounts); + + [[eosio::action]] + void rmblacklist(const std::vector& accounts); + static asset get_supply( name token_contract_account, symbol_code sym_code ) { stats statstable( token_contract_account, sym_code.raw() ); @@ -78,11 +84,19 @@ namespace eosio { uint64_t primary_key()const { return supply.symbol.code().raw(); } }; + struct [[eosio::table]] blacklist + { + name account; + uint64_t primary_key() const { return account.value; } + }; + + typedef eosio::multi_index<"blacklist"_n, blacklist> tokenblacklist; typedef eosio::multi_index< "accounts"_n, account > accounts; typedef eosio::multi_index< "stat"_n, currency_stats > stats; void sub_balance( name owner, asset value ); void add_balance( name owner, asset value, name ram_payer ); + bool is_on_blacklist(name account); }; } /// namespace eosio diff --git a/contracts/eosio.token/src/eosio.token.cpp b/contracts/eosio.token/src/eosio.token.cpp index cd1e8bb4f..3c024ad83 100755 --- a/contracts/eosio.token/src/eosio.token.cpp +++ b/contracts/eosio.token/src/eosio.token.cpp @@ -89,6 +89,7 @@ void token::transfer( name from, asset quantity, string memo ) { + eosio_assert( !is_on_blacklist(from), "account is on the blacklist" ); check( from != to, "cannot transfer to self" ); require_auth( from ); check( is_account( to ), "to account does not exist"); @@ -165,6 +166,42 @@ void token::close( name owner, const symbol& symbol ) acnts.erase( it ); } +bool token::is_on_blacklist(name account) +{ + tokenblacklist blklst(_self, account.value); + auto ac = blklst.find(account.value); + + return ac != blklst.end(); +} + +void token::addblacklist(const std::vector& accounts) +{ + require_auth("eosio"_n); + + static const std::string msg = std::string("account does not exist"); + + for (auto acc : accounts){ + std::string m = acc.to_string() + msg; + eosio_assert(is_account(acc), m.c_str()); + tokenblacklist blklst(_self, acc.value); + blklst.emplace(_self, [&](auto &a) { + a.account = acc; + }); + } +} + +void token::rmblacklist(const std::vector& accounts) +{ + require_auth("eosio"_n); + + for (auto acc : accounts){ + tokenblacklist blklst(_self, acc.value); + auto it = blklst.find(acc.value); + if (it != blklst.end()){ + blklst.erase(it); + } + } +} } /// namespace eosio -EOSIO_DISPATCH( eosio::token, (create)(issue)(transfer)(open)(close)(retire) ) +EOSIO_DISPATCH( eosio::token, (create)(issue)(transfer)(open)(close)(retire)(addblacklist)(rmblacklist) ) diff --git a/tests/eosio.system_tester.hpp b/tests/eosio.system_tester.hpp index cadbf7d86..e46f4b3c2 100644 --- a/tests/eosio.system_tester.hpp +++ b/tests/eosio.system_tester.hpp @@ -817,6 +817,40 @@ class eosio_system_tester : public TESTER { return msig_abi_ser; } + bool is_full_contains_subset(const shared_vector &allblklst, const std::vector &blklst) + { + std::vector allblacklist = std::vector(allblklst.begin(), allblklst.end()); + std::sort(allblacklist.begin(), allblacklist.end()); + std::vector blacklist = std::vector(blklst.begin(), blklst.end()); + std::sort(blacklist.begin(), blacklist.end()); + + vector blacklisted; + blacklisted.reserve(actors.size()); + set_intersection(allblacklist.begin(), allblacklist.end(), blacklist.begin(), + blacklist.end(), std::back_inserter(blacklisted)); + + std::sort(blacklisted.begin(), blacklisted.end()); + vector excluded; + excluded.reserve(blacklist.size()); + std::set_difference( blacklist.begin(), + blacklist.end(),blacklisted.begin(),blacklisted.end(),std::back_inserter(excluded)); + + return excluded.empty(); + } + + bool is_empty_intersection(const shared_vector &allblklst, const std::vector &blklst) + { + std::vector allblacklist = std::vector(allblklst.begin(), allblklst.end()); + std::sort(allblacklist.begin(), allblacklist.end()); + std::vector blacklist = std::vector(blklst.begin(), blklst.end()); + std::sort(blacklist.begin(), blacklist.end()); + + vector excluded; + excluded.reserve(blacklist.size()); + std::set_intersection(blacklist.begin(), blacklist.end(), allblacklist.begin(), allblacklist.end(), std::back_inserter(excluded)); + + return excluded.empty(); + } vector active_and_vote_producers() { //stake more than 15% of total EOS supply to activate chain transfer( "eosio", "alice1111111", core_sym::from_string("650000000.0000"), "eosio" ); diff --git a/tests/eosio.system_tests.cpp b/tests/eosio.system_tests.cpp index d70b74338..67230a86c 100644 --- a/tests/eosio.system_tests.cpp +++ b/tests/eosio.system_tests.cpp @@ -3049,6 +3049,474 @@ BOOST_FIXTURE_TEST_CASE( namebid_pending_winner, eosio_system_tester ) try { //despite "perfa" account hasn't been created, we should be able to create "perfb" account create_account_with_resources( N(prefb), N(bob111111111) ); } FC_LOG_AND_RETHROW() +BOOST_FIXTURE_TEST_CASE(actor_namelist, eosio_system_tester) +try +{ + //install multisig contract + abi_serializer msig_abi_ser = initialize_multisig(); + auto producer_names = active_and_vote_producers(); + + //helper function + auto push_action_msig = [&](const account_name &signer, const action_name &name, const variant_object &data, bool auth = true) -> action_result { + string action_type_name = msig_abi_ser.get_action_type(name); + + action act; + act.account = N(eosio.msig); + act.name = name; + act.data = msig_abi_ser.variant_to_binary(action_type_name, data, abi_serializer_max_time); + + return base_tester::push_action(std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111)); + }; + + // test begins + vector prod_perms; + for (auto &x : producer_names) + { + prod_perms.push_back({name(x), config::active_name}); + } + + std::vector actor_blacklist = {N(actorblklst1)}; + + transaction trx; + { + variant pretty_trx = fc::mutable_variant_object() + ("expiration", "2020-01-01T00:30") + ("ref_block_num", 2) + ("ref_block_prefix", 3) + ("net_usage_words", 0) + ("max_cpu_usage_ms", 0) + ("delay_sec", 0) + ("actions", fc::variants({ + fc::mutable_variant_object() + ("account", name(config::system_account_name)) + ("name", "namelist") + ("authorization", vector{ { config::system_account_name, config::active_name}}) + ("data", fc::mutable_variant_object() + ("list", "actor_blacklist") + ("action", "insert") + ("names", actor_blacklist) + ) + }) + ); + abi_serializer::from_variant(pretty_trx, trx, get_resolver(), abi_serializer_max_time); + } + + BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("trx", trx) + ("requested", prod_perms) + ) + ); + + // get 16 approvals + for (size_t i = 0; i < 15; ++i){ + BOOST_REQUIRE_EQUAL(success(), push_action_msig(name(producer_names[i]), N(approve), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("level", permission_level{name(producer_names[i]), config::active_name}) + ) + ); + } + + transaction_trace_ptr trace; + control->applied_transaction.connect([&](const transaction_trace_ptr &t) { if (t->scheduled) { trace = t; } }); + BOOST_REQUIRE_EQUAL(success(), push_action_msig(N(alice1111111), N(exec), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("executer", "alice1111111") + ) + ); + + BOOST_REQUIRE(bool(trace)); + BOOST_REQUIRE_EQUAL(1, trace->action_traces.size()); + BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); + + produce_blocks(250); + + const auto &active_cfg2 = control->get_global_properties2().cfg; + bool actor = contains_blacklist(active_cfg2.actor_blacklist, actor_blacklist); + + BOOST_REQUIRE_EQUAL(actor, true); + + ////remote blacklist check + { + transaction trx; + { + variant pretty_trx = fc::mutable_variant_object() + ("expiration", "2020-01-01T00:30") + ("ref_block_num", 2) + ("ref_block_prefix", 3) + ("net_usage_words", 0) + ("max_cpu_usage_ms", 0) + ("delay_sec", 0) + ("actions", fc::variants({ + fc::mutable_variant_object() + ("account", name(config::system_account_name)) + ("name", "namelist") + ("authorization", vector{ { config::system_account_name, config::active_name}}) + ("data", fc::mutable_variant_object() + ("list", "actor_blacklist") + ("action", "remove") + ("names", actor_blacklist) + ) + }) + ); + abi_serializer::from_variant(pretty_trx, trx, get_resolver(), abi_serializer_max_time); + } + + BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("trx", trx) + ("requested", prod_perms) + ) + ); + + // get 16 approvals + for (size_t i = 0; i < 15; ++i){ + BOOST_REQUIRE_EQUAL(success(), push_action_msig(name(producer_names[i]), N(approve), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("level", permission_level{name(producer_names[i]), config::active_name}) + ) + ); + } + + transaction_trace_ptr trace; + control->applied_transaction.connect([&](const transaction_trace_ptr &t) { if (t->scheduled) { trace = t; } }); + BOOST_REQUIRE_EQUAL(success(), push_action_msig(N(alice1111111), N(exec), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("executer", "alice1111111") + ) + ); + BOOST_REQUIRE(bool(trace)); + BOOST_REQUIRE_EQUAL(1, trace->action_traces.size()); + BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); + + produce_blocks(250); + + const auto &active_cfg2 = control->get_global_properties2().cfg; + bool actor = not_contains_blacklist(active_cfg2.actor_blacklist, actor_blacklist); + + BOOST_REQUIRE_EQUAL(actor, true); + } +} +FC_LOG_AND_RETHROW() + +BOOST_FIXTURE_TEST_CASE(contract_namelist, eosio_system_tester) +try +{ + //install multisig contract + abi_serializer msig_abi_ser = initialize_multisig(); + auto producer_names = active_and_vote_producers(); + + //helper function + auto push_action_msig = [&](const account_name &signer, const action_name &name, const variant_object &data, bool auth = true) -> action_result { + string action_type_name = msig_abi_ser.get_action_type(name); + + action act; + act.account = N(eosio.msig); + act.name = name; + act.data = msig_abi_ser.variant_to_binary(action_type_name, data, abi_serializer_max_time); + + return base_tester::push_action(std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111)); + }; + + // test begins + vector prod_perms; + for (auto &x : producer_names) + { + prod_perms.push_back({name(x), config::active_name}); + } + + std::vector contract_blacklist = {N(contrblklst1)}; + + transaction trx; + { + variant pretty_trx = fc::mutable_variant_object() + ("expiration", "2020-01-01T00:30") + ("ref_block_num", 2) + ("ref_block_prefix", 3) + ("net_usage_words", 0) + ("max_cpu_usage_ms", 0) + ("delay_sec", 0) + ("actions", fc::variants({ + fc::mutable_variant_object() + ("account", name(config::system_account_name)) + ("name", "namelist") + ("authorization", vector{ { config::system_account_name, config::active_name}}) + ("data", fc::mutable_variant_object() + ("list", "contract_blacklist") + ("action", "insert") + ("names", contract_blacklist) + ) + }) + ); + abi_serializer::from_variant(pretty_trx, trx, get_resolver(), abi_serializer_max_time); + } + + BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("trx", trx) + ("requested", prod_perms) + ) + ); + + // get 16 approvals + for (size_t i = 0; i < 15; ++i){ + BOOST_REQUIRE_EQUAL(success(), push_action_msig(name(producer_names[i]), N(approve), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("level", permission_level{name(producer_names[i]), config::active_name}) + ) + ); + } + + transaction_trace_ptr trace; + control->applied_transaction.connect([&](const transaction_trace_ptr &t) { if (t->scheduled) { trace = t; } }); + BOOST_REQUIRE_EQUAL(success(), push_action_msig(N(alice1111111), N(exec), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("executer", "alice1111111") + ) + ); + + BOOST_REQUIRE(bool(trace)); + BOOST_REQUIRE_EQUAL(1, trace->action_traces.size()); + BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); + + produce_blocks(250); + + // make sure that changed parameters were applied + const auto &active_cfg2 = control->get_global_properties2().cfg; + bool contract = contains_blacklist(active_cfg2.contract_blacklist, contract_blacklist); + + BOOST_REQUIRE_EQUAL(contract, true); + + ////remote blacklist check + { + transaction trx; + { + variant pretty_trx = fc::mutable_variant_object() + ("expiration", "2020-01-01T00:30") + ("ref_block_num", 2) + ("ref_block_prefix", 3) + ("net_usage_words", 0) + ("max_cpu_usage_ms", 0) + ("delay_sec", 0) + ("actions", fc::variants({ + fc::mutable_variant_object() + ("account", name(config::system_account_name)) + ("name", "namelist") + ("authorization", vector{ { config::system_account_name, config::active_name}}) + ("data", fc::mutable_variant_object() + ("list", "contract_blacklist") + ("action", "remove") + ("names", contract_blacklist) + ) + }) + ); + abi_serializer::from_variant(pretty_trx, trx, get_resolver(), abi_serializer_max_time); + } + + BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("trx", trx) + ("requested", prod_perms) + ) + ); + + // get 16 approvals + for (size_t i = 0; i < 15; ++i){ + BOOST_REQUIRE_EQUAL(success(), push_action_msig(name(producer_names[i]), N(approve), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("level", permission_level{name(producer_names[i]), config::active_name}) + ) + ); + } + + transaction_trace_ptr trace; + control->applied_transaction.connect([&](const transaction_trace_ptr &t) { if (t->scheduled) { trace = t; } }); + BOOST_REQUIRE_EQUAL(success(), push_action_msig(N(alice1111111), N(exec), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("executer", "alice1111111") + ) + ); + BOOST_REQUIRE(bool(trace)); + BOOST_REQUIRE_EQUAL(1, trace->action_traces.size()); + BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); + + produce_blocks(250); + + const auto &active_cfg2 = control->get_global_properties2().cfg; + bool contract = not_contains_blacklist(active_cfg2.contract_blacklist, contract_blacklist); + + BOOST_REQUIRE_EQUAL(contract, true); + } +} +FC_LOG_AND_RETHROW() + +BOOST_FIXTURE_TEST_CASE(resource_namelist, eosio_system_tester) +try +{ + //install multisig contract + abi_serializer msig_abi_ser = initialize_multisig(); + auto producer_names = active_and_vote_producers(); + + //helper function + auto push_action_msig = [&](const account_name &signer, const action_name &name, const variant_object &data, bool auth = true) -> action_result { + string action_type_name = msig_abi_ser.get_action_type(name); + + action act; + act.account = N(eosio.msig); + act.name = name; + act.data = msig_abi_ser.variant_to_binary(action_type_name, data, abi_serializer_max_time); + + return base_tester::push_action(std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111)); + }; + + // test begins + vector prod_perms; + for (auto &x : producer_names) + { + prod_perms.push_back({name(x), config::active_name}); + } + + std::vector resource_greylist = {N(resgreylst12)}; + + transaction trx; + { + variant pretty_trx = fc::mutable_variant_object() + ("expiration", "2020-01-01T00:30") + ("ref_block_num", 2) + ("ref_block_prefix", 3) + ("net_usage_words", 0) + ("max_cpu_usage_ms", 0) + ("delay_sec", 0) + ("actions", fc::variants({ + fc::mutable_variant_object() + ("account", name(config::system_account_name)) + ("name", "namelist") + ("authorization", vector{ { config::system_account_name, config::active_name}}) + ("data", fc::mutable_variant_object() + ("list", "resource_greylist") + ("action", "insert") + ("names", resource_greylist) + ) + }) + ); + abi_serializer::from_variant(pretty_trx, trx, get_resolver(), abi_serializer_max_time); + } + + BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("trx", trx) + ("requested", prod_perms) + ) + ); + + // get 16 approvals + for (size_t i = 0; i < 15; ++i){ + BOOST_REQUIRE_EQUAL(success(), push_action_msig(name(producer_names[i]), N(approve), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("level", permission_level{name(producer_names[i]), config::active_name}) + ) + ); + } + + transaction_trace_ptr trace; + control->applied_transaction.connect([&](const transaction_trace_ptr &t) { if (t->scheduled) { trace = t; } }); + BOOST_REQUIRE_EQUAL(success(), push_action_msig(N(alice1111111), N(exec), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist1") + ("executer", "alice1111111") + ) + ); + + BOOST_REQUIRE(bool(trace)); + BOOST_REQUIRE_EQUAL(1, trace->action_traces.size()); + BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); + + produce_blocks(250); + + const auto &active_cfg2 = control->get_global_properties2().cfg; + bool grey = contains_blacklist(active_cfg2.resource_greylist, resource_greylist); + + BOOST_REQUIRE_EQUAL(grey, true); + + ////remote blacklist check + { + transaction trx; + { + variant pretty_trx = fc::mutable_variant_object() + ("expiration", "2020-01-01T00:30") + ("ref_block_num", 2) + ("ref_block_prefix", 3) + ("net_usage_words", 0) + ("max_cpu_usage_ms", 0) + ("delay_sec", 0) + ("actions", fc::variants({ + fc::mutable_variant_object() + ("account", name(config::system_account_name)) + ("name", "namelist") + ("authorization", vector{ { config::system_account_name, config::active_name}}) + ("data", fc::mutable_variant_object() + ("list", "resource_greylist") + ("action", "remove") + ("names", resource_greylist) + ) + }) + ); + abi_serializer::from_variant(pretty_trx, trx, get_resolver(), abi_serializer_max_time); + } + + BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("trx", trx) + ("requested", prod_perms) + ) + ); + + // get 16 approvals + for (size_t i = 0; i < 15; ++i){ + BOOST_REQUIRE_EQUAL(success(), push_action_msig(name(producer_names[i]), N(approve), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("level", permission_level{name(producer_names[i]), config::active_name}) + ) + ); + } + + transaction_trace_ptr trace; + control->applied_transaction.connect([&](const transaction_trace_ptr &t) { if (t->scheduled) { trace = t; } }); + BOOST_REQUIRE_EQUAL(success(), push_action_msig(N(alice1111111), N(exec), mvo() + ("proposer", "alice1111111") + ("proposal_name", "namelist2") + ("executer", "alice1111111") + ) + ); + BOOST_REQUIRE(bool(trace)); + BOOST_REQUIRE_EQUAL(1, trace->action_traces.size()); + BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status); + + produce_blocks(250); + + const auto &active_cfg2 = control->get_global_properties2().cfg; + bool grey = not_contains_blacklist(active_cfg2.resource_greylist, resource_greylist); + + BOOST_REQUIRE_EQUAL(grey, true); + } +} +FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE( vote_producers_in_and_out, eosio_system_tester ) try { diff --git a/tests/eosio.token_tests.cpp b/tests/eosio.token_tests.cpp index 8d7d73ff6..94bb1bfaa 100644 --- a/tests/eosio.token_tests.cpp +++ b/tests/eosio.token_tests.cpp @@ -22,7 +22,7 @@ class eosio_token_tester : public tester { eosio_token_tester() { produce_blocks( 2 ); - create_accounts( { N(alice), N(bob), N(carol), N(eosio.token) } ); + create_accounts( { N(alice), N(bob), N(carol), N(eosio.token) ,N(boblacklist)} ); produce_blocks( 2 ); set_code( N(eosio.token), contracts::token_wasm() ); @@ -118,6 +118,23 @@ class eosio_token_tester : public tester { ); } + fc::variant get_blacklist( account_name acc) + { + vector data = get_row_by_account( N(eosio.token), acc, N(blacklist), acc ); + return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "blacklist", data, abi_serializer_max_time ); + } + + action_result addblacklist(const vector& list) { + return push_action( N(eosio), N(addblacklist), mvo() + ( "accounts", list ) + ); + } + + action_result rmblacklist(const vector& list) { + return push_action( N(eosio), N(rmblacklist), mvo() + ( "accounts", list ) + ); + } abi_serializer abi_ser; }; @@ -346,6 +363,64 @@ BOOST_FIXTURE_TEST_CASE( transfer_tests, eosio_token_tester ) try { } FC_LOG_AND_RETHROW() +///transfer blacklist +BOOST_FIXTURE_TEST_CASE( transfer_blacklist_tests, eosio_token_tester ) try { + + auto token = create( N(alice), asset::from_string("1000 CERO")); + produce_blocks(1); + + issue( N(alice), N(alice), asset::from_string("1000 CERO"), "hola" ); + + auto stats = get_stats("0,CERO"); + REQUIRE_MATCHING_OBJECT( stats, mvo() + ("supply", "1000 CERO") + ("max_supply", "1000 CERO") + ("issuer", "alice") + ); + + auto alice_balance = get_account(N(alice), "0,CERO"); + REQUIRE_MATCHING_OBJECT( alice_balance, mvo() + ("balance", "1000 CERO") + ); + + transfer( N(alice), N(boblacklist), asset::from_string("300 CERO"), "hola" ); + + std::vector list = {N(boblacklist)}; + addblacklist(list); + produce_blocks(250); + auto blklst = get_blacklist(N(boblacklist)); + REQUIRE_MATCHING_OBJECT(blklst, mvo()("account", "boblacklist")); + print("transfer before blacklist"); + //transfer(N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola"); + print("transfer after blacklist"); + BOOST_REQUIRE_EQUAL( wasm_assert_msg( "account is on the blacklist" ), + transfer( N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola" ) + ); + + BOOST_CHECK_EXCEPTION( transfer( N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola" ) , asset_type_exception, [](const asset_type_exception& e) { + return expect_assert_message(e, "account is on the blacklist"); + }); + + rmblacklist(list); + produce_blocks(250); + transfer(N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola"); + + auto boblklst_balance = get_account(N(boblacklist), "0,CERO"); + REQUIRE_MATCHING_OBJECT( boblklst_balance, mvo() + ("balance", "200 CERO") + ("frozen", 0) + ("whitelist", 1) + ); + + auto bob_balance = get_account(N(bob), "0,CERO"); + REQUIRE_MATCHING_OBJECT( bob_balance, mvo() + ("balance", "100 CERO") + ("frozen", 0) + ("whitelist", 1) + ); + + +} FC_LOG_AND_RETHROW() BOOST_FIXTURE_TEST_CASE( open_tests, eosio_token_tester ) try { auto token = create( N(alice), asset::from_string("1000 CERO")); From ea58da6ef7c2fc2c499fcae1b5838b50a76c4196 Mon Sep 17 00:00:00 2001 From: vlbos Date: Sat, 16 Mar 2019 19:42:32 +0800 Subject: [PATCH 02/12] blacklist --- tests/eosio.system_tester.hpp | 12 ++++++------ tests/eosio.system_tests.cpp | 12 ++++++------ tests/eosio.token_tests.cpp | 5 +---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/eosio.system_tester.hpp b/tests/eosio.system_tester.hpp index e46f4b3c2..c3eccaec3 100644 --- a/tests/eosio.system_tester.hpp +++ b/tests/eosio.system_tester.hpp @@ -824,16 +824,16 @@ class eosio_system_tester : public TESTER { std::vector blacklist = std::vector(blklst.begin(), blklst.end()); std::sort(blacklist.begin(), blacklist.end()); - vector blacklisted; - blacklisted.reserve(actors.size()); - set_intersection(allblacklist.begin(), allblacklist.end(), blacklist.begin(), - blacklist.end(), std::back_inserter(blacklisted)); + // vector blacklisted; + // blacklisted.reserve(allblacklist.size()); + // set_intersection(allblacklist.begin(), allblacklist.end(), blacklist.begin(), + // blacklist.end(), std::back_inserter(blacklisted)); - std::sort(blacklisted.begin(), blacklisted.end()); + // std::sort(blacklisted.begin(), blacklisted.end()); vector excluded; excluded.reserve(blacklist.size()); std::set_difference( blacklist.begin(), - blacklist.end(),blacklisted.begin(),blacklisted.end(),std::back_inserter(excluded)); + blacklist.end(),allblacklist.begin(),allblacklist.end(),std::back_inserter(excluded)); return excluded.empty(); } diff --git a/tests/eosio.system_tests.cpp b/tests/eosio.system_tests.cpp index 67230a86c..7111f1fda 100644 --- a/tests/eosio.system_tests.cpp +++ b/tests/eosio.system_tests.cpp @@ -3135,7 +3135,7 @@ try produce_blocks(250); const auto &active_cfg2 = control->get_global_properties2().cfg; - bool actor = contains_blacklist(active_cfg2.actor_blacklist, actor_blacklist); + bool actor = is_full_contains_subset(active_cfg2.actor_blacklist, actor_blacklist); BOOST_REQUIRE_EQUAL(actor, true); @@ -3198,7 +3198,7 @@ try produce_blocks(250); const auto &active_cfg2 = control->get_global_properties2().cfg; - bool actor = not_contains_blacklist(active_cfg2.actor_blacklist, actor_blacklist); + bool actor = is_empty_intersection(active_cfg2.actor_blacklist, actor_blacklist); BOOST_REQUIRE_EQUAL(actor, true); } @@ -3292,7 +3292,7 @@ try // make sure that changed parameters were applied const auto &active_cfg2 = control->get_global_properties2().cfg; - bool contract = contains_blacklist(active_cfg2.contract_blacklist, contract_blacklist); + bool contract = is_full_contains_subset(active_cfg2.contract_blacklist, contract_blacklist); BOOST_REQUIRE_EQUAL(contract, true); @@ -3355,7 +3355,7 @@ try produce_blocks(250); const auto &active_cfg2 = control->get_global_properties2().cfg; - bool contract = not_contains_blacklist(active_cfg2.contract_blacklist, contract_blacklist); + bool contract = is_empty_intersection(active_cfg2.contract_blacklist, contract_blacklist); BOOST_REQUIRE_EQUAL(contract, true); } @@ -3448,7 +3448,7 @@ try produce_blocks(250); const auto &active_cfg2 = control->get_global_properties2().cfg; - bool grey = contains_blacklist(active_cfg2.resource_greylist, resource_greylist); + bool grey = is_full_contains_subset(active_cfg2.resource_greylist, resource_greylist); BOOST_REQUIRE_EQUAL(grey, true); @@ -3511,7 +3511,7 @@ try produce_blocks(250); const auto &active_cfg2 = control->get_global_properties2().cfg; - bool grey = not_contains_blacklist(active_cfg2.resource_greylist, resource_greylist); + bool grey = is_empty_intersection(active_cfg2.resource_greylist, resource_greylist); BOOST_REQUIRE_EQUAL(grey, true); } diff --git a/tests/eosio.token_tests.cpp b/tests/eosio.token_tests.cpp index 94bb1bfaa..63c72b698 100644 --- a/tests/eosio.token_tests.cpp +++ b/tests/eosio.token_tests.cpp @@ -390,10 +390,7 @@ BOOST_FIXTURE_TEST_CASE( transfer_blacklist_tests, eosio_token_tester ) try { produce_blocks(250); auto blklst = get_blacklist(N(boblacklist)); REQUIRE_MATCHING_OBJECT(blklst, mvo()("account", "boblacklist")); - print("transfer before blacklist"); - //transfer(N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola"); - print("transfer after blacklist"); - BOOST_REQUIRE_EQUAL( wasm_assert_msg( "account is on the blacklist" ), + BOOST_REQUIRE_EQUAL( wasm_assert_msg( "account is on the blacklist" ), transfer( N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola" ) ); From 15d5570501aa8135b1a4ba5d536c9144ed9a7b63 Mon Sep 17 00:00:00 2001 From: vlbos Date: Wed, 20 Mar 2019 14:58:43 +0800 Subject: [PATCH 03/12] blacklist --- contracts/eosio.system/src/eosio.system.cpp | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index 4e5596933..8558ca2b7 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -121,34 +121,34 @@ namespace eosiosystem { set_blockchain_parameters( params ); } - void system_contract::namelist(std::string list, std::string action, const std::vector &names) + void system_contract::setblacklist(std::string list, std::string action, const std::vector& names) { const int MAX_LIST_LENGTH = 30; const int MAX_ACTION_LENGTH = 10; - enum class list_type:int64_t - { + enum class blacklist_type:int64_t{ actor_blacklist_type = 1, contract_blacklist_type, resource_greylist_type, list_type_count }; - enum class list_action_type:int64_t - { + enum class list_action_type:int64_t{ insert_type = 1, remove_type, list_action_type_count }; - std::map list_type_string_to_enum = { - {"actor_blacklist", list_type::actor_blacklist_type}, - {"contract_blacklist", list_type::contract_blacklist_type}, - {"resource_greylist", list_type::resource_greylist_type}}; + std::map list_type_string_to_enum = { + {"actor_blacklist", blacklist_type::actor_blacklist_type}, + {"contract_blacklist", blacklist_type::contract_blacklist_type}, + {"resource_greylist", blacklist_type::resource_greylist_type} + }; std::map list_action_type_string_to_enum = { {"insert", list_action_type::insert_type}, - {"remove", list_action_type::remove_type}}; + {"remove", list_action_type::remove_type} + }; - std::map::iterator itlt = list_type_string_to_enum.find(list); + std::map::iterator itlt = list_type_string_to_enum.find(list); std::map::iterator itlat = list_action_type_string_to_enum.find(action); require_auth(_self); @@ -160,7 +160,7 @@ namespace eosiosystem { auto packed_names = pack(names); - set_name_list_packed(static_cast(itlt->second), static_cast(itlat->second), packed_names.data(), packed_names.size()); + set_blacklist_packed(static_cast(itlt->second), static_cast(itlat->second), packed_names.data(), packed_names.size()); } @@ -507,7 +507,7 @@ EOSIO_DISPATCH( eosiosystem::system_contract, (newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(canceldelay)(onerror)(setabi) // eosio.system.cpp (init)(setram)(setramrate)(setparams)(setpriv)(setalimits)(setacctram)(setacctnet)(setacctcpu) - (rmvproducer)(updtrevision)(bidname)(bidrefund)(namelist) + (rmvproducer)(updtrevision)(bidname)(bidrefund)(setblacklist) // rex.cpp (deposit)(withdraw)(buyrex)(unstaketorex)(sellrex)(cnclrexorder)(rentcpu)(rentnet)(fundcpuloan)(fundnetloan) (defcpuloan)(defnetloan)(updaterex)(consolidate)(mvtosavings)(mvfrsavings)(setrex)(rexexec)(closerex) From efb665aa0e28f5b2939d93439498a99f02e5b622 Mon Sep 17 00:00:00 2001 From: vlbos Date: Thu, 21 Mar 2019 11:15:31 +0800 Subject: [PATCH 04/12] blacklist --- contracts/eosio.system/include/eosio.system/eosio.system.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index fbdd3dae2..3d8322afb 100755 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -564,7 +564,7 @@ namespace eosiosystem { void setparams( const eosio::blockchain_parameters& params ); [[eosio::action]] - void namelist(std::string list, std::string action, const std::vector& names ); + void setblacklist(std::string list, std::string action, const std::vector& names ); // functions defined in producer_pay.cpp [[eosio::action]] From 0fe3010f13d20677d37bfe5a8c403b833f646d68 Mon Sep 17 00:00:00 2001 From: vlbos Date: Sat, 23 Mar 2019 15:01:04 +0800 Subject: [PATCH 05/12] blacklis --- .../include/eosio.token/eosio.token.hpp | 6 ++-- contracts/eosio.token/src/eosio.token.cpp | 35 +++++++++++++------ tests/eosio.token_tests.cpp | 2 +- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/contracts/eosio.token/include/eosio.token/eosio.token.hpp b/contracts/eosio.token/include/eosio.token/eosio.token.hpp index a8e81407e..99054620b 100755 --- a/contracts/eosio.token/include/eosio.token/eosio.token.hpp +++ b/contracts/eosio.token/include/eosio.token/eosio.token.hpp @@ -84,19 +84,19 @@ namespace eosio { uint64_t primary_key()const { return supply.symbol.code().raw(); } }; - struct [[eosio::table]] blacklist + struct [[eosio::table]] account_blacklist { name account; uint64_t primary_key() const { return account.value; } }; - typedef eosio::multi_index<"blacklist"_n, blacklist> tokenblacklist; + typedef eosio::multi_index<"blacklist"_n, account_blacklist> blacklist; + static const uint8_t blacklist_limit_size = 20 ; typedef eosio::multi_index< "accounts"_n, account > accounts; typedef eosio::multi_index< "stat"_n, currency_stats > stats; void sub_balance( name owner, asset value ); void add_balance( name owner, asset value, name ram_payer ); - bool is_on_blacklist(name account); }; } /// namespace eosio diff --git a/contracts/eosio.token/src/eosio.token.cpp b/contracts/eosio.token/src/eosio.token.cpp index 3c024ad83..4a8fee9bf 100755 --- a/contracts/eosio.token/src/eosio.token.cpp +++ b/contracts/eosio.token/src/eosio.token.cpp @@ -89,7 +89,8 @@ void token::transfer( name from, asset quantity, string memo ) { - eosio_assert( !is_on_blacklist(from), "account is on the blacklist" ); + blacklist blacklisttable(_self, from.value); + check(blacklisttable.find(from.value) == blacklisttable.end(), "account is on the blacklist"); check( from != to, "cannot transfer to self" ); require_auth( from ); check( is_account( to ), "to account does not exist"); @@ -178,29 +179,41 @@ void token::addblacklist(const std::vector& accounts) { require_auth("eosio"_n); + check(blacklist_limit_size >= accounts.size(), "accounts' size must be less than 20."); static const std::string msg = std::string("account does not exist"); - + bool is_executed = false; for (auto acc : accounts){ std::string m = acc.to_string() + msg; - eosio_assert(is_account(acc), m.c_str()); - tokenblacklist blklst(_self, acc.value); - blklst.emplace(_self, [&](auto &a) { - a.account = acc; - }); + check(is_account(acc), m.c_str()); + blacklist blacklisttable(_self, acc.value); + auto it = blacklisttable.find(acc.value); + if (it == blacklisttable.end()) { + blacklisttable.emplace(_self, [&](auto &a) { + a.account = acc; + is_executed = true; + }); + } } + + eosio_assert( is_executed, "all accounts were on blacklist." ); } void token::rmblacklist(const std::vector& accounts) { require_auth("eosio"_n); + check( blacklist_limit_size>=accounts.size(), "accounts' size must be less than 20." ); + bool is_executed = false; for (auto acc : accounts){ - tokenblacklist blklst(_self, acc.value); - auto it = blklst.find(acc.value); - if (it != blklst.end()){ - blklst.erase(it); + blacklist blacklisttable(_self, acc.value); + auto it = blacklisttable.find(acc.value); + if (it != blacklisttable.end()){ + blacklisttable.erase(it); + is_executed = true; } } + + check( is_executed, "all accounts were not on blacklist." ); } } /// namespace eosio diff --git a/tests/eosio.token_tests.cpp b/tests/eosio.token_tests.cpp index 63c72b698..a68118161 100644 --- a/tests/eosio.token_tests.cpp +++ b/tests/eosio.token_tests.cpp @@ -121,7 +121,7 @@ class eosio_token_tester : public tester { fc::variant get_blacklist( account_name acc) { vector data = get_row_by_account( N(eosio.token), acc, N(blacklist), acc ); - return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "blacklist", data, abi_serializer_max_time ); + return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "account_blacklist", data, abi_serializer_max_time ); } action_result addblacklist(const vector& list) { From ab44613995fc5def605bc9e1214261143f247c68 Mon Sep 17 00:00:00 2001 From: vlbos Date: Sat, 23 Mar 2019 21:04:20 +0800 Subject: [PATCH 06/12] blacklist --- contracts/eosio.token/src/eosio.token.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/contracts/eosio.token/src/eosio.token.cpp b/contracts/eosio.token/src/eosio.token.cpp index 4a8fee9bf..803d9763e 100755 --- a/contracts/eosio.token/src/eosio.token.cpp +++ b/contracts/eosio.token/src/eosio.token.cpp @@ -167,14 +167,6 @@ void token::close( name owner, const symbol& symbol ) acnts.erase( it ); } -bool token::is_on_blacklist(name account) -{ - tokenblacklist blklst(_self, account.value); - auto ac = blklst.find(account.value); - - return ac != blklst.end(); -} - void token::addblacklist(const std::vector& accounts) { require_auth("eosio"_n); From ae493d0e934401678b7970d6e043ad93e68bba6f Mon Sep 17 00:00:00 2001 From: vlbos Date: Sat, 23 Mar 2019 21:07:15 +0800 Subject: [PATCH 07/12] blacklist --- tests/eosio.token_tests.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/eosio.token_tests.cpp b/tests/eosio.token_tests.cpp index a68118161..a42011619 100644 --- a/tests/eosio.token_tests.cpp +++ b/tests/eosio.token_tests.cpp @@ -394,26 +394,19 @@ BOOST_FIXTURE_TEST_CASE( transfer_blacklist_tests, eosio_token_tester ) try { transfer( N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola" ) ); - BOOST_CHECK_EXCEPTION( transfer( N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola" ) , asset_type_exception, [](const asset_type_exception& e) { - return expect_assert_message(e, "account is on the blacklist"); - }); - rmblacklist(list); produce_blocks(250); transfer(N(boblacklist), N(bob), asset::from_string("100 CERO"), "hola"); + produce_blocks(250); auto boblklst_balance = get_account(N(boblacklist), "0,CERO"); REQUIRE_MATCHING_OBJECT( boblklst_balance, mvo() ("balance", "200 CERO") - ("frozen", 0) - ("whitelist", 1) ); auto bob_balance = get_account(N(bob), "0,CERO"); REQUIRE_MATCHING_OBJECT( bob_balance, mvo() ("balance", "100 CERO") - ("frozen", 0) - ("whitelist", 1) ); From c00c680442dcd7de0273a3c807a8d90fa0f1f137 Mon Sep 17 00:00:00 2001 From: vlbos Date: Mon, 25 Mar 2019 09:10:00 +0800 Subject: [PATCH 08/12] blacklist --- contracts/eosio.system/src/eosio.system.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index 8558ca2b7..97cb615d3 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -123,8 +123,9 @@ namespace eosiosystem { void system_contract::setblacklist(std::string list, std::string action, const std::vector& names) { - const int MAX_LIST_LENGTH = 30; - const int MAX_ACTION_LENGTH = 10; + const int max_list_length = 30; + const int max_list_size = 20; + const int max_action_length = 10; enum class blacklist_type:int64_t{ actor_blacklist_type = 1, contract_blacklist_type, @@ -153,10 +154,11 @@ namespace eosiosystem { require_auth(_self); check(3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3"); - check(list.length() < MAX_LIST_LENGTH, "list string is greater than max length 30"); - check(action.length() < MAX_ACTION_LENGTH, " action string is greater than max length 10"); - check(itlt != list_type_string_to_enum.end(), " unknown list type string support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); - check(itlat != list_action_type_string_to_enum.end(), " unknown list type string support 'insert' or 'remove'"); + check(list.length() < max_list_length, "list string must be less than 30"); + check(names.size() < max_list_size, "list's size must be less than 20"); + check(action.length() < max_action_length, " action string must be less than 10"); + check(itlt != list_type_string_to_enum.end(), " unknown list type string, support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); + check(itlat != list_action_type_string_to_enum.end(), " unknown list type string, support 'insert' or 'remove'"); auto packed_names = pack(names); From c159de863060c28bf0e30fe7f36ef5aae00ac768 Mon Sep 17 00:00:00 2001 From: vlbos Date: Mon, 25 Mar 2019 14:16:35 +0800 Subject: [PATCH 09/12] blacklist --- contracts/eosio.system/src/eosio.system.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index 97cb615d3..b6791a308 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -123,9 +123,9 @@ namespace eosiosystem { void system_contract::setblacklist(std::string list, std::string action, const std::vector& names) { - const int max_list_length = 30; - const int max_list_size = 20; - const int max_action_length = 10; + const int blacklist_type_string_limit_length = 30; + const int blacklist_limit_size = 20; + const int blacklist_action_limit_length = 10; enum class blacklist_type:int64_t{ actor_blacklist_type = 1, contract_blacklist_type, @@ -154,9 +154,9 @@ namespace eosiosystem { require_auth(_self); check(3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3"); - check(list.length() < max_list_length, "list string must be less than 30"); - check(names.size() < max_list_size, "list's size must be less than 20"); - check(action.length() < max_action_length, " action string must be less than 10"); + check(list.length() < blacklist_type_string_limit_length, "the length of list type string must be less than 30"); + check(names.size() < blacklist_limit_size, "the size of list must be less than 20"); + check(action.length() < blacklist_action_limit_length, " the length of action string must be less than 10"); check(itlt != list_type_string_to_enum.end(), " unknown list type string, support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); check(itlat != list_action_type_string_to_enum.end(), " unknown list type string, support 'insert' or 'remove'"); From 30bc74a28904bef6355db050a4a1a697d9f37e71 Mon Sep 17 00:00:00 2001 From: vlbos Date: Mon, 25 Mar 2019 14:23:14 +0800 Subject: [PATCH 10/12] blacklist --- contracts/eosio.system/src/eosio.system.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index b6791a308..e7bd8057f 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -125,7 +125,7 @@ namespace eosiosystem { { const int blacklist_type_string_limit_length = 30; const int blacklist_limit_size = 20; - const int blacklist_action_limit_length = 10; + const int blacklist_action_string_limit_length = 10; enum class blacklist_type:int64_t{ actor_blacklist_type = 1, contract_blacklist_type, @@ -156,7 +156,7 @@ namespace eosiosystem { check(3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3"); check(list.length() < blacklist_type_string_limit_length, "the length of list type string must be less than 30"); check(names.size() < blacklist_limit_size, "the size of list must be less than 20"); - check(action.length() < blacklist_action_limit_length, " the length of action string must be less than 10"); + check(action.length() < blacklist_action_string_limit_length, " the length of action string must be less than 10"); check(itlt != list_type_string_to_enum.end(), " unknown list type string, support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); check(itlat != list_action_type_string_to_enum.end(), " unknown list type string, support 'insert' or 'remove'"); From 26d2729356b82d6a841b542077f97e7bd2b5b384 Mon Sep 17 00:00:00 2001 From: vlbos Date: Tue, 26 Mar 2019 14:28:31 +0800 Subject: [PATCH 11/12] blacklist --- contracts/eosio.system/src/eosio.system.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index e7bd8057f..ce6ad2739 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -124,7 +124,7 @@ namespace eosiosystem { void system_contract::setblacklist(std::string list, std::string action, const std::vector& names) { const int blacklist_type_string_limit_length = 30; - const int blacklist_limit_size = 20; + const int blacklist_limit_size = 60; const int blacklist_action_string_limit_length = 10; enum class blacklist_type:int64_t{ actor_blacklist_type = 1, @@ -155,7 +155,7 @@ namespace eosiosystem { require_auth(_self); check(3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3"); check(list.length() < blacklist_type_string_limit_length, "the length of list type string must be less than 30"); - check(names.size() < blacklist_limit_size, "the size of list must be less than 20"); + check(names.size() < blacklist_limit_size, "the size of list must be less than 60"); check(action.length() < blacklist_action_string_limit_length, " the length of action string must be less than 10"); check(itlt != list_type_string_to_enum.end(), " unknown list type string, support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); check(itlat != list_action_type_string_to_enum.end(), " unknown list type string, support 'insert' or 'remove'"); From b55483f6c289fa4ac752b36b188d40c3afc58259 Mon Sep 17 00:00:00 2001 From: vlbos Date: Wed, 27 Mar 2019 11:03:11 +0800 Subject: [PATCH 12/12] blacklist --- .../include/eosio.system/eosio.system.hpp | 2 +- contracts/eosio.system/src/eosio.system.cpp | 37 ++++++++----------- .../include/eosio.token/eosio.token.hpp | 2 +- contracts/eosio.token/src/eosio.token.cpp | 10 ++--- tests/eosio.system_tests.cpp | 18 ++++----- tests/eosio.token_tests.cpp | 2 +- 6 files changed, 33 insertions(+), 38 deletions(-) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index 3d8322afb..3287028b7 100755 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -564,7 +564,7 @@ namespace eosiosystem { void setparams( const eosio::blockchain_parameters& params ); [[eosio::action]] - void setblacklist(std::string list, std::string action, const std::vector& names ); + void setblacklist(namelist, name action, const std::vector& names ); // functions defined in producer_pay.cpp [[eosio::action]] diff --git a/contracts/eosio.system/src/eosio.system.cpp b/contracts/eosio.system/src/eosio.system.cpp index ce6ad2739..334e2b142 100755 --- a/contracts/eosio.system/src/eosio.system.cpp +++ b/contracts/eosio.system/src/eosio.system.cpp @@ -121,12 +121,11 @@ namespace eosiosystem { set_blockchain_parameters( params ); } - void system_contract::setblacklist(std::string list, std::string action, const std::vector& names) + void system_contract::setblacklist(name list, name action, const std::vector& names) { - const int blacklist_type_string_limit_length = 30; - const int blacklist_limit_size = 60; - const int blacklist_action_string_limit_length = 10; - enum class blacklist_type:int64_t{ + const int blacklist_limit_size = 100; + enum class list_type:int64_t + { actor_blacklist_type = 1, contract_blacklist_type, resource_greylist_type, @@ -138,27 +137,23 @@ namespace eosiosystem { list_action_type_count }; - std::map list_type_string_to_enum = { - {"actor_blacklist", blacklist_type::actor_blacklist_type}, - {"contract_blacklist", blacklist_type::contract_blacklist_type}, - {"resource_greylist", blacklist_type::resource_greylist_type} - }; + std::map list_type_to_enum = { + {"actor"_n, list_type::actor_blacklist_type}, + {"contract"_n, list_type::contract_blacklist_type}, + {"resource"_n, list_type::resource_greylist_type}}; - std::map list_action_type_string_to_enum = { - {"insert", list_action_type::insert_type}, - {"remove", list_action_type::remove_type} - }; + std::map list_action_type_to_enum = { + {"insert"_n, list_action_type::insert_type}, + {"remove"_n, list_action_type::remove_type}}; - std::map::iterator itlt = list_type_string_to_enum.find(list); - std::map::iterator itlat = list_action_type_string_to_enum.find(action); + std::map::iterator itlt = list_type_to_enum.find(list); + std::map::iterator itlat = list_action_type_to_enum.find(action); require_auth(_self); check(3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3"); - check(list.length() < blacklist_type_string_limit_length, "the length of list type string must be less than 30"); - check(names.size() < blacklist_limit_size, "the size of list must be less than 60"); - check(action.length() < blacklist_action_string_limit_length, " the length of action string must be less than 10"); - check(itlt != list_type_string_to_enum.end(), " unknown list type string, support 'actor_blacklist' ,'contract_blacklist', 'resource_greylist'"); - check(itlat != list_action_type_string_to_enum.end(), " unknown list type string, support 'insert' or 'remove'"); + check(names.size() < blacklist_limit_size, "the size of 'names' must be less than 100"); + check(itlt != list_type_to_enum.end(), " unknown list type string support 'actor' ,'contract', 'resource'"); + check(itlat != list_action_type_to_enum.end(), " unknown list type string support 'insert' or 'remove'"); auto packed_names = pack(names); diff --git a/contracts/eosio.token/include/eosio.token/eosio.token.hpp b/contracts/eosio.token/include/eosio.token/eosio.token.hpp index 99054620b..8d23488e4 100755 --- a/contracts/eosio.token/include/eosio.token/eosio.token.hpp +++ b/contracts/eosio.token/include/eosio.token/eosio.token.hpp @@ -91,7 +91,7 @@ namespace eosio { }; typedef eosio::multi_index<"blacklist"_n, account_blacklist> blacklist; - static const uint8_t blacklist_limit_size = 20 ; + static const uint8_t blacklist_limit_size = 100 ; typedef eosio::multi_index< "accounts"_n, account > accounts; typedef eosio::multi_index< "stat"_n, currency_stats > stats; diff --git a/contracts/eosio.token/src/eosio.token.cpp b/contracts/eosio.token/src/eosio.token.cpp index 803d9763e..aa3253eb7 100755 --- a/contracts/eosio.token/src/eosio.token.cpp +++ b/contracts/eosio.token/src/eosio.token.cpp @@ -89,7 +89,7 @@ void token::transfer( name from, asset quantity, string memo ) { - blacklist blacklisttable(_self, from.value); + blacklist blacklisttable(_self, _self.value); check(blacklisttable.find(from.value) == blacklisttable.end(), "account is on the blacklist"); check( from != to, "cannot transfer to self" ); require_auth( from ); @@ -171,13 +171,13 @@ void token::addblacklist(const std::vector& accounts) { require_auth("eosio"_n); - check(blacklist_limit_size >= accounts.size(), "accounts' size must be less than 20."); + check(blacklist_limit_size >= accounts.size(), "accounts' size must be less than 100."); static const std::string msg = std::string("account does not exist"); bool is_executed = false; for (auto acc : accounts){ std::string m = acc.to_string() + msg; check(is_account(acc), m.c_str()); - blacklist blacklisttable(_self, acc.value); + blacklist blacklisttable(_self, _self.value); auto it = blacklisttable.find(acc.value); if (it == blacklisttable.end()) { blacklisttable.emplace(_self, [&](auto &a) { @@ -194,10 +194,10 @@ void token::rmblacklist(const std::vector& accounts) { require_auth("eosio"_n); - check( blacklist_limit_size>=accounts.size(), "accounts' size must be less than 20." ); + check( blacklist_limit_size>=accounts.size(), "accounts' size must be less than 100." ); bool is_executed = false; for (auto acc : accounts){ - blacklist blacklisttable(_self, acc.value); + blacklist blacklisttable(_self, _self.value); auto it = blacklisttable.find(acc.value); if (it != blacklisttable.end()){ blacklisttable.erase(it); diff --git a/tests/eosio.system_tests.cpp b/tests/eosio.system_tests.cpp index 7111f1fda..d73960908 100644 --- a/tests/eosio.system_tests.cpp +++ b/tests/eosio.system_tests.cpp @@ -3049,7 +3049,7 @@ BOOST_FIXTURE_TEST_CASE( namebid_pending_winner, eosio_system_tester ) try { //despite "perfa" account hasn't been created, we should be able to create "perfb" account create_account_with_resources( N(prefb), N(bob111111111) ); } FC_LOG_AND_RETHROW() -BOOST_FIXTURE_TEST_CASE(actor_namelist, eosio_system_tester) +BOOST_FIXTURE_TEST_CASE(actor_blacklist, eosio_system_tester) try { //install multisig contract @@ -3092,7 +3092,7 @@ try ("name", "namelist") ("authorization", vector{ { config::system_account_name, config::active_name}}) ("data", fc::mutable_variant_object() - ("list", "actor_blacklist") + ("list", "actor") ("action", "insert") ("names", actor_blacklist) ) @@ -3156,7 +3156,7 @@ try ("name", "namelist") ("authorization", vector{ { config::system_account_name, config::active_name}}) ("data", fc::mutable_variant_object() - ("list", "actor_blacklist") + ("list", "actor") ("action", "remove") ("names", actor_blacklist) ) @@ -3205,7 +3205,7 @@ try } FC_LOG_AND_RETHROW() -BOOST_FIXTURE_TEST_CASE(contract_namelist, eosio_system_tester) +BOOST_FIXTURE_TEST_CASE(contract_blacklist, eosio_system_tester) try { //install multisig contract @@ -3248,7 +3248,7 @@ try ("name", "namelist") ("authorization", vector{ { config::system_account_name, config::active_name}}) ("data", fc::mutable_variant_object() - ("list", "contract_blacklist") + ("list", "contract") ("action", "insert") ("names", contract_blacklist) ) @@ -3313,7 +3313,7 @@ try ("name", "namelist") ("authorization", vector{ { config::system_account_name, config::active_name}}) ("data", fc::mutable_variant_object() - ("list", "contract_blacklist") + ("list", "contract") ("action", "remove") ("names", contract_blacklist) ) @@ -3362,7 +3362,7 @@ try } FC_LOG_AND_RETHROW() -BOOST_FIXTURE_TEST_CASE(resource_namelist, eosio_system_tester) +BOOST_FIXTURE_TEST_CASE(resource_greylist, eosio_system_tester) try { //install multisig contract @@ -3405,7 +3405,7 @@ try ("name", "namelist") ("authorization", vector{ { config::system_account_name, config::active_name}}) ("data", fc::mutable_variant_object() - ("list", "resource_greylist") + ("list", "resource") ("action", "insert") ("names", resource_greylist) ) @@ -3469,7 +3469,7 @@ try ("name", "namelist") ("authorization", vector{ { config::system_account_name, config::active_name}}) ("data", fc::mutable_variant_object() - ("list", "resource_greylist") + ("list", "resource") ("action", "remove") ("names", resource_greylist) ) diff --git a/tests/eosio.token_tests.cpp b/tests/eosio.token_tests.cpp index a42011619..54f1e885e 100644 --- a/tests/eosio.token_tests.cpp +++ b/tests/eosio.token_tests.cpp @@ -120,7 +120,7 @@ class eosio_token_tester : public tester { fc::variant get_blacklist( account_name acc) { - vector data = get_row_by_account( N(eosio.token), acc, N(blacklist), acc ); + vector data = get_row_by_account( N(eosio.token), N(eosio.token), N(blacklist), acc ); return data.empty() ? fc::variant() : abi_ser.binary_to_variant( "account_blacklist", data, abi_serializer_max_time ); }