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

Commit

Permalink
Merge pull request #781 from brianjohnson5972/genblock-refactor-config
Browse files Browse the repository at this point in the history
Added configuration for pending transaction queue depth limit.
  • Loading branch information
heifner authored Nov 26, 2017
2 parents 313cf3b + 6f15606 commit d3adeae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
8 changes: 5 additions & 3 deletions libraries/chain/chain_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ processed_transaction chain_controller::_push_transaction(const signed_transacti
if (!_pending_tx_session.valid())
_pending_tx_session = _db.start_undo_session(true);

FC_ASSERT( _pending_transactions.size() < 1000, "too many pending transactions, try again later" );
FC_ASSERT( _pending_transactions.size() < _pending_txn_depth_limit, "too many pending transactions, try again later" );

auto temp_session = _db.start_undo_session(true);
validate_referenced_accounts(trx);
Expand Down 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 @@ -1206,7 +1206,9 @@ chain_controller::chain_controller(database& database, fork_database& fork_db, b
_per_auth_account_txn_msg_rate_limit_time_frame_sec(rate_limit.per_auth_account_txn_msg_rate_time_frame_sec),
_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) {
_per_code_account_txn_msg_rate_limit(rate_limit.per_code_account_txn_msg_rate),
_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: 4 additions & 0 deletions libraries/chain/include/eos/chain/chain_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,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 @@ -432,6 +434,8 @@ namespace eosio { namespace chain {
const uint32_t _per_auth_account_txn_msg_rate_limit;
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
3 changes: 3 additions & 0 deletions libraries/chain/include/eos/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const static int default_per_code_account_rate = 18000;
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;

const static uint32 default_max_block_size = 5 * 1024 * 1024;
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
9 changes: 8 additions & 1 deletion plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"Limits the maximum database storage that an account's code is allowed.")
("row-overhead-db-limit-bytes", bpo::value<uint32_t>()->default_value(config::default_row_overhead_db_limit_bytes),
"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),
"clear chain database and replay all blocks")
Expand Down Expand Up @@ -201,6 +205,9 @@ 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->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
8 changes: 7 additions & 1 deletion tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +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 }),
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 Down

0 comments on commit d3adeae

Please sign in to comment.