diff --git a/src/parsec/agent/impl.hpp b/src/parsec/agent/impl.hpp index 8ee71ec8c..aa4d78a9a 100644 --- a/src/parsec/agent/impl.hpp +++ b/src/parsec/agent/impl.hpp @@ -16,7 +16,7 @@ namespace cbdc::parsec::agent { class impl : public interface { public: /// States for a ticket managed by this agent. - enum class state { + enum class state : std::uint8_t { /// Initial state. init, /// Begin request sent to broker. @@ -121,7 +121,7 @@ namespace cbdc::parsec::agent { std::shared_ptr m_threads; std::optional m_tx_id; bool m_wounded{false}; - broker::held_locks_set_type m_requested_locks{}; + broker::held_locks_set_type m_requested_locks; bool m_restarted{false}; void handle_begin(broker::interface::ticketnum_or_errcode_type res); diff --git a/src/parsec/agent/runners/evm/impl.cpp b/src/parsec/agent/runners/evm/impl.cpp index aa4c6827a..9406f0942 100644 --- a/src/parsec/agent/runners/evm/impl.cpp +++ b/src/parsec/agent/runners/evm/impl.cpp @@ -456,7 +456,7 @@ namespace cbdc::parsec::agent::runner { return std::make_pair( min_gas, - !(evmtx.m_gas_limit < min_gas && !is_readonly_run)); + !evmtx.m_gas_limit < min_gas || is_readonly_run); } auto evm_runner::make_message(const evmc::address& from, diff --git a/src/parsec/agent/runners/evm/messages.hpp b/src/parsec/agent/runners/evm/messages.hpp index 0798c7459..05ec3e703 100644 --- a/src/parsec/agent/runners/evm/messages.hpp +++ b/src/parsec/agent/runners/evm/messages.hpp @@ -22,12 +22,12 @@ namespace cbdc::parsec::agent::runner { /// EVM account type struct evm_account { /// Balance in the account. - evmc::uint256be m_balance{}; + evmc::uint256be m_balance; /// Signature nonce. - evmc::uint256be m_nonce{}; + evmc::uint256be m_nonce; /// Set of keys modified during contract execution. - std::set m_modified{}; + std::set m_modified; /// Flag set if the account is being destructed. bool m_destruct{false}; }; @@ -44,8 +44,8 @@ namespace cbdc::parsec::agent::runner { /// Type for tracking storage key accesses between accounts. struct evm_access_tuple { - evmc::address m_address{}; - std::vector m_storage_keys{}; + evmc::address m_address; + std::vector m_storage_keys; auto operator==(const evm_access_tuple& rhs) const -> bool { return m_address == rhs.m_address && m_storage_keys == rhs.m_storage_keys; @@ -67,23 +67,23 @@ namespace cbdc::parsec::agent::runner { /// Type of transaction. evm_tx_type m_type{}; /// To address or std::nullopt if contract creation. - std::optional m_to{}; + std::optional m_to; /// Value to transfer. - evmc::uint256be m_value{}; + evmc::uint256be m_value; /// Nonce for from account. - evmc::uint256be m_nonce{}; + evmc::uint256be m_nonce; /// Gas price. - evmc::uint256be m_gas_price{}; + evmc::uint256be m_gas_price; /// Maximum gas for this transaction. - evmc::uint256be m_gas_limit{}; + evmc::uint256be m_gas_limit; /// Maximum tip fee. - evmc::uint256be m_gas_tip_cap{}; + evmc::uint256be m_gas_tip_cap; /// Maximum base fee. - evmc::uint256be m_gas_fee_cap{}; + evmc::uint256be m_gas_fee_cap; /// Contract input data. - std::vector m_input{}; + std::vector m_input; /// List of storage key accesses. - evm_access_list m_access_list{}; + evm_access_list m_access_list; /// Transaction signature. evm_sig m_sig; }; @@ -99,11 +99,11 @@ namespace cbdc::parsec::agent::runner { /// EVM log output type. struct evm_log { /// Address for the log. - evmc::address m_addr{}; + evmc::address m_addr; /// Log data. - std::vector m_data{}; + std::vector m_data; /// List of log topics. - std::vector m_topics{}; + std::vector m_topics; }; /// EVM transaction receipt type. @@ -113,11 +113,11 @@ namespace cbdc::parsec::agent::runner { /// Created contract address, if applicable. std::optional m_create_address; /// Gas used in transaction. - evmc::uint256be m_gas_used{}; + evmc::uint256be m_gas_used; /// List of logs emitted during transaction. - std::vector m_logs{}; + std::vector m_logs; /// EVM output data. - std::vector m_output_data{}; + std::vector m_output_data; /// Ticket number that ran this TX - needed to map /// to pretend blocks cbdc::parsec::agent::runner::interface::ticket_number_type @@ -136,16 +136,16 @@ namespace cbdc::parsec::agent::runner { /// Ticket number interface::ticket_number_type m_ticket_number {}; /// Transactions executed by the ticket - std::vector m_transactions{}; + std::vector m_transactions; }; /// Describes the parameters of a query on EVM logs - used to transfer /// these parameters from the getLogs API method to the runner struct evm_log_query { /// The addresses for which logs are queried - std::vector m_addresses{}; + std::vector m_addresses; /// The topics for which logs are queried - std::vector m_topics{}; + std::vector m_topics; /// The start of the block range to query logs for cbdc::parsec::agent::runner::interface::ticket_number_type m_from_block {}; diff --git a/src/parsec/agent/runners/evm/rlp.hpp b/src/parsec/agent/runners/evm/rlp.hpp index ca433db48..1366c8c90 100644 --- a/src/parsec/agent/runners/evm/rlp.hpp +++ b/src/parsec/agent/runners/evm/rlp.hpp @@ -19,7 +19,7 @@ namespace cbdc { /// Possible types for an RLP value - enum class rlp_value_type { + enum class rlp_value_type : std::uint8_t { /// A collection of RLP values array, /// A singular RLP value (byte array) @@ -90,10 +90,9 @@ namespace cbdc { /// \tparam address or byte array type. /// \return byte array or address. template - [[nodiscard]] auto value() const -> typename std::enable_if_t< - std::is_same::value - || std::is_same::value, - T> { + requires std::is_same_v + || std::is_same_v + [[nodiscard]] auto value() const -> T { auto res = T(); auto buf = cbdc::buffer(); buf.extend(sizeof(res.bytes)); diff --git a/src/parsec/agent/runners/evm/serialization.cpp b/src/parsec/agent/runners/evm/serialization.cpp index 5529dc32d..a9cb7c666 100644 --- a/src/parsec/agent/runners/evm/serialization.cpp +++ b/src/parsec/agent/runners/evm/serialization.cpp @@ -234,7 +234,7 @@ namespace cbdc::parsec::agent::runner { auto maybe_addr = cbdc::from_buffer( maybe_addr_buf.value()); if(maybe_addr) { - return maybe_addr.value(); + return maybe_addr; } } } @@ -249,7 +249,7 @@ namespace cbdc::parsec::agent::runner { auto maybe_val = cbdc::from_buffer(maybe_val_buf.value()); if(maybe_val) { - return maybe_val.value(); + return maybe_val; } } return std::nullopt; diff --git a/src/parsec/agent/runners/evm/util.hpp b/src/parsec/agent/runners/evm/util.hpp index 7709c35b9..9b0f07f1c 100644 --- a/src/parsec/agent/runners/evm/util.hpp +++ b/src/parsec/agent/runners/evm/util.hpp @@ -6,16 +6,14 @@ #ifndef OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_EVM_UTIL_H_ #define OPENCBDC_TX_SRC_PARSEC_AGENT_RUNNERS_EVM_UTIL_H_ -#include "messages.hpp" #include "parsec/broker/interface.hpp" #include "util/common/buffer.hpp" -#include "util/common/hash.hpp" -#include "util/common/keys.hpp" #include "util/common/logging.hpp" #include #include #include +#include #include #include #include @@ -51,10 +49,8 @@ namespace cbdc::parsec::agent::runner { /// \return object containing the parsed T or std::nullopt if /// parse failed template - auto from_hex(const std::string& hex) -> - typename std::enable_if_t::value - || std::is_same::value, - std::optional> { + requires std::is_same_v || std::is_same_v + auto from_hex(const std::string& hex) -> std::optional { auto maybe_bytes = cbdc::buffer::from_hex_prefixed(hex); if(!maybe_bytes.has_value()) { return std::nullopt; diff --git a/src/parsec/agent/runners/interface.hpp b/src/parsec/agent/runners/interface.hpp index 9557f7257..0a2f6deaa 100644 --- a/src/parsec/agent/runners/interface.hpp +++ b/src/parsec/agent/runners/interface.hpp @@ -21,7 +21,7 @@ namespace cbdc::parsec::agent::runner { class interface { public: /// Error codes return during function execution. - enum class error_code { + enum class error_code : std::uint8_t { /// Function did not return a string value. result_value_type, /// Function did not return a string key. diff --git a/src/parsec/agent/server_interface.hpp b/src/parsec/agent/server_interface.hpp index da3fe9729..21b0c9488 100644 --- a/src/parsec/agent/server_interface.hpp +++ b/src/parsec/agent/server_interface.hpp @@ -53,7 +53,7 @@ namespace cbdc::parsec::agent::rpc { const cbdc::parsec::config& m_cfg; mutable std::mutex m_agents_mut; - std::atomic m_next_id{}; + std::atomic m_next_id; std::unordered_map> m_agents; blocking_queue m_cleanup_queue; diff --git a/src/parsec/broker/impl.cpp b/src/parsec/broker/impl.cpp index 1776796e8..7a1226b4c 100644 --- a/src/parsec/broker/impl.cpp +++ b/src/parsec/broker/impl.cpp @@ -157,7 +157,7 @@ namespace cbdc::parsec::broker { if(!m_directory->key_location( key, - [=, this](std::optional res) { handle_find_key(ticket_number, key, @@ -295,7 +295,7 @@ namespace cbdc::parsec::broker { auto sidx = shard.first; if(!m_shards[sidx]->commit( ticket_number, - [=, this](const parsec::runtime_locking_shard::interface:: + [commit_cb, ticket_number, sidx, this](const parsec::runtime_locking_shard::interface:: commit_return_type& comm_res) { handle_commit(commit_cb, ticket_number, sidx, comm_res); })) { @@ -544,7 +544,7 @@ namespace cbdc::parsec::broker { shard.second.m_state = shard_state_type::finishing; if(!m_shards[sidx]->finish( ticket_number, - [=, this](const parsec::runtime_locking_shard:: + [result_callback, ticket_number, sidx, this](const parsec::runtime_locking_shard:: interface::finish_return_type& res) { handle_finish(result_callback, ticket_number, @@ -560,7 +560,7 @@ namespace cbdc::parsec::broker { }(); if(maybe_error.has_value()) { - result_callback(maybe_error.value()); + result_callback(maybe_error); } else if(done) { result_callback(std::nullopt); } @@ -617,7 +617,7 @@ namespace cbdc::parsec::broker { shard.second.m_state = shard_state_type::rolling_back; if(!m_shards[sidx]->rollback( ticket_number, - [=, this](const parsec::runtime_locking_shard:: + [result_callback, ticket_number, sidx, this](const parsec::runtime_locking_shard:: interface::rollback_return_type& res) { handle_rollback(result_callback, ticket_number, @@ -782,7 +782,7 @@ namespace cbdc::parsec::broker { key, locktype, first_lock, - [=, this](const parsec::runtime_locking_shard::interface:: + [ticket_number, key, shard_idx, result_callback, this](const parsec::runtime_locking_shard::interface:: try_lock_return_type& lock_res) { handle_lock(ticket_number, key, @@ -873,7 +873,7 @@ namespace cbdc::parsec::broker { }(); if(maybe_error.has_value()) { - result_callback(maybe_error.value()); + result_callback(maybe_error); } else if(callback) { result_callback(std::nullopt); } @@ -962,7 +962,7 @@ namespace cbdc::parsec::broker { }}, res); if(maybe_error.has_value()) { - result_callback(maybe_error.value()); + result_callback(maybe_error); } else if(done) { result_callback(std::nullopt); } @@ -972,7 +972,7 @@ namespace cbdc::parsec::broker { auto impl::do_recovery(const recover_callback_type& result_callback) -> std::optional { - for(auto [ticket_number, ticket] : m_tickets) { + for(const auto& [ticket_number, ticket] : m_tickets) { size_t committed{}; for(auto& [sidx, t_state] : ticket->m_shard_states) { switch(t_state.m_state) { diff --git a/src/parsec/runtime_locking_shard/impl.hpp b/src/parsec/runtime_locking_shard/impl.hpp index ae3bc87f1..e3f65fa1a 100644 --- a/src/parsec/runtime_locking_shard/impl.hpp +++ b/src/parsec/runtime_locking_shard/impl.hpp @@ -121,7 +121,7 @@ namespace cbdc::parsec::runtime_locking_shard { key_set_type m_queued_locks; state_update_type m_state_update; broker_id_type m_broker_id{}; - std::optional m_wounded_details{}; + std::optional m_wounded_details; }; struct pending_callback_element_type { diff --git a/src/parsec/ticket_machine/impl.hpp b/src/parsec/ticket_machine/impl.hpp index ca6e7c3da..54016ad4a 100644 --- a/src/parsec/ticket_machine/impl.hpp +++ b/src/parsec/ticket_machine/impl.hpp @@ -31,7 +31,7 @@ namespace cbdc::parsec::ticket_machine { private: std::shared_ptr m_log; - std::atomic m_next_ticket_number{}; + std::atomic m_next_ticket_number; ticket_number_type m_range; }; } diff --git a/src/parsec/ticket_machine/state_machine.hpp b/src/parsec/ticket_machine/state_machine.hpp index 739d609d3..cea387c22 100644 --- a/src/parsec/ticket_machine/state_machine.hpp +++ b/src/parsec/ticket_machine/state_machine.hpp @@ -60,7 +60,7 @@ namespace cbdc::parsec::ticket_machine { std::atomic m_last_committed_idx{0}; - std::unique_ptr m_ticket_machine{}; + std::unique_ptr m_ticket_machine; std::shared_ptr m_logger; }; diff --git a/src/parsec/util.hpp b/src/parsec/util.hpp index 201b4e30c..e25401bc2 100644 --- a/src/parsec/util.hpp +++ b/src/parsec/util.hpp @@ -12,7 +12,7 @@ namespace cbdc::parsec { /// Type of load to generate for benchmarking - enum class load_type { + enum class load_type : std::uint8_t { /// Base token transfer transfer, /// ERC20 token transfer @@ -20,7 +20,7 @@ namespace cbdc::parsec { }; /// Execution/transaction model - enum class runner_type { + enum class runner_type : std::uint8_t { /// Transaction semantics defined using Lua. lua, /// Ethereum-style transactions using EVM. diff --git a/src/uhs/atomizer/archiver/archiverd.cpp b/src/uhs/atomizer/archiver/archiverd.cpp index 859eb98b8..cc38d7c48 100644 --- a/src/uhs/atomizer/archiver/archiverd.cpp +++ b/src/uhs/atomizer/archiver/archiverd.cpp @@ -16,7 +16,7 @@ auto main(int argc, char** argv) -> int { if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " []" - << std::endl; + << '\n'; return 0; } @@ -28,7 +28,7 @@ auto main(int argc, char** argv) -> int { auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); @@ -36,7 +36,7 @@ auto main(int argc, char** argv) -> int { const auto archiver_id = std::stoull(args[2]); if(opts.m_archiver_endpoints.size() <= archiver_id) { - std::cerr << "Archiver ID not in config file" << std::endl; + std::cerr << "Archiver ID not in config file" << '\n'; return -1; } diff --git a/src/uhs/atomizer/archiver/controller.cpp b/src/uhs/atomizer/archiver/controller.cpp index 7fc850cbd..fa14b2af8 100644 --- a/src/uhs/atomizer/archiver/controller.cpp +++ b/src/uhs/atomizer/archiver/controller.cpp @@ -233,7 +233,7 @@ namespace cbdc::archiver { = static_cast(blk.m_transactions.size()) / s_since_last_block.count(); - m_tp_sample_file << tx_throughput << std::endl; + m_tp_sample_file << tx_throughput << '\n'; m_samples++; } @@ -280,7 +280,7 @@ namespace cbdc::archiver { auto blk = from_buffer(buf); assert(blk.has_value()); m_logger->trace("found block", height, "-", blk.value().m_height); - return blk.value(); + return blk; } void controller::request_block(uint64_t height) { diff --git a/src/uhs/atomizer/atomizer/atomizer-raftd.cpp b/src/uhs/atomizer/atomizer/atomizer-raftd.cpp index a2e10cde0..06425906e 100644 --- a/src/uhs/atomizer/atomizer/atomizer-raftd.cpp +++ b/src/uhs/atomizer/atomizer/atomizer-raftd.cpp @@ -14,7 +14,7 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " " - << std::endl; + << '\n'; return 0; } @@ -23,13 +23,13 @@ auto main(int argc, char** argv) -> int { auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); if(opts.m_atomizer_endpoints.size() <= atomizer_id) { - std::cerr << "Atomizer ID not in config file" << std::endl; + std::cerr << "Atomizer ID not in config file" << '\n'; return -1; } diff --git a/src/uhs/atomizer/atomizer/controller.cpp b/src/uhs/atomizer/atomizer/controller.cpp index 9ab9ddd7d..d56e05bad 100644 --- a/src/uhs/atomizer/atomizer/controller.cpp +++ b/src/uhs/atomizer/atomizer/controller.cpp @@ -20,7 +20,7 @@ namespace cbdc::atomizer { : m_atomizer_id(atomizer_id), m_opts(opts), m_logger(std::move(log)), - m_raft_node(static_cast(atomizer_id), + m_raft_node(atomizer_id, opts.m_atomizer_raft_endpoints, m_opts.m_stxo_cache_depth, m_logger, diff --git a/src/uhs/atomizer/atomizer/state_machine.hpp b/src/uhs/atomizer/atomizer/state_machine.hpp index 16445bcd8..44bc9a46c 100644 --- a/src/uhs/atomizer/atomizer/state_machine.hpp +++ b/src/uhs/atomizer/atomizer/state_machine.hpp @@ -124,9 +124,9 @@ namespace cbdc::atomizer { /// Pointer to the atomizer instance. std::shared_ptr m_atomizer; /// Pointer to the nuraft snapshot metadata. - nuraft::ptr m_snp{}; + nuraft::ptr m_snp; /// Pointer to the state of the block cache. - std::shared_ptr m_blocks{}; + std::shared_ptr m_blocks; }; private: diff --git a/src/uhs/atomizer/sentinel/controller.cpp b/src/uhs/atomizer/sentinel/controller.cpp index ac2af005e..59c574220 100644 --- a/src/uhs/atomizer/sentinel/controller.cpp +++ b/src/uhs/atomizer/sentinel/controller.cpp @@ -157,7 +157,7 @@ namespace cbdc::sentinel { success = m_sentinel_clients[sentinel_id]->validate_transaction( tx, - [=, this](async_interface::validate_result v_res) { + [requested, sentinel_id, tx, ctx, this](async_interface::validate_result v_res) { auto r = requested; r.insert(sentinel_id); validate_result_handler(v_res, tx, ctx, r); diff --git a/src/uhs/atomizer/sentinel/controller.hpp b/src/uhs/atomizer/sentinel/controller.hpp index 483433cfa..dc9ccf574 100644 --- a/src/uhs/atomizer/sentinel/controller.hpp +++ b/src/uhs/atomizer/sentinel/controller.hpp @@ -73,12 +73,12 @@ namespace cbdc::sentinel { &secp256k1_context_destroy}; std::vector> - m_sentinel_clients{}; + m_sentinel_clients; - std::random_device m_r{}; + std::random_device m_r; std::default_random_engine m_rand{m_r()}; - std::uniform_int_distribution m_dist{}; - std::uniform_int_distribution m_shard_dist{}; + std::uniform_int_distribution m_dist; + std::uniform_int_distribution m_shard_dist; std::mutex m_rand_mut; privkey_t m_privkey{}; diff --git a/src/uhs/atomizer/sentinel/sentineld.cpp b/src/uhs/atomizer/sentinel/sentineld.cpp index 57f7aaa3a..5c29fd5f5 100644 --- a/src/uhs/atomizer/sentinel/sentineld.cpp +++ b/src/uhs/atomizer/sentinel/sentineld.cpp @@ -17,7 +17,7 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " " - << std::endl; + << '\n'; return -1; } @@ -26,13 +26,13 @@ auto main(int argc, char** argv) -> int { auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); if(opts.m_sentinel_endpoints.size() <= sentinel_id) { - std::cerr << "Sentinel ID not in config file" << std::endl; + std::cerr << "Sentinel ID not in config file" << '\n'; return -1; } diff --git a/src/uhs/atomizer/shard/controller.cpp b/src/uhs/atomizer/shard/controller.cpp index 12ab56929..bc1fcdbc9 100644 --- a/src/uhs/atomizer/shard/controller.cpp +++ b/src/uhs/atomizer/shard/controller.cpp @@ -111,7 +111,7 @@ namespace cbdc::shard { auto controller::atomizer_handler(cbdc::network::message_t&& pkt) -> std::optional { - auto maybe_blk = from_buffer(*pkt.m_pkt); + auto maybe_blk = from_buffer(std::move(*pkt.m_pkt)); if(!maybe_blk.has_value()) { m_logger->error("Invalid block packet"); return std::nullopt; diff --git a/src/uhs/atomizer/shard/shardd.cpp b/src/uhs/atomizer/shard/shardd.cpp index 0808fab94..003adaa22 100644 --- a/src/uhs/atomizer/shard/shardd.cpp +++ b/src/uhs/atomizer/shard/shardd.cpp @@ -17,7 +17,7 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " " - << std::endl; + << '\n'; return 0; } @@ -26,13 +26,13 @@ auto main(int argc, char** argv) -> int { auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); if(opts.m_shard_endpoints.size() <= shard_id) { - std::cerr << "Shard ID not in config file" << std::endl; + std::cerr << "Shard ID not in config file" << '\n'; return -1; } diff --git a/src/uhs/atomizer/watchtower/block_cache.cpp b/src/uhs/atomizer/watchtower/block_cache.cpp index 1c0d018e0..495966b56 100644 --- a/src/uhs/atomizer/watchtower/block_cache.cpp +++ b/src/uhs/atomizer/watchtower/block_cache.cpp @@ -27,7 +27,7 @@ namespace cbdc::watchtower { m_blks.pop(); } - m_blks.push(std::forward(blk)); + m_blks.push(std::forward(std::move(blk))); auto blk_height = m_blks.back().m_height; for(auto& tx : m_blks.back().m_transactions) { diff --git a/src/uhs/atomizer/watchtower/block_cache.hpp b/src/uhs/atomizer/watchtower/block_cache.hpp index a016553a8..7503906e1 100644 --- a/src/uhs/atomizer/watchtower/block_cache.hpp +++ b/src/uhs/atomizer/watchtower/block_cache.hpp @@ -44,19 +44,19 @@ namespace cbdc::watchtower { /// blocks in the cache. /// \param uhs_id UHS ID to check. /// \return a BlockCacheResult containing the block height and ID of the transaction that originated this UHS ID. - auto check_unspent(const hash_t& uhs_id) const + [[nodiscard]] auto check_unspent(const hash_t& uhs_id) const -> std::optional; /// Checks to see if the given UHS ID has been spent according to the /// blocks in the cache. /// \param uhs_id UHS ID to check. /// \return a BlockCacheResult containing the block height and ID of the transaction that spent this UHS ID. - auto check_spent(const hash_t& uhs_id) const + [[nodiscard]] auto check_spent(const hash_t& uhs_id) const -> std::optional; /// Returns the block height of the highest observed block. /// \return the highest block height. - auto best_block_height() const -> uint64_t; + [[nodiscard]] auto best_block_height() const -> uint64_t; private: size_t m_k_blks; diff --git a/src/uhs/atomizer/watchtower/controller.cpp b/src/uhs/atomizer/watchtower/controller.cpp index 7ffe9a2e7..777dba757 100644 --- a/src/uhs/atomizer/watchtower/controller.cpp +++ b/src/uhs/atomizer/watchtower/controller.cpp @@ -140,7 +140,7 @@ auto cbdc::watchtower::controller::internal_server_handler( auto cbdc::watchtower::controller::external_server_handler( cbdc::network::message_t&& pkt) -> std::optional { - auto deser = cbdc::buffer_serializer(*pkt.m_pkt); + auto deser = cbdc::buffer_serializer(std::move(*pkt.m_pkt)); auto req = request(deser); auto res_handler = overloaded{ [&](const cbdc::watchtower::status_update_request& su_req) diff --git a/src/uhs/atomizer/watchtower/error_cache.hpp b/src/uhs/atomizer/watchtower/error_cache.hpp index 663d6897d..c88db46d0 100644 --- a/src/uhs/atomizer/watchtower/error_cache.hpp +++ b/src/uhs/atomizer/watchtower/error_cache.hpp @@ -39,12 +39,12 @@ namespace cbdc::watchtower { /// Checks the cache for an error associated with the given Tx ID. /// \param tx_id the Tx ID to check. /// \return error information, or nullopt if not found. - auto check_tx_id(const hash_t& tx_id) const -> std::optional; + [[nodiscard]] auto check_tx_id(const hash_t& tx_id) const -> std::optional; /// Checks the cache for an error associated with the given UHS ID. /// \param uhs_id the UHS ID to check. /// \return error information, or nullopt if not found. - auto check_uhs_id(const hash_t& uhs_id) const + [[nodiscard]] auto check_uhs_id(const hash_t& uhs_id) const -> std::optional; private: diff --git a/src/uhs/atomizer/watchtower/status_update.hpp b/src/uhs/atomizer/watchtower/status_update.hpp index 1be86e0f8..898dc34f8 100644 --- a/src/uhs/atomizer/watchtower/status_update.hpp +++ b/src/uhs/atomizer/watchtower/status_update.hpp @@ -18,7 +18,7 @@ namespace cbdc::watchtower { /// The current status of the Watchtower's progress in searching for a /// particular UHS ID. - enum class search_status { + enum class search_status : std::uint8_t { /// The Watchtower has finished scanning the block history for the UHS /// ID in the request and hasn't found it. no_history, diff --git a/src/uhs/atomizer/watchtower/watchtowerd.cpp b/src/uhs/atomizer/watchtower/watchtowerd.cpp index cfdbec14a..f224d02a9 100644 --- a/src/uhs/atomizer/watchtower/watchtowerd.cpp +++ b/src/uhs/atomizer/watchtower/watchtowerd.cpp @@ -16,7 +16,7 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " " - << std::endl; + << '\n'; return 0; } @@ -25,7 +25,7 @@ auto main(int argc, char** argv) -> int { auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); diff --git a/src/uhs/client/client-cli.cpp b/src/uhs/client/client-cli.cpp index 439354d5a..34b656aed 100644 --- a/src/uhs/client/client-cli.cpp +++ b/src/uhs/client/client-cli.cpp @@ -21,7 +21,7 @@ auto mint_command(cbdc::client& client, const std::vector& args) static constexpr auto min_mint_arg_count = 7; if(args.size() < min_mint_arg_count) { std::cerr << "Mint requires args " - << std::endl; + << '\n'; return false; } @@ -31,7 +31,7 @@ auto mint_command(cbdc::client& client, const std::vector& args) const auto mint_tx = client.mint(n_outputs, static_cast(output_val)); std::cout << cbdc::to_string(cbdc::transaction::tx_id(mint_tx)) - << std::endl; + << '\n'; return true; } @@ -39,25 +39,25 @@ void print_tx_result( const std::optional& tx, const std::optional& resp, const cbdc::hash_t& pubkey) { - std::cout << "tx_id:" << std::endl + std::cout << "tx_id:" << '\n' << cbdc::to_string(cbdc::transaction::tx_id(tx.value())) - << std::endl; + << '\n'; const auto inputs = cbdc::client::export_send_inputs(tx.value(), pubkey); for(const auto& inp : inputs) { auto buf = cbdc::make_buffer(inp); - std::cout << "Data for recipient importinput:" << std::endl - << buf.to_hex() << std::endl; + std::cout << "Data for recipient importinput:" << '\n' + << buf.to_hex() << '\n'; } if(resp.has_value()) { std::cout << "Sentinel responded: " << cbdc::sentinel::to_string(resp.value().m_tx_status) - << std::endl; + << '\n'; if(resp.value().m_tx_error.has_value()) { std::cout << "Validation error: " << cbdc::transaction::validation::to_string( resp.value().m_tx_error.value()) - << std::endl; + << '\n'; } } } @@ -66,7 +66,7 @@ auto send_command(cbdc::client& client, const std::vector& args) -> bool { static constexpr auto min_send_arg_count = 7; if(args.size() < min_send_arg_count) { - std::cerr << "Send requires args " << std::endl; + std::cerr << "Send requires args " << '\n'; return false; } @@ -74,14 +74,14 @@ auto send_command(cbdc::client& client, const std::vector& args) static constexpr auto address_arg_idx = 6; auto pubkey = cbdc::address::decode(args[address_arg_idx]); if(!pubkey.has_value()) { - std::cout << "Could not decode address" << std::endl; + std::cout << "Could not decode address" << '\n'; return false; } const auto [tx, resp] = client.send(static_cast(value), pubkey.value()); if(!tx.has_value()) { - std::cout << "Could not generate valid send tx." << std::endl; + std::cout << "Could not generate valid send tx." << '\n'; return false; } @@ -93,7 +93,7 @@ auto fan_command(cbdc::client& client, const std::vector& args) -> bool { static constexpr auto min_fan_arg_count = 8; if(args.size() < min_fan_arg_count) { - std::cerr << "Fan requires args " << std::endl; + std::cerr << "Fan requires args " << '\n'; return false; } @@ -103,7 +103,7 @@ auto fan_command(cbdc::client& client, const std::vector& args) static constexpr auto address_arg_idx = 7; auto pubkey = cbdc::address::decode(args[address_arg_idx]); if(!pubkey.has_value()) { - std::cout << "Could not decode address" << std::endl; + std::cout << "Could not decode address" << '\n'; return false; } @@ -111,7 +111,7 @@ auto fan_command(cbdc::client& client, const std::vector& args) static_cast(value), pubkey.value()); if(!tx.has_value()) { - std::cout << "Could not generate valid send tx." << std::endl; + std::cout << "Could not generate valid send tx." << '\n'; return false; } @@ -138,7 +138,7 @@ void newaddress_command(cbdc::client& client) { }, addr_vec.begin(), addr_vec.end()); - std::cout << bech32::Encode(cbdc::config::bech32_hrp, data) << std::endl; + std::cout << bech32::Encode(cbdc::config::bech32_hrp, data) << '\n'; } auto importinput_command(cbdc::client& client, @@ -146,13 +146,13 @@ auto importinput_command(cbdc::client& client, static constexpr auto input_arg_idx = 5; auto buffer = cbdc::buffer::from_hex(args[input_arg_idx]); if(!buffer.has_value()) { - std::cout << "Invalid input encoding." << std::endl; + std::cout << "Invalid input encoding." << '\n'; return false; } auto in = cbdc::from_buffer(buffer.value()); if(!in.has_value()) { - std::cout << "Invalid input" << std::endl; + std::cout << "Invalid input" << '\n'; return false; } client.import_send_input(in.value()); @@ -164,12 +164,12 @@ auto confirmtx_command(cbdc::client& client, const auto tx_id = cbdc::hash_from_hex(args[5]); auto success = client.confirm_transaction(tx_id); if(!success) { - std::cout << "Unknown TXID" << std::endl; + std::cout << "Unknown TXID" << '\n'; return false; } std::cout << "Confirmed. Balance: " << cbdc::client::print_amount(client.balance()) - << " UTXOs: " << client.utxo_count() << std::endl; + << " UTXOs: " << client.utxo_count() << '\n'; return true; } @@ -180,14 +180,14 @@ auto main(int argc, char** argv) -> int { if(args.size() < min_arg_count) { std::cerr << "Usage: " << args[0] << " " - << " " << std::endl; + << " " << '\n'; return 0; } auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } @@ -241,7 +241,7 @@ auto main(int argc, char** argv) -> int { std::cout << "Balance: " << cbdc::client::print_amount(balance) << ", UTXOs: " << n_txos << ", pending TXs: " << client->pending_tx_count() - << std::endl; + << '\n'; } else if(command == "importinput") { if(!importinput_command(*client, args)) { return -1; @@ -251,7 +251,7 @@ auto main(int argc, char** argv) -> int { return -1; } } else { - std::cerr << "Unknown command" << std::endl; + std::cerr << "Unknown command" << '\n'; } // TODO: check that the send queue has drained before closing diff --git a/src/uhs/client/client.cpp b/src/uhs/client/client.cpp index 4b3bc60d6..a47132796 100644 --- a/src/uhs/client/client.cpp +++ b/src/uhs/client/client.cpp @@ -31,7 +31,7 @@ namespace cbdc { // see: https://github.com/bitcoin/bitcoin/pull/20861 const auto [hrp, enc_data] = bech32::Decode(addr_str); if(hrp != cbdc::config::bech32_hrp) { - std::cout << "Invalid address encoding" << std::endl; + std::cout << "Invalid address encoding" << '\n'; return std::nullopt; } auto data = std::vector(); @@ -47,7 +47,7 @@ namespace cbdc { != static_cast( cbdc::client::address_type::public_key) || data.size() != pubkey.size() + 1) { - std::cout << "Address is not a supported type" << std::endl; + std::cout << "Address is not a supported type" << '\n'; return std::nullopt; } diff --git a/src/uhs/client/client.hpp b/src/uhs/client/client.hpp index ae3cb6d2a..0f11d024c 100644 --- a/src/uhs/client/client.hpp +++ b/src/uhs/client/client.hpp @@ -292,7 +292,7 @@ namespace cbdc { std::unordered_map m_pending_inputs; - transaction::wallet m_wallet{}; + transaction::wallet m_wallet; std::string m_client_file; std::string m_wallet_file; diff --git a/src/uhs/sentinel/interface.hpp b/src/uhs/sentinel/interface.hpp index 9510ef3d5..b7c6a0076 100644 --- a/src/uhs/sentinel/interface.hpp +++ b/src/uhs/sentinel/interface.hpp @@ -15,7 +15,7 @@ namespace cbdc::sentinel { /// Status of the transaction following sentinel processing. - enum class tx_status { + enum class tx_status : std::uint8_t { /// Statically valid, and the sentinel has submitted /// the transaction to the network for processing. pending, diff --git a/src/uhs/transaction/transaction.hpp b/src/uhs/transaction/transaction.hpp index 0d39b6aed..3e1ed8b03 100644 --- a/src/uhs/transaction/transaction.hpp +++ b/src/uhs/transaction/transaction.hpp @@ -93,13 +93,13 @@ namespace cbdc::transaction { /// \see \ref cbdc::operator<<(serializer&, const transaction::full_tx&) struct full_tx { /// The set of inputs for the transaction - std::vector m_inputs{}; + std::vector m_inputs; /// The set of new outputs created by the transaction - std::vector m_outputs{}; + std::vector m_outputs; /// The set of witnesses - std::vector m_witness{}; + std::vector m_witness; auto operator==(const full_tx& rhs) const -> bool; diff --git a/src/uhs/twophase/coordinator/controller.cpp b/src/uhs/twophase/coordinator/controller.cpp index 5ddfc5d51..be7bbf3d1 100644 --- a/src/uhs/twophase/coordinator/controller.cpp +++ b/src/uhs/twophase/coordinator/controller.cpp @@ -47,7 +47,7 @@ namespace cbdc::coordinator { if(!m_logger) { std::cerr << "[ERROR] The logger pointer in coordinator::controller " - << "is null." << std::endl; + << "is null." << '\n'; return false; } diff --git a/src/uhs/twophase/coordinator/controller.hpp b/src/uhs/twophase/coordinator/controller.hpp index b9ca62009..7994a09bd 100644 --- a/src/uhs/twophase/coordinator/controller.hpp +++ b/src/uhs/twophase/coordinator/controller.hpp @@ -88,7 +88,7 @@ namespace cbdc::coordinator { /// The ID of the distributed transaction the command applies to, /// if applicable. - std::optional m_dtx_id{}; + std::optional m_dtx_id; auto operator==(const sm_command_header& rhs) const -> bool; }; @@ -99,7 +99,7 @@ namespace cbdc::coordinator { sm_command_header m_header{}; /// Associated transactions to prepare or commit, if applicable. - std::optional> m_data{}; + std::optional> m_data; }; /// \brief Current state of distributed transactions managed by a @@ -109,13 +109,13 @@ namespace cbdc::coordinator { /// operating. struct coordinator_state { /// Transactions in the prepare phase. - prepare_txs m_prepare_txs{}; + prepare_txs m_prepare_txs; /// Transactions in the commit phase. - commit_txs m_commit_txs{}; + commit_txs m_commit_txs; /// Transactions in the discard phase. - discard_txs m_discard_txs{}; + discard_txs m_discard_txs; auto operator==(const coordinator_state& rhs) const -> bool; }; @@ -143,7 +143,7 @@ namespace cbdc::coordinator { nuraft::ptr m_state_machine; std::shared_ptr m_raft_serv; - nuraft::raft_params m_raft_params{}; + nuraft::raft_params m_raft_params; std::atomic_bool m_running{false}; std::vector> m_shards; std::vector> m_shard_endpoints; diff --git a/src/uhs/twophase/coordinator/coordinatord.cpp b/src/uhs/twophase/coordinator/coordinatord.cpp index 967aea7f0..3495997a2 100644 --- a/src/uhs/twophase/coordinator/coordinatord.cpp +++ b/src/uhs/twophase/coordinator/coordinatord.cpp @@ -14,14 +14,14 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 4) { std::cout << "Usage: " << args[0] - << " " << std::endl; + << " " << '\n'; return 0; } auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); @@ -30,12 +30,12 @@ auto main(int argc, char** argv) -> int { auto node_id = std::stoull(args[3]); if(opts.m_coordinator_endpoints.size() <= coordinator_id) { - std::cerr << "Coordinator ID not configured" << std::endl; + std::cerr << "Coordinator ID not configured" << '\n'; return -1; } if(opts.m_coordinator_endpoints[coordinator_id].size() <= node_id) { - std::cerr << "Coordinator node ID not configured" << std::endl; + std::cerr << "Coordinator node ID not configured" << '\n'; return -1; } diff --git a/src/uhs/twophase/coordinator/distributed_tx.hpp b/src/uhs/twophase/coordinator/distributed_tx.hpp index 83b957124..c5516bcf6 100644 --- a/src/uhs/twophase/coordinator/distributed_tx.hpp +++ b/src/uhs/twophase/coordinator/distributed_tx.hpp @@ -120,7 +120,7 @@ namespace cbdc::coordinator { /// \return number of transactions in the batch [[nodiscard]] auto size() const -> size_t; - enum class dtx_state { + enum class dtx_state : std::uint8_t { /// dtx initial state, no action has been performed yet start, /// dtx is calling prepare on shards diff --git a/src/uhs/twophase/coordinator/state_machine.hpp b/src/uhs/twophase/coordinator/state_machine.hpp index 571e36389..ea60905c6 100644 --- a/src/uhs/twophase/coordinator/state_machine.hpp +++ b/src/uhs/twophase/coordinator/state_machine.hpp @@ -44,16 +44,16 @@ namespace cbdc::coordinator { std::unordered_map, cbdc::hashing::const_sip_hash> - m_prepare_txs{}; + m_prepare_txs; /// Maps dtx IDs in the commit phase to a byte array containing /// relevant data for recovery. std::unordered_map, cbdc::hashing::const_sip_hash> - m_commit_txs{}; + m_commit_txs; /// Set of dtx IDs in the discard phase. std::unordered_set> - m_discard_txs{}; + m_discard_txs; }; /// Commits a state machine command. diff --git a/src/uhs/twophase/locking_shard/controller.cpp b/src/uhs/twophase/locking_shard/controller.cpp index 8b961f78d..4a4980e50 100644 --- a/src/uhs/twophase/locking_shard/controller.cpp +++ b/src/uhs/twophase/locking_shard/controller.cpp @@ -33,7 +33,7 @@ namespace cbdc::locking_shard { if(!m_logger) { std::cerr << "[ERROR] The logger pointer in locking_shard::controller" - << " is null." << std::endl; + << " is null." << '\n'; return false; } diff --git a/src/uhs/twophase/locking_shard/locking_shardd.cpp b/src/uhs/twophase/locking_shard/locking_shardd.cpp index 92e738c77..40aad15ec 100644 --- a/src/uhs/twophase/locking_shard/locking_shardd.cpp +++ b/src/uhs/twophase/locking_shard/locking_shardd.cpp @@ -15,14 +15,14 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 4) { std::cout << "Usage: " << args[0] - << " " << std::endl; + << " " << '\n'; return 0; } auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto cfg = std::get(cfg_or_err); @@ -30,12 +30,12 @@ auto main(int argc, char** argv) -> int { auto node_id = std::stoull(args[3]); if(cfg.m_locking_shard_endpoints.size() <= shard_id) { - std::cerr << "Shard ID not in config file" << std::endl; + std::cerr << "Shard ID not in config file" << '\n'; return -1; } if(cfg.m_locking_shard_endpoints[shard_id].size() <= node_id) { - std::cerr << "Shard node ID not in config file" << std::endl; + std::cerr << "Shard node ID not in config file" << '\n'; return -1; } diff --git a/src/uhs/twophase/locking_shard/messages.hpp b/src/uhs/twophase/locking_shard/messages.hpp index 80669f535..7ea9143b2 100644 --- a/src/uhs/twophase/locking_shard/messages.hpp +++ b/src/uhs/twophase/locking_shard/messages.hpp @@ -29,7 +29,7 @@ namespace cbdc::locking_shard::rpc { hash_t m_dtx_id{}; /// If the command is lock or apply, the parameters for these /// commands - std::variant m_params{}; + std::variant m_params; auto operator==(const request& rhs) const -> bool; }; diff --git a/src/uhs/twophase/locking_shard/state_machine.hpp b/src/uhs/twophase/locking_shard/state_machine.hpp index 5c911bd87..d81c9a866 100644 --- a/src/uhs/twophase/locking_shard/state_machine.hpp +++ b/src/uhs/twophase/locking_shard/state_machine.hpp @@ -81,16 +81,16 @@ namespace cbdc::locking_shard { -> cbdc::locking_shard::rpc::response; std::atomic m_last_committed_idx{0}; - nuraft::ptr m_snapshot{}; - std::shared_mutex m_snapshots_mut{}; + nuraft::ptr m_snapshot; + std::shared_mutex m_snapshots_mut; - nuraft::ptr m_tmp_snapshot{}; - std::mutex m_tmp_mut{}; + nuraft::ptr m_tmp_snapshot; + std::mutex m_tmp_mut; - std::shared_ptr m_shard{}; - std::pair m_output_range{}; - std::string m_snapshot_dir{}; - std::string m_db_dir{}; + std::shared_ptr m_shard; + std::pair m_output_range; + std::string m_snapshot_dir; + std::string m_db_dir; std::shared_ptr m_logger; }; diff --git a/src/uhs/twophase/sentinel_2pc/controller.cpp b/src/uhs/twophase/sentinel_2pc/controller.cpp index 4c6fc797f..f00134176 100644 --- a/src/uhs/twophase/sentinel_2pc/controller.cpp +++ b/src/uhs/twophase/sentinel_2pc/controller.cpp @@ -188,7 +188,7 @@ namespace cbdc::sentinel_2pc { success = m_sentinel_clients[sentinel_id]->validate_transaction( tx, - [=, this](validate_result v_res) { + [requested, sentinel_id, tx, result_callback, ctx, this](validate_result v_res) { auto r = requested; r.insert(sentinel_id); validate_result_handler(v_res, diff --git a/src/uhs/twophase/sentinel_2pc/controller.hpp b/src/uhs/twophase/sentinel_2pc/controller.hpp index b5485ebf2..7bade3fb9 100644 --- a/src/uhs/twophase/sentinel_2pc/controller.hpp +++ b/src/uhs/twophase/sentinel_2pc/controller.hpp @@ -99,11 +99,11 @@ namespace cbdc::sentinel_2pc { coordinator::rpc::client m_coordinator_client; std::vector> - m_sentinel_clients{}; + m_sentinel_clients; - std::random_device m_r{}; + std::random_device m_r; std::default_random_engine m_rand{m_r()}; - std::uniform_int_distribution m_dist{}; + std::uniform_int_distribution m_dist; privkey_t m_privkey{}; }; diff --git a/src/uhs/twophase/sentinel_2pc/sentineld_2pc.cpp b/src/uhs/twophase/sentinel_2pc/sentineld_2pc.cpp index d562d9326..03c9fa074 100644 --- a/src/uhs/twophase/sentinel_2pc/sentineld_2pc.cpp +++ b/src/uhs/twophase/sentinel_2pc/sentineld_2pc.cpp @@ -13,7 +13,7 @@ auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " " - << std::endl; + << '\n'; return -1; } @@ -22,13 +22,13 @@ auto main(int argc, char** argv) -> int { auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto opts = std::get(cfg_or_err); if(opts.m_sentinel_endpoints.size() <= sentinel_id) { - std::cerr << "Sentinel ID not in config file" << std::endl; + std::cerr << "Sentinel ID not in config file" << '\n'; return -1; } diff --git a/src/util/common/blocking_queue.hpp b/src/util/common/blocking_queue.hpp index 6d3fc6ce6..3ebf81cfd 100644 --- a/src/util/common/blocking_queue.hpp +++ b/src/util/common/blocking_queue.hpp @@ -97,16 +97,14 @@ namespace cbdc { private: template - auto first_item() -> - typename std::enable_if>::value, - const TT&>::type { + auto first_item() -> const TT& + requires std::is_same_v> { return m_buffer.front(); } template - auto first_item() -> - typename std::enable_if>::value, - const TT&>::type { + auto first_item() -> const TT& + requires (!std::is_same_v>) { return m_buffer.top(); } diff --git a/src/util/common/buffer.cpp b/src/util/common/buffer.cpp index b85491d04..614409cc3 100644 --- a/src/util/common/buffer.cpp +++ b/src/util/common/buffer.cpp @@ -109,7 +109,7 @@ namespace cbdc { const std::string& prefix) -> std::optional { size_t offset = 0; - if(hex.rfind(prefix, 0) == 0) { + if(hex.starts_with(prefix)) { offset = prefix.size(); } auto hex_str = hex.substr(offset); diff --git a/src/util/common/buffer.hpp b/src/util/common/buffer.hpp index c35523dd6..7dc07d41f 100644 --- a/src/util/common/buffer.hpp +++ b/src/util/common/buffer.hpp @@ -87,7 +87,7 @@ namespace cbdc { = "0x") const -> std::string; private: - std::vector m_data{}; + std::vector m_data; }; } diff --git a/src/util/common/logging.hpp b/src/util/common/logging.hpp index 821ada900..eab239f18 100644 --- a/src/util/common/logging.hpp +++ b/src/util/common/logging.hpp @@ -126,7 +126,7 @@ namespace cbdc::logging { private: bool m_stdout{true}; log_level m_loglevel{}; - std::mutex m_stream_mut{}; + std::mutex m_stream_mut; std::unique_ptr m_logfile; auto static to_string(log_level level) -> std::string; @@ -136,14 +136,16 @@ namespace cbdc::logging { if(m_loglevel <= level) { std::stringstream ss; write_log_prefix(ss, level); - ((ss << " " << args), ...); + ((ss << " " << std::forward(args)), ...); ss << "\n"; auto formatted_statement = ss.str(); const std::lock_guard lock(m_stream_mut); if(m_stdout) { std::cout << formatted_statement; } - *m_logfile << formatted_statement; + if(m_logfile) { + *m_logfile << formatted_statement; + } } } }; diff --git a/src/util/network/socket_selector.cpp b/src/util/network/socket_selector.cpp index 58affffda..639194a53 100644 --- a/src/util/network/socket_selector.cpp +++ b/src/util/network/socket_selector.cpp @@ -23,7 +23,7 @@ namespace cbdc::network { // should still be safe. // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) auto unblock = FD_ISSET(m_unblock_fds[0], &m_ready_fds); - if(static_cast(unblock) != 0) { + if(unblock != 0) { auto dummy = char(); [[maybe_unused]] auto res = read(m_unblock_fds[0], &dummy, sizeof(dummy)); diff --git a/src/util/network/tcp_socket.hpp b/src/util/network/tcp_socket.hpp index c9969ce9c..821ec61dd 100644 --- a/src/util/network/tcp_socket.hpp +++ b/src/util/network/tcp_socket.hpp @@ -85,7 +85,7 @@ namespace cbdc::network { [[nodiscard]] auto connected() const -> bool; private: - std::optional m_addr{}; + std::optional m_addr; port_number_t m_port{}; std::atomic_bool m_connected{false}; }; diff --git a/src/util/raft/console_logger.hpp b/src/util/raft/console_logger.hpp index 1f869b02e..395ef0a51 100644 --- a/src/util/raft/console_logger.hpp +++ b/src/util/raft/console_logger.hpp @@ -12,7 +12,7 @@ namespace cbdc::raft { /// Map from NuRaft-internal log levels to names. - enum class log_level : int { + enum class log_level : std::uint8_t { trace = 6, debug = 5, info = 4, diff --git a/src/util/raft/util.hpp b/src/util/raft/util.hpp index e9d8edf55..fa4288463 100644 --- a/src/util/raft/util.hpp +++ b/src/util/raft/util.hpp @@ -17,9 +17,8 @@ namespace cbdc { /// \param obj object to serialize. /// \return a serialized buffer of the object. template - auto make_buffer(const T& obj) - -> std::enable_if_t>, - nuraft::ptr> { + requires std::is_same_v> + auto make_buffer(const T& obj) -> nuraft::ptr { auto pkt = nuraft::buffer::alloc(cbdc::serialized_size(obj)); auto ser = cbdc::nuraft_serializer(*pkt); ser << obj; diff --git a/src/util/rpc/client.hpp b/src/util/rpc/client.hpp index 2072bca6f..50878610f 100644 --- a/src/util/rpc/client.hpp +++ b/src/util/rpc/client.hpp @@ -101,7 +101,7 @@ namespace cbdc::rpc { = std::function)>; private: - std::atomic m_current_request_id{}; + std::atomic m_current_request_id; /// Subclasses must override this function to define the logic for /// call() to transmit a serialized RPC request and wait for a diff --git a/src/util/rpc/http/json_rpc_http_server.hpp b/src/util/rpc/http/json_rpc_http_server.hpp index afcd52402..95e231349 100644 --- a/src/util/rpc/http/json_rpc_http_server.hpp +++ b/src/util/rpc/http/json_rpc_http_server.hpp @@ -62,7 +62,7 @@ namespace cbdc::rpc { unsigned int m_code{}; }; - network::ip_address m_host{}; + network::ip_address m_host; uint16_t m_port{}; MHD_Daemon* m_daemon{}; handler_callback_type m_cb; diff --git a/src/util/rpc/server.hpp b/src/util/rpc/server.hpp index 5be0d0a01..f5a92d353 100644 --- a/src/util/rpc/server.hpp +++ b/src/util/rpc/server.hpp @@ -17,7 +17,7 @@ namespace cbdc::rpc { /// Type to distinguish between servers that implement synchronous versus /// asynchronous request handling. - enum class handler_type { + enum class handler_type : std::uint8_t { blocking, async }; diff --git a/src/util/serialization/format.hpp b/src/util/serialization/format.hpp index 683db3719..d932a3937 100644 --- a/src/util/serialization/format.hpp +++ b/src/util/serialization/format.hpp @@ -7,7 +7,6 @@ #define OPENCBDC_TX_SRC_SERIALIZATION_FORMAT_H_ #include "serializer.hpp" -#include "util/common/buffer.hpp" #include "util/common/config.hpp" #include "util/common/variant_overloaded.hpp" @@ -50,16 +49,16 @@ namespace cbdc { /// \tparam T an empty type /// \param s the serializer (to which nothing will be written) template - auto operator<<(serializer& s, T /* t */) -> - typename std::enable_if_t, serializer&> { + auto operator<<(serializer& s, T /* t */) -> serializer& + requires std::is_empty_v { return s; } /// Deserializes nothing if `T` is an empty type. /// \see \ref cbdc::operator<<(serializer&, T) template - auto operator>>(serializer& s, T& /* t */) -> - typename std::enable_if_t, serializer&> { + auto operator>>(serializer& s, T& /* t */) -> serializer& + requires std::is_empty_v { return s; } @@ -70,9 +69,8 @@ namespace cbdc { /// \tparam T the integral type of the value to serialize /// \param t the value to serialize template - auto operator<<(serializer& s, T t) -> - typename std::enable_if_t && !std::is_enum_v, - serializer&> { + auto operator<<(serializer& s, T t) -> serializer& + requires (std::is_integral_v && !std::is_enum_v) { s.write(&t, sizeof(t)); return s; } @@ -83,9 +81,8 @@ namespace cbdc { /// /// \see \ref cbdc::operator<<(serializer&, T) template - auto operator>>(serializer& s, T& t) -> - typename std::enable_if_t && !std::is_enum_v, - serializer&> { + auto operator>>(serializer& s, T& t) -> serializer& + requires (std::is_integral_v && !std::is_enum_v) { s.read(&t, sizeof(t)); return s; } @@ -100,7 +97,7 @@ namespace cbdc { /// \param arr the array of data to be serialized template auto operator<<(serializer& packet, const std::array& arr) -> - typename std::enable_if_t, serializer&> { + serializer& requires std::is_integral_v { packet.write(arr.data(), sizeof(T) * len); return packet; } @@ -108,8 +105,8 @@ namespace cbdc { /// Deserializes the array of integral values in-order. /// \see \ref cbdc::operator<<(serializer&, const std::array&) template - auto operator>>(serializer& packet, std::array& arr) -> - typename std::enable_if_t, serializer&> { + auto operator>>(serializer& packet, std::array& arr) -> serializer& + requires std::is_integral_v { packet.read(arr.data(), sizeof(T) * len); return packet; } @@ -380,9 +377,9 @@ namespace cbdc { /// Deserializes a variant whose alternatives are default-constructible. /// \see \ref cbdc::operator<<(serializer&, const std::variant&) template + requires (std::is_default_constructible_v && ...) auto operator>>(serializer& deser, std::variant& var) - -> std::enable_if_t<(std::is_default_constructible_v && ...), - serializer&> { + -> serializer& { using S = uint8_t; static_assert( std::variant_size_v> < std:: @@ -434,15 +431,15 @@ namespace cbdc { // available. /// Serializes an enum via its underlying type. template - auto operator<<(serializer& ser, T e) -> - typename std::enable_if_t, serializer&> { + auto operator<<(serializer& ser, T e) -> serializer& + requires std::is_enum_v { return ser << static_cast>(e); } /// Deserializes an enum. template - auto operator>>(serializer& deser, T& e) -> - typename std::enable_if_t, serializer&> { + auto operator>>(serializer& deser, T& e) -> serializer& + requires std::is_enum_v { std::underlying_type_t val{}; if(deser >> val) { e = static_cast(val); diff --git a/src/util/serialization/util.hpp b/src/util/serialization/util.hpp index 38c0dc24b..12d2615bc 100644 --- a/src/util/serialization/util.hpp +++ b/src/util/serialization/util.hpp @@ -8,6 +8,7 @@ #include "buffer_serializer.hpp" #include "size_serializer.hpp" +#include "util/serialization/serializer.hpp" #include @@ -30,8 +31,8 @@ namespace cbdc { /// template to be enabled. /// \return a serialized buffer of the object. template - auto make_buffer(const T& obj) - -> std::enable_if_t, cbdc::buffer> { + requires std::is_same_v + auto make_buffer(const T& obj) -> cbdc::buffer { auto sz = serialized_size(obj); auto pkt = cbdc::buffer(); pkt.extend(sz); diff --git a/tests/integration/gtest_evm_jsonrpc_client.cpp b/tests/integration/gtest_evm_jsonrpc_client.cpp index 9e5a01d60..b58798f16 100644 --- a/tests/integration/gtest_evm_jsonrpc_client.cpp +++ b/tests/integration/gtest_evm_jsonrpc_client.cpp @@ -59,7 +59,7 @@ namespace cbdc::test { ASSERT_FALSE(v.isMember(m_json_error_key)); ASSERT_TRUE(v.isMember(m_json_result_key)); out_txcount_str = v[m_json_result_key].asString(); - ASSERT_TRUE(out_txcount_str.length() > 0); + ASSERT_TRUE(!out_txcount_str.empty()); tx_done = true; }); @@ -98,7 +98,7 @@ namespace cbdc::test { ASSERT_TRUE(v[m_json_result_key].isString()); out_txid = v[m_json_result_key].asString(); - ASSERT_TRUE(out_txid.length() > 0); + ASSERT_TRUE(!out_txid.empty()); tx_done = true; }); diff --git a/tests/integration/replicated_atomizer_integration_tests.cpp b/tests/integration/replicated_atomizer_integration_tests.cpp index c66b09ac1..c68b23e5c 100644 --- a/tests/integration/replicated_atomizer_integration_tests.cpp +++ b/tests/integration/replicated_atomizer_integration_tests.cpp @@ -161,7 +161,7 @@ TEST_F(replicated_atomizer_integration_tests, raftnode_crash_recover) { for(; !m_cluster.connected_to_one(); ++intv) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - std::cout << std::endl; + std::cout << '\n'; m_logger->info("DONE: atomizer raft cluster has reconnected with new" " leader (after ~", 100 * intv, diff --git a/tests/unit/archiver_test.cpp b/tests/unit/archiver_test.cpp index 86c10eae5..eb06a3383 100644 --- a/tests/unit/archiver_test.cpp +++ b/tests/unit/archiver_test.cpp @@ -70,8 +70,8 @@ class ArchiverTest : public ::testing::Test { std::vector m_dummy_blocks; cbdc::config::options m_config_opts{}; - std::shared_ptr m_log{}; - std::unique_ptr m_archiver{}; + std::shared_ptr m_log; + std::unique_ptr m_archiver; }; TEST_F(ArchiverTest, archiver_running) { diff --git a/tests/unit/atomizer/messages_test.cpp b/tests/unit/atomizer/messages_test.cpp index cce69ccbc..826f62db7 100644 --- a/tests/unit/atomizer/messages_test.cpp +++ b/tests/unit/atomizer/messages_test.cpp @@ -9,7 +9,7 @@ class atomizer_messages_test : public ::testing::Test { protected: - cbdc::buffer m_target_packet{}; + cbdc::buffer m_target_packet; cbdc::buffer_serializer m_ser{m_target_packet}; cbdc::buffer_serializer m_deser{m_target_packet}; }; diff --git a/tests/unit/coordinator/messages_test.cpp b/tests/unit/coordinator/messages_test.cpp index de7897f6a..2481a6654 100644 --- a/tests/unit/coordinator/messages_test.cpp +++ b/tests/unit/coordinator/messages_test.cpp @@ -13,7 +13,7 @@ class coordinator_messages_test : public ::testing::Test { protected: - cbdc::buffer m_target_packet{}; + cbdc::buffer m_target_packet; cbdc::buffer_serializer m_ser{m_target_packet}; cbdc::buffer_serializer m_deser{m_target_packet}; diff --git a/tests/unit/locking_shard/format_test.cpp b/tests/unit/locking_shard/format_test.cpp index b24fb5425..1680328f2 100644 --- a/tests/unit/locking_shard/format_test.cpp +++ b/tests/unit/locking_shard/format_test.cpp @@ -10,7 +10,7 @@ class locking_shard_format_test : public ::testing::Test { protected: - cbdc::buffer m_target_packet{}; + cbdc::buffer m_target_packet; cbdc::buffer_serializer m_ser{m_target_packet}; cbdc::buffer_serializer m_deser{m_target_packet}; diff --git a/tests/unit/raft_test.cpp b/tests/unit/raft_test.cpp index 0ffa52574..28cb24f4e 100644 --- a/tests/unit/raft_test.cpp +++ b/tests/unit/raft_test.cpp @@ -70,7 +70,7 @@ class dummy_sm : public nuraft::state_machine { private: uint64_t m_last_commit_index = 0; - nuraft::ptr m_snapshot{}; + nuraft::ptr m_snapshot; }; class raft_test : public ::testing::Test { @@ -322,8 +322,8 @@ class raft_test : public ::testing::Test { static constexpr const auto m_endpoint = "endpoint"; std::vector> m_dummy_log_entries; static constexpr const auto m_log_file = "log_file"; - nuraft::raft_params m_raft_params{}; - std::vector m_raft_endpoints{}; + nuraft::raft_params m_raft_params; + std::vector m_raft_endpoints; }; TEST_F(raft_test, test_init) { diff --git a/tests/unit/sentinel_2pc/controller_test.cpp b/tests/unit/sentinel_2pc/controller_test.cpp index 4a35b6bf5..8d97356fe 100644 --- a/tests/unit/sentinel_2pc/controller_test.cpp +++ b/tests/unit/sentinel_2pc/controller_test.cpp @@ -97,7 +97,7 @@ class sentinel_2pc_test : public ::testing::Test { std::optional m_dummy_coordinator_thread; cbdc::config::options m_opts{}; std::unique_ptr m_ctl; - cbdc::transaction::full_tx m_valid_tx{}; + cbdc::transaction::full_tx m_valid_tx; std::shared_ptr m_logger; }; diff --git a/tests/unit/serialization/stream_serializer_test.cpp b/tests/unit/serialization/stream_serializer_test.cpp index 25bedbeba..758880184 100644 --- a/tests/unit/serialization/stream_serializer_test.cpp +++ b/tests/unit/serialization/stream_serializer_test.cpp @@ -23,8 +23,8 @@ class stream_serializer_test : public ::testing::Test { std::filesystem::remove_all(m_test_file); } - std::ifstream m_if{}; - std::ofstream m_of{}; + std::ifstream m_if; + std::ofstream m_of; cbdc::istream_serializer m_is{m_if}; cbdc::ostream_serializer m_os{m_of}; diff --git a/tests/unit/validation_test.cpp b/tests/unit/validation_test.cpp index df5655726..7c681a9f7 100644 --- a/tests/unit/validation_test.cpp +++ b/tests/unit/validation_test.cpp @@ -26,8 +26,8 @@ class WalletTxValidationTest : public ::testing::Test { = wallet1.send_to(200, wallet2.generate_key(), true).value(); } - cbdc::transaction::full_tx m_valid_tx{}; - cbdc::transaction::full_tx m_valid_tx_multi_inp{}; + cbdc::transaction::full_tx m_valid_tx; + cbdc::transaction::full_tx m_valid_tx_multi_inp; std::unique_ptr m_secp{secp256k1_context_create(SECP256K1_CONTEXT_SIGN diff --git a/tests/unit/wallet_test.cpp b/tests/unit/wallet_test.cpp index a1ff2c7b6..0334c9430 100644 --- a/tests/unit/wallet_test.cpp +++ b/tests/unit/wallet_test.cpp @@ -20,7 +20,7 @@ class WalletTest : public ::testing::Test { std::filesystem::remove(m_wallet_file); } - cbdc::transaction::wallet m_wallet{}; + cbdc::transaction::wallet m_wallet; static constexpr auto m_wallet_file = "test_wallet.dat"; }; @@ -104,8 +104,8 @@ class WalletTxTest : public ::testing::Test { m_sender.confirm_transaction(mint_tx); } - cbdc::transaction::wallet m_sender{}; - cbdc::transaction::wallet m_receiver{}; + cbdc::transaction::wallet m_sender; + cbdc::transaction::wallet m_receiver; }; TEST_F(WalletTxTest, basic) { @@ -126,7 +126,7 @@ class WalletMultiTxTest : public ::testing::Test { m_sender.confirm_transaction(mint_tx); } - cbdc::transaction::wallet m_sender{}; + cbdc::transaction::wallet m_sender; }; TEST_F(WalletMultiTxTest, inp_out_count) { diff --git a/tools/bench/atomizer-cli-watchtower.cpp b/tools/bench/atomizer-cli-watchtower.cpp index 38bdc6536..2e9e30970 100644 --- a/tools/bench/atomizer-cli-watchtower.cpp +++ b/tools/bench/atomizer-cli-watchtower.cpp @@ -41,14 +41,14 @@ auto main(int argc, char** argv) -> int { std::cerr << "Usage: " << args[0] << " " "[]" - << std::endl; + << '\n'; return 0; } auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto cfg = std::get(cfg_or_err); diff --git a/tools/bench/twophase_gen.cpp b/tools/bench/twophase_gen.cpp index 0b86eb518..c5b033781 100644 --- a/tools/bench/twophase_gen.cpp +++ b/tools/bench/twophase_gen.cpp @@ -16,19 +16,20 @@ #include #include +#include auto main(int argc, char** argv) -> int { auto args = cbdc::config::get_args(argc, argv); if(args.size() < 3) { std::cerr << "Usage: " << args[0] << " " - << std::endl; + << '\n'; return -1; } auto cfg_or_err = cbdc::config::load_options(args[1]); if(std::holds_alternative(cfg_or_err)) { std::cerr << "Error loading config file: " - << std::get(cfg_or_err) << std::endl; + << std::get(cfg_or_err) << '\n'; return -1; } auto cfg = std::get(cfg_or_err); @@ -225,7 +226,7 @@ auto main(int argc, char** argv) -> int { // We couldn't send a double-spend or a newly generated valid // transaction, emit a warning and wait for confirmations. - if(!tx) { + if (!tx) { logger->warn("Wallet out of outputs"); // If we couldn't send any txs this loop because we're out of // spendable outputs, sleep the send thread for some time in @@ -242,7 +243,7 @@ auto main(int argc, char** argv) -> int { .count(); auto res_cb - = [&, txn = tx.value(), send_time = send_time]( + = [&, txn = tx.value(), local_send_time = send_time]( cbdc::sentinel::rpc::client::execute_result_type res) { auto tx_id = cbdc::transaction::tx_id(txn); if(!res.has_value()) { @@ -259,7 +260,7 @@ auto main(int argc, char** argv) -> int { auto now = std::chrono::high_resolution_clock::now() .time_since_epoch() .count(); - const auto tx_delay = now - send_time; + const auto tx_delay = now - local_send_time; latency_log << now << " " << tx_delay << "\n"; constexpr auto max_invalid = 100000; if(cfg.m_invalid_rate > 0.0) { diff --git a/tools/shard-seeder/shard-seeder.cpp b/tools/shard-seeder/shard-seeder.cpp index c2fba0c26..89c5bbb40 100644 --- a/tools/shard-seeder/shard-seeder.cpp +++ b/tools/shard-seeder/shard-seeder.cpp @@ -36,7 +36,7 @@ auto main(int argc, char** argv) -> int { auto logger = cbdc::logging::log(cbdc::logging::log_level::info); static constexpr auto min_arg_count = 2; if(args.size() < min_arg_count) { - std::cout << "Usage: shard-seeder [config file]" << std::endl; + std::cout << "Usage: shard-seeder [config file]" << '\n'; return -1; }