Skip to content

Commit

Permalink
fix: ensure correct handling of mock endpoints
Browse files Browse the repository at this point in the history
This ensures that, regardless of what has been specified for mocking,
any module with no endpoints defined in the config will have a server
started for it in a mock system test.

Also includes removal of some newer clang-format plugins most of which
should eventually be reenabled.

Signed-off-by: Sam Stuewe <[email protected]>
  • Loading branch information
HalosGhost committed Sep 6, 2023
1 parent 211bbc9 commit 9d3a05c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 31 deletions.
7 changes: 6 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ Checks: '
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
readability-*,
google-explicit-constructor,
-readability-identifier-length'
-readability-identifier-length,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-bugprone-unchecked-optional-access,
-cppcoreguidelines-avoid-do-while,
-modernize-use-emplace,
-readability-convert-member-functions-to-static'
CheckOptions:
- {key: cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal, value: true}
- {key: modernize-use-override.AllowOverrideAndFinal, value: true}
Expand Down
6 changes: 4 additions & 2 deletions src/uhs/sentinel/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ namespace cbdc::sentinel {
/// \return the response from the sentinel or std::nullopt if
/// processing failed.
virtual auto execute_transaction(transaction::full_tx tx)
-> std::optional<execute_response> = 0;
-> std::optional<execute_response>
= 0;

/// Validate transaction and generate a sentinel attestation if the
/// transaction is valid.
/// \param tx transaction to validate and attest to.
/// \return sentinel attestation for the given transaction, or
/// std::nullopt if the transaction is invalid.
virtual auto validate_transaction(transaction::full_tx tx)
-> std::optional<validate_response> = 0;
-> std::optional<validate_response>
= 0;
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/uhs/twophase/locking_shard/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ namespace cbdc::locking_shard {
/// txs in the input vector had their relevant input hashes
/// locked by the shard. Otherwise std::nullopt.
virtual auto lock_outputs(std::vector<tx>&& txs, const hash_t& dtx_id)
-> std::optional<std::vector<bool>> = 0;
-> std::optional<std::vector<bool>>
= 0;

/// Completes a previous lock operation by deleting input hashes and
/// creating output hashes, or unlocking input hashes.
Expand Down
6 changes: 4 additions & 2 deletions src/uhs/twophase/locking_shard/status_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ namespace cbdc::locking_shard {
/// \return true if the UHS ID is unspent, or std::nullopt if the query
/// failed.
[[nodiscard]] virtual auto check_unspent(const hash_t& uhs_id)
-> std::optional<bool> = 0;
-> std::optional<bool>
= 0;

/// Queries whether the given TX ID is confirmed in the cache of
/// recently confirmed TX IDs.
/// \param tx_id TX ID to query.
/// \return true if the TX ID is present in the cache, or std::nullopt
/// if the query failed.
[[nodiscard]] virtual auto check_tx_id(const hash_t& tx_id)
-> std::optional<bool> = 0;
-> std::optional<bool>
= 0;
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/util/rpc/async_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ namespace cbdc::rpc {

using server_type = server<Request, Response, InBuffer, OutBuffer>;

static constexpr auto raw_mode
= std::is_same_v<Request,
buffer> && std::is_same_v<Response, buffer>;
static constexpr auto raw_mode = std::is_same_v<Request, buffer>
&& std::is_same_v<Response, buffer>;
};

/// \brief Asynchronous pass-through RPC server.
Expand Down
3 changes: 2 additions & 1 deletion src/util/rpc/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ namespace cbdc::rpc {
virtual auto call_raw(cbdc::buffer request_buf,
request_id_type request_id,
std::chrono::milliseconds timeout)
-> std::optional<response_type> = 0;
-> std::optional<response_type>
= 0;

virtual auto call_raw(cbdc::buffer request_buf,
request_id_type request_id,
Expand Down
8 changes: 4 additions & 4 deletions src/util/serialization/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ namespace cbdc {
-> serializer& {
using S = uint8_t;
static_assert(
std::variant_size_v<std::remove_reference_t<decltype(var)>> < std::
numeric_limits<S>::max());
std::variant_size_v<std::remove_reference_t<decltype(var)>>
< std::numeric_limits<S>::max());
auto idx = static_cast<S>(var.index());
ser << idx;
std::visit(
Expand All @@ -385,8 +385,8 @@ namespace cbdc {
serializer&> {
using S = uint8_t;
static_assert(
std::variant_size_v<std::remove_reference_t<decltype(var)>> < std::
numeric_limits<S>::max());
std::variant_size_v<std::remove_reference_t<decltype(var)>>
< std::numeric_limits<S>::max());
S idx{};
deser >> idx;
auto var_idx = static_cast<size_t>(idx);
Expand Down
47 changes: 30 additions & 17 deletions tests/integration/mock_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,42 @@ namespace cbdc::test {
const std::unordered_set<mock_system_module>& disabled_modules,
config::options opts)
: m_opts(std::move(opts)) {
m_module_endpoints.insert({mock_system_module::watchtower,
m_opts.m_watchtower_internal_endpoints});
if(!m_opts.m_watchtower_internal_endpoints.empty()) {
m_module_endpoints.emplace(mock_system_module::watchtower,
m_opts.m_watchtower_internal_endpoints);
}

if(!m_opts.m_atomizer_endpoints.empty()) {
m_module_endpoints.emplace(mock_system_module::atomizer,
m_opts.m_atomizer_endpoints);
}

m_module_endpoints.insert(
{mock_system_module::atomizer, m_opts.m_atomizer_endpoints});
if(!m_opts.m_coordinator_endpoints.empty()) {
auto coord_eps = std::vector<network::endpoint_t>();
for(const auto& node_eps : m_opts.m_coordinator_endpoints) {
coord_eps.insert(coord_eps.end(),
node_eps.begin(),
node_eps.end());
}

auto coord_eps = std::vector<network::endpoint_t>();
for(const auto& node_eps : m_opts.m_coordinator_endpoints) {
coord_eps.insert(coord_eps.end(),
node_eps.begin(),
node_eps.end());
m_module_endpoints.emplace(mock_system_module::coordinator,
coord_eps);
}
m_module_endpoints.insert(
{mock_system_module::coordinator, coord_eps});

m_module_endpoints.insert(
{mock_system_module::archiver, m_opts.m_archiver_endpoints});
if(!m_opts.m_archiver_endpoints.empty()) {
m_module_endpoints.emplace(mock_system_module::archiver,
m_opts.m_archiver_endpoints);
}

m_module_endpoints.insert(
{mock_system_module::shard, m_opts.m_shard_endpoints});
if(!m_opts.m_shard_endpoints.empty()) {
m_module_endpoints.emplace(mock_system_module::shard,
m_opts.m_shard_endpoints);
}

m_module_endpoints.insert(
{mock_system_module::sentinel, m_opts.m_sentinel_endpoints});
if(!m_opts.m_sentinel_endpoints.empty()) {
m_module_endpoints.emplace(mock_system_module::sentinel,
m_opts.m_sentinel_endpoints);
}

for(const auto& m : disabled_modules) {
m_module_endpoints.erase(m);
Expand Down

0 comments on commit 9d3a05c

Please sign in to comment.