From 2af9d1eb8a14f3ecd397258683bf582b8ad0c8fa Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 11:31:59 -0300 Subject: [PATCH] style: Removed blank lines and added [[nodiscard]] --- .clang-tidy | 1 + src/authorship/block_builder.hpp | 3 +- src/authorship/block_builder_factory.hpp | 11 +- src/authorship/impl/block_builder_error.cpp | 1 - .../impl/block_builder_factory_impl.cpp | 1 - .../impl/block_builder_factory_impl.hpp | 8 +- src/authorship/impl/block_builder_impl.hpp | 8 +- src/authorship/impl/proposer_impl.cpp | 1 - src/authorship/impl/proposer_impl.hpp | 2 - src/authorship/proposer.hpp | 14 +-- src/base/blob.cpp | 2 - src/base/blob.hpp | 33 +++--- src/base/buffer.cpp | 7 +- src/base/buffer.hpp | 16 ++- src/base/buffer_back_insert_iterator.hpp | 1 - src/base/hexutil.cpp | 2 - src/base/logger.cpp | 2 - src/base/logger.hpp | 2 - src/base/mp_utils.cpp | 2 - src/base/mp_utils.hpp | 2 - src/base/outcome_throw.hpp | 2 - src/base/type_traits.hpp | 1 - src/base/unused.hpp | 1 - src/base/visitor.hpp | 2 - src/base/wrapper.hpp | 3 - src/blockchain/block_header_repository.hpp | 57 +++++----- src/blockchain/block_storage.hpp | 1 - src/blockchain/block_tree.hpp | 14 +-- .../impl/block_header_repository.cpp | 25 ++--- src/blockchain/impl/block_tree_error.cpp | 2 - src/blockchain/impl/block_tree_impl.cpp | 5 - src/blockchain/impl/block_tree_impl.hpp | 29 ++--- src/blockchain/impl/common.hpp | 3 - .../key_value_block_header_repository.cpp | 7 +- .../key_value_block_header_repository.hpp | 3 - .../impl/key_value_block_storage.cpp | 5 +- .../impl/key_value_block_storage.hpp | 4 - src/blockchain/impl/storage_util.cpp | 2 - src/blockchain/impl/storage_util.hpp | 4 - src/blockchain/impl/types.cpp | 4 - src/clock/clock.hpp | 2 - src/clock/impl/basic_waitable_timer.cpp | 2 - src/clock/impl/basic_waitable_timer.hpp | 2 - src/clock/impl/clock_impl.cpp | 2 - src/clock/impl/clock_impl.hpp | 2 - src/clock/timer.hpp | 2 - src/crdt/globaldb/keypair_file_storage.hpp | 2 +- src/crdt/globaldb/pubsub_broadcaster_ext.cpp | 16 ++- src/crdt/impl/crdt_datastore.cpp | 104 +++++++++--------- 49 files changed, 163 insertions(+), 264 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index a64b6054..bbaa281f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -24,6 +24,7 @@ Checks: > -google-build-using-namespace, -google-explicit-constructor, -google-readability-namespace-comments, + -google-readability-todo, hicpp-multiway-paths-covered, diff --git a/src/authorship/block_builder.hpp b/src/authorship/block_builder.hpp index 894fb0fd..d4e1600f 100644 --- a/src/authorship/block_builder.hpp +++ b/src/authorship/block_builder.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_AUTHORSHIP_BLOCK_BUILDER_HPP #define SUPERGENIUS_SRC_AUTHORSHIP_BLOCK_BUILDER_HPP @@ -25,7 +24,7 @@ namespace sgns::authorship { /** * Create a block from extrinsics and header */ - virtual outcome::result bake() const = 0; + [[nodiscard]] virtual outcome::result bake() const = 0; }; } // namespace sgns::authorship diff --git a/src/authorship/block_builder_factory.hpp b/src/authorship/block_builder_factory.hpp index 212e9d57..e7a663dc 100644 --- a/src/authorship/block_builder_factory.hpp +++ b/src/authorship/block_builder_factory.hpp @@ -1,13 +1,8 @@ - #ifndef SUPERGENIUS_SRC_AUTHORSHIP_BLOCK_BUILDER_FACTORY_HPP #define SUPERGENIUS_SRC_AUTHORSHIP_BLOCK_BUILDER_FACTORY_HPP -#include - #include "authorship/block_builder.hpp" #include "primitives/block_id.hpp" -#include "runtime/block_builder.hpp" -#include "runtime/core.hpp" #include "integration/IComponent.hpp" namespace sgns::authorship { @@ -24,10 +19,8 @@ namespace sgns::authorship { * Prepares BlockBuilder for creating block on top of parent block and using * provided digests. Also initialises the block created in BlockBuilder */ - virtual outcome::result> create( - const primitives::BlockId &parent_id, - primitives::Digest inherent_digest) const = 0; - + [[nodiscard]] virtual outcome::result> create( + const primitives::BlockId &parent_id, primitives::Digest inherent_digest ) const = 0; }; } // namespace sgns::authorship diff --git a/src/authorship/impl/block_builder_error.cpp b/src/authorship/impl/block_builder_error.cpp index 2c38572e..caf398a1 100644 --- a/src/authorship/impl/block_builder_error.cpp +++ b/src/authorship/impl/block_builder_error.cpp @@ -1,4 +1,3 @@ - #include "authorship/impl/block_builder_error.hpp" OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::authorship, BlockBuilderError, e) { diff --git a/src/authorship/impl/block_builder_factory_impl.cpp b/src/authorship/impl/block_builder_factory_impl.cpp index c752792c..9481824d 100644 --- a/src/authorship/impl/block_builder_factory_impl.cpp +++ b/src/authorship/impl/block_builder_factory_impl.cpp @@ -1,4 +1,3 @@ - #include "authorship/impl/block_builder_factory_impl.hpp" #include "authorship/impl/block_builder_impl.hpp" diff --git a/src/authorship/impl/block_builder_factory_impl.hpp b/src/authorship/impl/block_builder_factory_impl.hpp index 4c9e3d74..d52f227a 100644 --- a/src/authorship/impl/block_builder_factory_impl.hpp +++ b/src/authorship/impl/block_builder_factory_impl.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_AUTHORSHIP_IMPL_BLOCK_BUILDER_FACTORY_IMPL_HPP #define SUPERGENIUS_SRC_AUTHORSHIP_IMPL_BLOCK_BUILDER_FACTORY_IMPL_HPP @@ -18,10 +17,9 @@ namespace sgns::authorship { //std::shared_ptr r_block_builder, std::shared_ptr header_backend); - outcome::result> create( - const sgns::primitives::BlockId &parent_id, - primitives::Digest inherent_digest) const override; - + [[nodiscard]] outcome::result> create( + const sgns::primitives::BlockId &parent_id, primitives::Digest inherent_digest ) const override; + std::string GetName() override { return "BlockBuilderFactoryImpl"; diff --git a/src/authorship/impl/block_builder_impl.hpp b/src/authorship/impl/block_builder_impl.hpp index e6e4235e..297a5488 100644 --- a/src/authorship/impl/block_builder_impl.hpp +++ b/src/authorship/impl/block_builder_impl.hpp @@ -1,13 +1,9 @@ - #ifndef SUPERGENIUS_SRC_AUTHORSHIP_IMPL_BLOCK_BUILDER_IMPL_HPP #define SUPERGENIUS_SRC_AUTHORSHIP_IMPL_BLOCK_BUILDER_IMPL_HPP #include "authorship/block_builder.hpp" #include "base/logger.hpp" -#include "primitives/block_id.hpp" -#include "runtime/block_builder.hpp" -#include "runtime/core.hpp" namespace sgns::authorship { @@ -21,9 +17,9 @@ namespace sgns::authorship { outcome::result pushExtrinsic( const primitives::Extrinsic &extrinsic) override; - outcome::result bake() const override; + [[nodiscard]] outcome::result bake() const override; - private: +private: primitives::BlockHeader block_header_; //std::shared_ptr r_block_builder_; base::Logger logger_; diff --git a/src/authorship/impl/proposer_impl.cpp b/src/authorship/impl/proposer_impl.cpp index c499bd4c..2c146d4f 100644 --- a/src/authorship/impl/proposer_impl.cpp +++ b/src/authorship/impl/proposer_impl.cpp @@ -1,4 +1,3 @@ - #include "authorship/impl/proposer_impl.hpp" namespace sgns::authorship { diff --git a/src/authorship/impl/proposer_impl.hpp b/src/authorship/impl/proposer_impl.hpp index e9b895f9..033c7eea 100644 --- a/src/authorship/impl/proposer_impl.hpp +++ b/src/authorship/impl/proposer_impl.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_AUTHORSHIP_IMPL_AITHORING_IMPL_HPP #define SUPERGENIUS_SRC_AUTHORSHIP_IMPL_AITHORING_IMPL_HPP @@ -6,7 +5,6 @@ #include "authorship/block_builder_factory.hpp" #include "base/logger.hpp" -#include "runtime/block_builder.hpp" #include "transaction_pool/transaction_pool.hpp" namespace sgns::authorship { diff --git a/src/authorship/proposer.hpp b/src/authorship/proposer.hpp index 8fd3f95a..1b41f940 100644 --- a/src/authorship/proposer.hpp +++ b/src/authorship/proposer.hpp @@ -1,9 +1,6 @@ - - #ifndef SUPERGENIUS_SRC_AUTHORSHIP_PROPOSER_TEST_HPP #define SUPERGENIUS_SRC_AUTHORSHIP_PROPOSER_TEST_HPP -#include "clock/clock.hpp" #include "primitives/block.hpp" #include "primitives/block_id.hpp" #include "primitives/digest.hpp" @@ -17,19 +14,18 @@ namespace sgns::authorship { */ class Proposer : public IComponent { public: - virtual ~Proposer() = default; + ~Proposer() override = default; - /** + /** * Creates block from provided parameters * @param parent_block_id hash or number of parent * @param inherent_data additional data on block from unsigned extrinsics * @param inherent_digests - chain-specific block auxilary data * @return proposed block or error */ - virtual outcome::result propose( - const primitives::BlockId &parent_block_id, - const primitives::InherentData &inherent_data, - const primitives::Digest &inherent_digest) = 0; + virtual outcome::result propose( const primitives::BlockId &parent_block_id, + const primitives::InherentData &inherent_data, + const primitives::Digest &inherent_digest ) = 0; }; } // namespace sgns::authorship diff --git a/src/base/blob.cpp b/src/base/blob.cpp index 4ccd2370..43a0a3cd 100644 --- a/src/base/blob.cpp +++ b/src/base/blob.cpp @@ -1,5 +1,3 @@ - - #include "base/blob.hpp" OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::base, BlobError, e) { diff --git a/src/base/blob.hpp b/src/base/blob.hpp index 4ba74368..1b3d32aa 100644 --- a/src/base/blob.hpp +++ b/src/base/blob.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_BLOB_HPP #define SUPERGENIUS_BLOB_HPP @@ -55,30 +53,33 @@ namespace sgns::base { /** * Converts current blob to std::string */ - std::string toString() const noexcept { - return std::string{this->begin(), this->end()}; + [[nodiscard]] std::string toString() const noexcept + { + return std::string{ this->begin(), this->end() }; } /** * Converts current blob to a readable std::string */ - std::string toReadableString() const noexcept { - std::string out_str; - char temp_buf[3]; - for ( auto it = this->begin(); it != this->end(); ++it ) - { - snprintf( temp_buf, sizeof( temp_buf ), "%02x", *it ); - out_str.append( temp_buf, sizeof( temp_buf ) - 1 ); - } - return out_str; + [[nodiscard]] std::string toReadableString() const noexcept + { + std::string out_str; + char temp_buf[3]; + for ( auto it = this->begin(); it != this->end(); ++it ) + { + snprintf( temp_buf, sizeof( temp_buf ), "%02x", *it ); + out_str.append( temp_buf, sizeof( temp_buf ) - 1 ); + } + return out_str; } /** * Converts current blob to hex string. */ - std::string toHex() const noexcept { - // return hex_lower({this->begin(), this->end()}); - return hex_lower(gsl::make_span(*this)); + [[nodiscard]] std::string toHex() const noexcept + { + // return hex_lower({this->begin(), this->end()}); + return hex_lower( gsl::make_span( *this ) ); } /** diff --git a/src/base/buffer.cpp b/src/base/buffer.cpp index 5254b7cd..6a8deb3a 100644 --- a/src/base/buffer.cpp +++ b/src/base/buffer.cpp @@ -1,5 +1,3 @@ - - #include "base/buffer.hpp" #include "base/hexutil.hpp" #include @@ -36,8 +34,9 @@ namespace sgns::base { return hex_lower(data_); } - const std::string_view Buffer::toString() const { - return std::string_view(reinterpret_cast(data_.data()), data_.size()); // NOLINT + std::string_view Buffer::toString() const + { + return { reinterpret_cast( data_.data() ), data_.size() }; } bool Buffer::empty() const { diff --git a/src/base/buffer.hpp b/src/base/buffer.hpp index ed619a3c..93348058 100644 --- a/src/base/buffer.hpp +++ b/src/base/buffer.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_BUFFER_HPP #define SUPERGENIUS_BUFFER_HPP @@ -110,29 +108,29 @@ namespace sgns::base { /** * @brief Iterator, which points to last of this buffer. */ - const_reverse_iterator rbegin() const; + [[nodiscard]] const_reverse_iterator rbegin() const; /** * @brief Iterator, which points to the element previous to first in this * buffer. */ - const_reverse_iterator rend() const; + [[nodiscard]] const_reverse_iterator rend() const; /** * @brief Iterator, which points to begin of this buffer. */ - const_iterator begin() const; + [[nodiscard]] const_iterator begin() const; /** * @brief Iterator, which points to the element next to the last in this * buffer. */ - const_iterator end() const; + [[nodiscard]] const_iterator end() const; /** * @brief Getter for size of this buffer. */ - size_t size() const; + [[nodiscard]] size_t size() const; /** * @brief Put a 8-bit {@param n} in this buffer. @@ -239,9 +237,9 @@ namespace sgns::base { * @note Does not ensure correct encoding * @return string */ - const std::string_view toString() const; + std::string_view toString() const; - private: +private: std::vector data_; template diff --git a/src/base/buffer_back_insert_iterator.hpp b/src/base/buffer_back_insert_iterator.hpp index 161a700a..353b0934 100644 --- a/src/base/buffer_back_insert_iterator.hpp +++ b/src/base/buffer_back_insert_iterator.hpp @@ -1,4 +1,3 @@ - #include "base/buffer.hpp" using sgns::base::Buffer; diff --git a/src/base/hexutil.cpp b/src/base/hexutil.cpp index ab36309f..687fe5be 100644 --- a/src/base/hexutil.cpp +++ b/src/base/hexutil.cpp @@ -1,5 +1,3 @@ - - #include "base/hexutil.hpp" #include diff --git a/src/base/logger.cpp b/src/base/logger.cpp index c79757cc..180d7db4 100644 --- a/src/base/logger.cpp +++ b/src/base/logger.cpp @@ -1,5 +1,3 @@ - - #include "base/logger.hpp" #include diff --git a/src/base/logger.hpp b/src/base/logger.hpp index 42b2299d..f6fa1549 100644 --- a/src/base/logger.hpp +++ b/src/base/logger.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_LOGGER_HPP #define SUPERGENIUS_LOGGER_HPP diff --git a/src/base/mp_utils.cpp b/src/base/mp_utils.cpp index ba3687d8..4f0d990f 100644 --- a/src/base/mp_utils.cpp +++ b/src/base/mp_utils.cpp @@ -1,5 +1,3 @@ - - #include "base/mp_utils.hpp" #include diff --git a/src/base/mp_utils.hpp b/src/base/mp_utils.hpp index 6d804352..4c221940 100644 --- a/src/base/mp_utils.hpp +++ b/src/base/mp_utils.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_MP_UTILS_HPP #define SUPERGENIUS_SRC_CRYPTO_MP_UTILS_HPP diff --git a/src/base/outcome_throw.hpp b/src/base/outcome_throw.hpp index c946cebd..b628697c 100644 --- a/src/base/outcome_throw.hpp +++ b/src/base/outcome_throw.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_COMMON_OUTCOME_THROW_HPP #define SUPERGENIUS_SRC_COMMON_OUTCOME_THROW_HPP diff --git a/src/base/type_traits.hpp b/src/base/type_traits.hpp index 3139e600..4f644f3b 100644 --- a/src/base/type_traits.hpp +++ b/src/base/type_traits.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_TYPE_TRAITS #define SUPERGENIUS_TYPE_TRAITS diff --git a/src/base/unused.hpp b/src/base/unused.hpp index 3acba424..83c921ba 100644 --- a/src/base/unused.hpp +++ b/src/base/unused.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_UNUSED #define SUPERGENIUS_UNUSED diff --git a/src/base/visitor.hpp b/src/base/visitor.hpp index 8b650d49..ce658f3a 100644 --- a/src/base/visitor.hpp +++ b/src/base/visitor.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_VISITOR_HPP #define SUPERGENIUS_VISITOR_HPP diff --git a/src/base/wrapper.hpp b/src/base/wrapper.hpp index 2ce23ac0..3808902d 100644 --- a/src/base/wrapper.hpp +++ b/src/base/wrapper.hpp @@ -1,9 +1,6 @@ - - #ifndef SUPERGENIUS_SRC_COMMON_WRAPPER_HPP #define SUPERGENIUS_SRC_COMMON_WRAPPER_HPP -#include #include #include diff --git a/src/blockchain/block_header_repository.hpp b/src/blockchain/block_header_repository.hpp index 74de4c46..e96b89ce 100644 --- a/src/blockchain/block_header_repository.hpp +++ b/src/blockchain/block_header_repository.hpp @@ -31,48 +31,51 @@ namespace sgns::blockchain virtual ~BlockHeaderRepository() = default; /** - * @param hash - a blake2_256 hash of an SCALE encoded block header - * @return the number of the block with the provided hash in case one is in - * the storage or an error - */ - virtual outcome::result getNumberByHash( const base::Hash256 &hash ) const = 0; + * @param hash - a blake2_256 hash of an SCALE encoded block header + * @return the number of the block with the provided hash in case one is in + * the storage or an error + */ + [[nodiscard]] virtual outcome::result getNumberByHash( + const base::Hash256 &hash ) const = 0; /** - * @param number - the number of a block, contained in a block header - * @return the hash of the block with the provided number in case one is in - * the storage or an error - */ - virtual outcome::result getHashByNumber( const primitives::BlockNumber &number ) const = 0; + * @param number - the number of a block, contained in a block header + * @return the hash of the block with the provided number in case one is in + * the storage or an error + */ + [[nodiscard]] virtual outcome::result getHashByNumber( + const primitives::BlockNumber &number ) const = 0; /** - * @return block header with corresponding id or an error - */ - virtual outcome::result getBlockHeader( const primitives::BlockId &id ) const = 0; + * @return block header with corresponding id or an error + */ + [[nodiscard]] virtual outcome::result getBlockHeader( + const primitives::BlockId &id ) const = 0; virtual outcome::result putBlockHeader( const primitives::BlockHeader &header ) = 0; virtual outcome::result removeBlockHeader( const primitives::BlockId &id ) = 0; /** - * @param id of a block which status is returned - * @return status of a block or a storage error - */ - virtual outcome::result getBlockStatus( + * @param id of a block which status is returned + * @return status of a block or a storage error + */ + [[nodiscard]] virtual outcome::result getBlockStatus( const primitives::BlockId &id ) const = 0; /** - * @param id of a block which number is returned - * @return block number or a none optional if the corresponding block header - * is not in storage or a storage error - */ - auto getNumberById( const primitives::BlockId &id ) const -> outcome::result; + * @param id of a block which number is returned + * @return block number or a none optional if the corresponding block header + * is not in storage or a storage error + */ + [[nodiscard]] outcome::result getNumberById( const primitives::BlockId &id ) const; /** - * @param id of a block which hash is returned - * @return block hash or a none optional if the corresponding block header - * is not in storage or a storage error - */ - auto getHashById( const primitives::BlockId &id ) const -> outcome::result; + * @param id of a block which hash is returned + * @return block hash or a none optional if the corresponding block header + * is not in storage or a storage error + */ + [[nodiscard]] outcome::result getHashById( const primitives::BlockId &id ) const; }; } diff --git a/src/blockchain/block_storage.hpp b/src/blockchain/block_storage.hpp index cbc07ac9..f1d31188 100644 --- a/src/blockchain/block_storage.hpp +++ b/src/blockchain/block_storage.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_BLOCK_STORAGE_HPP #define SUPERGENIUS_SRC_BLOCK_STORAGE_HPP diff --git a/src/blockchain/block_tree.hpp b/src/blockchain/block_tree.hpp index 775296b8..26b248ec 100644 --- a/src/blockchain/block_tree.hpp +++ b/src/blockchain/block_tree.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_BLOCK_TREE_HPP #define SUPERGENIUS_BLOCK_TREE_HPP @@ -157,7 +155,7 @@ namespace sgns::blockchain { * @note deepest leaf is also a result of "SelectBestChain": if we are the * leader, we connect a block, which we constructed, to that deepest leaf */ - virtual primitives::BlockInfo deepestLeaf() const = 0; + [[nodiscard]] virtual primitives::BlockInfo deepestLeaf() const = 0; /** * @brief Get the most recent block of the best (longest) chain among those @@ -167,15 +165,15 @@ namespace sgns::blockchain { * @param max_number is the max block number that the resulting block (and * the target one) may possess */ - virtual outcome::result getBestContaining( - const primitives::BlockHash &target_hash, - const boost::optional &max_number) const = 0; + [[nodiscard]] virtual outcome::result getBestContaining( + const primitives::BlockHash &target_hash, + const boost::optional &max_number ) const = 0; /** * Get all leaves of our tree * @return collection of the leaves */ - virtual std::vector getLeaves() const = 0; + [[nodiscard]] virtual std::vector getLeaves() const = 0; /** * Get children of the block with specified hash @@ -188,7 +186,7 @@ namespace sgns::blockchain { * Get the last finalized block * @return hash of the block */ - virtual primitives::BlockInfo getLastFinalized() const = 0; + [[nodiscard]] virtual primitives::BlockInfo getLastFinalized() const = 0; }; } // namespace sgns::blockchain diff --git a/src/blockchain/impl/block_header_repository.cpp b/src/blockchain/impl/block_header_repository.cpp index 24690b65..a6075682 100644 --- a/src/blockchain/impl/block_header_repository.cpp +++ b/src/blockchain/impl/block_header_repository.cpp @@ -1,29 +1,26 @@ - - #include "blockchain/block_header_repository.hpp" #include "base/visitor.hpp" namespace sgns::blockchain { - auto BlockHeaderRepository::getNumberById(const primitives::BlockId &id) const - -> outcome::result { - return visit_in_place( - id, [](const primitives::BlockNumber &n) { return n; }, - [this](const base::Hash256 &hash) { return getNumberByHash(hash); }); - } + outcome::result BlockHeaderRepository::getNumberById( const primitives::BlockId &id ) const + { + return visit_in_place( + id, []( const primitives::BlockNumber &n ) { return n; }, + [this]( const base::Hash256 &hash ) { return getNumberByHash( hash ); } ); + } /** * @param id of a block which hash is returned * @return block hash or a none optional if the corresponding block header * is not in storage or a storage error */ - auto BlockHeaderRepository::getHashById(const primitives::BlockId &id) const - -> outcome::result { - return visit_in_place( - id, - [this](const primitives::BlockNumber &n) { return getHashByNumber(n); }, - [](const base::Hash256 &hash) { return hash; }); + outcome::result BlockHeaderRepository::getHashById( const primitives::BlockId &id ) const + { + return visit_in_place( + id, [this]( const primitives::BlockNumber &n ) { return getHashByNumber( n ); }, + []( const base::Hash256 &hash ) { return hash; } ); } } // namespace sgns::blockchain diff --git a/src/blockchain/impl/block_tree_error.cpp b/src/blockchain/impl/block_tree_error.cpp index d3920141..f4dc4ec6 100644 --- a/src/blockchain/impl/block_tree_error.cpp +++ b/src/blockchain/impl/block_tree_error.cpp @@ -1,5 +1,3 @@ - - #include "blockchain/block_tree_error.hpp" OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::blockchain, BlockTreeError, e) { diff --git a/src/blockchain/impl/block_tree_impl.cpp b/src/blockchain/impl/block_tree_impl.cpp index 4f080392..c546cfae 100644 --- a/src/blockchain/impl/block_tree_impl.cpp +++ b/src/blockchain/impl/block_tree_impl.cpp @@ -1,14 +1,9 @@ - #include "blockchain/impl/block_tree_impl.hpp" #include #include "blockchain/block_tree_error.hpp" -#include "blockchain/impl/common.hpp" #include "blockchain/impl/storage_util.hpp" -#include "base/visitor.hpp" -#include "crypto/blake2/blake2b.h" -#include "scale/scale.hpp" #include "storage/database_error.hpp" OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::blockchain, BlockTreeImpl::Error, e) { diff --git a/src/blockchain/impl/block_tree_impl.hpp b/src/blockchain/impl/block_tree_impl.hpp index ad0a1d84..eba1492e 100644 --- a/src/blockchain/impl/block_tree_impl.hpp +++ b/src/blockchain/impl/block_tree_impl.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_BLOCK_TREE_IMPL_HPP #define SUPERGENIUS_SRC_BLOCK_TREE_IMPL_HPP @@ -7,16 +6,13 @@ #include #include #include -#include #include #include "blockchain/block_header_repository.hpp" #include "blockchain/block_storage.hpp" -#include "blockchain/impl/common.hpp" #include "base/logger.hpp" #include "crypto/hasher.hpp" #include "network/extrinsic_observer.hpp" -#include "transaction_pool/transaction_pool.hpp" namespace sgns::blockchain { /** @@ -99,14 +95,14 @@ namespace sgns::blockchain { ~BlockTreeImpl() override = default; - outcome::result getBlockHeader( - const primitives::BlockId &block) const override; + [[nodiscard]] outcome::result getBlockHeader( + const primitives::BlockId &block ) const override; - outcome::result getBlockBody( - const primitives::BlockId &block) const override; + [[nodiscard]] outcome::result getBlockBody( + const primitives::BlockId &block ) const override; - outcome::result getBlockJustification( - const primitives::BlockId &block) const override; + [[nodiscard]] outcome::result getBlockJustification( + const primitives::BlockId &block ) const override; outcome::result addBlockHeader( const primitives::BlockHeader &header) override; @@ -137,18 +133,17 @@ namespace sgns::blockchain { BlockHashVecRes longestPath() override; - primitives::BlockInfo deepestLeaf() const override; + [[nodiscard]] primitives::BlockInfo deepestLeaf() const override; - outcome::result getBestContaining( - const primitives::BlockHash &target_hash, - const boost::optional &max_number) - const override; + [[nodiscard]] outcome::result getBestContaining( + const primitives::BlockHash &target_hash, + const boost::optional &max_number ) const override; - std::vector getLeaves() const override; + [[nodiscard]] std::vector getLeaves() const override; BlockHashVecRes getChildren(const primitives::BlockHash &block) override; - primitives::BlockInfo getLastFinalized() const override; + [[nodiscard]] primitives::BlockInfo getLastFinalized() const override; std::string GetName() override { diff --git a/src/blockchain/impl/common.hpp b/src/blockchain/impl/common.hpp index e4aac9f6..b1466ae0 100644 --- a/src/blockchain/impl/common.hpp +++ b/src/blockchain/impl/common.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_BLOCKCHAIN_COMMON_HPP #define SUPERGENIUS_BLOCKCHAIN_COMMON_HPP @@ -7,7 +5,6 @@ #include "base/buffer.hpp" #include "primitives/block_id.hpp" -#include "storage/buffer_map_types.hpp" #include namespace sgns::blockchain { diff --git a/src/blockchain/impl/key_value_block_header_repository.cpp b/src/blockchain/impl/key_value_block_header_repository.cpp index bfcadf36..687ec27c 100644 --- a/src/blockchain/impl/key_value_block_header_repository.cpp +++ b/src/blockchain/impl/key_value_block_header_repository.cpp @@ -1,17 +1,12 @@ - - #include "blockchain/impl/key_value_block_header_repository.hpp" -#include - #include +#include "blockchain/impl/common.hpp" #include "blockchain/impl/storage_util.hpp" -#include "base/hexutil.hpp" #include "scale/scale.hpp" #include "blockchain/impl/proto/SGBlocks.pb.h" -using sgns::blockchain::prefix::Prefix; using sgns::base::Hash256; using sgns::primitives::BlockId; using sgns::primitives::BlockNumber; diff --git a/src/blockchain/impl/key_value_block_header_repository.hpp b/src/blockchain/impl/key_value_block_header_repository.hpp index 5b203ad9..e485d804 100644 --- a/src/blockchain/impl/key_value_block_header_repository.hpp +++ b/src/blockchain/impl/key_value_block_header_repository.hpp @@ -1,11 +1,8 @@ - - #ifndef SUPERGENIUS_CORE_BLOCKCHAIN_IMPL_KEY_VALUE_BLOCK_HEADER_REPOSITORY_HPP #define SUPERGENIUS_CORE_BLOCKCHAIN_IMPL_KEY_VALUE_BLOCK_HEADER_REPOSITORY_HPP #include "blockchain/block_header_repository.hpp" -#include "blockchain/impl/common.hpp" #include "crypto/hasher.hpp" #include #include diff --git a/src/blockchain/impl/key_value_block_storage.cpp b/src/blockchain/impl/key_value_block_storage.cpp index acac3381..05357635 100644 --- a/src/blockchain/impl/key_value_block_storage.cpp +++ b/src/blockchain/impl/key_value_block_storage.cpp @@ -1,11 +1,10 @@ - - #include "blockchain/impl/key_value_block_storage.hpp" +#include "blockchain/impl/common.hpp" #include "blockchain/impl/storage_util.hpp" -#include "scale/scale.hpp" #include "storage/database_error.hpp" #include "blockchain/impl/proto/SGBlocks.pb.h" +#include "storage/predefined_keys.hpp" OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::blockchain, KeyValueBlockStorage::Error, diff --git a/src/blockchain/impl/key_value_block_storage.hpp b/src/blockchain/impl/key_value_block_storage.hpp index a541b098..f30e407b 100644 --- a/src/blockchain/impl/key_value_block_storage.hpp +++ b/src/blockchain/impl/key_value_block_storage.hpp @@ -1,14 +1,10 @@ - - #ifndef SUPERGENIUS_KEY_VALUE_BLOCK_STORAGE_HPP #define SUPERGENIUS_KEY_VALUE_BLOCK_STORAGE_HPP #include "blockchain/block_storage.hpp" -#include "blockchain/impl/common.hpp" #include "base/logger.hpp" #include "crypto/hasher.hpp" -#include "storage/predefined_keys.hpp" #include #include "blockchain/impl/key_value_block_header_repository.hpp" diff --git a/src/blockchain/impl/storage_util.cpp b/src/blockchain/impl/storage_util.cpp index 15ea30a1..75143539 100644 --- a/src/blockchain/impl/storage_util.cpp +++ b/src/blockchain/impl/storage_util.cpp @@ -1,5 +1,3 @@ - - #include "blockchain/impl/storage_util.hpp" #include "blockchain/impl/common.hpp" diff --git a/src/blockchain/impl/storage_util.hpp b/src/blockchain/impl/storage_util.hpp index 8af7eb74..12e08b03 100644 --- a/src/blockchain/impl/storage_util.hpp +++ b/src/blockchain/impl/storage_util.hpp @@ -1,12 +1,8 @@ - - #ifndef SUPERGENIUS_CORE_BLOCKCHAIN_IMPL_PERSISTENT_MAP_UTIL_HPP #define SUPERGENIUS_CORE_BLOCKCHAIN_IMPL_PERSISTENT_MAP_UTIL_HPP #include "base/buffer.hpp" -#include "primitives/block_header.hpp" #include "primitives/block_id.hpp" -#include "storage/buffer_map_types.hpp" #include #include diff --git a/src/blockchain/impl/types.cpp b/src/blockchain/impl/types.cpp index 41ae92bf..4141f294 100644 --- a/src/blockchain/impl/types.cpp +++ b/src/blockchain/impl/types.cpp @@ -1,11 +1,7 @@ - - #include "blockchain/impl/common.hpp" #include "blockchain/impl/storage_util.hpp" #include "base/visitor.hpp" -#include "storage/in_memory/in_memory_storage.hpp" #include "storage/trie/supergenius_trie/supergenius_trie_impl.hpp" -#include "storage/trie/serialization/trie_serializer_impl.hpp" #include #include diff --git a/src/clock/clock.hpp b/src/clock/clock.hpp index 9034d53f..a12a58fd 100644 --- a/src/clock/clock.hpp +++ b/src/clock/clock.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_CLOCK_HPP #define SUPERGENIUS_CLOCK_HPP diff --git a/src/clock/impl/basic_waitable_timer.cpp b/src/clock/impl/basic_waitable_timer.cpp index d6c1fdb4..361f371d 100644 --- a/src/clock/impl/basic_waitable_timer.cpp +++ b/src/clock/impl/basic_waitable_timer.cpp @@ -1,5 +1,3 @@ - - #include "clock/impl/basic_waitable_timer.hpp" namespace sgns::clock { diff --git a/src/clock/impl/basic_waitable_timer.hpp b/src/clock/impl/basic_waitable_timer.hpp index 0b51dfdf..9d2a18c1 100644 --- a/src/clock/impl/basic_waitable_timer.hpp +++ b/src/clock/impl/basic_waitable_timer.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_BASIC_WAITABLE_TIMER_HPP #define SUPERGENIUS_BASIC_WAITABLE_TIMER_HPP diff --git a/src/clock/impl/clock_impl.cpp b/src/clock/impl/clock_impl.cpp index 9553a995..b0a8c0ad 100644 --- a/src/clock/impl/clock_impl.cpp +++ b/src/clock/impl/clock_impl.cpp @@ -1,5 +1,3 @@ - - #include "clock/impl/clock_impl.hpp" namespace sgns::clock { diff --git a/src/clock/impl/clock_impl.hpp b/src/clock/impl/clock_impl.hpp index 8bb49d00..b46aa423 100644 --- a/src/clock/impl/clock_impl.hpp +++ b/src/clock/impl/clock_impl.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_CORE_CLOCK_IMPL_CLOCK_IMPL_HPP #define SUPERGENIUS_CORE_CLOCK_IMPL_CLOCK_IMPL_HPP diff --git a/src/clock/timer.hpp b/src/clock/timer.hpp index 45740508..9cb55e2b 100644 --- a/src/clock/timer.hpp +++ b/src/clock/timer.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_TIMER_HPP #define SUPERGENIUS_TIMER_HPP diff --git a/src/crdt/globaldb/keypair_file_storage.hpp b/src/crdt/globaldb/keypair_file_storage.hpp index 67fac2fd..46d74d22 100644 --- a/src/crdt/globaldb/keypair_file_storage.hpp +++ b/src/crdt/globaldb/keypair_file_storage.hpp @@ -13,7 +13,7 @@ class KeyPairFileStorage public: KeyPairFileStorage(const boost::filesystem::path& keyPath); - outcome::result GetKeyPair() const; + [[nodiscard]] outcome::result GetKeyPair() const; private: boost::filesystem::path m_keyPath; diff --git a/src/crdt/globaldb/pubsub_broadcaster_ext.cpp b/src/crdt/globaldb/pubsub_broadcaster_ext.cpp index 8d2cc81f..5a7464fb 100644 --- a/src/crdt/globaldb/pubsub_broadcaster_ext.cpp +++ b/src/crdt/globaldb/pubsub_broadcaster_ext.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace sgns::crdt { @@ -34,14 +35,11 @@ namespace } } -PubSubBroadcasterExt::PubSubBroadcasterExt( - std::shared_ptr pubSubTopic, - std::shared_ptr dagSyncer, - libp2p::multi::Multiaddress dagSyncerMultiaddress) - : gossipPubSubTopic_(pubSubTopic) - , dagSyncer_(dagSyncer) - , dataStore_(nullptr) - , dagSyncerMultiaddress_(dagSyncerMultiaddress) +PubSubBroadcasterExt::PubSubBroadcasterExt( std::shared_ptr pubSubTopic, + std::shared_ptr dagSyncer, + libp2p::multi::Multiaddress dagSyncerMultiaddress ) : + gossipPubSubTopic_( std::move( pubSubTopic ) ), dagSyncer_( std::move( dagSyncer ) ), dataStore_( nullptr ), + dagSyncerMultiaddress_( std::move( dagSyncerMultiaddress ) ) { if (gossipPubSubTopic_ != nullptr) { @@ -97,7 +95,7 @@ void PubSubBroadcasterExt::OnMessage(boost::optional& aDatastore, const HierarchicalKey& aKey, - const std::shared_ptr& aDagSyncer, const std::shared_ptr& aBroadcaster, - const std::shared_ptr& aOptions) + CrdtDatastore::CrdtDatastore( const std::shared_ptr &aDatastore, const HierarchicalKey &aKey, + const std::shared_ptr &aDagSyncer, + const std::shared_ptr &aBroadcaster, + const std::shared_ptr &aOptions ) : namespaceKey_( aKey ) { - this->namespaceKey_ = aKey; - - // /s - auto fullSetNs = aKey.ChildString(setsNamespace_); - // /h - auto fullHeadsNs = aKey.ChildString(headsNamespace_); - - int numberOfDagWorkers = 5; - if (aOptions != nullptr && !aOptions->Verify().has_failure() && - aOptions->Verify().value() == CrdtOptions::VerifyErrorCode::Success) - { - this->options_ = aOptions; - this->putHookFunc_ = options_->putHookFunc; - this->deleteHookFunc_ = options_->deleteHookFunc; - this->logger_ = options_->logger; - numberOfDagWorkers = options_->numWorkers; - } + // /s + auto fullSetNs = aKey.ChildString( setsNamespace_ ); + // /h + auto fullHeadsNs = aKey.ChildString( headsNamespace_ ); + + int numberOfDagWorkers = 5; + if ( aOptions != nullptr && !aOptions->Verify().has_failure() && + aOptions->Verify().value() == CrdtOptions::VerifyErrorCode::Success ) + { + this->options_ = aOptions; + this->putHookFunc_ = options_->putHookFunc; + this->deleteHookFunc_ = options_->deleteHookFunc; + this->logger_ = options_->logger; + numberOfDagWorkers = options_->numWorkers; + } - this->dataStore_ = aDatastore; + this->dataStore_ = aDatastore; - this->dagSyncer_ = aDagSyncer; - this->broadcaster_ = aBroadcaster; + this->dagSyncer_ = aDagSyncer; + this->broadcaster_ = aBroadcaster; - this->set_ = std::make_shared(CrdtSet(aDatastore, fullSetNs, this->putHookFunc_, this->deleteHookFunc_)); - this->heads_ = std::make_shared(CrdtHeads(aDatastore, fullHeadsNs)); + this->set_ = + std::make_shared( CrdtSet( aDatastore, fullSetNs, this->putHookFunc_, this->deleteHookFunc_ ) ); + this->heads_ = std::make_shared( CrdtHeads( aDatastore, fullHeadsNs ) ); - int numberOfHeads = 0; - uint64_t maxHeight = 0; - if (this->heads_ != nullptr) - { - std::vector heads; - auto getListResult = this->heads_->GetList(heads, maxHeight); - if (!getListResult.has_failure()) + int numberOfHeads = 0; + uint64_t maxHeight = 0; + if ( this->heads_ != nullptr ) { - numberOfHeads = heads.size(); + std::vector heads; + auto getListResult = this->heads_->GetList( heads, maxHeight ); + if ( !getListResult.has_failure() ) + { + numberOfHeads = heads.size(); + } } - } - LOG_INFO("crdt Datastore created. Number of heads: " << numberOfHeads << " Current max-height: " << maxHeight); + LOG_INFO( "crdt Datastore created. Number of heads: " << numberOfHeads << " Current max-height: " << maxHeight ); - // Starting HandleNext worker thread - this->handleNextFuture_ = std::async(std::bind(&CrdtDatastore::HandleNext, this)); + // Starting HandleNext worker thread + this->handleNextFuture_ = std::async( std::bind( &CrdtDatastore::HandleNext, this ) ); - // Starting Rebroadcast worker thread - this->rebroadcastFuture_ = std::async(std::bind(&CrdtDatastore::Rebroadcast, this)); + // Starting Rebroadcast worker thread + this->rebroadcastFuture_ = std::async( std::bind( &CrdtDatastore::Rebroadcast, this ) ); - // Starting DAG worker threads - for (int i = 0; i < numberOfDagWorkers; ++i) - { - auto dagWorker = std::make_shared(); - dagWorker->dagWorkerFuture_ = std::async(std::bind(&CrdtDatastore::SendJobWorker, this, dagWorker)); - this->dagWorkers_.push_back(dagWorker); - } + // Starting DAG worker threads + for ( int i = 0; i < numberOfDagWorkers; ++i ) + { + auto dagWorker = std::make_shared(); + dagWorker->dagWorkerFuture_ = std::async( std::bind( &CrdtDatastore::SendJobWorker, this, dagWorker ) ); + this->dagWorkers_.push_back( dagWorker ); + } } CrdtDatastore::~CrdtDatastore() @@ -180,11 +180,11 @@ namespace sgns::crdt auto broadcasterNextResult = broadcaster_->Next(); if (broadcasterNextResult.has_failure()) { - if (broadcasterNextResult.error().value() != (int)Broadcaster::ErrorCode::ErrNoMoreBroadcast) - { - LogDebug("Failed to get next broadcaster (error code " + - std::to_string(broadcasterNextResult.error().value()) + ")"); - } + if ( broadcasterNextResult.error().value() != static_cast( Broadcaster::ErrorCode::ErrNoMoreBroadcast ) ) + { + LogDebug( "Failed to get next broadcaster (error code " + + std::to_string( broadcasterNextResult.error().value() ) + ")" ); + } continue; } @@ -223,7 +223,7 @@ namespace sgns::crdt void CrdtDatastore::Rebroadcast() { LogDebug("Rebroadcast thread started"); - std::chrono::milliseconds rebroadcastIntervalMilliseconds = std::chrono::milliseconds(threadSleepTimeInMilliseconds_); + auto rebroadcastIntervalMilliseconds = std::chrono::milliseconds( threadSleepTimeInMilliseconds_ ); if (options_ != nullptr) { rebroadcastIntervalMilliseconds = std::chrono::milliseconds(options_->rebroadcastIntervalMilliseconds);