From c0b1f766c725dd15974dfaffc53846e7f0c28e7c Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:01:44 -0300 Subject: [PATCH 01/11] chore: Expanded Google lints --- .clang-tidy | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index bbaa281f..7e41dbc2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,11 +20,15 @@ Checks: > -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-special-member-functions, - google-*, - -google-build-using-namespace, - -google-explicit-constructor, - -google-readability-namespace-comments, - -google-readability-todo, + google-build-explicit-make-pair, + google-build-namespaces, + google-default-arguments, + google-global-names-in-headers, + google-readability-avoid-underscore-in-googletest-name, + google-readability-casting, + google-runtime-int, + google-runtime-operator, + google-upgrade-googletest-case, hicpp-multiway-paths-covered, @@ -61,3 +65,6 @@ CheckOptions: - { key: readability-identifier-naming.TypeDefCase, value: CamelCase } - { key: readability-identifier-naming.ClassMemberPrefix, value: m_ } + + - { key: modernize-use-std-print.ReplacementPrintFunction, value: "fmt::print"} + - { key: modernize-use-std-print.ReplacementPrintlnFunction, value: "fmt::println"} From 7984ddf0a989d911e625416f7f88866d201546b8 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:02:00 -0300 Subject: [PATCH 02/11] chore: Added test dirs to gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7e9dd1b0..8934abf6 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,8 @@ Testing # Autogenerated Tooling .build.Debug -cmake-build-*/ \ No newline at end of file +cmake-build-*/ + +# Testing residuals +CRDT.Datastore.TEST.unit/ +CRDT.Datastore.TEST/ \ No newline at end of file From 5f7734854e56dda50ee22270f11b8afb45ff16f9 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:04:32 -0300 Subject: [PATCH 03/11] style: Reformatted and small refactor --- src/base/blob.hpp | 4 +++- src/blockchain/block_header_repository.hpp | 2 +- .../impl/block_header_repository.cpp | 24 +++++++------------ src/blockchain/impl/proto/SGBlocks.proto | 5 +++- src/primitives/block_header.hpp | 5 ++-- src/primitives/digest.hpp | 7 +----- test/testutil/outcome.hpp | 2 -- 7 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/base/blob.hpp b/src/base/blob.hpp index 1b3d32aa..9feaec77 100644 --- a/src/base/blob.hpp +++ b/src/base/blob.hpp @@ -65,11 +65,13 @@ namespace sgns::base { { std::string out_str; char temp_buf[3]; - for ( auto it = this->begin(); it != this->end(); ++it ) + + for ( auto it : this ) { snprintf( temp_buf, sizeof( temp_buf ), "%02x", *it ); out_str.append( temp_buf, sizeof( temp_buf ) - 1 ); } + return out_str; } diff --git a/src/blockchain/block_header_repository.hpp b/src/blockchain/block_header_repository.hpp index e96b89ce..b2ff340f 100644 --- a/src/blockchain/block_header_repository.hpp +++ b/src/blockchain/block_header_repository.hpp @@ -28,7 +28,7 @@ namespace sgns::blockchain class BlockHeaderRepository : public IComponent { public: - virtual ~BlockHeaderRepository() = default; + ~BlockHeaderRepository() override = default; /** * @param hash - a blake2_256 hash of an SCALE encoded block header diff --git a/src/blockchain/impl/block_header_repository.cpp b/src/blockchain/impl/block_header_repository.cpp index a6075682..644484d1 100644 --- a/src/blockchain/impl/block_header_repository.cpp +++ b/src/blockchain/impl/block_header_repository.cpp @@ -2,8 +2,8 @@ #include "base/visitor.hpp" -namespace sgns::blockchain { - +namespace sgns::blockchain +{ outcome::result BlockHeaderRepository::getNumberById( const primitives::BlockId &id ) const { return visit_in_place( @@ -11,16 +11,10 @@ namespace sgns::blockchain { [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 - */ - 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 + 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; } ); + } +} diff --git a/src/blockchain/impl/proto/SGBlocks.proto b/src/blockchain/impl/proto/SGBlocks.proto index 5399d08c..e8c66e63 100644 --- a/src/blockchain/impl/proto/SGBlocks.proto +++ b/src/blockchain/impl/proto/SGBlocks.proto @@ -1,14 +1,17 @@ syntax = "proto3"; package SGBlocks; + message BlockID { uint64 block_number = 1; } + message BlockHashData { bytes hash = 1;// } + message BlockHeaderData { bytes parent_hash = 1;// @@ -17,10 +20,10 @@ message BlockHeaderData bytes extrinsics_root = 4; // bytes digest = 5;// } + message BlockPayloadData { bytes hash = 1;// BlockHeaderData header = 2;// repeated bytes block_body = 3;// } - diff --git a/src/primitives/block_header.hpp b/src/primitives/block_header.hpp index a07dd980..a95cef77 100644 --- a/src/primitives/block_header.hpp +++ b/src/primitives/block_header.hpp @@ -2,7 +2,6 @@ #define SUPERGENIUS_PRIMITIVES_BLOCK_HEADER_HPP #include -#include #include #include "base/blob.hpp" @@ -40,9 +39,9 @@ namespace sgns::primitives out << bh.parent_hash << CompactInteger( bh.number ) << bh.state_root << bh.extrinsics_root; out << bh.digest.size(); - for ( auto it = bh.digest.begin(); it != bh.digest.end(); ++it ) + for ( const auto &it : bh.digest ) { - out << ( *it ).which(); + out << it.which(); } return out; } diff --git a/src/primitives/digest.hpp b/src/primitives/digest.hpp index d785dfd1..7e8c21b6 100644 --- a/src/primitives/digest.hpp +++ b/src/primitives/digest.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_PRIMITIVES_DIGEST_HPP #define SUPERGENIUS_SRC_PRIMITIVES_DIGEST_HPP @@ -9,7 +7,6 @@ #include "primitives/scheduled_change.hpp" namespace sgns::primitives { - /// Verification engine unique ID. using VerificationEngineId = base::Blob<4>; @@ -88,8 +85,6 @@ namespace sgns::primitives { return s >> dic.verification_engine_id >> dic.data; } - /// Some other thing. Unsupported and experimental. - using Other = base::Buffer; /// Digest item that is able to encode/decode 'system' digest items and /// provide opaque access to other items. /// Note: order of types in variant matters. Should match type ids from here: @@ -97,7 +92,7 @@ namespace sgns::primitives { Unused<1>, // 1 ChangesTrieRoot, // 2 Unused<3>, // 3 - Verification, // 4 + Verification, // 4 Seal, // 5 PreRuntime>; // 6 diff --git a/test/testutil/outcome.hpp b/test/testutil/outcome.hpp index a2746bd0..2272c83c 100644 --- a/test/testutil/outcome.hpp +++ b/test/testutil/outcome.hpp @@ -4,8 +4,6 @@ #define SUPERGENIUS_GTEST_OUTCOME_UTIL_HPP #include -#include "base/visitor.hpp" -#include "outcome/outcome.hpp" #define PP_CAT(a, b) PP_CAT_I(a, b) #define PP_CAT_I(a, b) PP_CAT_II(~, a##b) From 873181f217e6617a2f28abd03c0bfff0d84e8999 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:04:48 -0300 Subject: [PATCH 04/11] docs: Enhanced docs for visit_in_place --- src/base/visitor.hpp | 110 ++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 58 deletions(-) diff --git a/src/base/visitor.hpp b/src/base/visitor.hpp index ce658f3a..f2643f54 100644 --- a/src/base/visitor.hpp +++ b/src/base/visitor.hpp @@ -1,40 +1,40 @@ #ifndef SUPERGENIUS_VISITOR_HPP #define SUPERGENIUS_VISITOR_HPP -#include // for std::decay -#include // for std::forward +#include +#include -#include // for boost::apply_visitor +#include -namespace sgns { +namespace sgns +{ + template struct lambda_visitor; - template - struct lambda_visitor; + template + struct lambda_visitor : public Lambda, public lambda_visitor + { + using Lambda::operator(); + using lambda_visitor::operator(); - template - struct lambda_visitor - : public Lambda, public lambda_visitor { - using Lambda::operator(); - using lambda_visitor::operator(); + lambda_visitor( Lambda lambda, Lambdas... lambdas ) : Lambda( lambda ), lambda_visitor( lambdas... ) + { + } + }; - // NOLINTNEXTLINE(google-explicit-constructor) - lambda_visitor(Lambda lambda, Lambdas... lambdas) - : Lambda(lambda), lambda_visitor(lambdas...) {} - }; + template struct lambda_visitor : public Lambda + { + using Lambda::operator(); - template - struct lambda_visitor : public Lambda { - using Lambda::operator(); + lambda_visitor( Lambda lambda ) : Lambda( lambda ) + { + } + }; - // NOLINTNEXTLINE(google-explicit-constructor) - lambda_visitor(Lambda lambda) : Lambda(lambda) {} - }; - - /** + /** * @brief Convenient in-place compile-time visitor creation, from a set of * lambdas * - * @code + * @code{.cpp} * make_visitor([](int a){ return 1; }, * [](std::string b) { return 2; }); * @nocode @@ -48,50 +48,44 @@ namespace sgns { * } * @nocode * - * @param lambdas * @return visitor */ - template - constexpr auto make_visitor(Fs &&... fs) { - using visitor_type = lambda_visitor...>; - return visitor_type(std::forward(fs)...); - } + template constexpr auto make_visitor( Fs &&...fs ) + { + using visitor_type = lambda_visitor...>; + return visitor_type( std::forward( fs )... ); + } - /** - * @brief Inplace visitor for boost::variant. - * @code + /** + * @brief Inplace visitor for boost::variant. Bascially poor man's pattern matching for variants. + * @code{.cpp} * boost::variant value = "1234"; - * ... + * * visit_in_place(value, * [](int v) { std::cout << "(int)" << v; }, * [](std::string v) { std::cout << "(string)" << v;} * ); * @nocode - * - * @param variant - * @param lambdas - * @param lambdas */ - template - constexpr decltype(auto) visit_in_place(TVariant &&variant, - TVisitors &&... visitors) { - return boost::apply_visitor( - make_visitor(std::forward(visitors)...), - std::forward(variant)); - } + template + constexpr decltype( auto ) visit_in_place( TVariant &&variant, TVisitors &&...visitors ) + { + return boost::apply_visitor( make_visitor( std::forward( visitors )... ), + std::forward( variant ) ); + } - /// apply Matcher to optional T - template - constexpr decltype(auto) match(T &&t, Matcher &&m) { - return std::forward(t) ? std::forward(m)(*std::forward(t)) - : std::forward(m)(); - } + /// apply Matcher to optional T + template constexpr decltype( auto ) match( T &&t, Matcher &&m ) + { + return std::forward( t ) ? std::forward( m )( *std::forward( t ) ) + : std::forward( m )(); + } - /// construct visitor from Fs and apply it to optional T - template - constexpr decltype(auto) match_in_place(T &&t, Fs &&... fs) { - return match(std::forward(t), make_visitor(std::forward(fs)...)); - } -} // namespace sgns + /// construct visitor from Fs and apply it to optional T + template constexpr decltype( auto ) match_in_place( T &&t, Fs &&...fs ) + { + return match( std::forward( t ), make_visitor( std::forward( fs )... ) ); + } +} -#endif // SUPERGENIUS_VISITOR_HPP +#endif From 968c9f34ae30975867ca18dea49d6c4671bdbb78 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:05:08 -0300 Subject: [PATCH 05/11] style: Reformat --- .../key_value_block_header_repository.cpp | 202 +++++++++--------- src/blockchain/impl/storage_util.cpp | 15 +- 2 files changed, 108 insertions(+), 109 deletions(-) diff --git a/src/blockchain/impl/key_value_block_header_repository.cpp b/src/blockchain/impl/key_value_block_header_repository.cpp index 687ec27c..dfceafb7 100644 --- a/src/blockchain/impl/key_value_block_header_repository.cpp +++ b/src/blockchain/impl/key_value_block_header_repository.cpp @@ -11,111 +11,111 @@ using sgns::base::Hash256; using sgns::primitives::BlockId; using sgns::primitives::BlockNumber; -namespace sgns::blockchain { - - KeyValueBlockHeaderRepository::KeyValueBlockHeaderRepository( - std::shared_ptr db, - std::shared_ptr hasher, - const std::string &net_id) - : db_{std::move(db)}, hasher_{std::move(hasher)} { - BOOST_ASSERT(hasher_); - block_header_key_prefix = net_id + std::string(BLOCKCHAIN_PATH); - } - - outcome::result KeyValueBlockHeaderRepository::getNumberByHash( - const Hash256 &hash) const { - OUTCOME_TRY((auto &&, key), idToBufferKey(*db_, hash)); - - auto maybe_number = BufferToNumber(key); - - return maybe_number; - } - - outcome::result - KeyValueBlockHeaderRepository::getHashByNumber( - const primitives::BlockNumber &number) const { - OUTCOME_TRY((auto &&, header), getBlockHeader(number)); - OUTCOME_TRY((auto &&, enc_header), scale::encode(header)); - return hasher_->blake2b_256(enc_header); - } - - outcome::result - KeyValueBlockHeaderRepository::getBlockHeader(const BlockId &id) const { - OUTCOME_TRY((auto &&, header_string_val), idToStringKey(*db_,id)); - - auto header_res = db_->Get({block_header_key_prefix + header_string_val}); - if (!header_res) { - return (isNotFoundError(header_res.error())) ? Error::BLOCK_NOT_FOUND - : header_res.error(); +namespace sgns::blockchain +{ + + KeyValueBlockHeaderRepository::KeyValueBlockHeaderRepository( std::shared_ptr db, + std::shared_ptr hasher, + const std::string &net_id ) : + db_{ std::move( db ) }, hasher_{ std::move( hasher ) } + { + BOOST_ASSERT( hasher_ ); + block_header_key_prefix = net_id + std::string( BLOCKCHAIN_PATH ); } - //return scale::decode(header_res.value()); - return GetBlockHeaderFromSerialized(header_res.value().toVector()); - } - - outcome::result KeyValueBlockHeaderRepository::putBlockHeader( - const primitives::BlockHeader &header) { - //OUTCOME_TRY((auto &&, encoded_header), scale::encode(header)); - auto encoded_header = GetHeaderSerializedData(header); - auto header_hash = hasher_->blake2b_256(encoded_header); - - - OUTCOME_TRY((auto &&, id_string), idToStringKey(*db_, header.number)); - BOOST_OUTCOME_TRYV2( auto &&, db_->Put({header_hash.toReadableString() }, NumberToBuffer(header.number))); - BOOST_OUTCOME_TRYV2(auto &&, db_->Put({block_header_key_prefix + id_string}, base::Buffer{std::move(encoded_header)})); - - return header_hash; - } - - outcome::result - KeyValueBlockHeaderRepository::removeBlockHeader(const BlockId &id) { - OUTCOME_TRY((auto &&, header_string_val), idToStringKey(*db_,id)); - - return db_->Remove({block_header_key_prefix + header_string_val}); - } - - outcome::result KeyValueBlockHeaderRepository::getBlockStatus( - const primitives::BlockId &id) const { - return getBlockHeader(id).has_value() ? BlockStatus::InChain - : BlockStatus::Unknown; - } - - std::string KeyValueBlockHeaderRepository::GetHeaderPath() const - { - return block_header_key_prefix; - } - - std::vector KeyValueBlockHeaderRepository::GetHeaderSerializedData(const primitives::BlockHeader &header) - { - SGBlocks::BlockHeaderData header_proto; - header_proto.set_parent_hash(header.parent_hash.toReadableString()); - header_proto.set_block_number(header.number); - header_proto.set_state_root(header.state_root.toReadableString()); - header_proto.set_extrinsics_root(header.extrinsics_root.toReadableString()); - //header_proto.set_digest(header.digest.toReadableString()); - - size_t size = header_proto.ByteSizeLong(); - std::vector serialized_proto( size ); - - header_proto.SerializeToArray( serialized_proto.data(), serialized_proto.size() ); - - return serialized_proto; - } - primitives::BlockHeader KeyValueBlockHeaderRepository::GetBlockHeaderFromSerialized(const std::vector &serialized_data) const - { - primitives::BlockHeader block_header; - SGBlocks::BlockHeaderData header_proto; - if ( !header_proto.ParseFromArray( serialized_data.data(), serialized_data.size() ) ) + outcome::result KeyValueBlockHeaderRepository::getNumberByHash( const Hash256 &hash ) const { - std::cerr << "Failed to parse BlockHeaderData from array." << std::endl; + OUTCOME_TRY( ( auto &&, key ), idToBufferKey( *db_, hash ) ); + + return BufferToNumber( key ); } - block_header.parent_hash = (Hash256::fromReadableString(header_proto.parent_hash())).value(); - block_header.number = header_proto.block_number(); - block_header.state_root = (Hash256::fromReadableString(header_proto.state_root())).value(); - block_header.extrinsics_root = (Hash256::fromReadableString(header_proto.extrinsics_root())).value(); + outcome::result KeyValueBlockHeaderRepository::getHashByNumber( + const primitives::BlockNumber &number ) const + { + OUTCOME_TRY( ( auto &&, header ), getBlockHeader( number ) ); + OUTCOME_TRY( ( auto &&, enc_header ), scale::encode( header ) ); + + return hasher_->blake2b_256( enc_header ); + } + + outcome::result KeyValueBlockHeaderRepository::getBlockHeader( const BlockId &id ) const + { + OUTCOME_TRY( ( auto &&, header_string_val ), idToStringKey( *db_, id ) ); + + auto header_res = db_->Get( { block_header_key_prefix + header_string_val } ); + if ( !header_res ) + { + return ( isNotFoundError( header_res.error() ) ) ? Error::BLOCK_NOT_FOUND : header_res.error(); + } - return block_header; - } + //return scale::decode(header_res.value()); + return GetBlockHeaderFromSerialized( header_res.value().toVector() ); + } + + outcome::result KeyValueBlockHeaderRepository::putBlockHeader( + const primitives::BlockHeader &header ) + { + //OUTCOME_TRY((auto &&, encoded_header), scale::encode(header)); + auto encoded_header = GetHeaderSerializedData( header ); + auto header_hash = hasher_->blake2b_256( encoded_header ); + + OUTCOME_TRY( ( auto &&, id_string ), idToStringKey( *db_, header.number ) ); + BOOST_OUTCOME_TRYV2( auto &&, db_->Put( { header_hash.toReadableString() }, NumberToBuffer( header.number ) ) ); + BOOST_OUTCOME_TRYV2( + auto &&, db_->Put( { block_header_key_prefix + id_string }, base::Buffer{ std::move( encoded_header ) } ) ); + + return header_hash; + } + + outcome::result KeyValueBlockHeaderRepository::removeBlockHeader( const BlockId &id ) + { + OUTCOME_TRY( ( auto &&, header_string_val ), idToStringKey( *db_, id ) ); -} // namespace sgns::blockchain + return db_->Remove( { block_header_key_prefix + header_string_val } ); + } + + outcome::result KeyValueBlockHeaderRepository::getBlockStatus( const primitives::BlockId &id ) const + { + return getBlockHeader( id ).has_value() ? BlockStatus::InChain : BlockStatus::Unknown; + } + + std::string KeyValueBlockHeaderRepository::GetHeaderPath() const + { + return block_header_key_prefix; + } + + std::vector KeyValueBlockHeaderRepository::GetHeaderSerializedData( const primitives::BlockHeader &header ) + { + SGBlocks::BlockHeaderData header_proto; + header_proto.set_parent_hash( header.parent_hash.toReadableString() ); + header_proto.set_block_number( header.number ); + header_proto.set_state_root( header.state_root.toReadableString() ); + header_proto.set_extrinsics_root( header.extrinsics_root.toReadableString() ); + //header_proto.set_digest(header.digest.toReadableString()); + + size_t size = header_proto.ByteSizeLong(); + std::vector serialized_proto( size ); + + header_proto.SerializeToArray( serialized_proto.data(), serialized_proto.size() ); + + return serialized_proto; + } + + primitives::BlockHeader KeyValueBlockHeaderRepository::GetBlockHeaderFromSerialized( + const std::vector &serialized_data ) const + { + primitives::BlockHeader block_header; + SGBlocks::BlockHeaderData header_proto; + if ( !header_proto.ParseFromArray( serialized_data.data(), serialized_data.size() ) ) + { + std::cerr << "Failed to parse BlockHeaderData from array." << std::endl; + } + block_header.parent_hash = ( Hash256::fromReadableString( header_proto.parent_hash() ) ).value(); + block_header.number = header_proto.block_number(); + block_header.state_root = ( Hash256::fromReadableString( header_proto.state_root() ) ).value(); + block_header.extrinsics_root = ( Hash256::fromReadableString( header_proto.extrinsics_root() ) ).value(); + + return block_header; + } +} diff --git a/src/blockchain/impl/storage_util.cpp b/src/blockchain/impl/storage_util.cpp index 75143539..2b83b5fc 100644 --- a/src/blockchain/impl/storage_util.cpp +++ b/src/blockchain/impl/storage_util.cpp @@ -21,7 +21,6 @@ OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::blockchain, KeyValueRepositoryError, e) { } namespace sgns::blockchain { - outcome::result putWithPrefix(crdt::GlobalDB &db, prefix::Prefix prefix, BlockNumber num, @@ -56,7 +55,7 @@ namespace sgns::blockchain { size_t size = blockID.ByteSizeLong(); std::vector serialized_proto( size ); - blockID.SerializeToArray( serialized_proto.data(), serialized_proto.size() ); + blockID.SerializeToArray( serialized_proto.data(), static_cast(serialized_proto.size()) ); return base::Buffer{serialized_proto}; /**base::Buffer retval; @@ -85,14 +84,15 @@ namespace sgns::blockchain { if (key.size() > sizeof(primitives::BlockNumber)) { return outcome::failure(KeyValueRepositoryError::INVALID_KEY); } - primitives::BlockNumber num; + SGBlocks::BlockID blockID; - if ( !blockID.ParseFromArray( key.toVector().data(), key.toVector().size() ) ) + + if ( !blockID.ParseFromArray( key.toVector().data(), static_cast(key.toVector().size()) ) ) { std::cerr << "Failed to parse BlockID from array." << std::endl; } - num = blockID.block_number(); - return num; + + return blockID.block_number(); /*primitives::BlockNumber retval = 0; //Little endian @@ -118,8 +118,7 @@ namespace sgns::blockchain { return false; } - auto &&error = result.error(); - return (error == storage::DatabaseError::NOT_FOUND); + return (result.error() == storage::DatabaseError::NOT_FOUND); } } // namespace sgns::blockchain From d5500cf18d40c3bbd2dbd5f90099b381df984d4c Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:05:27 -0300 Subject: [PATCH 06/11] tests: Better structure for header tests --- .../block_header_repository_test.cpp | 139 +++++++++--------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/test/src/blockchain/block_header_repository_test.cpp b/test/src/blockchain/block_header_repository_test.cpp index ffd7609d..daf7bd9b 100644 --- a/test/src/blockchain/block_header_repository_test.cpp +++ b/test/src/blockchain/block_header_repository_test.cpp @@ -1,33 +1,39 @@ - -#include "blockchain/block_header_repository.hpp" - #include #include -#include - +#include "blockchain/block_header_repository.hpp" #include "blockchain/impl/key_value_block_header_repository.hpp" #include "blockchain/impl/storage_util.hpp" #include "crypto/hasher/hasher_impl.hpp" +#include "primitives/block_header.hpp" #include "scale/scale.hpp" #include "testutil/literals.hpp" #include "testutil/outcome.hpp" -#include "testutil/storage/base_rocksdb_test.hpp" #include "testutil/storage/base_crdt_test.hpp" using sgns::base::Buffer; using sgns::base::Hash256; using sgns::blockchain::BlockHeaderRepository; using sgns::blockchain::KeyValueBlockHeaderRepository; -using sgns::blockchain::numberAndHashToLookupKey; -using sgns::blockchain::NumberToBuffer; -using sgns::blockchain::prependPrefix; using sgns::blockchain::putWithPrefix; using sgns::blockchain::prefix::Prefix; using sgns::primitives::BlockHeader; using sgns::primitives::BlockId; using sgns::primitives::BlockNumber; +static BlockHeader defaultHeader( BlockNumber number ) +{ + return { .parent_hash = "ABCDEF"_hash256, + .number = number, + .state_root = "010203"_hash256, + .extrinsics_root = "DEADBEEF"_hash256 }; +} + +static BlockHeader defaultHeader() +{ + return defaultHeader( 42 ); +} + class BlockHeaderRepositoryFixture : public test::CRDTFixture { public: @@ -43,9 +49,8 @@ class BlockHeaderRepositoryFixture : public test::CRDTFixture header_repo_ = std::make_shared( db_, hasher, db_path_ ); } - outcome::result storeHeader( BlockNumber num, BlockHeader &&header ) + outcome::result storeHeader( BlockHeader &&header ) { - header.number = num; OUTCOME_TRY( ( auto &&, enc_header ), sgns::scale::encode( header ) ); auto hash = hasher->blake2b_256( enc_header ); @@ -54,14 +59,6 @@ class BlockHeaderRepositoryFixture : public test::CRDTFixture return hash; } - static BlockHeader getDefaultHeader() - { - return { .parent_hash = "ABCDEF"_hash256, - .number = 42, - .state_root = "010203"_hash256, - .extrinsics_root = "DEADBEEF"_hash256 }; - } - std::shared_ptr hasher; std::shared_ptr header_repo_; }; @@ -73,35 +70,6 @@ class BlockHeaderRepositoryNumberParametrizedFixture : public BlockHeaderReposit const std::vector ParamValues = { 1, 42, 12345, 0, 0xFFFFFFFF }; -/** - * @given HeaderBackend instance with several headers in the storage - * @when accessing a header that wasn't put into storage - * @then result is error - */ -TEST_F( BlockHeaderRepositoryFixture, UnexistingHeader ) -{ - // auto chosen_number = ParamValues[0]; - // for ( auto c : ParamValues ) - // { - // if ( c != chosen_number ) - // { - // EXPECT_OUTCOME_TRUE_1( storeHeader( c, getDefaultHeader() ) ); - // } - // } - // BlockHeader not_in_storage = getDefaultHeader(); - // not_in_storage.number = chosen_number; - // EXPECT_OUTCOME_TRUE( enc_header, sgns::scale::encode( not_in_storage ) ); - // auto hash = hasher->blake2b_256( enc_header ); - // EXPECT_OUTCOME_FALSE_1( header_repo_->getBlockHeader( chosen_number ) ); - // EXPECT_OUTCOME_FALSE_1( header_repo_->getBlockHeader( hash ) ); - // EXPECT_OUTCOME_FALSE_1( header_repo_->getHashById( chosen_number ) ); - // EXPECT_OUTCOME_FALSE_1( header_repo_->getNumberById( hash ) ); - - // // doesn't require access to storage, as it basically returns its argument - // EXPECT_OUTCOME_TRUE_1( header_repo_->getHashById( hash ) ); - // EXPECT_OUTCOME_TRUE_1( header_repo_->getNumberById( chosen_number ) ); -} - /** * @given HeaderBackend instance * @when learning block hash by its number through HeaderBackend @@ -110,12 +78,12 @@ TEST_F( BlockHeaderRepositoryFixture, UnexistingHeader ) */ TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetHashByNumber ) { - //EXPECT_OUTCOME_TRUE(hash, storeHeader(GetParam(), getDefaultHeader())); - //EXPECT_OUTCOME_TRUE(maybe_hash, header_repo_->getHashByNumber(GetParam())); - //ASSERT_THAT(hash, testing::ContainerEq(maybe_hash)); - //EXPECT_OUTCOME_TRUE(maybe_another_hash, - // header_repo_->getHashById(GetParam())); - //ASSERT_THAT(hash, testing::ContainerEq(maybe_another_hash)); + EXPECT_OUTCOME_TRUE( hash, storeHeader( defaultHeader( GetParam() ) ) ); + EXPECT_OUTCOME_TRUE( maybe_hash, header_repo_->getHashByNumber( GetParam() ) ); + ASSERT_THAT( hash, testing::ContainerEq( maybe_hash ) ); + + EXPECT_OUTCOME_TRUE( maybe_another_hash, header_repo_->getHashById( GetParam() ) ); + ASSERT_THAT( hash, testing::ContainerEq( maybe_another_hash ) ); } /** @@ -126,12 +94,12 @@ TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetHashByNumber ) */ TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetNumberByHash ) { - //EXPECT_OUTCOME_TRUE(hash, storeHeader(GetParam(), getDefaultHeader())); - //EXPECT_OUTCOME_TRUE(maybe_number, header_repo_->getNumberByHash(hash)); - //ASSERT_EQ(GetParam(), maybe_number); - //EXPECT_OUTCOME_TRUE(maybe_another_number, - // header_repo_->getNumberById(GetParam())); - //ASSERT_EQ(GetParam(), maybe_another_number); + EXPECT_OUTCOME_TRUE( hash, storeHeader( defaultHeader( GetParam() ) ) ); + EXPECT_OUTCOME_TRUE( maybe_number, header_repo_->getNumberByHash( hash ) ); + ASSERT_EQ( GetParam(), maybe_number ); + + EXPECT_OUTCOME_TRUE( maybe_another_number, header_repo_->getNumberById( GetParam() ) ); + ASSERT_EQ( GetParam(), maybe_another_number ); } /** @@ -142,13 +110,50 @@ TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetNumberByHash ) */ TEST_P( BlockHeaderRepositoryNumberParametrizedFixture, GetHeader ) { - //EXPECT_OUTCOME_TRUE(hash, storeHeader(GetParam(), getDefaultHeader())); - //EXPECT_OUTCOME_TRUE(header_by_num, header_repo_->getBlockHeader(GetParam())); - //EXPECT_OUTCOME_TRUE(header_by_hash, header_repo_->getBlockHeader(hash)); - //auto header_should_be = getDefaultHeader(); - //header_should_be.number = GetParam(); - //ASSERT_EQ(header_by_hash, header_should_be); - //ASSERT_EQ(header_by_num, header_should_be); + auto header = defaultHeader( GetParam() ); + + EXPECT_OUTCOME_TRUE( hash, storeHeader( BlockHeader( header ) ) ); + + EXPECT_OUTCOME_TRUE( header_by_num, header_repo_->getBlockHeader( GetParam() ) ); + EXPECT_OUTCOME_TRUE( header_by_hash, header_repo_->getBlockHeader( hash ) ); + + ASSERT_EQ( header_by_hash, header ); + ASSERT_EQ( header_by_num, header ); +} + +/** + * @given HeaderBackend instance with several headers in the storage + * @when accessing a header that wasn't put into storage + * @then result is error + */ +TEST_F( BlockHeaderRepositoryFixture, UnexistingHeader ) +{ + auto block_number = ParamValues[0]; + + for ( auto number : ParamValues ) + { + if ( number != block_number ) + { + EXPECT_OUTCOME_TRUE_1( storeHeader( defaultHeader( number ) ) ); + } + } + + BlockHeader not_in_storage = defaultHeader(); + not_in_storage.number = block_number; + + EXPECT_OUTCOME_TRUE( enc_header, sgns::scale::encode( not_in_storage ) ); + auto hash = hasher->blake2b_256( enc_header ); + + EXPECT_OUTCOME_FALSE_1( header_repo_->getBlockHeader( block_number ) ); + EXPECT_OUTCOME_FALSE_1( header_repo_->getBlockHeader( hash ) ); + + EXPECT_OUTCOME_FALSE_1( header_repo_->getHashById( block_number ) ); + EXPECT_OUTCOME_FALSE_1( header_repo_->getNumberById( hash ) ); + + // These methods work because they don't have to access the storage, they just return the params. + // This happens because id is a variant of both hash and number. + EXPECT_OUTCOME_TRUE_1( header_repo_->getHashById( hash ) ); + EXPECT_OUTCOME_TRUE_1( header_repo_->getNumberById( block_number ) ); } INSTANTIATE_TEST_SUITE_P( Numbers, BlockHeaderRepositoryNumberParametrizedFixture, testing::ValuesIn( ParamValues ) ); From 0a69fab0594ea6183c14e56047d214ae6801c087 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:06:06 -0300 Subject: [PATCH 07/11] chore: Added reformats to ignore blame --- .git-blame-ignore-revs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 75368fec..73a4b57a 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -2,4 +2,6 @@ # git config blame.ignoreRevsFile .git-blame-ignore-revs # Reformats -cd55bda30ece6f3af73bdbaea84e5cda93f8973a \ No newline at end of file +cd55bda30ece6f3af73bdbaea84e5cda93f8973a +968c9f34ae30975867ca18dea49d6c4671bdbb78 +5f7734854e56dda50ee22270f11b8afb45ff16f9 \ No newline at end of file From 4b5481a66516a5c87a70a0fbff7a00542bd0f4dd Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Tue, 7 May 2024 15:11:48 -0300 Subject: [PATCH 08/11] fix: Reverted range iteration on this --- src/base/blob.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/blob.hpp b/src/base/blob.hpp index 9feaec77..53622685 100644 --- a/src/base/blob.hpp +++ b/src/base/blob.hpp @@ -66,7 +66,7 @@ namespace sgns::base { std::string out_str; char temp_buf[3]; - for ( auto it : this ) + 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 ); From c16e406b5582bc2e9f313bd6e025a93312efb537 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 8 May 2024 07:25:16 -0300 Subject: [PATCH 09/11] docs: Removed unprofessional statement in visit_in_place --- src/base/visitor.hpp | 2 +- src/crypto/crypto_store.hpp | 10 ++-------- src/crypto/crypto_store/crypto_store_impl.cpp | 18 +++++++++-------- src/crypto/crypto_store/crypto_store_impl.hpp | 5 +---- src/crypto/crypto_store/key_type.hpp | 16 ++++++--------- src/crypto/ed25519/ed25519_provider_impl.hpp | 7 ++----- src/crypto/ed25519_provider.hpp | 7 ++----- src/crypto/ed25519_types.cpp | 4 +--- src/crypto/ed25519_types.hpp | 9 +++------ src/crypto/hasher.hpp | 6 ++---- .../pbkdf2/impl/pbkdf2_provider_impl.cpp | 5 +---- .../pbkdf2/impl/pbkdf2_provider_impl.hpp | 6 ++---- src/crypto/pbkdf2/pbkdf2_provider.hpp | 2 -- src/crypto/random_generator.hpp | 6 ++---- .../random_generator/boost_generator.hpp | 13 +++++------- .../secp256k1/secp256k1_provider_impl.hpp | 6 ++---- src/crypto/secp256k1_provider.hpp | 6 ++---- src/crypto/secp256k1_types.hpp | 5 ++--- src/crypto/sha/sha256.hpp | 6 ++---- src/crypto/sr25519/sr25519_provider_impl.cpp | 6 ++---- src/crypto/sr25519/sr25519_provider_impl.hpp | 8 ++------ src/crypto/sr25519_types.cpp | 4 +--- src/crypto/sr25519_types.hpp | 7 ++----- src/crypto/twox/twox.cpp | 16 +-------------- src/crypto/twox/twox.hpp | 19 +++++++----------- src/crypto/vrf/vrf_provider_impl.cpp | 7 ++----- src/crypto/vrf/vrf_provider_impl.hpp | 7 ++----- src/crypto/vrf_provider.hpp | 7 ++----- src/extensions/extension.hpp | 6 ++---- src/extensions/extension_factory.hpp | 5 ++--- src/extensions/impl/crypto_extension.cpp | 1 - src/extensions/impl/crypto_extension.hpp | 6 ++---- .../impl/extension_factory_impl.cpp | 3 +-- .../impl/extension_factory_impl.hpp | 5 ++--- src/extensions/impl/extension_impl.cpp | 11 +--------- src/extensions/impl/extension_impl.hpp | 5 ++--- src/extensions/impl/io_extension.hpp | 5 ++--- src/injector/application_injector.cpp | 1 - src/injector/application_injector.hpp | 11 +--------- .../block_producing_node_injector.hpp | 15 ++------------ src/macro/unreachable.hpp | 4 +--- src/network/common.hpp | 6 ++---- src/network/extrinsic_gossiper.hpp | 6 ++---- src/network/extrinsic_observer.hpp | 7 ++----- src/scale/detail/fixed_witdh_integer.hpp | 4 ---- .../finality/impl/voting_round_impl.cpp | 20 ++++++++----------- 46 files changed, 101 insertions(+), 240 deletions(-) diff --git a/src/base/visitor.hpp b/src/base/visitor.hpp index f2643f54..00fca38b 100644 --- a/src/base/visitor.hpp +++ b/src/base/visitor.hpp @@ -57,7 +57,7 @@ namespace sgns } /** - * @brief Inplace visitor for boost::variant. Bascially poor man's pattern matching for variants. + * @brief Inplace visitor for boost::variant. * @code{.cpp} * boost::variant value = "1234"; * diff --git a/src/crypto/crypto_store.hpp b/src/crypto/crypto_store.hpp index d56cfb47..fce64965 100644 --- a/src/crypto/crypto_store.hpp +++ b/src/crypto/crypto_store.hpp @@ -1,17 +1,11 @@ - - #ifndef SUPERGENIUS_CRYPTO_STORE_HPP #define SUPERGENIUS_CRYPTO_STORE_HPP -#include - #include #include #include -#include "crypto/bip39/bip39_provider.hpp" #include "crypto/crypto_store/key_type.hpp" #include "crypto/ed25519_types.hpp" -#include "crypto/secp256k1_types.hpp" #include "crypto/sr25519_types.hpp" namespace sgns::crypto { @@ -110,6 +104,6 @@ namespace sgns::crypto { */ virtual SR25519Keys getSr25519PublicKeys(KeyTypeId key_type) const = 0; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_CRYPTO_STORE_HPP +#endif diff --git a/src/crypto/crypto_store/crypto_store_impl.cpp b/src/crypto/crypto_store/crypto_store_impl.cpp index 4e136073..91a96da2 100644 --- a/src/crypto/crypto_store/crypto_store_impl.cpp +++ b/src/crypto/crypto_store/crypto_store_impl.cpp @@ -1,11 +1,8 @@ - - #include "crypto/crypto_store/crypto_store_impl.hpp" #include #include -#include "base/visitor.hpp" #include "crypto/bip39/mnemonic.hpp" #include @@ -32,9 +29,14 @@ namespace sgns::crypto { } std::ifstream file; - auto close_file = gsl::finally([&file] { - if (file.is_open()) file.close(); - }); + auto close_file = gsl::finally( + [&file] + { + if ( file.is_open() ) + { + file.close(); + } + } ); file.open(file_path.string(), std::ios::in); if (!file.is_open()) { @@ -293,7 +295,7 @@ namespace sgns::crypto { } } - return ED25519Keys(keys.begin(), keys.end()); + return { keys.begin(), keys.end() }; } CryptoStore::SR25519Keys CryptoStoreImpl::getSr25519PublicKeys( @@ -340,7 +342,7 @@ namespace sgns::crypto { } } - return SR25519Keys(keys.begin(), keys.end()); + return { keys.begin(), keys.end() }; } } // namespace sgns::crypto diff --git a/src/crypto/crypto_store/crypto_store_impl.hpp b/src/crypto/crypto_store/crypto_store_impl.hpp index 01ca31b6..38272814 100644 --- a/src/crypto/crypto_store/crypto_store_impl.hpp +++ b/src/crypto/crypto_store/crypto_store_impl.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_CRYPTO_STORE_IMPL_HPP #define SUPERGENIUS_CRYPTO_STORE_IMPL_HPP @@ -15,7 +13,6 @@ #include "crypto/sr25519_provider.hpp" namespace sgns::crypto { - namespace store { using KeyPair = boost::variant; using PublicKey = base::Blob<32>; @@ -42,7 +39,7 @@ namespace sgns::crypto { inline std::ostream &operator<<(std::ostream &out, const CryptoStoreError &test_struct) { - return out << (int)test_struct; + return out << static_cast(test_struct); } class CryptoStoreImpl : public CryptoStore { diff --git a/src/crypto/crypto_store/key_type.hpp b/src/crypto/crypto_store/key_type.hpp index a5350dec..f1442949 100644 --- a/src/crypto/crypto_store/key_type.hpp +++ b/src/crypto/crypto_store/key_type.hpp @@ -1,13 +1,9 @@ - - #ifndef SUPERGENIUS_CRYPTO_KEY_TYPE_HPP #define SUPERGENIUS_CRYPTO_KEY_TYPE_HPP -#include "base/blob.hpp" #include "outcome/outcome.hpp" namespace sgns::crypto { - enum class KeyTypeError { UNSUPPORTED_KEY_TYPE = 1, UNSUPPORTED_KEY_TYPE_ID, @@ -23,12 +19,12 @@ namespace sgns::crypto { * Types are 32bit integers, which represent encoded 4-char strings * Big-endian byte order is used */ - static constexpr KeyTypeId kProd = 1886547812u; // "prod" - static constexpr KeyTypeId kGran = 1735549294u; // "gran" - static constexpr KeyTypeId kAcco = 1633903471u; // "acco" - static constexpr KeyTypeId kImon = 1768779630u; // "imon" - static constexpr KeyTypeId kAudi = 1635083369u; // "audi" - static constexpr KeyTypeId kLp2p = 1819292272u; // "lp2p" + static constexpr KeyTypeId kProd = 1886547812U; // "prod" + static constexpr KeyTypeId kGran = 1735549294U; // "gran" + static constexpr KeyTypeId kAcco = 1633903471U; // "acco" + static constexpr KeyTypeId kImon = 1768779630U; // "imon" + static constexpr KeyTypeId kAudi = 1635083369U; // "audi" + static constexpr KeyTypeId kLp2p = 1819292272U; // "lp2p" } // namespace supported_key_types /** diff --git a/src/crypto/ed25519/ed25519_provider_impl.hpp b/src/crypto/ed25519/ed25519_provider_impl.hpp index 5fe25bc2..84c33d05 100644 --- a/src/crypto/ed25519/ed25519_provider_impl.hpp +++ b/src/crypto/ed25519/ed25519_provider_impl.hpp @@ -1,12 +1,9 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_ED25519_ED25519_PROVIDER_IMPL_HPP #define SUPERGENIUS_SRC_CRYPTO_ED25519_ED25519_PROVIDER_IMPL_HPP #include "crypto/ed25519_provider.hpp" namespace sgns::crypto { - class ED25519ProviderImpl : public ED25519Provider { public: ~ED25519ProviderImpl() override = default; @@ -30,6 +27,6 @@ namespace sgns::crypto { } }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_ED25519_ED25519_PROVIDER_IMPL_HPP +#endif diff --git a/src/crypto/ed25519_provider.hpp b/src/crypto/ed25519_provider.hpp index 8cc956e6..2ac39109 100644 --- a/src/crypto/ed25519_provider.hpp +++ b/src/crypto/ed25519_provider.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_ED25519_PROVIDER_HPP #define SUPERGENIUS_SRC_CRYPTO_ED25519_PROVIDER_HPP @@ -9,7 +7,6 @@ #include "integration/IComponent.hpp" namespace sgns::crypto { - enum class ED25519ProviderError { FAILED_GENERATE_KEYPAIR = 1, SIGN_UNKNOWN_ERROR, // unknown error occurred during call to `sign` method @@ -55,8 +52,8 @@ namespace sgns::crypto { gsl::span message, const ED25519PublicKey &public_key) const = 0; }; -} // namespace sgns::crypto +} OUTCOME_HPP_DECLARE_ERROR_2(sgns::crypto, ED25519ProviderError) -#endif // SUPERGENIUS_SRC_CRYPTO_ED25519_PROVIDER_HPP +#endif diff --git a/src/crypto/ed25519_types.cpp b/src/crypto/ed25519_types.cpp index e1afcfb3..5cc361a9 100644 --- a/src/crypto/ed25519_types.cpp +++ b/src/crypto/ed25519_types.cpp @@ -1,5 +1,3 @@ - - #include "ed25519_types.hpp" namespace sgns::crypto { @@ -10,4 +8,4 @@ namespace sgns::crypto { bool ED25519Keypair::operator!=(const ED25519Keypair &other) const { return !(*this == other); } -} // namespace sgns::crypto +} diff --git a/src/crypto/ed25519_types.hpp b/src/crypto/ed25519_types.hpp index f3527312..b3e76cfe 100644 --- a/src/crypto/ed25519_types.hpp +++ b/src/crypto/ed25519_types.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_ED25519_TYPES_HPP #define SUPERGENIUS_SRC_CRYPTO_ED25519_TYPES_HPP @@ -8,7 +6,6 @@ #include "integration/IComponent.hpp" namespace sgns::crypto { - namespace constants::ed25519 { /** * Important constants to deal with ed25519 @@ -19,7 +16,7 @@ namespace sgns::crypto { SIGNATURE_SIZE = ed25519_signature_SIZE, SEED_SIZE = PRIVKEY_SIZE, }; - } // namespace constants::ed25519 + } using ED25519PrivateKey = base::Blob; using ED25519PublicKey = base::Blob; @@ -47,6 +44,6 @@ namespace sgns::crypto { using ED25519Signature = base::Blob; using ED25519Seed = base::Blob; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_ED25519_TYPES_HPP +#endif diff --git a/src/crypto/hasher.hpp b/src/crypto/hasher.hpp index bcf2806f..d8267151 100644 --- a/src/crypto/hasher.hpp +++ b/src/crypto/hasher.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_HASHER_HASHER_HPP_ #define SUPERGENIUS_SRC_HASHER_HASHER_HPP_ @@ -75,6 +73,6 @@ namespace sgns::crypto { */ [[nodiscard]] virtual Hash256 sha2_256( gsl::span buffer ) const = 0; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_HASHER_HASHER_HPP_ +#endif diff --git a/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.cpp b/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.cpp index 4f59ddc2..fb685ee3 100644 --- a/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.cpp +++ b/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.cpp @@ -1,11 +1,8 @@ - - #include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" #include namespace sgns::crypto { - outcome::result Pbkdf2ProviderImpl::deriveKey( gsl::span data, gsl::span salt, @@ -30,7 +27,7 @@ namespace sgns::crypto { return out; } -} // namespace sgns::crypto +} OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::crypto, Pbkdf2ProviderError, error) { using Error = sgns::crypto::Pbkdf2ProviderError; diff --git a/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp b/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp index 72e8bb4c..81848df6 100644 --- a/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp +++ b/src/crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_IMPL_HPP #define SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_IMPL_HPP @@ -17,6 +15,6 @@ namespace sgns::crypto { size_t key_length) const override; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_IMPL_HPP +#endif diff --git a/src/crypto/pbkdf2/pbkdf2_provider.hpp b/src/crypto/pbkdf2/pbkdf2_provider.hpp index b57ff902..4b656467 100644 --- a/src/crypto/pbkdf2/pbkdf2_provider.hpp +++ b/src/crypto/pbkdf2/pbkdf2_provider.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_HPP #define SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_HPP diff --git a/src/crypto/random_generator.hpp b/src/crypto/random_generator.hpp index 5abc5997..7d80e4b8 100644 --- a/src/crypto/random_generator.hpp +++ b/src/crypto/random_generator.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_HPP #define SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_HPP @@ -8,6 +6,6 @@ namespace sgns::crypto { using RandomGenerator = libp2p::crypto::random::RandomGenerator; using CSPRNG = libp2p::crypto::random::CSPRNG; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_HPP +#endif diff --git a/src/crypto/random_generator/boost_generator.hpp b/src/crypto/random_generator/boost_generator.hpp index 762fd108..b9831ad7 100644 --- a/src/crypto/random_generator/boost_generator.hpp +++ b/src/crypto/random_generator/boost_generator.hpp @@ -1,15 +1,12 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_BOOST_GENERATOR_HPP #define SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_BOOST_GENERATOR_HPP #include "libp2p/crypto/random_generator/boost_generator.hpp" -namespace sgns::crypto { - - using BoostRandomGenerator = libp2p::crypto::random::BoostRandomGenerator; - using CSPRNG = libp2p::crypto::random::CSPRNG; - +namespace sgns::crypto +{ + using BoostRandomGenerator = libp2p::crypto::random::BoostRandomGenerator; + using CSPRNG = libp2p::crypto::random::CSPRNG; } -#endif // SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_BOOST_GENERATOR_HPP +#endif diff --git a/src/crypto/secp256k1/secp256k1_provider_impl.hpp b/src/crypto/secp256k1/secp256k1_provider_impl.hpp index 5fb4743a..7529862b 100644 --- a/src/crypto/secp256k1/secp256k1_provider_impl.hpp +++ b/src/crypto/secp256k1/secp256k1_provider_impl.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_IMPL_HPP #define SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_IMPL_HPP @@ -7,7 +6,6 @@ #include "crypto/secp256k1_provider.hpp" namespace sgns::crypto { - enum class Secp256k1ProviderError { INVALID_ARGUMENT = 1, INVALID_V_VALUE, @@ -37,8 +35,8 @@ namespace sgns::crypto { std::unique_ptr context_; }; -} // namespace sgns::crypto +} OUTCOME_HPP_DECLARE_ERROR_2(sgns::crypto, Secp256k1ProviderError); -#endif // SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_IMPL_HPP +#endif diff --git a/src/crypto/secp256k1_provider.hpp b/src/crypto/secp256k1_provider.hpp index 585b1655..611ce24d 100644 --- a/src/crypto/secp256k1_provider.hpp +++ b/src/crypto/secp256k1_provider.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_HPP #define SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_HPP @@ -6,7 +5,6 @@ #include "outcome/outcome.hpp" namespace sgns::crypto { - /** * @class Secp256k1Provider provides public key recovery functionality */ @@ -37,6 +35,6 @@ namespace sgns::crypto { const secp256k1::MessageHash &message_hash) const = 0; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_HPP +#endif diff --git a/src/crypto/secp256k1_types.hpp b/src/crypto/secp256k1_types.hpp index d097865e..1387ef1e 100644 --- a/src/crypto/secp256k1_types.hpp +++ b/src/crypto/secp256k1_types.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_CRYPTO_SECP256K1_TYPES_HPP #define SUPERGENIUS_SRC_CRYPTO_SECP256K1_TYPES_HPP @@ -44,6 +43,6 @@ namespace sgns::crypto::secp256k1 { * 32-byte sequence of bytes (presumably blake2s hash) */ using MessageHash = base::Hash256; -} // namespace sgns::crypto::secp256k1 +} -#endif // SUPERGENIUS_SRC_CRYPTO_SECP256K1_TYPES_HPP +#endif diff --git a/src/crypto/sha/sha256.hpp b/src/crypto/sha/sha256.hpp index f443e99e..e7ea4435 100644 --- a/src/crypto/sha/sha256.hpp +++ b/src/crypto/sha/sha256.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SHA256_HPP #define SUPERGENIUS_SHA256_HPP @@ -22,6 +20,6 @@ namespace sgns::crypto { * @return hashed bytes */ base::Hash256 sha256(gsl::span input); -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SHA256_HPP +#endif diff --git a/src/crypto/sr25519/sr25519_provider_impl.cpp b/src/crypto/sr25519/sr25519_provider_impl.cpp index 7ebbac7c..c1c4bb00 100644 --- a/src/crypto/sr25519/sr25519_provider_impl.cpp +++ b/src/crypto/sr25519/sr25519_provider_impl.cpp @@ -1,9 +1,7 @@ - - #include "crypto/sr25519/sr25519_provider_impl.hpp" #include "crypto/sr25519_types.hpp" -#include "libp2p/crypto/random_generator.hpp" +#include namespace sgns::crypto { SR25519ProviderImpl::SR25519ProviderImpl(std::shared_ptr generator) @@ -62,7 +60,7 @@ namespace sgns::crypto { } return outcome::success(result); } -} // namespace sgns::crypto +} OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::crypto, SR25519ProviderError, e) { using sgns::crypto::SR25519ProviderError; diff --git a/src/crypto/sr25519/sr25519_provider_impl.hpp b/src/crypto/sr25519/sr25519_provider_impl.hpp index cc98c761..b58778c3 100644 --- a/src/crypto/sr25519/sr25519_provider_impl.hpp +++ b/src/crypto/sr25519/sr25519_provider_impl.hpp @@ -1,9 +1,6 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_SR25519_SR25519_PROVIDER_IMPL_HPP #define SUPERGENIUS_SRC_CRYPTO_SR25519_SR25519_PROVIDER_IMPL_HPP -#include "crypto/random_generator.hpp" #include "crypto/sr25519_provider.hpp" namespace libp2p::crypto::random { @@ -11,7 +8,6 @@ namespace libp2p::crypto::random { } namespace sgns::crypto { - class SR25519ProviderImpl : public SR25519Provider { using CSPRNG = libp2p::crypto::random::CSPRNG; @@ -41,6 +37,6 @@ namespace sgns::crypto { std::shared_ptr generator_; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_SR25519_SR25519_PROVIDER_IMPL_HPP +#endif diff --git a/src/crypto/sr25519_types.cpp b/src/crypto/sr25519_types.cpp index 173f7869..b26eaaa9 100644 --- a/src/crypto/sr25519_types.cpp +++ b/src/crypto/sr25519_types.cpp @@ -1,5 +1,3 @@ - - #include "crypto/sr25519_types.hpp" namespace sgns::crypto { @@ -19,4 +17,4 @@ namespace sgns::crypto { return !(*this == other); } -} // namespace sgns::crypto +} diff --git a/src/crypto/sr25519_types.hpp b/src/crypto/sr25519_types.hpp index f071ecc7..c42e49ab 100644 --- a/src/crypto/sr25519_types.hpp +++ b/src/crypto/sr25519_types.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_VRF_TYPES #define SUPERGENIUS_SRC_CRYPTO_VRF_TYPES @@ -10,7 +8,6 @@ extern "C" { #include #include "base/blob.hpp" -#include "base/mp_utils.hpp" #include "integration/IComponent.hpp" namespace sgns::crypto { @@ -147,6 +144,6 @@ namespace sgns::crypto { return s >> o.output >> o.proof; } -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_VRF_TYPES +#endif diff --git a/src/crypto/twox/twox.cpp b/src/crypto/twox/twox.cpp index b079fdcb..674f8ab3 100644 --- a/src/crypto/twox/twox.cpp +++ b/src/crypto/twox/twox.cpp @@ -1,15 +1,10 @@ - - #include "crypto/twox/twox.hpp" #include namespace sgns::crypto { - void make_twox64(const uint8_t *in, uint32_t len, uint8_t *out) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto *ptr = reinterpret_cast(out); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[0] = XXH64(in, len, 0); } @@ -20,11 +15,8 @@ namespace sgns::crypto { } void make_twox128(const uint8_t *in, uint32_t len, uint8_t *out) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto *ptr = reinterpret_cast(out); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[0] = XXH64(in, len, 0); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[1] = XXH64(in, len, 1); } @@ -35,15 +27,10 @@ namespace sgns::crypto { } void make_twox256(const uint8_t *in, uint32_t len, uint8_t *out) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto *ptr = reinterpret_cast(out); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[0] = XXH64(in, len, 0); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[1] = XXH64(in, len, 1); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[2] = XXH64(in, len, 2); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) ptr[3] = XXH64(in, len, 3); } @@ -52,5 +39,4 @@ namespace sgns::crypto { make_twox256(buf.data(), buf.size(), hash.data()); return hash; } - -} // namespace sgns::crypto +} diff --git a/src/crypto/twox/twox.hpp b/src/crypto/twox/twox.hpp index 8d53ccab..af941217 100644 --- a/src/crypto/twox/twox.hpp +++ b/src/crypto/twox/twox.hpp @@ -1,20 +1,15 @@ - - #ifndef SUPERGENIUS_CRYPTO_TWOX_HPP #define SUPERGENIUS_CRYPTO_TWOX_HPP #include "base/blob.hpp" -namespace sgns::crypto { - - // TODO(warchant): PRE-357 refactor to span - - base::Hash64 make_twox64(gsl::span buf); - - base::Hash128 make_twox128(gsl::span buf); +namespace sgns::crypto +{ + base::Hash64 make_twox64( gsl::span buf ); - base::Hash256 make_twox256(gsl::span buf); + base::Hash128 make_twox128( gsl::span buf ); -} // namespace sgns::crypto + base::Hash256 make_twox256( gsl::span buf ); +} -#endif // SUPERGENIUS_CRYPTO_TWOX_HPP +#endif diff --git a/src/crypto/vrf/vrf_provider_impl.cpp b/src/crypto/vrf/vrf_provider_impl.cpp index abc90ade..5d942243 100644 --- a/src/crypto/vrf/vrf_provider_impl.cpp +++ b/src/crypto/vrf/vrf_provider_impl.cpp @@ -1,5 +1,3 @@ - - #include "crypto/vrf/vrf_provider_impl.hpp" #include @@ -69,8 +67,7 @@ namespace sgns::crypto { output.output.data(), output.proof.data(), base::uint128_t_to_bytes(threshold).data()); - return VRFVerifyOutput{/*.is_valid = */res.result == Sr25519SignatureResult::Ok, - /*.is_less = */res.is_less}; + return VRFVerifyOutput{ res.result == Sr25519SignatureResult::Ok, res.is_less }; } -} // namespace sgns::crypto +} diff --git a/src/crypto/vrf/vrf_provider_impl.hpp b/src/crypto/vrf/vrf_provider_impl.hpp index b96c8430..6ac6be70 100644 --- a/src/crypto/vrf/vrf_provider_impl.hpp +++ b/src/crypto/vrf/vrf_provider_impl.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_VERIFICATION_VRF_VRF_HPP #define SUPERGENIUS_SRC_VERIFICATION_VRF_VRF_HPP @@ -10,7 +8,6 @@ #include "crypto/random_generator.hpp" namespace sgns::crypto { - class VRFProviderImpl : public VRFProvider { public: explicit VRFProviderImpl(std::shared_ptr generator); @@ -36,6 +33,6 @@ namespace sgns::crypto { private: std::shared_ptr generator_; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_VERIFICATION_VRF_VRF_HPP +#endif diff --git a/src/crypto/vrf_provider.hpp b/src/crypto/vrf_provider.hpp index fb8f7e22..dcf348dd 100644 --- a/src/crypto/vrf_provider.hpp +++ b/src/crypto/vrf_provider.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_CRYPTO_VRF_VRF_PROVIDER_HPP #define SUPERGENIUS_SRC_CRYPTO_VRF_VRF_PROVIDER_HPP @@ -10,7 +8,6 @@ #include "integration/IComponent.hpp" namespace sgns::crypto { - /** * SR25519 based verifiable random function implementation */ @@ -42,6 +39,6 @@ namespace sgns::crypto { const SR25519PublicKey &public_key, const VRFThreshold &threshold) const = 0; }; -} // namespace sgns::crypto +} -#endif // SUPERGENIUS_SRC_CRYPTO_VRF_VRF_PROVIDER_HPP +#endif diff --git a/src/extensions/extension.hpp b/src/extensions/extension.hpp index 4566335c..95949e7e 100644 --- a/src/extensions/extension.hpp +++ b/src/extensions/extension.hpp @@ -1,9 +1,7 @@ - #ifndef SUPERGENIUS_SRC_EXTENSION_HPP #define SUPERGENIUS_SRC_EXTENSION_HPP #include -#include #include "runtime/types.hpp" #include "runtime/wasm_result.hpp" @@ -487,6 +485,6 @@ namespace sgns::extensions { virtual runtime::WasmResult ext_misc_runtime_version_version_1( runtime::WasmSpan data) const = 0; }; -} // namespace sgns::extensions +} -#endif // SUPERGENIUS_SRC_EXTENSION_HPP +#endif diff --git a/src/extensions/extension_factory.hpp b/src/extensions/extension_factory.hpp index 8c959861..15f05380 100644 --- a/src/extensions/extension_factory.hpp +++ b/src/extensions/extension_factory.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_EXTENSIONS_EXTENSION_FACTORY_HPP #define SUPERGENIUS_SRC_EXTENSIONS_EXTENSION_FACTORY_HPP @@ -25,6 +24,6 @@ namespace sgns::extensions { std::shared_ptr storage_provider) const = 0; }; -} // namespace sgns::extensions +} -#endif // SUPERGENIUS_SRC_EXTENSIONS_EXTENSION_FACTORY_HPP +#endif diff --git a/src/extensions/impl/crypto_extension.cpp b/src/extensions/impl/crypto_extension.cpp index 48f4f7c0..99eecae0 100644 --- a/src/extensions/impl/crypto_extension.cpp +++ b/src/extensions/impl/crypto_extension.cpp @@ -1,4 +1,3 @@ - #include "extensions/impl/crypto_extension.hpp" #include diff --git a/src/extensions/impl/crypto_extension.hpp b/src/extensions/impl/crypto_extension.hpp index bd5dcd24..7766bdbd 100644 --- a/src/extensions/impl/crypto_extension.hpp +++ b/src/extensions/impl/crypto_extension.hpp @@ -1,9 +1,7 @@ - #ifndef SUPERGENIUS_SRC_CRYPTO_EXTENSION_HPP #define SUPERGENIUS_SRC_CRYPTO_EXTENSION_HPP #include "base/logger.hpp" -#include "crypto/bip39/bip39_types.hpp" #include "crypto/crypto_store.hpp" #include "runtime/wasm_memory.hpp" @@ -204,6 +202,6 @@ namespace sgns::extensions { std::shared_ptr bip39_provider_; base::Logger logger_; }; -} // namespace sgns::extensions +} -#endif // SUPERGENIUS_SRC_CRYPTO_EXTENSION_HPP +#endif diff --git a/src/extensions/impl/extension_factory_impl.cpp b/src/extensions/impl/extension_factory_impl.cpp index 01a90dd0..9e37bfe2 100644 --- a/src/extensions/impl/extension_factory_impl.cpp +++ b/src/extensions/impl/extension_factory_impl.cpp @@ -1,4 +1,3 @@ - #include "extensions/impl/extension_factory_impl.hpp" #include "extensions/impl/extension_impl.hpp" @@ -46,4 +45,4 @@ namespace sgns::extensions { bip39_provider_, core_factory_method_); } -} // namespace sgns::extensions +} diff --git a/src/extensions/impl/extension_factory_impl.hpp b/src/extensions/impl/extension_factory_impl.hpp index 81a43eae..9d754fdc 100644 --- a/src/extensions/impl/extension_factory_impl.hpp +++ b/src/extensions/impl/extension_factory_impl.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_EXTENSIONS_IMPL_EXTENSION_FACTORY_IMPL_HPP #define SUPERGENIUS_SRC_EXTENSIONS_IMPL_EXTENSION_FACTORY_IMPL_HPP @@ -45,6 +44,6 @@ namespace sgns::extensions { MiscExtension::CoreFactoryMethod core_factory_method_; }; -} // namespace sgns::extensions +} -#endif // SUPERGENIUS_SRC_EXTENSIONS_IMPL_EXTENSION_FACTORY_IMPL_HPP +#endif diff --git a/src/extensions/impl/extension_impl.cpp b/src/extensions/impl/extension_impl.cpp index 80ed3c7c..48ecc9e0 100644 --- a/src/extensions/impl/extension_impl.cpp +++ b/src/extensions/impl/extension_impl.cpp @@ -1,14 +1,5 @@ #include "extensions/impl/extension_impl.hpp" -#include "crypto/bip39/impl/bip39_provider_impl.hpp" -#include "crypto/crypto_store/crypto_store_impl.hpp" -#include "crypto/ed25519/ed25519_provider_impl.hpp" -#include "crypto/hasher/hasher_impl.hpp" -#include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp" -#include "crypto/random_generator/boost_generator.hpp" -#include "crypto/secp256k1/secp256k1_provider_impl.hpp" -#include "crypto/sr25519/sr25519_provider_impl.hpp" - namespace sgns::extensions { ExtensionImpl::ExtensionImpl( @@ -365,4 +356,4 @@ namespace sgns::extensions { msg); } -} // namespace sgns::extensions +} diff --git a/src/extensions/impl/extension_impl.hpp b/src/extensions/impl/extension_impl.hpp index 273bf04d..6be0ff7f 100644 --- a/src/extensions/impl/extension_impl.hpp +++ b/src/extensions/impl/extension_impl.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_EXTENSION_IMPL_HPP #define SUPERGENIUS_SRC_EXTENSION_IMPL_HPP @@ -247,6 +246,6 @@ namespace sgns::extensions { MiscExtension misc_ext_; StorageExtension storage_ext_; }; -} // namespace sgns::extensions +} -#endif // SUPERGENIUS_SRC_EXTENSION_IMPL_HPP +#endif diff --git a/src/extensions/impl/io_extension.hpp b/src/extensions/impl/io_extension.hpp index 8986f930..22de7237 100644 --- a/src/extensions/impl/io_extension.hpp +++ b/src/extensions/impl/io_extension.hpp @@ -1,4 +1,3 @@ - #ifndef SUPERGENIUS_SRC_IO_EXTENSION_HPP #define SUPERGENIUS_SRC_IO_EXTENSION_HPP @@ -44,6 +43,6 @@ namespace sgns::extensions { std::shared_ptr memory_; base::Logger logger_; }; -} // namespace sgns::extensions +} -#endif // SUPERGENIUS_SRC_IO_EXTENSION_HPP +#endif diff --git a/src/injector/application_injector.cpp b/src/injector/application_injector.cpp index e7c731fe..2ea6a05a 100644 --- a/src/injector/application_injector.cpp +++ b/src/injector/application_injector.cpp @@ -1,4 +1,3 @@ - #include "injector/application_injector.hpp" OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::injector, InjectorError, e) { diff --git a/src/injector/application_injector.hpp b/src/injector/application_injector.hpp index b7a856e9..39692a23 100644 --- a/src/injector/application_injector.hpp +++ b/src/injector/application_injector.hpp @@ -1,6 +1,6 @@ - #ifndef SUPERGENIUS_SRC_INJECTOR_APPLICATION_INJECTOR_HPP #define SUPERGENIUS_SRC_INJECTOR_APPLICATION_INJECTOR_HPP + #include #include @@ -42,25 +42,18 @@ #include "blockchain/impl/key_value_block_header_repository.hpp" #include "blockchain/impl/key_value_block_storage.hpp" #include "blockchain/impl/storage_util.hpp" -#include "boost/di/extension/injections/extensible_injector.hpp" #include "clock/impl/basic_waitable_timer.hpp" #include "clock/impl/clock_impl.hpp" #include "base/outcome_throw.hpp" #include "verification/authority/authority_manager.hpp" #include "verification/authority/authority_update_observer.hpp" #include "verification/authority/impl/authority_manager_impl.hpp" -#include "verification/production/production_lottery.hpp" -#include "verification/production/common.hpp" -#include "verification/production/impl/production_lottery_impl.hpp" #include "verification/production/impl/production_synchronizer_impl.hpp" #include "verification/production/impl/epoch_storage_impl.hpp" #include "verification/finality/finalization_observer.hpp" #include "verification/finality/impl/environment_impl.hpp" #include "verification/finality/impl/finalization_composite.hpp" #include "verification/finality/impl/vote_crypto_provider_impl.hpp" -#include "verification/finality/structs.hpp" -#include "verification/finality/vote_graph.hpp" -#include "verification/finality/vote_tracker.hpp" #include "verification/validation/production_block_validator.hpp" #include "primitives/production_configuration.hpp" #include "crypto/ed25519/ed25519_provider_impl.hpp" @@ -75,7 +68,6 @@ #include "network/impl/remote_sync_protocol_client.hpp" #include "network/impl/router_libp2p.hpp" #include "network/impl/sync_protocol_observer_impl.hpp" -#include "network/sync_protocol_client.hpp" #include "network/sync_protocol_observer.hpp" #include "network/types/sync_clients_set.hpp" #include "runtime/binaryen/module/wasm_module_impl.hpp" @@ -98,7 +90,6 @@ #include "storage/predefined_keys.hpp" #include "storage/trie/impl/trie_storage_backend_impl.hpp" #include "storage/trie/impl/trie_storage_impl.hpp" -#include "storage/trie/supergenius_trie/supergenius_node.hpp" #include "storage/trie/supergenius_trie/supergenius_trie_factory_impl.hpp" #include "storage/trie/serialization/supergenius_codec.hpp" #include "storage/trie/serialization/trie_serializer_impl.hpp" diff --git a/src/injector/block_producing_node_injector.hpp b/src/injector/block_producing_node_injector.hpp index 37b21d20..23e6ff6e 100644 --- a/src/injector/block_producing_node_injector.hpp +++ b/src/injector/block_producing_node_injector.hpp @@ -1,21 +1,10 @@ - #ifndef SUPERGENIUS_SRC_INJECTOR_BLOCK_PRODUCING_NODE_INJECTOR_HPP #define SUPERGENIUS_SRC_INJECTOR_BLOCK_PRODUCING_NODE_INJECTOR_HPP #include "application/app_config.hpp" -#include "application/impl/local_key_storage.hpp" -#include "verification/production/impl/production_impl.hpp" -#include "verification/production/impl/syncing_production_observer.hpp" -#include "verification/finality/impl/syncing_round_observer.hpp" -#include "injector/application_injector.hpp" -#include "injector/validating_node_injector.hpp" -#include "runtime/dummy/finality_api_dummy.hpp" -#include "storage/in_memory/in_memory_storage.hpp" #include "platform/platform.hpp" namespace sgns::injector { - namespace di = boost::di; - template auto makeBlockProducingNodeInjector( const application::AppConfigPtr &app_config, Ts &&... args) { @@ -65,6 +54,6 @@ namespace sgns::injector { // user-defined overrides... std::forward(args)...); } -} // namespace sgns::injector +} -#endif // SUPERGENIUS_SRC_INJECTOR_BLOCK_PRODUCING_NODE_INJECTOR_HPP +#endif diff --git a/src/macro/unreachable.hpp b/src/macro/unreachable.hpp index 4bf62767..19d7e06b 100644 --- a/src/macro/unreachable.hpp +++ b/src/macro/unreachable.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_UNREACHABLE_HPP #define SUPERGENIUS_UNREACHABLE_HPP @@ -20,4 +18,4 @@ class Unreachable_At_Line {}; #undef GCC_VERSION -#endif // SUPERGENIUS_UNREACHABLE_HPP +#endif diff --git a/src/network/common.hpp b/src/network/common.hpp index 49281f66..19e2256f 100644 --- a/src/network/common.hpp +++ b/src/network/common.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_NETWORK_COMMON_HPP #define SUPERGENIUS_NETWORK_COMMON_HPP @@ -8,6 +6,6 @@ namespace sgns::network { const libp2p::peer::Protocol kSyncProtocol = "/supergenius-sync/1.0.0"; const libp2p::peer::Protocol kGossipProtocol = "/supergenius-gossip/1.0.0"; -} // namespace sgns::network +} -#endif // SUPERGENIUS_NETWORK_COMMON_HPP +#endif diff --git a/src/network/extrinsic_gossiper.hpp b/src/network/extrinsic_gossiper.hpp index 73a89c91..ac82cd44 100644 --- a/src/network/extrinsic_gossiper.hpp +++ b/src/network/extrinsic_gossiper.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_NETWORK_EXTRINSIC_GOSSIPER_HPP #define SUPERGENIUS_SRC_NETWORK_EXTRINSIC_GOSSIPER_HPP @@ -20,6 +18,6 @@ namespace sgns::network { virtual void transactionAnnounce( const network::TransactionAnnounce &announce) = 0; }; -} // namespace sgns::network +} -#endif // SUPERGENIUS_SRC_NETWORK_EXTRINSIC_GOSSIPER_HPP +#endif diff --git a/src/network/extrinsic_observer.hpp b/src/network/extrinsic_observer.hpp index bbc28c32..035eecc6 100644 --- a/src/network/extrinsic_observer.hpp +++ b/src/network/extrinsic_observer.hpp @@ -1,5 +1,3 @@ - - #ifndef SUPERGENIUS_SRC_NETWORK_EXTRINSIC_OBSERVER_HPP #define SUPERGENIUS_SRC_NETWORK_EXTRINSIC_OBSERVER_HPP @@ -10,7 +8,6 @@ #include "integration/IComponent.hpp" namespace sgns::network { - class ExtrinsicObserver : public IComponent { public: virtual ~ExtrinsicObserver() = default; @@ -19,6 +16,6 @@ namespace sgns::network { const primitives::Extrinsic &extrinsic) = 0; }; -} // namespace sgns::network +} -#endif // SUPERGENIUS_SRC_NETWORK_EXTRINSIC_OBSERVER_HPP +#endif diff --git a/src/scale/detail/fixed_witdh_integer.hpp b/src/scale/detail/fixed_witdh_integer.hpp index 976e3fce..ffe4359f 100644 --- a/src/scale/detail/fixed_witdh_integer.hpp +++ b/src/scale/detail/fixed_witdh_integer.hpp @@ -1,12 +1,8 @@ - - #ifndef SUPERGENIUS_SCALE_UTIL_HPP #define SUPERGENIUS_SCALE_UTIL_HPP -#include #include #include -#include #include #include "base/outcome_throw.hpp" diff --git a/src/verification/finality/impl/voting_round_impl.cpp b/src/verification/finality/impl/voting_round_impl.cpp index bfd2925c..4d1fbb3d 100644 --- a/src/verification/finality/impl/voting_round_impl.cpp +++ b/src/verification/finality/impl/voting_round_impl.cpp @@ -9,7 +9,6 @@ #include "base/visitor.hpp" #include "verification/finality/finality.hpp" #include "verification/finality/impl/voting_round_error.hpp" -#include "primitives/justification.hpp" namespace sgns::verification::finality { @@ -128,15 +127,13 @@ namespace sgns::verification::finality { } void VotingRoundImpl::constructCurrentState() { - current_round_state_ = std::make_shared(RoundState{ - /*.last_finalized_block =*/ previous_round_state_->finalized.value_or( - previous_round_state_->last_finalized_block), - /*.best_prevote_candidate =*/ - convertToPrevote(previous_round_state_->finalized.value_or( - previous_round_state_->last_finalized_block)), - /*.best_final_candidate =*/ - convertToBlockInfo(previous_round_state_->finalized.value_or( - previous_round_state_->last_finalized_block))}); + current_round_state_ = std::make_shared( + RoundState{ .last_finalized_block = + previous_round_state_->finalized.value_or( previous_round_state_->last_finalized_block ), + .best_prevote_candidate = convertToPrevote( + previous_round_state_->finalized.value_or( previous_round_state_->last_finalized_block ) ), + .best_final_candidate = convertToBlockInfo( previous_round_state_->finalized.value_or( + previous_round_state_->last_finalized_block ) ) } ); } void VotingRoundImpl::play() { @@ -478,8 +475,7 @@ namespace sgns::verification::finality { finalized.error().message()); return; } - env_->onCompleted(CompletedRound{/*.round_number =*/ round_number_, - /*.state =*/ current_round_state_}); + env_->onCompleted( CompletedRound{ round_number_, current_round_state_ } ); } else { logger_->error("Validation of vote {} failed", f.vote.block_hash.toHex()); env_->onCompleted(VotingRoundError::FIN_VALIDATION_FAILED); From c1bde274d702af3eced58dda8ae944b1c8f00815 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 8 May 2024 10:22:05 -0300 Subject: [PATCH 10/11] revert: Re-added outcome to testutil's header --- test/testutil/outcome.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/testutil/outcome.hpp b/test/testutil/outcome.hpp index 2272c83c..506f6668 100644 --- a/test/testutil/outcome.hpp +++ b/test/testutil/outcome.hpp @@ -1,9 +1,8 @@ - - #ifndef SUPERGENIUS_GTEST_OUTCOME_UTIL_HPP #define SUPERGENIUS_GTEST_OUTCOME_UTIL_HPP #include +#include "outcome/outcome.hpp" #define PP_CAT(a, b) PP_CAT_I(a, b) #define PP_CAT_I(a, b) PP_CAT_II(~, a##b) @@ -198,4 +197,4 @@ << outcome::result(_error_).error().message() << "'"; \ } -#endif // SUPERGENIUS_GTEST_OUTCOME_UTIL_HPP +#endif From cef9ed8816db15bde94347d66691c86dab78e7e1 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 8 May 2024 10:24:26 -0300 Subject: [PATCH 11/11] refactor: Removed redundant destructor --- src/blockchain/block_header_repository.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/blockchain/block_header_repository.hpp b/src/blockchain/block_header_repository.hpp index b2ff340f..81fe23d7 100644 --- a/src/blockchain/block_header_repository.hpp +++ b/src/blockchain/block_header_repository.hpp @@ -28,8 +28,6 @@ namespace sgns::blockchain class BlockHeaderRepository : public IComponent { public: - ~BlockHeaderRepository() override = 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