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] Make /v1/chain/get_accounts_by_authorizers multi-threaded #411

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void chain_api_plugin::plugin_startup() {
}

if (chain.transaction_finality_status_enabled()) {
_http_plugin.add_async_api({
_http_plugin.add_api({
CHAIN_RO_CALL_WITH_400(get_transaction_status, 200, http_params_types::params_required),
});
}
Expand Down
51 changes: 51 additions & 0 deletions plugins/chain_plugin/test/test_account_query_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <eosio/chain/types.hpp>
#include <eosio/chain/block_state.hpp>
#include <eosio/chain_plugin/account_query_db.hpp>
#include <eosio/chain/thread_utils.hpp>

#ifdef NON_VALIDATING_TEST
#define TESTER tester
Expand Down Expand Up @@ -97,6 +98,56 @@ BOOST_FIXTURE_TEST_CASE(updateauth_test, TESTER) { try {

} FC_LOG_AND_RETHROW() }

BOOST_FIXTURE_TEST_CASE(updateauth_test_multi_threaded, TESTER) { try {

// instantiate an account_query_db
auto aq_db = account_query_db(*control);

//link aq_db to the `accepted_block` signal on the controller
auto c = control->accepted_block.connect([&](const block_state_ptr& blk) {
aq_db.commit_block( blk);
});

produce_blocks(10);

const auto tester_account = "tester"_n;
const string role = "first";
produce_block();
create_account(tester_account);

named_thread_pool thread_pool( "test", 5 );

for( size_t i = 0; i < 100; ++i ) {
boost::asio::post( thread_pool.get_executor(), [&aq_db, tester_account, role]() {
params pars;
pars.keys.emplace_back( get_public_key( tester_account, role ) );
const auto results = aq_db.get_accounts_by_authorizers( pars );
} );
}

for( size_t i = 0; i < 50; ++i ) {
const auto trace_ptr = push_action( config::system_account_name, updateauth::get_name(), tester_account,
fc::mutable_variant_object()
( "account", tester_account )
( "permission", "role"_n )
( "parent", "active" )
( "auth", authority( get_public_key( tester_account, role ), 5 ) )
);
aq_db.cache_transaction_trace( trace_ptr );
produce_block();
}

thread_pool.stop();

params pars;
pars.keys.emplace_back( get_public_key( tester_account, role ) );
const auto results = aq_db.get_accounts_by_authorizers( pars );
BOOST_TEST_REQUIRE(find_account_auth(results, tester_account, "role"_n) == true);

thread_pool.stop();

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(future_fork_test) { try {
tester node_a(setup_policy::none);
tester node_b(setup_policy::none);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace eosio {
void add_async_handler(const string& url, const url_handler& handler);
void add_async_api(const api_description& api) {
for (const auto& call : api)
add_handler(call.first, call.second);
add_async_handler(call.first, call.second);
}

// standard exception handling for api handlers
Expand Down