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

Commit

Permalink
address @heifner's review comments on #8044
Browse files Browse the repository at this point in the history
  • Loading branch information
arhag committed Oct 10, 2019
1 parent 228fa94 commit ba88a49
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
11 changes: 5 additions & 6 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ struct controller_impl {
db_read_mode read_mode = db_read_mode::SPECULATIVE;
bool in_trx_requiring_checks = false; ///< if true, checks that are normally skipped on replay (e.g. auth checks) cannot be skipped
optional<fc::microseconds> subjective_cpu_leeway;
uint32_t global_greylist_limit = config::maximum_elastic_resource_multiplier;
bool trusted_producer_light_validation = false;
uint32_t snapshot_head_block = 0;
named_thread_pool thread_pool;
Expand Down Expand Up @@ -3002,18 +3001,18 @@ void controller::set_subjective_cpu_leeway(fc::microseconds leeway) {
my->subjective_cpu_leeway = leeway;
}

void controller::set_global_greylist_limit( uint32_t limit ) {
void controller::set_greylist_limit( uint32_t limit ) {
EOS_ASSERT( 0 < limit && limit <= chain::config::maximum_elastic_resource_multiplier,
misc_exception,
"Invalid limit (${limit}) passed into set_global_greylist_limit. "
"Invalid limit (${limit}) passed into set_greylist_limit. "
"Must be between 1 and ${max}.",
("limit", limit)("max", chain::config::maximum_elastic_resource_multiplier)
);
my->global_greylist_limit = limit;
my->conf.greylist_limit = limit;
}

uint32_t controller::get_global_greylist_limit()const {
return my->global_greylist_limit;
uint32_t controller::get_greylist_limit()const {
return my->conf.greylist_limit;
}

void controller::add_resource_greylist(const account_name &name) {
Expand Down
5 changes: 3 additions & 2 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace eosio { namespace chain {

flat_set<account_name> resource_greylist;
flat_set<account_name> trusted_producers;
uint32_t greylist_limit = chain::config::maximum_elastic_resource_multiplier;
};

enum class block_status {
Expand Down Expand Up @@ -271,8 +272,8 @@ namespace eosio { namespace chain {
validation_mode get_validation_mode()const;

void set_subjective_cpu_leeway(fc::microseconds leeway);
void set_global_greylist_limit( uint32_t limit );
uint32_t get_global_greylist_limit()const;
void set_greylist_limit( uint32_t limit );
uint32_t get_greylist_limit()const;

void add_to_ram_correction( account_name account, uint64_t ram_bytes );
bool all_subjective_mitigations_disabled()const;
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ namespace bacc = boost::accumulators;
bool greylisted_net = false;
bool greylisted_cpu = false;

uint32_t global_greylist_limit = control.get_global_greylist_limit();
uint32_t specified_greylist_limit = control.get_greylist_limit();
for( const auto& a : bill_to_accounts ) {
uint32_t greylist_limit = config::maximum_elastic_resource_multiplier;
if( !force_elastic_limits && control.is_producing_block() ) {
if( control.is_resource_greylisted(a) ) {
greylist_limit = 1;
} else {
greylist_limit = global_greylist_limit;
greylist_limit = specified_greylist_limit;
}
}
auto [net_limit, net_was_greylisted] = rl.get_account_net_limit(a, greylist_limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class producer_plugin : public appbase::plugin<producer_plugin> {
fc::optional<int32_t> max_scheduled_transaction_time_per_block_ms;
fc::optional<int32_t> subjective_cpu_leeway_us;
fc::optional<double> incoming_defer_ratio;
fc::optional<uint32_t> global_greylist_limit;
fc::optional<uint32_t> greylist_limit;
};

struct whitelist_blacklist {
Expand Down Expand Up @@ -121,7 +121,7 @@ class producer_plugin : public appbase::plugin<producer_plugin> {

} //eosio

FC_REFLECT(eosio::producer_plugin::runtime_options, (max_transaction_time)(max_irreversible_block_age)(produce_time_offset_us)(last_block_time_offset_us)(max_scheduled_transaction_time_per_block_ms)(subjective_cpu_leeway_us)(incoming_defer_ratio)(global_greylist_limit));
FC_REFLECT(eosio::producer_plugin::runtime_options, (max_transaction_time)(max_irreversible_block_age)(produce_time_offset_us)(last_block_time_offset_us)(max_scheduled_transaction_time_per_block_ms)(subjective_cpu_leeway_us)(incoming_defer_ratio)(greylist_limit));
FC_REFLECT(eosio::producer_plugin::greylist_params, (accounts));
FC_REFLECT(eosio::producer_plugin::whitelist_blacklist, (actor_whitelist)(actor_blacklist)(contract_whitelist)(contract_blacklist)(action_blacklist)(key_blacklist) )
FC_REFLECT(eosio::producer_plugin::integrity_hash_information, (head_block_id)(integrity_hash))
Expand Down
12 changes: 6 additions & 6 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ void producer_plugin::set_program_options(
"Limits the maximum time (in milliseconds) that is allowed for sending blocks to a keosd provider for signing")
("greylist-account", boost::program_options::value<vector<string>>()->composing()->multitoken(),
"account that can not access to extended CPU/NET virtual resources")
("global-greylist-limit", boost::program_options::value<uint32_t>()->default_value(1000),
"Limit (between 1 and 1000) on the multiple that CPU/NET virtual resources can extend during low congestion (only enforced subjectively; use 1000 to not enforce any limit)")
("greylist-limit", boost::program_options::value<uint32_t>()->default_value(1000),
"Limit (between 1 and 1000) on the multiple that CPU/NET virtual resources can extend during low usage (only enforced subjectively; use 1000 to not enforce any limit)")
("produce-time-offset-us", boost::program_options::value<int32_t>()->default_value(0),
"offset of non last block producing time in microseconds. Negative number results in blocks to go out sooner, and positive number results in blocks to go out later")
("last-block-time-offset-us", boost::program_options::value<int32_t>()->default_value(0),
Expand Down Expand Up @@ -813,8 +813,8 @@ void producer_plugin::plugin_initialize(const boost::program_options::variables_
}

{
uint32_t global_greylist_limit = options.at("global-greylist-limit").as<uint32_t>();
chain.set_global_greylist_limit( global_greylist_limit );
uint32_t greylist_limit = options.at("greylist-limit").as<uint32_t>();
chain.set_greylist_limit( greylist_limit );
}

} FC_LOG_AND_RETHROW() }
Expand Down Expand Up @@ -944,8 +944,8 @@ void producer_plugin::update_runtime_options(const runtime_options& options) {
chain.set_subjective_cpu_leeway(fc::microseconds(*options.subjective_cpu_leeway_us));
}

if (options.global_greylist_limit) {
chain.set_global_greylist_limit(*options.global_greylist_limit);
if (options.greylist_limit) {
chain.set_greylist_limit(*options.greylist_limit);
}
}

Expand Down
18 changes: 9 additions & 9 deletions unittests/whitelist_blacklist_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ BOOST_AUTO_TEST_CASE( blacklist_sender_bypass ) { try {

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE( global_greylist_tests ) { try {
BOOST_AUTO_TEST_CASE( greylist_limit_tests ) { try {
controller::config contrl_config;
{
// Hack to get the default controller config used in tester (since v1.8.x does not have the base_tester::default_config helper function).
Expand Down Expand Up @@ -861,7 +861,7 @@ BOOST_AUTO_TEST_CASE( global_greylist_tests ) { try {
c.produce_block();
c.produce_block( fc::days(1) );

// Reducing the global greylist from 1000 to 4 should not make a difference since it would not be the
// Reducing the greylist limit from 1000 to 4 should not make a difference since it would not be the
// bottleneck at this level of congestion. But dropping it to 3 would make a difference.
{
auto user_elastic_cpu_limit = rm.get_account_cpu_limit_ex(user_account).first.max;
Expand All @@ -884,8 +884,8 @@ BOOST_AUTO_TEST_CASE( global_greylist_tests ) { try {
BOOST_REQUIRE( user_net_res2.first.max < 3*reqauth_net_charge );
}

ilog("setting global greylist limit to 4");
c.control->set_global_greylist_limit( 4 );
ilog("setting greylist limit to 4");
c.control->set_greylist_limit( 4 );
c.produce_block();

push_reqauth( user_account, config::active_name, cfg.min_transaction_cpu_usage );
Expand All @@ -895,8 +895,8 @@ BOOST_AUTO_TEST_CASE( global_greylist_tests ) { try {
push_reqauth( user_account, config::active_name, cfg.min_transaction_cpu_usage );
c.produce_block();

ilog("setting global greylist limit to 3");
c.control->set_global_greylist_limit( 3 );
ilog("setting greylist limit to 3");
c.control->set_greylist_limit( 3 );
c.produce_block( fc::days(1) );

push_reqauth( user_account, config::active_name, cfg.min_transaction_cpu_usage );
Expand All @@ -914,11 +914,11 @@ BOOST_AUTO_TEST_CASE( global_greylist_tests ) { try {
push_reqauth( user_account, config::active_name, cfg.min_transaction_cpu_usage );
c.produce_block();

// Finally, dropping the global greylist limit to 1 will restrict the user's NET bandwidth so much that this user
// Finally, dropping the greylist limit to 1 will restrict the user's NET bandwidth so much that this user
// cannot push even a single reqauth just like when they were under full congestion.
// However, this time the exception will be due to greylist_net_usage_exceeded rather than tx_net_usage_exceeded.
ilog("setting global greylist limit to 1");
c.control->set_global_greylist_limit( 1 );
ilog("setting greylist limit to 1");
c.control->set_greylist_limit( 1 );
c.produce_block( fc::days(1) );
BOOST_REQUIRE_EQUAL( rm.get_account_cpu_limit_ex(user_account, 1).first.max, user_cpu_per_day );
BOOST_REQUIRE_EQUAL( rm.get_account_net_limit_ex(user_account, 1).first.max, user_net_per_day );
Expand Down

0 comments on commit ba88a49

Please sign in to comment.