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

Commit

Permalink
Added configuration for block generation time limit and moved pending…
Browse files Browse the repository at this point in the history
… transaction depth limit into rate limiting configuration structure.
  • Loading branch information
brianjohnson5972 committed Nov 25, 2017
1 parent 49e48d1 commit 6f15606
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions libraries/chain/chain_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ signed_block chain_controller::_generate_block(
pending_block.cycles[0].resize(1); // single thread

for( const auto& pending_trx : _pending_transactions ) {
if( (fc::time_point::now() - start) > fc::milliseconds(200) ||
if( (fc::time_point::now() - start) > _gen_block_time_limit ||
pending_block_size > gprops.configuration.max_blk_size)
{
pending.push_back(pending_trx);
Expand Down Expand Up @@ -1199,7 +1199,6 @@ chain_controller::chain_controller(database& database, fork_database& fork_db, b
uint32_t txn_execution_time, uint32_t rcvd_block_txn_execution_time,
uint32_t create_block_txn_execution_time,
const txn_msg_limits& rate_limit,
uint32_t pending_txn_depth_limit,
const applied_irreverisable_block_func& applied_func)
: _db(database), _fork_db(fork_db), _block_log(blocklog), _admin(std::move(admin)), _block_interval_seconds(block_interval_seconds),
_txn_execution_time(txn_execution_time),
Expand All @@ -1208,7 +1207,8 @@ chain_controller::chain_controller(database& database, fork_database& fork_db, b
_per_auth_account_txn_msg_rate_limit(rate_limit.per_auth_account_txn_msg_rate),
_per_code_account_txn_msg_rate_limit_time_frame_sec(rate_limit.per_code_account_txn_msg_rate_time_frame_sec),
_per_code_account_txn_msg_rate_limit(rate_limit.per_code_account_txn_msg_rate),
_pending_txn_depth_limit(pending_txn_depth_limit) {
_pending_txn_depth_limit(rate_limit.pending_txn_depth_limit),
_gen_block_time_limit(rate_limit.gen_block_time_limit) {

if (applied_func)
applied_irreversible_block.connect(*applied_func);
Expand Down
4 changes: 3 additions & 1 deletion libraries/chain/include/eos/chain/chain_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace eosio { namespace chain {
uint32_t txn_execution_time, uint32_t rcvd_block_txn_execution_time,
uint32_t create_block_txn_execution_time,
const txn_msg_limits& rate_limit,
uint32_t pending_txn_depth_limit,
const applied_irreverisable_block_func& applied_func = {});
chain_controller(const chain_controller&) = delete;
chain_controller(chain_controller&&) = delete;
Expand Down Expand Up @@ -304,6 +303,8 @@ namespace eosio { namespace chain {
uint32_t per_auth_account_txn_msg_rate = config::default_per_auth_account_rate;
fc::time_point_sec per_code_account_txn_msg_rate_time_frame_sec = fc::time_point_sec(config::default_per_code_account_rate_time_frame_seconds);
uint32_t per_code_account_txn_msg_rate = config::default_per_code_account_rate;
uint32_t pending_txn_depth_limit = config::default_pending_txn_depth_limit;
fc::microseconds gen_block_time_limit = config::default_gen_block_time_limit;
};

private:
Expand Down Expand Up @@ -434,6 +435,7 @@ namespace eosio { namespace chain {
const fc::time_point_sec _per_code_account_txn_msg_rate_limit_time_frame_sec;
const uint32_t _per_code_account_txn_msg_rate_limit;
const uint32_t _pending_txn_depth_limit;
const fc::microseconds _gen_block_time_limit;

flat_map<uint32_t,block_id_type> _checkpoints;

Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/eos/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const static int default_per_code_account_max_db_limit_mbytes = 5;
const static int default_row_overhead_db_limit_bytes = 8 + 8 + 8 + 8; // storage for scope/code/table + 8 extra

const static int default_pending_txn_depth_limit = 1000;
const static fc::microseconds default_gen_block_time_limit = fc::milliseconds(200);

const static uint32 required_producer_participation = 33 * config::percent1;

Expand Down
1 change: 1 addition & 0 deletions libraries/fc/include/fc/time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace fc {
microseconds& operator-=(const microseconds& c) { _count -= c._count; return *this; }
int64_t count()const { return _count; }
int64_t to_seconds()const { return _count/1000000; }
int64_t to_milliseconds()const { return _count/1000; }
private:
friend class time_point;
int64_t _count;
Expand Down
7 changes: 4 additions & 3 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class chain_plugin_impl {
uint32_t txn_execution_time;
uint32_t create_block_txn_execution_time;
txn_msg_limits cfg_txn_msg_limits;
uint32_t pending_txn_depth_limit;
};

#ifdef NDEBUG
Expand Down Expand Up @@ -110,6 +109,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"The overhead to apply per row for approximating total database storage.")
("pending-txn-depth-limit", bpo::value<uint32_t>()->default_value(config::default_pending_txn_depth_limit),
"The maximum depth the pending transaction queue will be allowed to reach till new pushed transactions are rejected.")
("gen-block-time-limit-msec", bpo::value<uint32_t>()->default_value(config::default_gen_block_time_limit.to_milliseconds()),
"The maximum allowed for generating a block before subsequent transactions get put back on the pending transaction queue.")
;
cli.add_options()
("replay-blockchain", bpo::bool_switch()->default_value(false),
Expand Down Expand Up @@ -204,7 +205,8 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
my->cfg_txn_msg_limits.per_code_account_txn_msg_rate_time_frame_sec = fc::time_point_sec(options.at("per-code-account-transaction-msg-rate-limit-time-frame-sec").as<uint32_t>());
my->cfg_txn_msg_limits.per_code_account_txn_msg_rate = options.at("per-code-account-transaction-msg-rate-limit").as<uint32_t>();

my->pending_txn_depth_limit = options.at("pending-txn-depth-limit").as<uint32_t>();
my->cfg_txn_msg_limits.pending_txn_depth_limit = options.at("pending-txn-depth-limit").as<uint32_t>();
my->cfg_txn_msg_limits.gen_block_time_limit = fc::milliseconds(options.at("gen-block-time-limit-msec").as<uint32_t>());

chain::wasm_interface::get().per_code_account_max_db_limit_mbytes = options.at("per-code-account-max-storage-db-limit-mbytes").as<uint32_t>();
chain::wasm_interface::get().row_overhead_db_limit_bytes = options.at("row-overhead-db-limit-bytes").as<uint32_t>();
Expand Down Expand Up @@ -242,7 +244,6 @@ void chain_plugin::plugin_startup()
my->rcvd_block_txn_execution_time,
my->create_block_txn_execution_time,
my->cfg_txn_msg_limits,
my->pending_txn_depth_limit,
applied_func));

if(!my->readonly) {
Expand Down
12 changes: 8 additions & 4 deletions tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ testing_blockchain::testing_blockchain(chainbase::database& db, fork_database& f
::eosio::chain_plugin::default_transaction_execution_time * 1000,
::eosio::chain_plugin::default_received_block_transaction_execution_time * 1000,
::eosio::chain_plugin::default_create_block_transaction_execution_time * 1000,
chain_controller::txn_msg_limits{ fc::time_point_sec(30), 100000, fc::time_point_sec(30), 100000 },
config::default_pending_txn_depth_limit),
chain_controller::txn_msg_limits{ fc::time_point_sec(30),
100000,
fc::time_point_sec(30),
100000,
config::default_pending_txn_depth_limit,
config::default_gen_block_time_limit
}),
db(db),
fixture(fixture) {}

Expand All @@ -112,8 +117,7 @@ testing_blockchain::testing_blockchain(chainbase::database& db, fork_database& f
transaction_execution_time_msec * 1000,
received_block_execution_time_msec * 1000,
create_block_execution_time_msec * 1000,
rate_limits,
config::default_pending_txn_depth_limit),
rate_limits),
db(db),
fixture(fixture) {}

Expand Down

0 comments on commit 6f15606

Please sign in to comment.