提交 a55c134e 编写于 作者: A arhag

basic validation of blockchain parameters #3343

上级 0f84d7f8
......@@ -19,6 +19,7 @@ add_library( eosio_chain
transaction_context.cpp
eosio_contract.cpp
eosio_contract_abi.cpp
chain_config.cpp
# chain_config.cpp
# block_trace.cpp
......
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#include <eosio/chain/chain_config.hpp>
#include <eosio/chain/exceptions.hpp>
namespace eosio { namespace chain {
void chain_config::validate()const {
EOS_ASSERT( target_block_net_usage_pct <= config::percent_100, action_validate_exception,
"target block net usage percentage cannot exceed 100%" );
EOS_ASSERT( target_block_net_usage_pct >= config::percent_1/10, action_validate_exception,
"target block net usage percentage must be at least 0.1%" );
EOS_ASSERT( target_block_cpu_usage_pct <= config::percent_100, action_validate_exception,
"target block cpu usage percentage cannot exceed 100%" );
EOS_ASSERT( target_block_cpu_usage_pct >= config::percent_1/10, action_validate_exception,
"target block cpu usage percentage must be at least 0.1%" );
EOS_ASSERT( max_transaction_net_usage < max_block_net_usage, action_validate_exception,
"max transaction net usage must be less than max block net usage" );
EOS_ASSERT( max_transaction_cpu_usage < max_block_cpu_usage, action_validate_exception,
"max transaction cpu usage must be less than max block cpu usage" );
EOS_ASSERT( base_per_transaction_net_usage < max_transaction_net_usage, action_validate_exception,
"base net usage per transaction must be less than the max transaction net usage" );
EOS_ASSERT( (max_transaction_net_usage - base_per_transaction_net_usage) >= config::min_net_usage_delta_between_base_and_max_for_trx,
action_validate_exception,
"max transaction net usage must be at least ${delta} bytes larger than base net usage per transaction",
("delta", config::min_net_usage_delta_between_base_and_max_for_trx) );
EOS_ASSERT( context_free_discount_net_usage_den > 0, action_validate_exception,
"net usage discount ratio for context free data cannot have a 0 denominator" );
EOS_ASSERT( context_free_discount_net_usage_num <= context_free_discount_net_usage_den, action_validate_exception,
"net usage discount ratio for context free data cannot exceed 1" );
EOS_ASSERT( min_transaction_cpu_usage <= max_transaction_cpu_usage, action_validate_exception,
"min transaction cpu usage cannot exceed max transaction cpu usage" );
EOS_ASSERT( max_transaction_cpu_usage < (max_block_cpu_usage - min_transaction_cpu_usage), action_validate_exception,
"max transaction cpu usage must be at less than the difference between the max block cpu usage and the min transaction cpu usage" );
}
} } // namespace eosio::chain
......@@ -365,6 +365,7 @@ struct controller_impl {
bs.block_id = head->id;
});
conf.genesis.initial_configuration.validate();
db.create<global_property_object>([&](auto& gpo ){
gpo.configuration = conf.genesis.initial_configuration;
});
......
......@@ -38,6 +38,8 @@ struct chain_config {
uint16_t max_authority_depth; ///< recursion depth limit for checking if an authority is satisfied
uint32_t max_generated_transaction_count; ///< the number of generated transactions per action (TODO: implement?)
void validate()const;
template<typename Stream>
friend Stream& operator << ( Stream& out, const chain_config& c ) {
return out << "Max Block Net Usage: " << c.max_block_net_usage << ", "
......
......@@ -81,6 +81,10 @@ const static uint16_t default_max_inline_action_depth = 4;
const static uint16_t default_max_auth_depth = 6;
const static uint32_t default_max_gen_trx_count = 16;
const static uint32_t min_net_usage_delta_between_base_and_max_for_trx = 10*1024;
// Should be large enough to allow recovery from badly set blockchain parameters without a hard fork
// (unless net_usage_leeway is set to 0 and so are the net limits of all accounts that can help with resetting blockchain parameters).
const static uint32_t fixed_net_overhead_of_packed_trx = 16; // TODO: is this reasonable?
const static uint32_t fixed_overhead_shared_vector_ram_bytes = 16; ///< overhead accounts for fixed portion of size of shared_vector field
......
......@@ -179,6 +179,7 @@ class privileged_api : public context_aware_api {
datastream<const char*> ds( packed_blockchain_parameters, datalen );
chain::chain_config cfg;
fc::raw::unpack(ds, cfg);
cfg.validate();
context.db.modify( context.control.get_global_properties(),
[&]( auto& gprops ) {
gprops.configuration = cfg;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册