From fec13cad456829853a62e4c595417c926a7effe5 Mon Sep 17 00:00:00 2001 From: canepat <16927169+canepat@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:57:29 +0200 Subject: [PATCH] move block cache from rpcdaemon to core (#1323) small cleanups --- .../{silkrpc => core}/common/block_cache.hpp | 16 +++++----------- .../common/block_cache_test.cpp | 0 silkworm/core/types/block_test.cpp | 1 + silkworm/silkrpc/commands/debug_api.hpp | 2 +- silkworm/silkrpc/commands/erigon_api.hpp | 2 +- silkworm/silkrpc/commands/eth_api.hpp | 2 +- silkworm/silkrpc/commands/ots_api.hpp | 2 +- silkworm/silkrpc/commands/parity_api.hpp | 2 +- silkworm/silkrpc/commands/trace_api.hpp | 2 +- silkworm/silkrpc/core/cached_chain.hpp | 2 +- silkworm/silkrpc/core/call_many.hpp | 2 +- silkworm/silkrpc/core/evm_debug.hpp | 2 +- silkworm/silkrpc/core/evm_trace.hpp | 2 +- silkworm/silkrpc/daemon.hpp | 1 + silkworm/silkrpc/http/request_handler.cpp | 7 +++++-- silkworm/silkrpc/http/server.cpp | 5 ++--- silkworm/silkrpc/test/context_test_base.cpp | 2 +- 17 files changed, 25 insertions(+), 27 deletions(-) rename silkworm/{silkrpc => core}/common/block_cache.hpp (69%) rename silkworm/{silkrpc => core}/common/block_cache_test.cpp (100%) diff --git a/silkworm/silkrpc/common/block_cache.hpp b/silkworm/core/common/block_cache.hpp similarity index 69% rename from silkworm/silkrpc/common/block_cache.hpp rename to silkworm/core/common/block_cache.hpp index 50a8b436e3..7910b16d86 100644 --- a/silkworm/silkrpc/common/block_cache.hpp +++ b/silkworm/core/common/block_cache.hpp @@ -17,19 +17,13 @@ #pragma once #include -#include -#include +#include #include -#include #include #include -#include -#include -#include -#include -#include +#include namespace silkworm { @@ -38,16 +32,16 @@ class BlockCache { explicit BlockCache(std::size_t capacity = 1024, bool shared_cache = true) : block_cache_(capacity, shared_cache) {} - std::optional> get(const evmc::bytes32& key) { + std::optional> get(const evmc::bytes32& key) { return block_cache_.get_as_copy(key); } - void insert(const evmc::bytes32& key, const std::shared_ptr block) { + void insert(const evmc::bytes32& key, const std::shared_ptr& block) { block_cache_.put(key, block); } private: - lru_cache> block_cache_; + lru_cache> block_cache_; }; } // namespace silkworm diff --git a/silkworm/silkrpc/common/block_cache_test.cpp b/silkworm/core/common/block_cache_test.cpp similarity index 100% rename from silkworm/silkrpc/common/block_cache_test.cpp rename to silkworm/core/common/block_cache_test.cpp diff --git a/silkworm/core/types/block_test.cpp b/silkworm/core/types/block_test.cpp index 674ed94266..2415949df4 100644 --- a/silkworm/core/types/block_test.cpp +++ b/silkworm/core/types/block_test.cpp @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ + #include "block.hpp" #include diff --git a/silkworm/silkrpc/commands/debug_api.hpp b/silkworm/silkrpc/commands/debug_api.hpp index 84bd8039f9..1ba1de4829 100644 --- a/silkworm/silkrpc/commands/debug_api.hpp +++ b/silkworm/silkrpc/commands/debug_api.hpp @@ -23,9 +23,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/silkworm/silkrpc/commands/erigon_api.hpp b/silkworm/silkrpc/commands/erigon_api.hpp index 5f1786a689..93f1f3a56f 100644 --- a/silkworm/silkrpc/commands/erigon_api.hpp +++ b/silkworm/silkrpc/commands/erigon_api.hpp @@ -22,9 +22,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/silkworm/silkrpc/commands/eth_api.hpp b/silkworm/silkrpc/commands/eth_api.hpp index 80e3853b86..ff158b7f4d 100644 --- a/silkworm/silkrpc/commands/eth_api.hpp +++ b/silkworm/silkrpc/commands/eth_api.hpp @@ -24,10 +24,10 @@ #include #include +#include #include #include #include -#include #include #include #include diff --git a/silkworm/silkrpc/commands/ots_api.hpp b/silkworm/silkrpc/commands/ots_api.hpp index 4fea3ffc02..3fd34abfd8 100644 --- a/silkworm/silkrpc/commands/ots_api.hpp +++ b/silkworm/silkrpc/commands/ots_api.hpp @@ -23,9 +23,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/silkworm/silkrpc/commands/parity_api.hpp b/silkworm/silkrpc/commands/parity_api.hpp index bb83efd4ff..889142a545 100644 --- a/silkworm/silkrpc/commands/parity_api.hpp +++ b/silkworm/silkrpc/commands/parity_api.hpp @@ -22,9 +22,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/silkworm/silkrpc/commands/trace_api.hpp b/silkworm/silkrpc/commands/trace_api.hpp index 53f7a1c3a7..a8d1307645 100644 --- a/silkworm/silkrpc/commands/trace_api.hpp +++ b/silkworm/silkrpc/commands/trace_api.hpp @@ -23,9 +23,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/silkworm/silkrpc/core/cached_chain.hpp b/silkworm/silkrpc/core/cached_chain.hpp index f07154b4a6..763f98e86c 100644 --- a/silkworm/silkrpc/core/cached_chain.hpp +++ b/silkworm/silkrpc/core/cached_chain.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/silkworm/silkrpc/core/call_many.hpp b/silkworm/silkrpc/core/call_many.hpp index e152cbdd55..77d64789d0 100644 --- a/silkworm/silkrpc/core/call_many.hpp +++ b/silkworm/silkrpc/core/call_many.hpp @@ -26,12 +26,12 @@ #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" #include #pragma GCC diagnostic pop #include -#include #include #include #include diff --git a/silkworm/silkrpc/core/evm_debug.hpp b/silkworm/silkrpc/core/evm_debug.hpp index 12d6178066..f6ca51a503 100644 --- a/silkworm/silkrpc/core/evm_debug.hpp +++ b/silkworm/silkrpc/core/evm_debug.hpp @@ -27,12 +27,12 @@ #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" #include #pragma GCC diagnostic pop #include -#include #include #include #include diff --git a/silkworm/silkrpc/core/evm_trace.hpp b/silkworm/silkrpc/core/evm_trace.hpp index 122286d217..b2e8a4914a 100644 --- a/silkworm/silkrpc/core/evm_trace.hpp +++ b/silkworm/silkrpc/core/evm_trace.hpp @@ -32,12 +32,12 @@ #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" #include #pragma GCC diagnostic pop #include -#include #include #include #include diff --git a/silkworm/silkrpc/daemon.hpp b/silkworm/silkrpc/daemon.hpp index 890693c31b..59c0e69b34 100644 --- a/silkworm/silkrpc/daemon.hpp +++ b/silkworm/silkrpc/daemon.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/silkworm/silkrpc/http/request_handler.cpp b/silkworm/silkrpc/http/request_handler.cpp index 6845a469a7..17d39efe5e 100644 --- a/silkworm/silkrpc/http/request_handler.cpp +++ b/silkworm/silkrpc/http/request_handler.cpp @@ -46,7 +46,7 @@ boost::asio::awaitable RequestHandler::handle(const http::Request& request reply.content = ""; reply.status = http::StatusType::no_content; } else { - SILK_DEBUG << "handle_user_request content: " << request.content; + SILK_TRACE << "handle HTTP request content #size: " << request.content.size(); const auto request_json = nlohmann::json::parse(request.content); @@ -97,7 +97,7 @@ boost::asio::awaitable RequestHandler::handle(const http::Request& request co_await do_write(reply); - SILK_INFO << "handle_user_request t=" << clock_time::since(start) << "ns"; + SILK_TRACE << "handle HTTP request t=" << clock_time::since(start) << "ns"; } boost::asio::awaitable RequestHandler::handle_request_and_create_reply(const nlohmann::json& request_json, http::Reply& reply) { @@ -119,16 +119,19 @@ boost::asio::awaitable RequestHandler::handle_request_and_create_reply(con const auto json_glaze_handler = rpc_api_table_.find_json_glaze_handler(method); if (json_glaze_handler) { co_await handle_request(request_id, *json_glaze_handler, request_json, reply); + SILK_TRACE << "handle RPC request: " << method; co_return; } const auto json_handler = rpc_api_table_.find_json_handler(method); if (json_handler) { co_await handle_request(request_id, *json_handler, request_json, reply); + SILK_TRACE << "handle RPC request: " << method; co_return; } const auto stream_handler = rpc_api_table_.find_stream_handler(method); if (stream_handler) { co_await handle_request(*stream_handler, request_json); + SILK_TRACE << "handle RPC stream request: " << method; co_return; } diff --git a/silkworm/silkrpc/http/server.cpp b/silkworm/silkrpc/http/server.cpp index 91306fa082..ae9dad142e 100644 --- a/silkworm/silkrpc/http/server.cpp +++ b/silkworm/silkrpc/http/server.cpp @@ -32,7 +32,6 @@ #include #include -#include #include namespace silkworm::rpc::http { @@ -70,7 +69,7 @@ Server::Server(const std::string& end_point, } void Server::start() { - boost::asio::co_spawn(acceptor_.get_executor(), run(), [&](std::exception_ptr eptr) { + boost::asio::co_spawn(acceptor_.get_executor(), run(), [&](const std::exception_ptr& eptr) { if (eptr) std::rethrow_exception(eptr); }); } @@ -94,7 +93,7 @@ boost::asio::awaitable Server::run() { SILK_TRACE << "Server::run starting connection for socket: " << &new_connection->socket(); auto connection_loop = [=]() -> boost::asio::awaitable { co_await new_connection->read_loop(); }; - boost::asio::co_spawn(io_context_, connection_loop, [&](std::exception_ptr eptr) { + boost::asio::co_spawn(io_context_, connection_loop, [&](const std::exception_ptr& eptr) { if (eptr) std::rethrow_exception(eptr); }); } diff --git a/silkworm/silkrpc/test/context_test_base.cpp b/silkworm/silkrpc/test/context_test_base.cpp index 3504e349a5..150dc16667 100644 --- a/silkworm/silkrpc/test/context_test_base.cpp +++ b/silkworm/silkrpc/test/context_test_base.cpp @@ -16,9 +16,9 @@ #include "context_test_base.hpp" +#include #include #include -#include #include #include #include