Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] Add new parameters to txn-test-gen plugin #355

Merged
merged 5 commits into from
Jun 10, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ struct txn_test_gen_plugin_impl {
name newaccountA;
name newaccountB;
name newaccountT;
fc::microseconds trx_expiration;
bool stop_on_trx_failed;

void push_next_transaction(const std::shared_ptr<std::vector<signed_transaction>>& trxs, const std::function<void(const fc::exception_ptr&)>& next ) {
chain_plugin& cp = app().get_plugin<chain_plugin>();
Expand Down Expand Up @@ -333,7 +335,7 @@ struct txn_test_gen_plugin_impl {
send_transaction([this](const fc::exception_ptr& e){
if (e) {
elog("pushing transaction failed: ${e}", ("e", e->to_detail_string()));
if(running)
if(running && stop_on_trx_failed)
stop_generation();
}
}, nonce_prefix++);
Expand Down Expand Up @@ -376,7 +378,7 @@ struct txn_test_gen_plugin_impl {
trx.actions.push_back(act_a_to_b);
trx.context_free_actions.emplace_back(action({}, config::null_account_name, name("nonce"), fc::raw::pack( std::to_string(nonce_prefix)+std::to_string(nonce++) )));
trx.set_reference_block(reference_block_id);
trx.expiration = cc.head_block_time() + fc::seconds(30);
trx.expiration = cc.head_block_time() + trx_expiration;
trx.max_net_usage_words = 100;
trx.sign(a_priv_key, chainid);
trxs.emplace_back(std::move(trx));
Expand All @@ -387,7 +389,7 @@ struct txn_test_gen_plugin_impl {
trx.actions.push_back(act_b_to_a);
trx.context_free_actions.emplace_back(action({}, config::null_account_name, name("nonce"), fc::raw::pack( std::to_string(nonce_prefix)+std::to_string(nonce++) )));
trx.set_reference_block(reference_block_id);
trx.expiration = cc.head_block_time() + fc::seconds(30);
trx.expiration = cc.head_block_time() + trx_expiration;
trx.max_net_usage_words = 100;
trx.sign(b_priv_key, chainid);
trxs.emplace_back(std::move(trx));
Expand Down Expand Up @@ -442,6 +444,8 @@ void txn_test_gen_plugin::set_program_options(options_description&, options_desc
("txn-reference-block-lag", bpo::value<int32_t>()->default_value(0), "Lag in number of blocks from the head block when selecting the reference block for transactions (-1 means Last Irreversible Block)")
("txn-test-gen-threads", bpo::value<uint16_t>()->default_value(2), "Number of worker threads in txn_test_gen thread pool")
("txn-test-gen-account-prefix", bpo::value<string>()->default_value("txn.test."), "Prefix to use for accounts generated and used by this plugin")
("txn-test-gen-expiration-seconds", bpo::value<uint16_t>()->default_value(30), "expiration in seconds for transactions generated by this plugin")
("txn-test-gen-stop-on-push-failed", bpo::value<bool>()->default_value(true), "stop generation when pushed transaction failed")
;
}

Expand All @@ -454,6 +458,11 @@ void txn_test_gen_plugin::plugin_initialize(const variables_map& options) {
my->newaccountA = eosio::chain::name(thread_pool_account_prefix + "a");
my->newaccountB = eosio::chain::name(thread_pool_account_prefix + "b");
my->newaccountT = eosio::chain::name(thread_pool_account_prefix + "t");
my->trx_expiration = fc::seconds(options.at("txn-test-gen-expiration-seconds").as<uint16_t>());
EOS_ASSERT(my->trx_expiration < fc::seconds(3600), chain::plugin_config_exception,
"txn-test-gen-expiration-seconds must be smaller than 3600");
my->stop_on_trx_failed = options.at("txn-test-gen-stop-on-push-failed").as<bool>();

EOS_ASSERT( my->thread_pool_size > 0, chain::plugin_config_exception,
"txn-test-gen-threads ${num} must be greater than 0", ("num", my->thread_pool_size) );
} FC_LOG_AND_RETHROW()
Expand Down