diff --git a/silkworm/sentry/CMakeLists.txt b/silkworm/sentry/CMakeLists.txt index 3326d0951a..57f6638f1c 100644 --- a/silkworm/sentry/CMakeLists.txt +++ b/silkworm/sentry/CMakeLists.txt @@ -23,6 +23,10 @@ find_package(Microsoft.GSL REQUIRED) find_package(OpenSSL REQUIRED) find_package(Snappy REQUIRED) +if(SILKWORM_CLANG_TIDY) + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-warnings-as-errors=*") +endif() + # sentry common add_subdirectory(common) diff --git a/silkworm/sentry/discovery/discovery.cpp b/silkworm/sentry/discovery/discovery.cpp index acd3aec92c..fbae1e2d42 100644 --- a/silkworm/sentry/discovery/discovery.cpp +++ b/silkworm/sentry/discovery/discovery.cpp @@ -38,7 +38,7 @@ class DiscoveryImpl { concurrency::ExecutorPool& executor_pool, std::vector peer_urls, bool with_dynamic_discovery, - const std::filesystem::path& data_dir_path, + std::filesystem::path data_dir_path, uint64_t network_id, std::function node_key, std::function node_url, @@ -77,21 +77,21 @@ DiscoveryImpl::DiscoveryImpl( concurrency::ExecutorPool& executor_pool, std::vector peer_urls, bool with_dynamic_discovery, - const std::filesystem::path& data_dir_path, + std::filesystem::path data_dir_path, uint64_t network_id, - std::function node_key, + std::function node_key, // NOLINT(performance-unnecessary-value-param) std::function node_url, std::function node_record, std::vector bootnodes, uint16_t disc_v4_port) : peer_urls_(std::move(peer_urls)), with_dynamic_discovery_(with_dynamic_discovery), - data_dir_path_(data_dir_path), + data_dir_path_(std::move(data_dir_path)), node_id_([node_key] { return node_key().public_key(); }), network_id_(network_id), node_db_(executor_pool.any_executor()), bootnodes_(std::move(bootnodes)), - disc_v4_discovery_(executor_pool.any_executor(), disc_v4_port, node_key, node_url, node_record, node_db_.interface()) { + disc_v4_discovery_(executor_pool.any_executor(), disc_v4_port, node_key, std::move(node_url), std::move(node_record), node_db_.interface()) { } Task DiscoveryImpl::run() { @@ -139,8 +139,10 @@ Task> DiscoveryImpl::request_peer_candidat using namespace std::chrono_literals; std::vector exclude_ids; - for (auto& url : exclude_urls) + exclude_ids.reserve(exclude_urls.size()); + for (auto& url : exclude_urls) { exclude_ids.push_back(url.public_key()); + } auto now = std::chrono::system_clock::now(); node_db::NodeDb::FindPeerCandidatesQuery query{ diff --git a/silkworm/sentry/grpc/interfaces/peer_info.hpp b/silkworm/sentry/grpc/interfaces/peer_info.hpp index cbeb0ece64..ed7f9a9597 100644 --- a/silkworm/sentry/grpc/interfaces/peer_info.hpp +++ b/silkworm/sentry/grpc/interfaces/peer_info.hpp @@ -25,12 +25,12 @@ namespace silkworm::sentry::grpc::interfaces { api::PeerInfo peer_info_from_proto_peer_info(const types::PeerInfo& info); -types::PeerInfo proto_peer_info_from_peer_info(const api::PeerInfo& info); +types::PeerInfo proto_peer_info_from_peer_info(const api::PeerInfo&); api::PeerInfos peer_infos_from_proto_peers_reply(const ::sentry::PeersReply& reply); -::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::PeerInfos& infos); +::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::PeerInfos&); std::optional peer_info_opt_from_proto_peer_reply(const ::sentry::PeerByIdReply& reply); -::sentry::PeerByIdReply proto_peer_reply_from_peer_info_opt(const std::optional& info_opt); +::sentry::PeerByIdReply proto_peer_reply_from_peer_info_opt(const std::optional&); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/message_sender.cpp b/silkworm/sentry/message_sender.cpp index 582bf41421..ce1f2b013a 100644 --- a/silkworm/sentry/message_sender.cpp +++ b/silkworm/sentry/message_sender.cpp @@ -29,7 +29,7 @@ Task MessageSender::run(PeerManager& peer_manager) { api::router::SendMessageCall::PeerKeys sent_peer_keys; - auto sender = [&message = call.message(), &sent_peer_keys, peer_filter = call.peer_filter()](std::shared_ptr peer) { + auto sender = [&message = call.message(), &sent_peer_keys, peer_filter = call.peer_filter()](const std::shared_ptr& peer) { auto key_opt = peer->peer_public_key(); if (key_opt && (!peer_filter.peer_public_key || (key_opt.value() == peer_filter.peer_public_key.value()))) { sent_peer_keys.push_back(key_opt.value()); diff --git a/silkworm/sentry/multi_sentry_client.cpp b/silkworm/sentry/multi_sentry_client.cpp index cc6bf9fdb4..70e9558e31 100644 --- a/silkworm/sentry/multi_sentry_client.cpp +++ b/silkworm/sentry/multi_sentry_client.cpp @@ -50,13 +50,13 @@ class MultiSentryClientImpl : public api::Service { std::function(std::shared_ptr)> callback) { using namespace concurrency::awaitable_wait_for_one; - std::function(size_t)> call_factory = [&clients, &callback](size_t index) -> Task { + auto call_factory = [&clients, &callback](size_t index) -> Task { auto client = clients[index]; auto service = co_await client->service(); co_await callback(service); }; - auto group_task = concurrency::generate_parallel_group_task(clients.size(), std::move(call_factory)); + auto group_task = concurrency::generate_parallel_group_task(clients.size(), call_factory); try { co_await (std::move(group_task) || concurrency::timeout(timeout)); diff --git a/silkworm/sentry/peer_manager_api.cpp b/silkworm/sentry/peer_manager_api.cpp index 3c2ec7a778..2cf8f672bc 100644 --- a/silkworm/sentry/peer_manager_api.cpp +++ b/silkworm/sentry/peer_manager_api.cpp @@ -91,7 +91,7 @@ Task PeerManagerApi::handle_peers_calls() { auto call = co_await peers_calls_channel_.receive(); api::PeerInfos peers; - co_await peer_manager_.enumerate_peers([&peers](std::shared_ptr peer) { + co_await peer_manager_.enumerate_peers([&peers](const std::shared_ptr& peer) { auto info_opt = make_peer_info(*peer); if (info_opt) { peers.push_back(info_opt.value()); @@ -109,7 +109,7 @@ Task PeerManagerApi::handle_peer_calls() { auto peer_public_key_opt = call.peer_public_key; std::optional info_opt; - co_await peer_manager_.enumerate_peers([&info_opt, &peer_public_key_opt](std::shared_ptr peer) { + co_await peer_manager_.enumerate_peers([&info_opt, &peer_public_key_opt](const std::shared_ptr& peer) { auto key_opt = peer->peer_public_key(); if (key_opt && peer_public_key_opt && (key_opt.value() == peer_public_key_opt.value())) { info_opt = make_peer_info(*peer); @@ -125,7 +125,7 @@ Task PeerManagerApi::handle_peer_penalize_calls() { while (true) { auto peer_public_key_opt = co_await peer_penalize_calls_channel_.receive(); - co_await peer_manager_.enumerate_peers([&peer_public_key_opt](std::shared_ptr peer) { + co_await peer_manager_.enumerate_peers([&peer_public_key_opt](const std::shared_ptr& peer) { auto key_opt = peer->peer_public_key(); if (key_opt && peer_public_key_opt && (key_opt.value() == peer_public_key_opt.value())) { peer->disconnect(rlpx::DisconnectReason::DisconnectRequested); diff --git a/silkworm/sentry/rlpx/auth/handshake.hpp b/silkworm/sentry/rlpx/auth/handshake.hpp index a8a38d4c9f..fc74ea29cf 100644 --- a/silkworm/sentry/rlpx/auth/handshake.hpp +++ b/silkworm/sentry/rlpx/auth/handshake.hpp @@ -23,6 +23,8 @@ #include +#include + #include #include #include @@ -71,9 +73,10 @@ class Handshake { class CapabilityMismatchError : public std::runtime_error { public: CapabilityMismatchError( - std::string required_capability_desc, - std::string peer_capabilities_desc) - : std::runtime_error("rlpx::auth::Handshake: no matching required capability " + required_capability_desc + " in " + peer_capabilities_desc) {} + const std::string& required_capability_desc, + const std::string& peer_capabilities_desc) + : std::runtime_error(absl::StrCat("rlpx::auth::Handshake: no matching required capability ", + required_capability_desc, " in ", peer_capabilities_desc)) {} }; private: diff --git a/silkworm/sentry/rlpx/peer.cpp b/silkworm/sentry/rlpx/peer.cpp index d5d8bd3fcd..0ef7a292d5 100644 --- a/silkworm/sentry/rlpx/peer.cpp +++ b/silkworm/sentry/rlpx/peer.cpp @@ -212,8 +212,8 @@ Task Peer::drop(const std::shared_ptr& peer, DisconnectReason reason return concurrency::co_spawn_sw(peer->strand_, Peer::drop_in_strand(peer, reason), use_awaitable); } -Task Peer::drop_in_strand(std::shared_ptr self, DisconnectReason reason) { - co_await self->drop(reason); +Task Peer::drop_in_strand(std::shared_ptr peer, DisconnectReason reason) { + co_await peer->drop(reason); } Task Peer::drop(DisconnectReason reason) { diff --git a/silkworm/sentry/session_sentry_client.cpp b/silkworm/sentry/session_sentry_client.cpp index b93c754d62..48a85ede19 100644 --- a/silkworm/sentry/session_sentry_client.cpp +++ b/silkworm/sentry/session_sentry_client.cpp @@ -181,7 +181,7 @@ class SessionSentryClientImpl : public api::SentryClient { SessionSentryClient::SessionSentryClient( std::shared_ptr sentry_client, StatusDataProvider status_data_provider) - : p_impl_(std::make_unique(sentry_client, status_data_provider)) { + : p_impl_(std::make_unique(std::move(sentry_client), std::move(status_data_provider))) { } SessionSentryClient::~SessionSentryClient() {