LCOV - code coverage report
Current view: top level - src/node - mining_args.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 93.9 % 49 46
Test Date: 2026-06-07 07:49:58 Functions: 100.0 % 4 4
Branches: 62.2 % 90 56

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 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/mining_args.h>
       6                 :             : 
       7                 :             : #include <common/args.h>
       8                 :             : #include <common/messages.h>
       9                 :             : #include <consensus/amount.h>
      10                 :             : #include <consensus/consensus.h>
      11                 :             : #include <node/mining_types.h>
      12                 :             : #include <policy/feerate.h>
      13                 :             : #include <policy/policy.h>
      14                 :             : #include <tinyformat.h>
      15                 :             : #include <util/moneystr.h>
      16                 :             : #include <util/result.h>
      17                 :             : #include <util/translation.h>
      18                 :             : 
      19                 :             : #include <cstdint>
      20                 :             : #include <optional>
      21                 :             : #include <string>
      22                 :             : #include <utility>
      23                 :             : 
      24                 :             : using common::AmountErrMsg;
      25                 :             : using util::Error;
      26                 :             : using util::Result;
      27                 :             : 
      28                 :             : namespace node {
      29                 :             : 
      30                 :       51821 : Result<void> CheckMiningOptions(BlockCreateOptions options, bool use_argnames)
      31                 :             : {
      32         [ +  - ]:       51821 :     options = FlattenMiningOptions(std::move(options));
      33         [ +  + ]:       51821 :     if (*options.block_reserved_weight < MINIMUM_BLOCK_RESERVED_WEIGHT) {
      34         [ +  - ]:           2 :         return Error{Untranslated(strprintf("%s (%d) is lower than minimum safety value of (%d)",
      35         [ -  + ]:           1 :                                             use_argnames ? "-blockreservedweight" : "block_reserved_weight",
      36         [ -  + ]:           2 :                                             *options.block_reserved_weight, MINIMUM_BLOCK_RESERVED_WEIGHT))};
      37                 :             :     }
      38         [ +  + ]:       51820 :     if (*options.block_reserved_weight > MAX_BLOCK_WEIGHT) {
      39         [ +  - ]:           2 :         return Error{Untranslated(strprintf("%s (%d) exceeds consensus maximum block weight (%d)",
      40         [ -  + ]:           1 :                                             use_argnames ? "-blockreservedweight" : "block_reserved_weight",
      41         [ -  + ]:           2 :                                             *options.block_reserved_weight, MAX_BLOCK_WEIGHT))};
      42                 :             :     }
      43         [ +  + ]:       51819 :     if (*options.block_max_weight > MAX_BLOCK_WEIGHT) {
      44         [ +  - ]:           2 :         return Error{Untranslated(strprintf("%s (%d) exceeds consensus maximum block weight (%d)",
      45         [ -  + ]:           1 :                                             use_argnames ? "-blockmaxweight" : "block_max_weight",
      46         [ -  + ]:           2 :                                             *options.block_max_weight, MAX_BLOCK_WEIGHT))};
      47                 :             :     }
      48         [ +  + ]:       51818 :     if (*options.block_reserved_weight > *options.block_max_weight) {
      49         [ +  - ]:           4 :         return Error{Untranslated(strprintf("%s (%d) exceeds %s (%d)",
      50                 :           2 :                                             use_argnames ? "-blockreservedweight" : "block_reserved_weight",
      51                 :           2 :                                             *options.block_reserved_weight,
      52         [ +  + ]:           2 :                                             use_argnames ? "-blockmaxweight" : "block_max_weight",
      53         [ +  + ]:           4 :                                             *options.block_max_weight))};
      54                 :             :     }
      55         [ -  + ]:       51816 :     if (options.coinbase_output_max_additional_sigops > MAX_BLOCK_SIGOPS_COST) {
      56         [ #  # ]:           0 :         return Error{Untranslated(strprintf("%s (%zu) exceeds consensus maximum block sigops cost (%d)",
      57                 :             :                                             "coinbase_output_max_additional_sigops",
      58                 :           0 :                                             options.coinbase_output_max_additional_sigops, MAX_BLOCK_SIGOPS_COST))};
      59                 :             :     }
      60                 :       51816 :     return {};
      61                 :             : }
      62                 :             : 
      63                 :        3106 : Result<BlockCreateOptions> ReadMiningArgs(const ArgsManager& args)
      64                 :             : {
      65                 :        3106 :     BlockCreateOptions options;
      66   [ +  -  +  -  :        6212 :     if (const auto arg{args.GetArg("-blockmintxfee")}) {
                   +  + ]
      67         [ +  - ]:          24 :         std::optional<CAmount> block_min_tx_fee{ParseMoney(*arg)};
      68   [ -  +  -  -  :          24 :         if (!block_min_tx_fee) return Error{AmountErrMsg("blockmintxfee", *arg)};
                   -  - ]
      69         [ -  + ]:        3130 :         options.block_min_fee_rate = CFeeRate{*block_min_tx_fee};
      70                 :           0 :     }
      71                 :             : 
      72   [ +  -  +  -  :        6212 :     if (const auto arg{args.GetBoolArg("-printpriority")}) options.print_modified_fee = *arg;
                   +  + ]
      73                 :             : 
      74   [ +  -  +  - ]:        3106 :     options.block_reserved_weight = args.GetArg<uint64_t>("-blockreservedweight");
      75   [ +  -  +  - ]:        3106 :     options.block_max_weight = args.GetArg<uint64_t>("-blockmaxweight");
      76                 :             : 
      77   [ +  -  +  +  :        6220 :     if (auto result{CheckMiningOptions(options, /*use_argnames=*/true)}; !result) return Error{util::ErrorString(result)};
                   +  - ]
      78                 :        3102 :     return options;
      79                 :        3106 : }
      80                 :             : 
      81                 :      100560 : BlockCreateOptions FlattenMiningOptions(BlockCreateOptions options)
      82                 :             : {
      83         [ +  + ]:      100560 :     if (!options.block_min_fee_rate) options.block_min_fee_rate = CFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
      84         [ +  + ]:      100560 :     if (!options.print_modified_fee) options.print_modified_fee = DEFAULT_PRINT_MODIFIED_FEE;
      85         [ +  + ]:      100560 :     if (!options.block_reserved_weight) options.block_reserved_weight = DEFAULT_BLOCK_RESERVED_WEIGHT;
      86         [ +  + ]:      100560 :     if (!options.block_max_weight) options.block_max_weight = DEFAULT_BLOCK_MAX_WEIGHT;
      87                 :      100560 :     return options;
      88                 :             : }
      89                 :             : 
      90                 :       48652 : BlockCreateOptions MergeMiningOptions(BlockCreateOptions x, const BlockCreateOptions& y)
      91                 :             : {
      92         [ +  - ]:       48652 :     if (!x.block_min_fee_rate) x.block_min_fee_rate = y.block_min_fee_rate;
      93         [ +  - ]:       48652 :     if (!x.print_modified_fee) x.print_modified_fee = y.print_modified_fee;
      94         [ +  - ]:       48652 :     if (!x.block_reserved_weight) x.block_reserved_weight = y.block_reserved_weight;
      95         [ +  + ]:       48652 :     if (!x.block_max_weight) x.block_max_weight = y.block_max_weight;
      96                 :       48652 :     return x;
      97                 :             : }
      98                 :             : 
      99                 :             : } // namespace node
        

Generated by: LCOV version 2.0-1