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

Net plugin sync priority #8142

Merged
merged 13 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 3 additions & 1 deletion plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ void chain_api_plugin::plugin_startup() {
ro_api.set_shorten_abi_errors( !_http_plugin.verbose_errors() );

_http_plugin.add_api({
CHAIN_RO_CALL(get_info, 200l),
CHAIN_RO_CALL(get_info, 200)
}, appbase::priority::medium);
_http_plugin.add_api({
CHAIN_RO_CALL(get_activated_protocol_features, 200),
CHAIN_RO_CALL(get_block, 200),
CHAIN_RO_CALL(get_block_header_state, 200),
Expand Down
11 changes: 6 additions & 5 deletions plugins/http_plugin/http_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ namespace eosio {

class http_plugin_impl {
public:
map<string,url_handler> url_handlers;
// key -> priority, url_handler
map<string,std::pair<int,url_handler>> url_handlers;
optional<tcp::endpoint> listen_endpoint;
string access_control_allow_origin;
string access_control_allow_headers;
Expand Down Expand Up @@ -311,11 +312,11 @@ namespace eosio {
if( handler_itr != url_handlers.end()) {
con->defer_http_response();
bytes_in_flight += body.size();
app().post( appbase::priority::low,
app().post( handler_itr->second.first,
[&ioc = thread_pool->get_executor(), &bytes_in_flight = this->bytes_in_flight, handler_itr,
resource{std::move( resource )}, body{std::move( body )}, con]() {
try {
handler_itr->second( resource, body,
handler_itr->second.second( resource, body,
[&ioc, &bytes_in_flight, con]( int code, fc::variant response_body ) {
boost::asio::post( ioc, [response_body{std::move( response_body )}, &bytes_in_flight, con, code]() mutable {
std::string json = fc::json::to_string( response_body );
Expand Down Expand Up @@ -651,9 +652,9 @@ namespace eosio {
}
}

void http_plugin::add_handler(const string& url, const url_handler& handler) {
void http_plugin::add_handler(const string& url, const url_handler& handler, int priority) {
fc_ilog( logger, "add api url: ${c}", ("c", url) );
my->url_handlers.insert(std::make_pair(url,handler));
my->url_handlers.insert(std::make_pair(url,std::make_pair(priority, handler)));
}

void http_plugin::handle_exception( const char *api_name, const char *call_name, const string& body, url_response_callback cb ) {
Expand Down
6 changes: 3 additions & 3 deletions plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ namespace eosio {
void plugin_shutdown();
void handle_sighup() override;

void add_handler(const string& url, const url_handler&);
void add_api(const api_description& api) {
void add_handler(const string& url, const url_handler&, int priority = appbase::priority::low);
void add_api(const api_description& api, int priority = appbase::priority::low) {
for (const auto& call : api)
add_handler(call.first, call.second);
add_handler(call.first, call.second, priority);
}

// standard exception handling for api handlers
Expand Down
2 changes: 1 addition & 1 deletion plugins/net_api_plugin/net_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void net_api_plugin::plugin_startup() {
INVOKE_R_V(net_mgr, connections), 201),
// CALL(net, net_mgr, open,
// INVOKE_V_R(net_mgr, open, std::string), 200),
});
}, appbase::priority::medium);
}

void net_api_plugin::plugin_initialize(const variables_map& options) {
Expand Down
3 changes: 2 additions & 1 deletion plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,8 @@ namespace eosio {
// called from connection strand
void connection::handle_message( const block_id_type& id, signed_block_ptr ptr ) {
peer_dlog( this, "received signed_block ${id}", ("id", ptr->block_num() ) );
app().post(priority::high, [ptr{std::move(ptr)}, id, c = shared_from_this()]() mutable {
auto priority = my_impl->sync_master->syncing_with_peer() ? priority::medium : priority::high;
app().post(priority, [ptr{std::move(ptr)}, id, c = shared_from_this()]() mutable {
c->process_signed_block( id, std::move( ptr ) );
});
my_impl->dispatcher->bcast_notice( id );
Expand Down
2 changes: 1 addition & 1 deletion plugins/producer_api_plugin/producer_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void producer_api_plugin::plugin_startup() {
producer_plugin::get_supported_protocol_features_params), 201),
CALL(producer, producer, get_account_ram_corrections,
INVOKE_R_R(producer, get_account_ram_corrections, producer_plugin::get_account_ram_corrections_params), 201),
});
}, appbase::priority::medium);
}

void producer_api_plugin::plugin_initialize(const variables_map& options) {
Expand Down