Skip to content

Commit

Permalink
node, db: adjust BackEnd and KV API namespaces (#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
canepat authored Jun 11, 2024
1 parent 30d4252 commit 20914cc
Show file tree
Hide file tree
Showing 35 changed files with 265 additions and 220 deletions.
13 changes: 4 additions & 9 deletions cmd/dev/backend_kv_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <silkworm/infra/concurrency/awaitable_wait_for_one.hpp>
#include <silkworm/infra/grpc/client/client_context_pool.hpp>
#include <silkworm/node/backend/ethereum_backend.hpp>
#include <silkworm/node/remote/ethbackend/grpc/server/backend_kv_server.hpp>
#include <silkworm/node/backend_kv_server.hpp>
#include <silkworm/sentry/eth/status_data_provider.hpp>
#include <silkworm/sentry/grpc/client/sentry_client.hpp>
#include <silkworm/sentry/multi_sentry_client.hpp>
Expand Down Expand Up @@ -68,7 +68,7 @@ struct StandaloneBackEndKVSettings : public SilkwormSettings {
};

//! Parse the command-line arguments into the BackEnd and KV server settings
int parse_command_line(int argc, char* argv[], CLI::App& app, StandaloneBackEndKVSettings& settings) {
void parse_command_line(int argc, char* argv[], CLI::App& app, StandaloneBackEndKVSettings& settings) {
auto& log_settings = settings.log_settings;
auto& node_settings = settings.node_settings;
auto& server_settings = settings.node_settings.server_settings;
Expand Down Expand Up @@ -106,8 +106,6 @@ int parse_command_line(int argc, char* argv[], CLI::App& app, StandaloneBackEndK
/*create=*/false,
/*readonly=*/true};
node_settings.chaindata_env_config.max_readers = max_readers;

return 0;
}

std::shared_ptr<silkworm::sentry::api::SentryClient> make_sentry_client(
Expand Down Expand Up @@ -160,10 +158,7 @@ int main(int argc, char* argv[]) {

try {
StandaloneBackEndKVSettings settings;
int result_code = parse_command_line(argc, argv, cli, settings);
if (result_code != 0) {
return result_code;
}
parse_command_line(argc, argv, cli, settings);

const auto pid = boost::this_process::get_id();
const auto tid = std::this_thread::get_id();
Expand Down Expand Up @@ -215,7 +210,7 @@ int main(int argc, char* argv[]) {
};
backend.set_node_name(node_name);

rpc::BackEndKvServer server{server_settings, backend};
node::BackEndKvServer server{server_settings, backend};

// Standalone BackEndKV server has no staged loop, so this simulates periodic state changes
Task<void> tasks;
Expand Down
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/api/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

#include "service.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

struct Client {
virtual ~Client() = default;

virtual std::shared_ptr<Service> service() = 0;
};

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/api/direct_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "direct_client.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

DirectClient::DirectClient(std::shared_ptr<DirectService> direct_service)
: direct_service_(std::move(direct_service)) {}
Expand All @@ -25,4 +25,4 @@ std::shared_ptr<api::Service> DirectClient::service() {
return direct_service_;
}

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/api/direct_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../api/client.hpp"
#include "../api/direct_service.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

struct DirectClient : public api::Client {
explicit DirectClient(std::shared_ptr<DirectService> direct_service);
Expand All @@ -33,4 +33,4 @@ struct DirectClient : public api::Client {
std::shared_ptr<DirectService> direct_service_;
};

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
9 changes: 7 additions & 2 deletions silkworm/db/remote/kv/api/direct_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

#include "direct_service.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

DirectService::DirectService() = default;

// rpc Version(google.protobuf.Empty) returns (types.VersionReply);
Task<Version> DirectService::version() {
co_return kCurrentVersion;
}

/** Temporal Point Queries **/

// rpc HistoryGet(HistoryGetReq) returns (HistoryGetReply);
Expand Down Expand Up @@ -54,4 +59,4 @@ Task<DomainRangeResult> DirectService::get_domain_range(const DomainRangeQuery&)
co_return DomainRangeResult{};
}

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
7 changes: 5 additions & 2 deletions silkworm/db/remote/kv/api/direct_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "service.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

//! Straightforward asynchronous implementation of KV API service relying on \code Domains.
//! This is used both client-side by 'direct' (i.e. no-gRPC) implementation and server-side by gRPC server.
Expand All @@ -33,6 +33,9 @@ class DirectService : public Service {
DirectService(DirectService&&) = delete;
DirectService& operator=(DirectService&&) = delete;

// rpc Version(google.protobuf.Empty) returns (types.VersionReply);
Task<Version> version() override;

/** Temporal Point Queries **/

// rpc HistoryGet(HistoryGetReq) returns (HistoryGetReply);
Expand All @@ -53,4 +56,4 @@ class DirectService : public Service {
Task<DomainRangeResult> get_domain_range(const DomainRangeQuery&) override;
};

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/api/endpoint/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

#include <silkworm/core/common/bytes.hpp>

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

using TxId = uint64_t;
using Timestamp = int64_t;

using ListOfBytes = std::vector<Bytes>;
using ListOfTimestamp = std::vector<Timestamp>;

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/api/endpoint/temporal_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "common.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

struct PointResult {
bool success{false};
Expand All @@ -47,4 +47,4 @@ struct DomainPointQuery {

using DomainPointResult = PointResult;

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/api/endpoint/temporal_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "common.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

struct IndexRangeQuery {
TxId tx_id{0};
Expand Down Expand Up @@ -74,4 +74,4 @@ struct DomainRangeQuery {

using DomainRangeResult = RangeResult;

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
28 changes: 28 additions & 0 deletions silkworm/db/remote/kv/api/endpoint/version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2024 The Silkworm Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#pragma once

#include <tuple>

namespace silkworm::kv::api {

using Version = std::tuple<uint32_t, uint32_t, uint32_t>;

//! Current KV API protocol version.
constexpr auto kCurrentVersion = Version{5, 1, 0};

} // namespace silkworm::kv::api
8 changes: 6 additions & 2 deletions silkworm/db/remote/kv/api/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@

#include "endpoint/temporal_point.hpp"
#include "endpoint/temporal_range.hpp"
#include "endpoint/version.hpp"

namespace silkworm::remote::kv::api {
namespace silkworm::kv::api {

struct Service {
virtual ~Service() = default;

// rpc Version(google.protobuf.Empty) returns (types.VersionReply);
virtual Task<Version> version() = 0;

/** Temporal Point Queries **/

// rpc HistoryGet(HistoryGetReq) returns (HistoryGetReply);
Expand All @@ -46,4 +50,4 @@ struct Service {
virtual Task<DomainRangeResult> get_domain_range(const DomainRangeQuery&) = 0;
};

} // namespace silkworm::remote::kv::api
} // namespace silkworm::kv::api
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/grpc/client/endpoint/temporal_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <silkworm/core/common/util.hpp>

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

namespace proto = ::remote;

Expand Down Expand Up @@ -65,4 +65,4 @@ api::DomainPointResult domain_get_result_from_response(const proto::DomainGetRep
return result;
}

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/grpc/client/endpoint/temporal_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

#include "../../../api/endpoint/temporal_point.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

::remote::HistoryGetReq history_get_request_from_query(const api::HistoryPointQuery&);
api::HistoryPointResult history_get_result_from_response(const ::remote::HistoryGetReply&);

::remote::DomainGetReq domain_get_request_from_query(const api::DomainPointQuery&);
api::DomainPointResult domain_get_result_from_response(const ::remote::DomainGetReply&);

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#include "../../test_util/sample_protos.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

using namespace evmc::literals;
using namespace silkworm::remote::kv::test_util;
using namespace silkworm::kv::test_util;
using namespace silkworm::test_util;
namespace proto = ::remote;

Expand Down Expand Up @@ -95,4 +95,4 @@ TEST_CASE("domain_get_result_from_response", "[node][remote][kv][grpc]") {
}
}

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/grpc/client/endpoint/temporal_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <silkworm/core/common/util.hpp>
#include <silkworm/infra/grpc/common/bytes.hpp>

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

namespace proto = ::remote;

Expand Down Expand Up @@ -96,4 +96,4 @@ api::DomainRangeResult domain_range_result_from_response(const ::remote::Pairs&
return result;
}

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/grpc/client/endpoint/temporal_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "../../../api/endpoint/temporal_range.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

::remote::IndexRangeReq index_range_request_from_query(const api::IndexRangeQuery&);
api::IndexRangeResult index_range_result_from_response(const ::remote::IndexRangeReply&);
Expand All @@ -31,4 +31,4 @@ api::HistoryRangeResult history_range_result_from_response(const ::remote::Pairs
::remote::DomainRangeReq domain_range_request_from_query(const api::DomainRangeQuery&);
api::DomainRangeResult domain_range_result_from_response(const ::remote::Pairs&);

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#include "../../test_util/sample_protos.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

using namespace evmc::literals;
using namespace silkworm::remote::kv::test_util;
using namespace silkworm::kv::test_util;
using namespace silkworm::test_util;
namespace proto = ::remote;

Expand Down Expand Up @@ -140,4 +140,4 @@ TEST_CASE("domain_range_result_from_response", "[node][remote][kv][grpc]") {
}
}

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
9 changes: 7 additions & 2 deletions silkworm/db/remote/kv/grpc/client/remote_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "endpoint/temporal_point.hpp"
#include "endpoint/temporal_range.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

namespace proto = ::remote;
using Stub = proto::KV::StubInterface;
Expand All @@ -48,6 +48,11 @@ class RemoteClientImpl final : public api::Service {
RemoteClientImpl(const RemoteClientImpl&) = delete;
RemoteClientImpl& operator=(const RemoteClientImpl&) = delete;

// rpc Version(google.protobuf.Empty) returns (types.VersionReply);
Task<api::Version> version() override {
co_return api::kCurrentVersion;
}

/** Temporal Point Queries **/

// rpc HistoryGet(HistoryGetReq) returns (HistoryGetReply);
Expand Down Expand Up @@ -106,4 +111,4 @@ std::shared_ptr<api::Service> RemoteClient::service() {
return p_impl_;
}

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
4 changes: 2 additions & 2 deletions silkworm/db/remote/kv/grpc/client/remote_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "../../api/client.hpp"
#include "../../api/service.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

class RemoteClientImpl;

Expand All @@ -40,4 +40,4 @@ struct RemoteClient : public api::Client {
std::shared_ptr<RemoteClientImpl> p_impl_;
};

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
6 changes: 3 additions & 3 deletions silkworm/db/remote/kv/grpc/client/remote_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

#include "../test_util/sample_protos.hpp"

namespace silkworm::remote::kv::grpc::client {
namespace silkworm::kv::grpc::client {

using namespace silkworm::grpc::test_util;
using namespace silkworm::remote::kv::test_util;
using namespace silkworm::kv::test_util;
namespace proto = ::remote;

using StrictMockKVStub = testing::StrictMock<proto::FixIssue24351_MockKVStub>;
Expand Down Expand Up @@ -181,4 +181,4 @@ TEST_CASE_METHOD(RemoteClientTestRunner, "KV::DomainRange", "[node][remote][kv][
}
}

} // namespace silkworm::remote::kv::grpc::client
} // namespace silkworm::kv::grpc::client
Loading

0 comments on commit 20914cc

Please sign in to comment.