Skip to content

Commit

Permalink
Remove _check_serialization_status check from jsonrpc plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Leśniak authored and vogel76 committed Feb 29, 2024
1 parent 39878eb commit c5c1feb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
4 changes: 1 addition & 3 deletions libraries/plugins/chain/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ class chain_plugin_impl
default_block_writer( db, app ),
webserver( app.get_plugin<hive::plugins::webserver::webserver_plugin>() ),
theApp( app )
{
theApp.get_plugin<hive::plugins::json_rpc::json_rpc_plugin>().add_serialization_status( [this](){ return db.has_hardfork( HIVE_HARDFORK_1_26 ); } );
}
{}

~chain_plugin_impl()
{
Expand Down
74 changes: 27 additions & 47 deletions libraries/plugins/json_rpc/json_rpc_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,11 @@ namespace detail
_logger->log(request, response);
}

void add_serialization_status( const std::function<bool()>& call );

DECLARE_API(
(get_methods)
(get_signature) )

std::unique_ptr< json_rpc_logger > _logger;
std::function<bool()> _check_serialization_status = [](){ return true; };

appbase::application& theApp;
};
Expand All @@ -254,11 +251,6 @@ namespace detail
json_rpc_plugin_impl::~json_rpc_plugin_impl() {}


void json_rpc_plugin_impl::add_serialization_status( const std::function<bool()>& serialization_status )
{
_check_serialization_status = serialization_status;
}

void json_rpc_plugin_impl::add_api_method( const string& api_name, const string& method_name, const api_method& api, const api_method_signature& sig )
{
wdump((api_name)(method_name));
Expand Down Expand Up @@ -437,50 +429,43 @@ namespace detail
{
STATSD_START_TIMER( "jsonrpc", "api", method_name, 1.0f, theApp );

if( _check_serialization_status() )
bool _change_of_serialization_is_allowed = false;
try
{
bool _change_of_serialization_is_allowed = false;
try
response.result = (*call)( func_args );
}
catch( fc::bad_cast_exception& e )
{
if( method_name == "network_broadcast_api.broadcast_transaction" ||
method_name == "database_api.verify_authority"
)
{
response.result = (*call)( func_args );
_change_of_serialization_is_allowed = true;
}
catch( fc::bad_cast_exception& e )
else
{
if( method_name == "network_broadcast_api.broadcast_transaction" ||
method_name == "database_api.verify_authority"
)
{
_change_of_serialization_is_allowed = true;
}
else
{
throw e;
}
throw e;
}
}
catch(...)
{
auto eptr = std::current_exception();
std::rethrow_exception( eptr );
}

if( _change_of_serialization_is_allowed )
{
try
{
mode_guard guard( hive::protocol::transaction_serialization_type::legacy );
ilog("Change of serialization( `${method_name}' ) - a legacy format is enabled now",("method_name", method_name) );
response.result = (*call)( func_args );
}
catch(...)
{
auto eptr = std::current_exception();
std::rethrow_exception( eptr );
}

if( _change_of_serialization_is_allowed )
{
try
{
mode_guard guard( hive::protocol::transaction_serialization_type::legacy );
ilog("Change of serialization( `${method_name}' ) - a legacy format is enabled now",("method_name", method_name) );
response.result = (*call)( func_args );
}
catch(...)
{
auto eptr = std::current_exception();
std::rethrow_exception( eptr );
}
}
}
else
{
response.result = (*call)( func_args );
}
}
}
Expand Down Expand Up @@ -689,11 +674,6 @@ string json_rpc_plugin::call( const string& message )

}

void json_rpc_plugin::add_serialization_status( const std::function<bool()>& serialization_status )
{
my->add_serialization_status( serialization_status );
}

} } } // hive::plugins::json_rpc

FC_REFLECT( hive::plugins::json_rpc::detail::json_rpc_error, (code)(message)(data) )
Expand Down

0 comments on commit c5c1feb

Please sign in to comment.