From 43be8be8eb5ddd70c997d909b453c57e2ee604a2 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Thu, 26 Sep 2024 16:02:54 +0200 Subject: [PATCH 1/6] chore: update to latest dependecies --- CMakeModules/cpp_graphql_gen.cmake | 2 +- conanfile.py | 10 +++++----- libraries/core_libs/consensus/src/dag/dag.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeModules/cpp_graphql_gen.cmake b/CMakeModules/cpp_graphql_gen.cmake index 3816ec6256..8fff070ad2 100644 --- a/CMakeModules/cpp_graphql_gen.cmake +++ b/CMakeModules/cpp_graphql_gen.cmake @@ -6,7 +6,7 @@ set(Boost_NO_WARN_NEW_VERSIONS 1) FetchContent_Declare( cppgraphqlgen GIT_REPOSITORY https://github.com/microsoft/cppgraphqlgen.git - GIT_TAG v4.5.6 + GIT_TAG v4.5.8 GIT_SHALLOW TRUE ) set(GRAPHQL_BUILD_TESTS OFF) diff --git a/conanfile.py b/conanfile.py index 221513fb83..35a1038e44 100644 --- a/conanfile.py +++ b/conanfile.py @@ -13,14 +13,14 @@ class TaraxaConan(ConanFile): generators = "cmake" def requirements(self): - self.requires("boost/1.85.0") + self.requires("boost/1.86.0") self.requires("cppcheck/2.12") #TODO(2.14.1) - self.requires("openssl/3.2.1") + self.requires("openssl/3.3.2") self.requires("cryptopp/8.9.0") - self.requires("gtest/1.14.0") - self.requires("lz4/1.9.4") + self.requires("gtest/1.15.0") + self.requires("lz4/1.10.0") self.requires("rocksdb/9.2.1") - self.requires("prometheus-cpp/1.1.0") + self.requires("prometheus-cpp/1.2.4") self.requires("jsoncpp/1.9.5") def _configure_boost_libs(self): diff --git a/libraries/core_libs/consensus/src/dag/dag.cpp b/libraries/core_libs/consensus/src/dag/dag.cpp index 05adb111f3..f8a2f2ad8e 100644 --- a/libraries/core_libs/consensus/src/dag/dag.cpp +++ b/libraries/core_libs/consensus/src/dag/dag.cpp @@ -148,7 +148,7 @@ bool Dag::computeOrder(const blk_hash_t &anchor, std::vector &ordere dfs.push({cur.first, true}); std::vector> neighbors; // iterate through neighbors - for (std::tie(adj_s, adj_e) = adjacenct_vertices(cur.first, graph_); adj_s != adj_e; adj_s++) { + for (std::tie(adj_s, adj_e) = boost::adjacent_vertices(cur.first, graph_); adj_s != adj_e; adj_s++) { if (epfriend.find(index_map[*adj_s]) == epfriend.end()) { // not in this epoch continue; } @@ -183,7 +183,7 @@ bool Dag::reachable(vertex_t const &from, vertex_t const &to) const { vertex_t t = st.top(); st.pop(); vertex_adj_iter_t s, e; - for (std::tie(s, e) = adjacenct_vertices(t, graph_); s != e; ++s) { + for (std::tie(s, e) = boost::adjacent_vertices(t, graph_); s != e; ++s) { if (visited.count(*s)) continue; if (*s == target) return true; visited.insert(*s); @@ -221,7 +221,7 @@ std::vector PivotTree::getGhostPath(const blk_hash_t &vertex) const cur = st.top(); st.pop(); post_order.emplace_back(cur); - for (std::tie(s, e) = adjacenct_vertices(cur, graph_); s != e; s++) { + for (std::tie(s, e) = boost::adjacent_vertices(cur, graph_); s != e; s++) { st.emplace(*s); } } @@ -232,7 +232,7 @@ std::vector PivotTree::getGhostPath(const blk_hash_t &vertex) const for (auto const &n : post_order) { auto total_w = 0; // get childrens - for (std::tie(s, e) = adjacenct_vertices(n, graph_); s != e; s++) { + for (std::tie(s, e) = boost::adjacent_vertices(n, graph_); s != e; s++) { if (weight_map.count(*s)) { // bigger timestamp total_w += weight_map[*s]; } @@ -248,7 +248,7 @@ std::vector PivotTree::getGhostPath(const blk_hash_t &vertex) const size_t heavist = 0; vertex_t next = root; - for (std::tie(s, e) = adjacenct_vertices(root, graph_); s != e; s++) { + for (std::tie(s, e) = boost::adjacent_vertices(root, graph_); s != e; s++) { if (!weight_map.count(*s)) continue; // bigger timestamp size_t w = weight_map[*s]; assert(w > 0); From 7667f49c83461bebd82793214a9d5822e8b8dd00 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Fri, 27 Sep 2024 11:19:57 +0200 Subject: [PATCH 2/6] update cpp-check --- CMakeModules/cppcheck.cmake | 1 + conanfile.py | 2 +- libraries/aleth/libdevcore/Common.h | 33 ------------------- .../config/include/config/config_utils.hpp | 2 +- libraries/config/src/config_utils.cpp | 2 +- libraries/core_libs/consensus/src/dag/dag.cpp | 1 - .../consensus/src/dag/dag_manager.cpp | 3 +- 7 files changed, 6 insertions(+), 38 deletions(-) diff --git a/CMakeModules/cppcheck.cmake b/CMakeModules/cppcheck.cmake index 1472b400d8..f8d8ceacf4 100644 --- a/CMakeModules/cppcheck.cmake +++ b/CMakeModules/cppcheck.cmake @@ -10,6 +10,7 @@ else () COMMAND ${CPP_CHECK_EXE} --error-exitcode=1 --enable=all + --check-level=exhaustive --suppress=missingInclude --suppress=missingIncludeSystem # find_if - useless here diff --git a/conanfile.py b/conanfile.py index 35a1038e44..9d1f5beccf 100644 --- a/conanfile.py +++ b/conanfile.py @@ -14,7 +14,7 @@ class TaraxaConan(ConanFile): def requirements(self): self.requires("boost/1.86.0") - self.requires("cppcheck/2.12") #TODO(2.14.1) + self.requires("cppcheck/2.15.0") self.requires("openssl/3.3.2") self.requires("cryptopp/8.9.0") self.requires("gtest/1.15.0") diff --git a/libraries/aleth/libdevcore/Common.h b/libraries/aleth/libdevcore/Common.h index 6c6b1b550b..6f89f48476 100644 --- a/libraries/aleth/libdevcore/Common.h +++ b/libraries/aleth/libdevcore/Common.h @@ -127,33 +127,6 @@ using strings = std::vector; // Null/Invalid values for convenience. extern bytes const NullBytes; -/// Interprets @a _u as a two's complement signed number and returns the -/// resulting s256. -inline s256 u2s(u256 _u) { - static const bigint c_end = bigint(1) << 256; - if (boost::multiprecision::bit_test(_u, 255)) - return s256(-(c_end - _u)); - else - return s256(_u); -} - -/// @returns the two's complement signed representation of the signed number _u. -inline u256 s2u(s256 _u) { - static const bigint c_end = bigint(1) << 256; - if (_u >= 0) - return u256(_u); - else - return u256(c_end + _u); -} - -/// @returns the smallest n >= 0 such that (1 << n) >= _x -inline unsigned int toLog2(u256 _x) { - unsigned ret; - for (ret = 0; _x >>= 1; ++ret) { - } - return ret; -} - template inline u256 exp10() { return exp10() * u256(10); @@ -164,12 +137,6 @@ inline u256 exp10<0>() { return u256(1); } -/// @returns the absolute distance between _a and _b. -template -inline N diff(N const& _a, N const& _b) { - return std::max(_a, _b) - std::min(_a, _b); -} - /// RAII utility class whose destructor calls a given function. class ScopeGuard { public: diff --git a/libraries/config/include/config/config_utils.hpp b/libraries/config/include/config/config_utils.hpp index 2586973d00..333c21bbdd 100644 --- a/libraries/config/include/config/config_utils.hpp +++ b/libraries/config/include/config/config_utils.hpp @@ -14,7 +14,7 @@ std::string getConfigErr(const std::vector &path); Json::Value getConfigData(Json::Value root, const std::vector &path, bool optional = false); std::string getConfigDataAsString(const Json::Value &root, const std::vector &path, bool optional = false, - std::string value = {}); + const std::string &value = {}); uint32_t getConfigDataAsUInt(const Json::Value &root, const std::vector &path, bool optional = false, uint32_t value = 0); diff --git a/libraries/config/src/config_utils.cpp b/libraries/config/src/config_utils.cpp index 2daab50d43..f7dc9dc475 100644 --- a/libraries/config/src/config_utils.cpp +++ b/libraries/config/src/config_utils.cpp @@ -28,7 +28,7 @@ Json::Value getConfigData(Json::Value root, const std::vector &path } std::string getConfigDataAsString(const Json::Value &root, const std::vector &path, bool optional, - std::string value) { + const std::string &value) { try { Json::Value ret = getConfigData(root, path, optional); if (ret.isNull()) { diff --git a/libraries/core_libs/consensus/src/dag/dag.cpp b/libraries/core_libs/consensus/src/dag/dag.cpp index f8a2f2ad8e..d6c45716fb 100644 --- a/libraries/core_libs/consensus/src/dag/dag.cpp +++ b/libraries/core_libs/consensus/src/dag/dag.cpp @@ -257,7 +257,6 @@ std::vector PivotTree::getGhostPath(const blk_hash_t &vertex) const next = *s; } else if (w == heavist) { if (index_map[*s] < index_map[next]) { - heavist = w; next = *s; } } diff --git a/libraries/core_libs/consensus/src/dag/dag_manager.cpp b/libraries/core_libs/consensus/src/dag/dag_manager.cpp index 27d178fe08..b08db434e4 100644 --- a/libraries/core_libs/consensus/src/dag/dag_manager.cpp +++ b/libraries/core_libs/consensus/src/dag/dag_manager.cpp @@ -375,7 +375,8 @@ uint DagManager::setDagBlockOrder(blk_hash_t const &new_anchor, PbftPeriod perio } else { db_->removeDagBlock(blk_hash); seen_blocks_.erase(blk_hash); - for (const auto &trx : dag_block->getTrxs()) expired_dag_blocks_transactions.emplace_back(trx); + const auto dag_trxs = dag_block->getTrxs(); + std::copy(dag_trxs.begin(), dag_trxs.end(), std::back_inserter(expired_dag_blocks_transactions)); } } } From 8fb001419d8ff153df536fa7729a70a3f4e3a1ff Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Mon, 30 Sep 2024 16:09:47 +0200 Subject: [PATCH 3/6] chore: additional check on ws --- libraries/core_libs/network/src/ws_server.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/core_libs/network/src/ws_server.cpp b/libraries/core_libs/network/src/ws_server.cpp index a2029556f9..cb991382f9 100644 --- a/libraries/core_libs/network/src/ws_server.cpp +++ b/libraries/core_libs/network/src/ws_server.cpp @@ -57,6 +57,8 @@ void WsSession::on_read(beast::error_code ec, std::size_t bytes_transferred) { } void WsSession::processAsync() { + if (closed_) return; + std::string request(static_cast(read_buffer_.data().data()), read_buffer_.size()); read_buffer_.consume(read_buffer_.size()); LOG(log_tr_) << "processAsync " << request; @@ -73,6 +75,8 @@ void WsSession::processAsync() { } void WsSession::writeAsync(std::string &&message) { + if (closed_) return; + LOG(log_tr_) << "WS WRITE " << message.c_str(); auto executor = ws_.get_executor(); if (!executor) { From 629447002fa43cb00d280645c3278a6897e39605 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 2 Oct 2024 10:47:45 +0200 Subject: [PATCH 4/6] fix cpp check --- CMakeModules/cppcheck.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeModules/cppcheck.cmake b/CMakeModules/cppcheck.cmake index f8d8ceacf4..33bb8c8186 100644 --- a/CMakeModules/cppcheck.cmake +++ b/CMakeModules/cppcheck.cmake @@ -20,7 +20,6 @@ else () # false positive --suppress=uninitMemberVar:${PROJECT_SOURCE_DIR}/*/UPnP.cpp # This is only enabled because of test functions and false positives - --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/Eth.cpp --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/Common.cpp --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/Base64.cpp --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/util.cpp @@ -28,6 +27,13 @@ else () --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/UPnP.cpp --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/logger.cpp --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/state_api.cpp + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/watches.hpp + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/vector_ref.h + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/RLP.h + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/FixedHash.h + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/CommonData.h + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/Common.h + --suppress=unusedFunction:${PROJECT_SOURCE_DIR}/*/Log.h # TODO remove this when we solve correct exit of programs --suppress=localMutex:${PROJECT_SOURCE_DIR}/*/main.cpp # Just style warning @@ -39,6 +45,7 @@ else () --suppress=unmatchedSuppression:${PROJECT_SOURCE_DIR}/*/Common.h --suppress=cstyleCast:${PROJECT_SOURCE_DIR}/*/vector_ref.h --suppress=cstyleCast:${PROJECT_SOURCE_DIR}/*/Common.h + --suppress=cstyleCast:${PROJECT_SOURCE_DIR}/*/transaction.cpp # not an issue here --suppress=virtualCallInConstructor:${PROJECT_SOURCE_DIR}/*/final_chain.cpp # just a warning From 05b9990f51f773772afca8b27577cff8a7cd761a Mon Sep 17 00:00:00 2001 From: mfrankovi Date: Thu, 3 Oct 2024 14:44:50 +0200 Subject: [PATCH 5/6] chore: rpc requests limit --- libraries/config/include/config/network.hpp | 2 ++ libraries/config/src/network.cpp | 5 +++ .../network/include/network/http_server.hpp | 9 +++-- .../network/include/network/ws_server.hpp | 8 ++++- .../core_libs/network/src/http_server.cpp | 35 +++++++++++++++---- libraries/core_libs/network/src/ws_server.cpp | 24 +++++++++++-- .../core_libs/node/include/node/node.hpp | 4 +-- libraries/core_libs/node/src/node.cpp | 24 ++++++------- 8 files changed, 84 insertions(+), 27 deletions(-) diff --git a/libraries/config/include/config/network.hpp b/libraries/config/include/config/network.hpp index d9f1c07c19..477a8155cd 100644 --- a/libraries/config/include/config/network.hpp +++ b/libraries/config/include/config/network.hpp @@ -22,6 +22,8 @@ struct ConnectionConfig { // Number of threads dedicated to the rpc calls processing, default = 5 uint16_t threads_num{5}; + uint32_t max_pending_tasks{100}; + void validate() const; }; diff --git a/libraries/config/src/network.cpp b/libraries/config/src/network.cpp index 98031b74bf..cb37200713 100644 --- a/libraries/config/src/network.cpp +++ b/libraries/config/src/network.cpp @@ -33,6 +33,11 @@ void dec_json(const Json::Value &json, ConnectionConfig &config) { config.ws_port = ws_port.asUInt(); } + // max pending tasks + if (auto max_pending_tasks = getConfigData(json, {"max_pending_tasks"}, true); !max_pending_tasks.isNull()) { + config.max_pending_tasks = max_pending_tasks.asUInt(); + } + // number of threads processing rpc calls if (auto threads_num = getConfigData(json, {"threads_num"}, true); !threads_num.isNull()) { config.threads_num = threads_num.asUInt(); diff --git a/libraries/core_libs/network/include/network/http_server.hpp b/libraries/core_libs/network/include/network/http_server.hpp index 615f0cb954..1641c1a051 100644 --- a/libraries/core_libs/network/include/network/http_server.hpp +++ b/libraries/core_libs/network/include/network/http_server.hpp @@ -4,6 +4,7 @@ #include #include +#include "common/thread_pool.hpp" #include "common/types.hpp" #include "logger/logger.hpp" @@ -22,8 +23,8 @@ class HttpHandler; class HttpServer : public std::enable_shared_from_this { public: - HttpServer(boost::asio::io_context& io, boost::asio::ip::tcp::endpoint ep, const addr_t& node_addr, - const std::shared_ptr& request_processor); + HttpServer(std::shared_ptr thread_pool, boost::asio::ip::tcp::endpoint ep, const addr_t& node_addr, + const std::shared_ptr& request_processor, uint32_t max_pending_tasks); virtual ~HttpServer() { HttpServer::stop(); } @@ -31,6 +32,8 @@ class HttpServer : public std::enable_shared_from_this { bool stop(); void accept(); + uint32_t numberOfPendingTasks() const; + bool pendingTasksOverLimit() const { return numberOfPendingTasks() > kMaxPendingTasks; } boost::asio::io_context& getIoContext() { return io_context_; } std::shared_ptr getShared(); std::shared_ptr createConnection(); @@ -45,6 +48,8 @@ class HttpServer : public std::enable_shared_from_this { boost::asio::io_context& io_context_; boost::asio::ip::tcp::acceptor acceptor_; boost::asio::ip::tcp::endpoint ep_; + std::weak_ptr thread_pool_; + const uint32_t kMaxPendingTasks; LOG_OBJECTS_DEFINE }; // QQ: diff --git a/libraries/core_libs/network/include/network/ws_server.hpp b/libraries/core_libs/network/include/network/ws_server.hpp index e1290c8aef..60a3f6ccbd 100644 --- a/libraries/core_libs/network/include/network/ws_server.hpp +++ b/libraries/core_libs/network/include/network/ws_server.hpp @@ -16,6 +16,7 @@ #include #include +#include "common/thread_pool.hpp" #include "config/config.hpp" #include "dag/dag_block.hpp" #include "final_chain/data.hpp" @@ -84,7 +85,8 @@ class WsSession : public std::enable_shared_from_this { // Accepts incoming connections and launches the sessions class WsServer : public std::enable_shared_from_this, public jsonrpc::AbstractServerConnector { public: - WsServer(boost::asio::io_context& ioc, tcp::endpoint endpoint, addr_t node_addr); + WsServer(std::shared_ptr thread_pool, tcp::endpoint endpoint, addr_t node_addr, + uint32_t max_pending_tasks); virtual ~WsServer(); WsServer(const WsServer&) = delete; @@ -101,6 +103,8 @@ class WsServer : public std::enable_shared_from_this, public jsonrpc:: void newPendingTransaction(const trx_hash_t& trx_hash); void newPillarBlockData(const pillar_chain::PillarBlockData& pillar_block_data); uint32_t numberOfSessions(); + uint32_t numberOfPendingTasks() const; + bool pendingTasksOverLimit() const { return numberOfPendingTasks() > kMaxPendingTasks; } virtual std::shared_ptr createSession(tcp::socket&& socket) = 0; @@ -118,6 +122,8 @@ class WsServer : public std::enable_shared_from_this, public jsonrpc:: boost::shared_mutex sessions_mtx_; protected: + std::weak_ptr thread_pool_; + uint32_t kMaxPendingTasks; const addr_t node_addr_; }; diff --git a/libraries/core_libs/network/src/http_server.cpp b/libraries/core_libs/network/src/http_server.cpp index 1c82a131db..e89cdc9a72 100644 --- a/libraries/core_libs/network/src/http_server.cpp +++ b/libraries/core_libs/network/src/http_server.cpp @@ -2,9 +2,15 @@ namespace taraxa::net { -HttpServer::HttpServer(boost::asio::io_context &io, boost::asio::ip::tcp::endpoint ep, const addr_t &node_addr, - const std::shared_ptr &request_processor) - : request_processor_(request_processor), io_context_(io), acceptor_(io), ep_(std::move(ep)) { +HttpServer::HttpServer(std::shared_ptr thread_pool, boost::asio::ip::tcp::endpoint ep, + const addr_t &node_addr, const std::shared_ptr &request_processor, + uint32_t max_pending_tasks) + : request_processor_(request_processor), + io_context_(thread_pool->unsafe_get_io_context()), + acceptor_(thread_pool->unsafe_get_io_context()), + ep_(std::move(ep)), + thread_pool_(thread_pool), + kMaxPendingTasks(max_pending_tasks) { LOG_OBJECTS_CREATE("HTTP"); LOG(log_si_) << "Taraxa HttpServer started at port: " << ep_.port(); } @@ -66,6 +72,14 @@ bool HttpServer::stop() { return true; } +uint32_t HttpServer::numberOfPendingTasks() const { + auto thread_pool = thread_pool_.lock(); + if (thread_pool) { + return thread_pool->num_pending_tasks(); + } + return 0; +} + std::shared_ptr HttpConnection::getShared() { try { return shared_from_this(); @@ -98,10 +112,17 @@ void HttpConnection::read() { } else { assert(server_->request_processor_); LOG(server_->log_dg_) << "Received: " << request_; - response_ = server_->request_processor_->process(request_); - boost::beast::http::async_write( - socket_, response_, - [this_sp = getShared()](auto const & /*ec*/, auto /*bytes_transferred*/) { this_sp->stop(); }); + + if (server_->pendingTasksOverLimit()) { + LOG(server_->log_er_) << "HttpConnection closed - pending tasks over the limit " + << server_->numberOfPendingTasks(); + stop(); + } else { + response_ = server_->request_processor_->process(request_); + boost::beast::http::async_write( + socket_, response_, + [this_sp = getShared()](auto const & /*ec*/, auto /*bytes_transferred*/) { this_sp->stop(); }); + } } }); } diff --git a/libraries/core_libs/network/src/ws_server.cpp b/libraries/core_libs/network/src/ws_server.cpp index cb991382f9..bb361550e8 100644 --- a/libraries/core_libs/network/src/ws_server.cpp +++ b/libraries/core_libs/network/src/ws_server.cpp @@ -49,8 +49,13 @@ void WsSession::on_read(beast::error_code ec, std::size_t bytes_transferred) { return close(is_normal(ec)); } - LOG(log_tr_) << "WS READ " << (static_cast(read_buffer_.data().data())); + auto ws_server = ws_server_.lock(); + if (ws_server && ws_server->pendingTasksOverLimit()) { + LOG(log_er_) << "WS closed - pending tasks over the limit " << ws_server->numberOfPendingTasks(); + return close(true); + } + LOG(log_tr_) << "WS READ " << (static_cast(read_buffer_.data().data())); processAsync(); // Do another read do_read(); @@ -202,8 +207,13 @@ bool WsSession::is_normal(const beast::error_code &ec) const { return false; } -WsServer::WsServer(boost::asio::io_context &ioc, tcp::endpoint endpoint, addr_t node_addr) - : ioc_(ioc), acceptor_(ioc), node_addr_(std::move(node_addr)) { +WsServer::WsServer(std::shared_ptr thread_pool, tcp::endpoint endpoint, addr_t node_addr, + uint32_t max_pending_tasks) + : ioc_(thread_pool->unsafe_get_io_context()), + acceptor_(thread_pool->unsafe_get_io_context()), + thread_pool_(thread_pool), + kMaxPendingTasks(max_pending_tasks), + node_addr_(std::move(node_addr)) { LOG_OBJECTS_CREATE("WS_SERVER"); beast::error_code ec; @@ -331,4 +341,12 @@ uint32_t WsServer::numberOfSessions() { return sessions.size(); } +uint32_t WsServer::numberOfPendingTasks() const { + auto thread_pool = thread_pool_.lock(); + if (thread_pool) { + return thread_pool->num_pending_tasks(); + } + return 0; +} + } // namespace taraxa::net \ No newline at end of file diff --git a/libraries/core_libs/node/include/node/node.hpp b/libraries/core_libs/node/include/node/node.hpp index 77573b7d78..2a658ecd2f 100644 --- a/libraries/core_libs/node/include/node/node.hpp +++ b/libraries/core_libs/node/include/node/node.hpp @@ -80,8 +80,8 @@ class FullNode : public std::enable_shared_from_this { using JsonRpcServer = ModularServer; // should be destroyed after all components, since they may depend on it through unsafe pointers - std::unique_ptr rpc_thread_pool_; - std::unique_ptr graphql_thread_pool_; + std::shared_ptr rpc_thread_pool_; + std::shared_ptr graphql_thread_pool_; // In cae we will you config for this TP, it needs to be unique_ptr !!! util::ThreadPool subscription_pool_; diff --git a/libraries/core_libs/node/src/node.cpp b/libraries/core_libs/node/src/node.cpp index 0ee48d9c94..c05a4d4e5c 100644 --- a/libraries/core_libs/node/src/node.cpp +++ b/libraries/core_libs/node/src/node.cpp @@ -173,7 +173,7 @@ void FullNode::start() { // Inits rpc related members if (conf_.network.rpc) { - rpc_thread_pool_ = std::make_unique(conf_.network.rpc->threads_num); + rpc_thread_pool_ = std::make_shared(conf_.network.rpc->threads_num); net::rpc::eth::EthParams eth_rpc_params; eth_rpc_params.address = getAddress(); eth_rpc_params.chain_id = conf_.genesis.chain_id; @@ -226,16 +226,15 @@ void FullNode::start() { if (conf_.network.rpc->http_port) { auto json_rpc_processor = std::make_shared(); jsonrpc_http_ = std::make_shared( - rpc_thread_pool_->unsafe_get_io_context(), - boost::asio::ip::tcp::endpoint{conf_.network.rpc->address, *conf_.network.rpc->http_port}, getAddress(), - json_rpc_processor); + rpc_thread_pool_, boost::asio::ip::tcp::endpoint{conf_.network.rpc->address, *conf_.network.rpc->http_port}, + getAddress(), json_rpc_processor, conf_.network.rpc->max_pending_tasks); jsonrpc_api_->addConnector(json_rpc_processor); jsonrpc_http_->start(); } if (conf_.network.rpc->ws_port) { jsonrpc_ws_ = std::make_shared( - rpc_thread_pool_->unsafe_get_io_context(), - boost::asio::ip::tcp::endpoint{conf_.network.rpc->address, *conf_.network.rpc->ws_port}, getAddress()); + rpc_thread_pool_, boost::asio::ip::tcp::endpoint{conf_.network.rpc->address, *conf_.network.rpc->ws_port}, + getAddress(), conf_.network.rpc->max_pending_tasks); jsonrpc_api_->addConnector(jsonrpc_ws_); jsonrpc_ws_->run(); } @@ -280,22 +279,23 @@ void FullNode::start() { *rpc_thread_pool_); } if (conf_.network.graphql) { - graphql_thread_pool_ = std::make_unique(conf_.network.graphql->threads_num); + graphql_thread_pool_ = std::make_shared(conf_.network.graphql->threads_num); if (conf_.network.graphql->ws_port) { graphql_ws_ = std::make_shared( - graphql_thread_pool_->unsafe_get_io_context(), - boost::asio::ip::tcp::endpoint{conf_.network.graphql->address, *conf_.network.graphql->ws_port}, - getAddress()); + graphql_thread_pool_, + boost::asio::ip::tcp::endpoint{conf_.network.graphql->address, *conf_.network.graphql->ws_port}, getAddress(), + conf_.network.rpc->max_pending_tasks); // graphql_ws_->run(); } if (conf_.network.graphql->http_port) { graphql_http_ = std::make_shared( - graphql_thread_pool_->unsafe_get_io_context(), + graphql_thread_pool_, boost::asio::ip::tcp::endpoint{conf_.network.graphql->address, *conf_.network.graphql->http_port}, getAddress(), std::make_shared(final_chain_, dag_mgr_, pbft_mgr_, trx_mgr_, db_, gas_pricer_, - as_weak(network_), conf_.genesis.chain_id)); + as_weak(network_), conf_.genesis.chain_id), + conf_.network.rpc->max_pending_tasks); graphql_http_->start(); } } From d8e2f09b02542ce1bd9a49508948b8c643dc34c2 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 16 Oct 2024 11:35:47 +0200 Subject: [PATCH 6/6] chore: fix log lvl --- .../tarcap/packets_handlers/latest/status_packet_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/status_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/status_packet_handler.cpp index 6a751ec456..bd30c35fc3 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/status_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/status_packet_handler.cpp @@ -68,7 +68,7 @@ void StatusPacketHandler::process(const threadpool::PacketData& packet_data, con } if (genesis_hash != kGenesisHash) { - LOG((peers_state_->getPeersCount()) ? log_nf_ : log_er_) + LOG((peers_state_->getPeersCount()) ? log_nf_ : log_wr_) << "Incorrect genesis hash " << genesis_hash << ", host " << packet_data.from_node_id_.abridged() << " will be disconnected"; disconnect(packet_data.from_node_id_, dev::p2p::UserReason);