提交 b237cbff 编写于 作者: A arhag

make min_transaction_cpu_usage into a consensus parameter #2960

上级 e9fa825b
......@@ -97,6 +97,7 @@
{"name":"max_block_cpu_usage", "type": "uint64"},
{"name":"target_block_cpu_usage_pct", "type": "uint32"},
{"name":"max_transaction_cpu_usage", "type":"uint32"},
{"name":"min_transaction_cpu_usage", "type":"uint32"},
{"name":"max_transaction_lifetime", "type":"uint32"},
{"name":"deferred_trx_expiration_window", "type":"uint32"},
{"name":"max_transaction_delay", "type":"uint32"},
......
......@@ -17,6 +17,7 @@ namespace eosio {
uint32_t max_block_cpu_usage;
uint32_t target_block_cpu_usage_pct;
uint32_t max_transaction_cpu_usage;
uint32_t min_transaction_cpu_usage;
uint32_t max_transaction_lifetime;
uint32_t deferred_trx_expiration_window;
......@@ -32,7 +33,7 @@ namespace eosio {
(context_free_discount_net_usage_num)(context_free_discount_net_usage_den)
(max_block_cpu_usage)(target_block_cpu_usage_pct)
(max_transaction_cpu_usage)
(max_transaction_cpu_usage)(min_transaction_cpu_usage)
(max_transaction_lifetime)(deferred_trx_expiration_window)(max_transaction_delay)
(max_inline_action_size)(max_inline_action_depth)
......
......@@ -686,7 +686,7 @@ struct controller_impl {
try {
auto onbtrx = std::make_shared<transaction_metadata>( get_on_block_transaction() );
push_transaction( onbtrx, fc::time_point::maximum(), true, config::default_min_transaction_cpu_usage_us);
push_transaction( onbtrx, fc::time_point::maximum(), true, self.get_global_properties().configuration.min_transaction_cpu_usage );
} catch ( ... ) {
ilog( "on block transaction failed, but shouldn't impact block generation, system contract needs update" );
}
......
......@@ -25,9 +25,10 @@ struct chain_config {
uint32_t context_free_discount_net_usage_num; ///< the numerator for the discount on net usage of context-free data
uint32_t context_free_discount_net_usage_den; ///< the denominator for the discount on net usage of context-free data
uint32_t max_block_cpu_usage; ///< the maxiumum cpu usage in instructions for a block
uint32_t max_block_cpu_usage; ///< the maxiumum billable cpu usage (in microseconds) for a block
uint32_t target_block_cpu_usage_pct; ///< the target percent (1% == 100, 100%= 10,000) of maximum cpu usage; exceeding this triggers congestion handling
uint32_t max_transaction_cpu_usage; ///< the maximum objectively measured cpu usage that the chain will allow regardless of account limits
uint32_t max_transaction_cpu_usage; ///< the maximum billable cpu usage (in microseconds) that the chain will allow regardless of account limits
uint32_t min_transaction_cpu_usage; ///< the minimum billable cpu usage (in microseconds) that the chain requires
uint32_t max_transaction_lifetime; ///< the maximum number of seconds that an input transaction's expiration can be ahead of the time of the block in which it is first included
uint32_t deferred_trx_expiration_window; ///< the number of seconds after the time a deferred transaction can first execute until it expires
......@@ -49,6 +50,7 @@ struct chain_config {
<< "Max Block CPU Usage: " << c.max_block_cpu_usage << ", "
<< "Target Block CPU Usage Percent: " << ((double)c.target_block_cpu_usage_pct / (double)config::percent_1) << "%, "
<< "Max Transaction CPU Usage: " << c.max_transaction_cpu_usage << ", "
<< "Min Transaction CPU Usage: " << c.min_transaction_cpu_usage << ", "
<< "Max Transaction Lifetime: " << c.max_transaction_lifetime << ", "
<< "Deferred Transaction Expiration Window: " << c.deferred_trx_expiration_window << ", "
......@@ -71,7 +73,7 @@ FC_REFLECT(eosio::chain::chain_config,
(context_free_discount_net_usage_num)(context_free_discount_net_usage_den)
(max_block_cpu_usage)(target_block_cpu_usage_pct)
(max_transaction_cpu_usage)
(max_transaction_cpu_usage)(min_transaction_cpu_usage)
(max_transaction_lifetime)(deferred_trx_expiration_window)(max_transaction_delay)
(max_inline_action_size)(max_inline_action_depth)
......
......@@ -65,8 +65,8 @@ const static uint32_t transaction_id_net_usage = 32; // 32
const static uint32_t default_max_block_cpu_usage = 100'000; /// max block cpu usage in microseconds
const static uint32_t default_target_block_cpu_usage_pct = 5 * percent_1; /// target 1000 TPS
const static uint32_t default_max_transaction_cpu_usage = default_max_block_cpu_usage / 2;
const static uint32_t default_min_transaction_cpu_usage_us = 100; /// 10000 TPS equiv
const static uint32_t default_max_transaction_cpu_usage = default_max_block_cpu_usage / 2; /// max trx cpu usage in microseconds
const static uint32_t default_min_transaction_cpu_usage = 100; /// min trx cpu usage in microseconds (10000 TPS equiv)
const static uint32_t default_max_trx_lifetime = 60*60; // 1 hour
const static uint32_t default_deferred_trx_expiration_window = 10*60; // 10 minutes
......
......@@ -28,6 +28,7 @@ struct genesis_state {
.max_block_cpu_usage = config::default_max_block_cpu_usage,
.target_block_cpu_usage_pct = config::default_target_block_cpu_usage_pct,
.max_transaction_cpu_usage = config::default_max_transaction_cpu_usage,
.min_transaction_cpu_usage = config::default_min_transaction_cpu_usage,
.max_transaction_lifetime = config::default_max_trx_lifetime,
.deferred_trx_expiration_window = config::default_deferred_trx_expiration_window,
......
......@@ -249,8 +249,10 @@ namespace eosio { namespace chain {
trace->elapsed = fc::time_point::now() - start;
if( billed_cpu_time_us == 0 )
billed_cpu_time_us = std::max( trace->elapsed.count(), static_cast<int64_t>(config::default_min_transaction_cpu_usage_us) );
if( billed_cpu_time_us == 0 ) {
const auto& cfg = control.get_global_properties().configuration;
billed_cpu_time_us = std::max( trace->elapsed.count(), static_cast<int64_t>(cfg.min_transaction_cpu_usage) );
}
validate_cpu_usage_to_bill( billed_cpu_time_us );
......@@ -324,11 +326,13 @@ namespace eosio { namespace chain {
}
void transaction_context::validate_cpu_usage_to_bill( int64_t billed_us, bool check_minimum )const {
#warning make min_transaction_cpu_us into a configuration parameter
EOS_ASSERT( !check_minimum || billed_us >= config::default_min_transaction_cpu_usage_us, transaction_exception,
"cannot bill CPU time less than the minimum of ${min_billable} us",
("min_billable", config::default_min_transaction_cpu_usage_us)("billed_cpu_time_us", billed_us)
);
if( check_minimum ) {
const auto& cfg = control.get_global_properties().configuration;
EOS_ASSERT( billed_us >= cfg.min_transaction_cpu_usage, transaction_exception,
"cannot bill CPU time less than the minimum of ${min_billable} us",
("min_billable", cfg.min_transaction_cpu_usage)("billed_cpu_time_us", billed_us)
);
}
if( billing_timer_exception_code == block_cpu_usage_exceeded::code_value ) {
EOS_ASSERT( billed_us <= objective_duration_limit.count(),
......
......@@ -692,7 +692,7 @@ BOOST_AUTO_TEST_CASE(checktime_fail_tests) { try {
0 ),
tx_cpu_usage_exceeded, is_tx_cpu_usage_exceeded );
uint32_t time_left_in_block_us = config::default_max_block_cpu_usage - config::default_min_transaction_cpu_usage_us;
uint32_t time_left_in_block_us = config::default_max_block_cpu_usage - config::default_min_transaction_cpu_usage;
std::string dummy_string = "nonce";
uint32_t increment = config::default_max_transaction_cpu_usage / 3;
for( auto i = 0; time_left_in_block_us > 2*increment; ++i ) {
......
......@@ -277,6 +277,7 @@ public:
("max_block_cpu_usage", 10000000 + n )
("target_block_cpu_usage_pct", 10 + n )
("max_transaction_cpu_usage", 1000000 + n )
("min_transaction_cpu_usage", 100 + n )
("max_transaction_lifetime", 3600 + n)
("deferred_trx_expiration_window", 600 + n)
("max_transaction_delay", 10*86400+n)
......@@ -2140,6 +2141,7 @@ fc::mutable_variant_object config_to_variant( const eosio::chain::chain_config&
( "max_block_cpu_usage", config.max_block_cpu_usage )
( "target_block_cpu_usage_pct", config.target_block_cpu_usage_pct )
( "max_transaction_cpu_usage", config.max_transaction_cpu_usage )
( "min_transaction_cpu_usage", config.min_transaction_cpu_usage )
( "max_transaction_lifetime", config.max_transaction_lifetime )
( "deferred_trx_expiration_window", config.deferred_trx_expiration_window )
( "max_transaction_delay", config.max_transaction_delay )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册