LCOV - code coverage report
Current view: top level - src/node - chainstatemanager_args.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 89.3 % 28 25
Test Date: 2024-11-04 05:10:19 Functions: 100.0 % 1 1
Branches: 61.3 % 62 38

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2022 The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <node/chainstatemanager_args.h>
       6                 :             : 
       7                 :             : #include <arith_uint256.h>
       8                 :             : #include <common/args.h>
       9                 :             : #include <common/system.h>
      10                 :             : #include <logging.h>
      11                 :             : #include <node/coins_view_args.h>
      12                 :             : #include <node/database_args.h>
      13                 :             : #include <tinyformat.h>
      14                 :             : #include <uint256.h>
      15                 :             : #include <util/result.h>
      16                 :             : #include <util/strencodings.h>
      17                 :             : #include <util/translation.h>
      18                 :             : #include <validation.h>
      19                 :             : 
      20                 :             : #include <algorithm>
      21                 :             : #include <chrono>
      22                 :             : #include <string>
      23                 :             : 
      24                 :             : namespace node {
      25                 :        2507 : util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManager::Options& opts)
      26                 :             : {
      27   [ +  -  +  + ]:        5014 :     if (auto value{args.GetIntArg("-checkblockindex")}) {
      28                 :             :         // Interpret bare -checkblockindex argument as 1 instead of 0.
      29   [ +  -  +  -  :          16 :         opts.check_block_index = args.GetArg("-checkblockindex")->empty() ? 1 : *value;
                   -  + ]
      30                 :             :     }
      31                 :             : 
      32   [ +  -  +  + ]:        5014 :     if (auto value{args.GetBoolArg("-checkpoints")}) opts.checkpoints_enabled = *value;
      33                 :             : 
      34   [ +  -  +  + ]:        5014 :     if (auto value{args.GetArg("-minimumchainwork")}) {
      35   [ +  -  +  + ]:          27 :         if (auto min_work{uint256::FromUserHex(*value)}) {
      36         [ +  - ]:          24 :             opts.minimum_chain_work = UintToArith256(*min_work);
      37                 :             :         } else {
      38   [ +  -  +  -  :          12 :             return util::Error{strprintf(Untranslated("Invalid minimum work specified (%s), must be up to %d hex digits"), *value, uint256::size() * 2)};
                   +  - ]
      39                 :             :         }
      40                 :           3 :     }
      41                 :             : 
      42   [ +  -  +  + ]:        5008 :     if (auto value{args.GetArg("-assumevalid")}) {
      43   [ +  -  +  + ]:          11 :         if (auto block_hash{uint256::FromUserHex(*value)}) {
      44         [ -  + ]:        2511 :             opts.assumed_valid_block = *block_hash;
      45                 :             :         } else {
      46   [ +  -  +  -  :           8 :             return util::Error{strprintf(Untranslated("Invalid assumevalid block hash specified (%s), must be up to %d hex digits (or 0 to disable)"), *value, uint256::size() * 2)};
                   +  - ]
      47                 :             :         }
      48                 :           2 :     }
      49                 :             : 
      50   [ +  -  +  + ]:        5004 :     if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
      51                 :             : 
      52                 :        2502 :     ReadDatabaseArgs(args, opts.block_tree_db);
      53                 :        2502 :     ReadDatabaseArgs(args, opts.coins_db);
      54                 :        2502 :     ReadCoinsViewArgs(args, opts.coins_view);
      55                 :             : 
      56         [ +  - ]:        2502 :     int script_threads = args.GetIntArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
      57         [ +  + ]:        2502 :     if (script_threads <= 0) {
      58                 :             :         // -par=0 means autodetect (number of cores - 1 script threads)
      59                 :             :         // -par=-n means "leave n cores free" (number of cores - n - 1 script threads)
      60                 :        2488 :         script_threads += GetNumCores();
      61                 :             :     }
      62                 :             :     // Subtract 1 because the main thread counts towards the par threads.
      63         [ +  - ]:        2502 :     opts.worker_threads_num = std::clamp(script_threads - 1, 0, MAX_SCRIPTCHECK_THREADS);
      64                 :        2502 :     LogPrintf("Script verification uses %d additional threads\n", opts.worker_threads_num);
      65                 :             : 
      66   [ +  -  -  + ]:        5004 :     if (auto max_size = args.GetIntArg("-maxsigcachesize")) {
      67                 :             :         // 1. When supplied with a max_size of 0, both the signature cache and
      68                 :             :         //    script execution cache create the minimum possible cache (2
      69                 :             :         //    elements). Therefore, we can use 0 as a floor here.
      70                 :             :         // 2. Multiply first, divide after to avoid integer truncation.
      71         [ #  # ]:           0 :         size_t clamped_size_each = std::max<int64_t>(*max_size, 0) * (1 << 20) / 2;
      72                 :           0 :         opts.script_execution_cache_bytes = clamped_size_each;
      73                 :           0 :         opts.signature_cache_bytes = clamped_size_each;
      74                 :             :     }
      75                 :             : 
      76                 :        2502 :     return {};
      77                 :             : }
      78                 :             : } // namespace node
        

Generated by: LCOV version 2.0-1