未验证 提交 df65f11f 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge pull request #2145 from wanderingbort/feature/2141-fix-producers-threshold

Fix for bad threshold on producers account
...@@ -1486,20 +1486,25 @@ void chain_controller::update_global_properties(const signed_block& b) { try { ...@@ -1486,20 +1486,25 @@ void chain_controller::update_global_properties(const signed_block& b) { try {
} }
}); });
_update_producers_authority();
auto active_producers_authority = authority(config::producers_authority_threshold, {}, {});
for(auto& name : gpo.active_producers.producers ) {
active_producers_authority.accounts.push_back({{name.producer_name, config::active_name}, 1});
}
auto& po = _db.get<permission_object, by_owner>( boost::make_tuple(config::producers_account_name,
config::active_name ) );
_db.modify(po,[active_producers_authority] (permission_object& po) {
po.auth = active_producers_authority;
});
} }
} FC_CAPTURE_AND_RETHROW() } } FC_CAPTURE_AND_RETHROW() }
void chain_controller::_update_producers_authority() {
const auto& gpo = get_global_properties();
uint32_t authority_threshold = EOS_PERCENT_CEIL(gpo.active_producers.producers.size(), config::producers_authority_threshold_pct);
auto active_producers_authority = authority(authority_threshold, {}, {});
for(auto& name : gpo.active_producers.producers ) {
active_producers_authority.accounts.push_back({{name.producer_name, config::active_name}, 1});
}
auto& po = _db.get<permission_object, by_owner>( boost::make_tuple(config::producers_account_name,
config::active_name ) );
_db.modify(po,[active_producers_authority] (permission_object& po) {
po.auth = active_producers_authority;
});
}
void chain_controller::add_checkpoints( const flat_map<uint32_t,block_id_type>& checkpts ) { void chain_controller::add_checkpoints( const flat_map<uint32_t,block_id_type>& checkpts ) {
for (const auto& i : checkpts) for (const auto& i : checkpts)
_checkpoints[i.first] = i.second; _checkpoints[i.first] = i.second;
...@@ -1606,6 +1611,7 @@ void chain_controller::_initialize_chain(contracts::chain_initializer& starter) ...@@ -1606,6 +1611,7 @@ void chain_controller::_initialize_chain(contracts::chain_initializer& starter)
_db.create<block_summary_object>([&](block_summary_object&) {}); _db.create<block_summary_object>([&](block_summary_object&) {});
starter.prepare_database(*this, _db); starter.prepare_database(*this, _db);
_update_producers_authority();
}); });
} }
} FC_CAPTURE_AND_RETHROW() } } FC_CAPTURE_AND_RETHROW() }
......
...@@ -391,7 +391,7 @@ void chain_initializer::prepare_database( chain_controller& chain, ...@@ -391,7 +391,7 @@ void chain_initializer::prepare_database( chain_controller& chain,
}; };
auto empty_authority = authority(0, {}, {}); auto empty_authority = authority(0, {}, {});
auto active_producers_authority = authority(config::producers_authority_threshold, {}, {}); auto active_producers_authority = authority(0, {}, {});
active_producers_authority.accounts.push_back({{config::system_account_name, config::active_name}, 1}); active_producers_authority.accounts.push_back({{config::system_account_name, config::active_name}, 1});
create_special_account(config::nobody_account_name, empty_authority, empty_authority); create_special_account(config::nobody_account_name, empty_authority, empty_authority);
......
...@@ -345,6 +345,7 @@ namespace eosio { namespace chain { ...@@ -345,6 +345,7 @@ namespace eosio { namespace chain {
/// Reset the object graph in-memory /// Reset the object graph in-memory
void _initialize_indexes(); void _initialize_indexes();
void _initialize_chain(contracts::chain_initializer& starter); void _initialize_chain(contracts::chain_initializer& starter);
void _update_producers_authority();
producer_schedule_type _calculate_producer_schedule()const; producer_schedule_type _calculate_producer_schedule()const;
const shared_producer_schedule_type& _head_producer_schedule()const; const shared_producer_schedule_type& _head_producer_schedule()const;
......
...@@ -58,9 +58,10 @@ const static uint16_t default_max_inline_depth = 4; ...@@ -58,9 +58,10 @@ const static uint16_t default_max_inline_depth = 4;
const static uint32_t default_max_inline_action_size = 4 * 1024; const static uint32_t default_max_inline_action_size = 4 * 1024;
const static uint32_t default_max_gen_trx_size = 64 * 1024; /// const static uint32_t default_max_gen_trx_size = 64 * 1024; ///
const static uint32_t default_max_gen_trx_count = 16; ///< the number of generated transactions per action const static uint32_t default_max_gen_trx_count = 16; ///< the number of generated transactions per action
const static uint32_t producers_authority_threshold = 14;
const static uint32_t rate_limiting_precision = 1000*1000; const static uint32_t rate_limiting_precision = 1000*1000;
const static uint32_t producers_authority_threshold_pct = 66 * config::percent_1;
const static uint16_t max_recursion_depth = 6; const static uint16_t max_recursion_depth = 6;
const static uint32_t default_base_per_transaction_net_usage = 100; // 100 bytes minimum (for signature and misc overhead) const static uint32_t default_base_per_transaction_net_usage = 100; // 100 bytes minimum (for signature and misc overhead)
...@@ -108,3 +109,8 @@ template<typename Number> ...@@ -108,3 +109,8 @@ template<typename Number>
Number EOS_PERCENT(Number value, uint32_t percentage) { Number EOS_PERCENT(Number value, uint32_t percentage) {
return value * percentage / eosio::chain::config::percent_100; return value * percentage / eosio::chain::config::percent_100;
} }
template<typename Number>
Number EOS_PERCENT_CEIL(Number value, uint32_t percentage) {
return ((value * percentage) + eosio::chain::config::percent_100 - eosio::chain::config::percent_1) / eosio::chain::config::percent_100;
}
...@@ -54,7 +54,8 @@ BOOST_FIXTURE_TEST_CASE(accounts_exists, tester) ...@@ -54,7 +54,8 @@ BOOST_FIXTURE_TEST_CASE(accounts_exists, tester)
auto& gpo = chain1_db.get<global_property_object>(); auto& gpo = chain1_db.get<global_property_object>();
const auto& producers_active_authority = chain1_db.get<permission_object, by_owner>(boost::make_tuple(config::producers_account_name, config::active_name)); const auto& producers_active_authority = chain1_db.get<permission_object, by_owner>(boost::make_tuple(config::producers_account_name, config::active_name));
BOOST_CHECK_EQUAL(producers_active_authority.auth.threshold, config::producers_authority_threshold); auto expected_threshold = EOS_PERCENT_CEIL(gpo.active_producers.producers.size(), config::producers_authority_threshold_pct);
BOOST_CHECK_EQUAL(producers_active_authority.auth.threshold, expected_threshold);
BOOST_CHECK_EQUAL(producers_active_authority.auth.accounts.size(), gpo.active_producers.producers.size()); BOOST_CHECK_EQUAL(producers_active_authority.auth.accounts.size(), gpo.active_producers.producers.size());
BOOST_CHECK_EQUAL(producers_active_authority.auth.keys.size(), 0); BOOST_CHECK_EQUAL(producers_active_authority.auth.keys.size(), 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册