Skip to content

Commit

Permalink
sentry: move common namespaces (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Jun 30, 2023
1 parent 3e49f52 commit c4225e6
Show file tree
Hide file tree
Showing 140 changed files with 597 additions and 617 deletions.
6 changes: 3 additions & 3 deletions cmd/dev/backend_kv_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ int parse_command_line(int argc, char* argv[], CLI::App& app, StandaloneBackEndK
return 0;
}

std::shared_ptr<silkworm::sentry::api::api_common::SentryClient> make_sentry_client(
std::shared_ptr<silkworm::sentry::api::SentryClient> make_sentry_client(
const NodeSettings& node_settings,
rpc::ClientContextPool& context_pool,
db::ROAccess db_access) {
std::shared_ptr<silkworm::sentry::api::api_common::SentryClient> sentry_client;
std::shared_ptr<silkworm::sentry::api::SentryClient> sentry_client;

db::EthStatusDataProvider eth_status_data_provider{db_access, node_settings.chain_config.value()};

Expand All @@ -133,7 +133,7 @@ std::shared_ptr<silkworm::sentry::api::api_common::SentryClient> make_sentry_cli
remote_sentry_client,
eth_status_data_provider.to_factory_function());
} else {
std::vector<std::shared_ptr<silkworm::sentry::api::api_common::SentryClient>> clients;
std::vector<std::shared_ptr<silkworm::sentry::api::SentryClient>> clients;

for (const auto& address_uri : node_settings.remote_sentry_addresses) {
// remote client
Expand Down
4 changes: 2 additions & 2 deletions cmd/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <silkworm/infra/grpc/server/server_context_pool.hpp>
#include <silkworm/node/db/eth_status_data_provider.hpp>
#include <silkworm/node/node.hpp>
#include <silkworm/sentry/api/api_common/sentry_client.hpp>
#include <silkworm/sentry/api/common/sentry_client.hpp>
#include <silkworm/sentry/grpc/client/sentry_client.hpp>
#include <silkworm/sentry/multi_sentry_client.hpp>
#include <silkworm/sentry/sentry.hpp>
Expand Down Expand Up @@ -215,7 +215,7 @@ void parse_silkworm_command_line(CLI::App& cli, int argc, char* argv[], Silkworm
class DummyServerCompletionQueue : public grpc::ServerCompletionQueue {
};

using SentryClientPtr = std::shared_ptr<sentry::api::api_common::SentryClient>;
using SentryClientPtr = std::shared_ptr<sentry::api::SentryClient>;
using SentryServerPtr = std::shared_ptr<sentry::Sentry>;
using SentryPtrPair = std::tuple<SentryClientPtr, SentryServerPtr>;

Expand Down
4 changes: 2 additions & 2 deletions cmd/state-transition/state_transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

#include "cmd/state-transition/expected_state.hpp"
#include "silkworm/core/common/cast.hpp"
#include "silkworm/core/common/util.hpp"
#include "silkworm/core/execution/execution.hpp"
#include "silkworm/core/protocol/param.hpp"
#include "silkworm/core/protocol/rule_set.hpp"
#include "silkworm/core/rlp/encode_vector.hpp"
#include "silkworm/core/state/in_memory_state.hpp"
#include "silkworm/sentry/common/ecc_key_pair.hpp"
#include "third_party/ethash/include/ethash/keccak.hpp"

namespace silkworm::cmd::state_transition {

Expand Down Expand Up @@ -178,7 +178,7 @@ std::unique_ptr<evmc::address> StateTransition::private_key_to_address(const std

auto private_key_bytes = from_hex(private_key).value();

sentry::common::EccKeyPair pair = sentry::common::EccKeyPair(private_key_bytes);
auto pair = sentry::EccKeyPair(private_key_bytes);

uint8_t out[kAddressLength];
auto public_key_hash = keccak256(pair.public_key().serialized());
Expand Down
4 changes: 2 additions & 2 deletions cmd/test/sentry_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <silkworm/infra/grpc/client/call.hpp>
#include <silkworm/infra/grpc/common/util.hpp>
#include <silkworm/infra/grpc/server/server_context_pool.hpp>
#include <silkworm/sentry/api/api_common/sentry_client.hpp>
#include <silkworm/sentry/api/common/sentry_client.hpp>
#include <silkworm/sentry/grpc/client/sentry_client.hpp>
#include <silkworm/sentry/sentry.hpp>

Expand All @@ -32,7 +32,7 @@ using namespace silkworm;
class DummyServerCompletionQueue : public grpc::ServerCompletionQueue {
};

boost::asio::awaitable<void> run(sentry::api::api_common::SentryClient& client) {
boost::asio::awaitable<void> run(sentry::api::SentryClient& client) {
auto service = co_await client.service();
try {
auto eth_version = co_await service->handshake();
Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/backend/ethereum_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace silkworm {
EthereumBackEnd::EthereumBackEnd(
const NodeSettings& node_settings,
mdbx::env* chaindata_env,
std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client)
std::shared_ptr<sentry::api::SentryClient> sentry_client)
: EthereumBackEnd(node_settings, chaindata_env, std::move(sentry_client), std::make_unique<StateChangeCollection>()) {
}

EthereumBackEnd::EthereumBackEnd(
const NodeSettings& node_settings,
mdbx::env* chaindata_env,
std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client,
std::shared_ptr<sentry::api::SentryClient> sentry_client,
std::unique_ptr<StateChangeCollection> state_change_collection)
: node_settings_(node_settings),
chaindata_env_(chaindata_env),
Expand Down
10 changes: 5 additions & 5 deletions silkworm/node/backend/ethereum_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <silkworm/core/common/base.hpp>
#include <silkworm/node/backend/state_change_collection.hpp>
#include <silkworm/node/common/settings.hpp>
#include <silkworm/sentry/api/api_common/sentry_client.hpp>
#include <silkworm/sentry/api/common/sentry_client.hpp>

namespace silkworm {

Expand All @@ -36,7 +36,7 @@ class EthereumBackEnd {
explicit EthereumBackEnd(
const NodeSettings& node_settings,
mdbx::env* chaindata_env,
std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client);
std::shared_ptr<sentry::api::SentryClient> sentry_client);
~EthereumBackEnd();

EthereumBackEnd(const EthereumBackEnd&) = delete;
Expand All @@ -46,7 +46,7 @@ class EthereumBackEnd {
[[nodiscard]] const std::string& node_name() const noexcept { return node_name_; }
[[nodiscard]] std::optional<uint64_t> chain_id() const noexcept { return chain_id_; }
[[nodiscard]] std::optional<evmc::address> etherbase() const noexcept { return node_settings_.etherbase; }
[[nodiscard]] std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client() const noexcept { return sentry_client_; }
[[nodiscard]] std::shared_ptr<sentry::api::SentryClient> sentry_client() const noexcept { return sentry_client_; }
[[nodiscard]] StateChangeCollection* state_change_source() const noexcept { return state_change_collection_.get(); }

void set_node_name(const std::string& node_name) noexcept;
Expand All @@ -58,15 +58,15 @@ class EthereumBackEnd {
EthereumBackEnd(
const NodeSettings& node_settings,
mdbx::env* chaindata_env,
std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client,
std::shared_ptr<sentry::api::SentryClient> sentry_client,
std::unique_ptr<StateChangeCollection> state_change_collection);

private:
const NodeSettings& node_settings_;
mdbx::env* chaindata_env_;
std::string node_name_{kDefaultNodeName};
std::optional<uint64_t> chain_id_{std::nullopt};
std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client_;
std::shared_ptr<sentry::api::SentryClient> sentry_client_;
std::unique_ptr<StateChangeCollection> state_change_collection_;
};

Expand Down
2 changes: 1 addition & 1 deletion silkworm/node/backend/ethereum_backend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST_CASE("EthereumBackEnd", "[silkworm][backend][ethereum_backend]") {

NodeSettings node_settings;

std::shared_ptr<sentry::api::api_common::SentryClient> null_sentry_client;
std::shared_ptr<sentry::api::SentryClient> null_sentry_client;

SECTION("EthereumBackEnd::EthereumBackEnd", "[silkworm][backend][ethereum_backend]") {
EthereumBackEnd backend{node_settings, &database_env, null_sentry_client};
Expand Down
34 changes: 17 additions & 17 deletions silkworm/node/backend/remote/backend_kv_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <silkworm/node/backend/remote/grpc/kv_calls.hpp>
#include <silkworm/node/backend/state_change_collection.hpp>
#include <silkworm/node/db/mdbx.hpp>
#include <silkworm/sentry/api/api_common/sentry_client.hpp>
#include <silkworm/sentry/api/common/sentry_client.hpp>

using namespace std::chrono_literals;

Expand Down Expand Up @@ -207,9 +207,9 @@ constexpr const char* kTestSentryNodeClientId{"MockSentryClient"};

class MockSentryClient
: public std::enable_shared_from_this<MockSentryClient>,
public silkworm::sentry::api::api_common::SentryClient,
public silkworm::sentry::api::api_common::Service {
boost::asio::awaitable<std::shared_ptr<silkworm::sentry::api::api_common::Service>> service() override {
public silkworm::sentry::api::SentryClient,
public silkworm::sentry::api::Service {
boost::asio::awaitable<std::shared_ptr<silkworm::sentry::api::Service>> service() override {
co_return shared_from_this();
}
[[nodiscard]] bool is_ready() override { return true; }
Expand All @@ -227,49 +227,49 @@ class MockSentryClient
const uint16_t port = 50555;
const std::string node_url_str = std::string("enode://") + kTestSentryNodeId + "@" + ip_str + ":" + std::to_string(port);

silkworm::sentry::api::api_common::NodeInfo info = {
silkworm::sentry::common::EnodeUrl{node_url_str},
silkworm::sentry::api::NodeInfo info = {
silkworm::sentry::EnodeUrl{node_url_str},
kTestSentryNodeClientId,
boost::asio::ip::tcp::endpoint{boost::asio::ip::make_address(ip_str), port},
port,
};
co_return NodeInfos{info};
}

boost::asio::awaitable<PeerKeys> send_message_by_id(silkworm::sentry::common::Message /*message*/, silkworm::sentry::common::EccPublicKey /*public_key*/) override {
boost::asio::awaitable<PeerKeys> send_message_by_id(silkworm::sentry::Message /*message*/, silkworm::sentry::EccPublicKey /*public_key*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<PeerKeys> send_message_to_random_peers(silkworm::sentry::common::Message /*message*/, size_t /*max_peers*/) override {
boost::asio::awaitable<PeerKeys> send_message_to_random_peers(silkworm::sentry::Message /*message*/, size_t /*max_peers*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<PeerKeys> send_message_to_all(silkworm::sentry::common::Message /*message*/) override {
boost::asio::awaitable<PeerKeys> send_message_to_all(silkworm::sentry::Message /*message*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<PeerKeys> send_message_by_min_block(silkworm::sentry::common::Message /*message*/, size_t /*max_peers*/) override {
boost::asio::awaitable<PeerKeys> send_message_by_min_block(silkworm::sentry::Message /*message*/, size_t /*max_peers*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<void> peer_min_block(silkworm::sentry::common::EccPublicKey /*public_key*/) override {
boost::asio::awaitable<void> peer_min_block(silkworm::sentry::EccPublicKey /*public_key*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<void> messages(
silkworm::sentry::api::api_common::MessageIdSet /*message_id_filter*/,
std::function<boost::asio::awaitable<void>(silkworm::sentry::api::api_common::MessageFromPeer)> /*consumer*/) override {
silkworm::sentry::api::MessageIdSet /*message_id_filter*/,
std::function<boost::asio::awaitable<void>(silkworm::sentry::api::MessageFromPeer)> /*consumer*/) override {
throw std::runtime_error("not implemented");
}

boost::asio::awaitable<silkworm::sentry::api::api_common::PeerInfos> peers() override {
boost::asio::awaitable<silkworm::sentry::api::PeerInfos> peers() override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<size_t> peer_count() override {
co_return kTestSentryPeerCount;
}
boost::asio::awaitable<std::optional<silkworm::sentry::api::api_common::PeerInfo>> peer_by_id(silkworm::sentry::common::EccPublicKey /*public_key*/) override {
boost::asio::awaitable<std::optional<silkworm::sentry::api::PeerInfo>> peer_by_id(silkworm::sentry::EccPublicKey /*public_key*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<void> penalize_peer(silkworm::sentry::common::EccPublicKey /*public_key*/) override {
boost::asio::awaitable<void> penalize_peer(silkworm::sentry::EccPublicKey /*public_key*/) override {
throw std::runtime_error("not implemented");
}
boost::asio::awaitable<void> peer_events(std::function<boost::asio::awaitable<void>(silkworm::sentry::api::api_common::PeerEvent)> /*consumer*/) override {
boost::asio::awaitable<void> peer_events(std::function<boost::asio::awaitable<void>(silkworm::sentry::api::PeerEvent)> /*consumer*/) override {
throw std::runtime_error("not implemented");
}
};
Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace silkworm::node {

constexpr uint64_t kMaxFileDescriptors{10'240};

using SentryClientPtr = std::shared_ptr<sentry::api::api_common::SentryClient>;
using SentryClientPtr = std::shared_ptr<sentry::api::SentryClient>;

class NodeImpl final {
public:
Expand All @@ -42,7 +42,7 @@ class NodeImpl final {
NodeImpl& operator=(const NodeImpl&) = delete;

execution::LocalClient& execution_local_client() { return execution_local_client_; }
std::shared_ptr<sentry::api::api_common::SentryClient> sentry_client() { return sentry_client_; }
std::shared_ptr<sentry::api::SentryClient> sentry_client() { return sentry_client_; }

void setup();

Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <silkworm/node/settings.hpp>
#include <silkworm/node/snapshot/settings.hpp>
#include <silkworm/node/stagedsync/local_client.hpp>
#include <silkworm/sentry/api/api_common/sentry_client.hpp>
#include <silkworm/sentry/api/common/sentry_client.hpp>
#include <silkworm/sentry/settings.hpp>

namespace silkworm::node {
Expand All @@ -34,7 +34,7 @@ class NodeImpl;

class Node {
public:
Node(Settings&, std::shared_ptr<sentry::api::api_common::SentryClient>, mdbx::env&);
Node(Settings&, std::shared_ptr<sentry::api::SentryClient>, mdbx::env&);
~Node();

Node(const Node&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include <silkworm/sentry/common/ecc_public_key.hpp>
#include <silkworm/sentry/common/message.hpp>

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

struct MessageFromPeer {
sentry::common::Message message;
std::optional<sentry::common::EccPublicKey> peer_public_key;
sentry::Message message;
std::optional<sentry::EccPublicKey> peer_public_key;
};

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include <set>

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

using MessageIdSet = std::set<uint8_t>;

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

#include <silkworm/sentry/common/enode_url.hpp>

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

struct NodeInfo {
sentry::common::EnodeUrl node_url;
sentry::EnodeUrl node_url;
std::string client_id;
boost::asio::ip::tcp::endpoint rlpx_server_listen_endpoint;
uint16_t rlpx_server_port;
};

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

#include <silkworm/sentry/common/ecc_public_key.hpp>

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

enum class PeerEventId {
kAdded,
kRemoved,
};

struct PeerEvent {
std::optional<sentry::common::EccPublicKey> peer_public_key;
std::optional<sentry::EccPublicKey> peer_public_key;
PeerEventId event_id;
};

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@

#include <silkworm/sentry/common/ecc_public_key.hpp>

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

struct PeerFilter {
std::optional<size_t> max_peers;
std::optional<sentry::common::EccPublicKey> peer_public_key;
std::optional<sentry::EccPublicKey> peer_public_key;

static PeerFilter with_max_peers(size_t max_peers) {
return {{max_peers}, std::nullopt};
}

static PeerFilter with_peer_public_key(sentry::common::EccPublicKey public_key) {
static PeerFilter with_peer_public_key(sentry::EccPublicKey public_key) {
return {std::nullopt, {std::move(public_key)}};
}
};

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

#include <silkworm/sentry/common/enode_url.hpp>

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

struct PeerInfo {
sentry::common::EnodeUrl url;
sentry::EnodeUrl url;
boost::asio::ip::tcp::endpoint local_endpoint;
boost::asio::ip::tcp::endpoint remote_endpoint;
bool is_inbound;
Expand All @@ -37,4 +37,4 @@ struct PeerInfo {

using PeerInfos = std::vector<PeerInfo>;

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "service.hpp"

namespace silkworm::sentry::api::api_common {
namespace silkworm::sentry::api {

struct SentryClient {
virtual ~SentryClient() = default;
Expand All @@ -36,4 +36,4 @@ struct SentryClient {
virtual Task<void> reconnect() = 0;
};

} // namespace silkworm::sentry::api::api_common
} // namespace silkworm::sentry::api
Loading

0 comments on commit c4225e6

Please sign in to comment.