From 8f241dbb138a9ddb5a8732663b8209439b8892e0 Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov Date: Mon, 30 Sep 2024 19:47:34 +0300 Subject: [PATCH] Fix: logger cli arg, crash on incompleted warp sync, etc. (#2226) * fix: crash while restart unfinished warp-sync Signed-off-by: Dmitriy Khaustov aka xDimon * fix: parsing cli args while setum log config file Signed-off-by: Dmitriy Khaustov aka xDimon * fix: grid tracker Signed-off-by: Dmitriy Khaustov aka xDimon * fix: parsing cli-arg for logger config file Signed-off-by: Dmitriy Khaustov aka xDimon * fix: test Signed-off-by: Dmitriy Khaustov aka xDimon --------- Signed-off-by: Dmitriy Khaustov aka xDimon --- .../impl/app_configuration_impl.cpp | 2 +- core/blockchain/impl/block_storage_impl.cpp | 1 + core/log/configurator.cpp | 3 ++- core/parachain/backing/grid_tracker.cpp | 2 +- node/main.cpp | 4 ++-- test/core/blockchain/block_storage_test.cpp | 20 ++++++++++--------- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/core/application/impl/app_configuration_impl.cpp b/core/application/impl/app_configuration_impl.cpp index 5a78d0b10f..12d6fe5a1a 100644 --- a/core/application/impl/app_configuration_impl.cpp +++ b/core/application/impl/app_configuration_impl.cpp @@ -814,7 +814,7 @@ namespace kagome::application { desc.add_options() ("help,h", "show this help message") ("version,v", "show version information") - ("logcfg", po::value(), "optional, path to config file of logger") + ("logcfg", po::value(), "optional, path to logger config file") ("log,l", po::value>(), "Sets a custom logging filter. Syntax is `=`, e.g. -llibp2p=off.\n" "Log levels (most to least verbose) are trace, debug, verbose, info, warn, error, critical, off. By default, all targets log `info`.\n" diff --git a/core/blockchain/impl/block_storage_impl.cpp b/core/blockchain/impl/block_storage_impl.cpp index 0e19b1fce0..12c00ff4ce 100644 --- a/core/blockchain/impl/block_storage_impl.cpp +++ b/core/blockchain/impl/block_storage_impl.cpp @@ -199,6 +199,7 @@ namespace kagome::blockchain { outcome::result BlockStorageImpl::putBlockHeader( const primitives::BlockHeader &header) { OUTCOME_TRY(encoded_header, scale::encode(header)); + header.updateHash(*hasher_); const auto &block_hash = header.hash(); OUTCOME_TRY(putToSpace( *storage_, Space::kHeader, block_hash, std::move(encoded_header))); diff --git a/core/log/configurator.cpp b/core/log/configurator.cpp index cf7f11e384..bd8049f09f 100644 --- a/core/log/configurator.cpp +++ b/core/log/configurator.cpp @@ -147,7 +147,8 @@ namespace kagome::log { po::options_description desc("General options"); desc.add_options() // clang-format off - ("logcfg", po::value(), "optional, path to logging config file") + ("logcfg", po::value()) + ("log", po::value()) // needed to avoid mix `--logcfg` and `--log` // clang-format on ; diff --git a/core/parachain/backing/grid_tracker.cpp b/core/parachain/backing/grid_tracker.cpp index 5477072613..c5cf1164e7 100644 --- a/core/parachain/backing/grid_tracker.cpp +++ b/core/parachain/backing/grid_tracker.cpp @@ -607,7 +607,7 @@ namespace kagome::parachain::grid { auto it = seconded_counts.find(group_index); if (it == seconded_counts.end()) { auto i = seconded_counts.emplace(group_index, - std::vector{group_size, 0}); + std::vector(group_size, 0)); counts = i.first->second; } else { counts = it->second; diff --git a/node/main.cpp b/node/main.cpp index 68a38f3627..5e4d87c639 100644 --- a/node/main.cpp +++ b/node/main.cpp @@ -123,11 +123,11 @@ int main(int argc, const char **argv, const char **env) { // Logging system auto logging_system = [&] { auto custom_log_config_path = - kagome::log::Configurator::getLogConfigFile(argc - 1, argv + 1); + kagome::log::Configurator::getLogConfigFile(argc, argv); if (custom_log_config_path.has_value()) { if (not std::filesystem::is_regular_file( custom_log_config_path.value())) { - std::cerr << "Provided wrong path to config file of logging\n"; + std::cerr << "Provided wrong path to logger config file\n"; exit(EXIT_FAILURE); } } diff --git a/test/core/blockchain/block_storage_test.cpp b/test/core/blockchain/block_storage_test.cpp index f9ad1daedf..ec6dd94c9a 100644 --- a/test/core/blockchain/block_storage_test.cpp +++ b/test/core/blockchain/block_storage_test.cpp @@ -48,6 +48,9 @@ class BlockStorageTest : public testing::Test { void SetUp() override { root_hash.fill(1); + hasher = std::make_shared(); + spaced_storage = std::make_shared(); + std::set required_spaces = {Space::kDefault, Space::kHeader, Space::kJustification, @@ -77,8 +80,9 @@ class BlockStorageTest : public testing::Test { std::shared_ptr createWithGenesis() { // calculate hash of genesis block at put block header - EXPECT_CALL(*hasher, blake2b_256(_)) - .WillRepeatedly(Return(genesis_block_hash)); + static auto encoded_header = Buffer(scale::encode(BlockHeader{}).value()); + ON_CALL(*hasher, blake2b_256(encoded_header.view())) + .WillByDefault(Return(genesis_block_hash)); EXPECT_OUTCOME_TRUE( new_block_storage, @@ -106,10 +110,6 @@ TEST_F(BlockStorageTest, CreateWithGenesis) { TEST_F(BlockStorageTest, CreateWithEmptyStorage) { auto empty_storage = std::make_shared(); - // calculate hash of genesis block at put block header - EXPECT_CALL(*hasher, blake2b_256(_)) - .WillRepeatedly(Return(genesis_block_hash)); - // check if storage contained genesis block EXPECT_CALL(*empty_storage, tryGetMock(_)) .WillRepeatedly(Return(std::nullopt)); @@ -169,7 +169,6 @@ TEST_F(BlockStorageTest, PutBlock) { Block block; block.header.number = 1; block.header.parent_hash = genesis_block_hash; - block.header.hash_opt = regular_block_hash; ASSERT_OUTCOME_SUCCESS_TRY(block_storage->putBlock(block)); } @@ -184,9 +183,12 @@ TEST_F(BlockStorageTest, PutWithStorageError) { auto block_storage = createWithGenesis(); Block block; - block.header.number = 666; + block.header.number = 1; block.header.parent_hash = genesis_block_hash; - block.header.hash_opt = regular_block_hash; + + auto encoded_header = Buffer(scale::encode(block.header).value()); + ON_CALL(*hasher, blake2b_256(encoded_header.view())) + .WillByDefault(Return(regular_block_hash)); Buffer key{regular_block_hash};