LCOV - code coverage report
Current view: top level - src/policy/fees - estimator_args.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 39.3 % 28 11
Test Date: 2026-08-25 06:16:57 Functions: 100.0 % 4 4
Branches: 12.5 % 64 8

             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 <policy/fees/estimator_args.h>
       6                 :             : 
       7                 :             : #include <common/args.h>
       8                 :             : #include <util/log.h>
       9                 :             : 
      10                 :             : #include <system_error>
      11                 :             : 
      12                 :             : namespace {
      13                 :             : constexpr const char* FEES_BASE_DIR{"fees"};
      14                 :             : constexpr const char* BLOCK_POLICY_ESTIMATES_FILENAME{"block_policy_estimates.dat"};
      15                 :             : constexpr const char* LEGACY_FEE_ESTIMATES_FILENAME{"fee_estimates.dat"};
      16                 :             : constexpr const char* MEMPOOL_POLICY_ESTIMATOR_FILENAME{"mempool_policy_estimator.dat"};
      17                 :             : 
      18                 :           1 : fs::path LegacyFeeEstPath(const ArgsManager& argsman)
      19                 :             : {
      20         [ +  - ]:           3 :     return argsman.GetDataDirNet() / LEGACY_FEE_ESTIMATES_FILENAME;
      21                 :             : }
      22                 :             : } // namespace
      23                 :             : 
      24                 :           1 : void MaybeMigrateLegacyFeeEstimates(const ArgsManager& argsman)
      25                 :             : {
      26                 :           1 :     const fs::path legacy_path{LegacyFeeEstPath(argsman)};
      27         [ +  - ]:           1 :     const fs::path block_policy_path{BlockPolicyFeeEstPath(argsman)};
      28   [ +  -  -  + ]:           1 :     if (!fs::exists(legacy_path)) return;
      29         [ #  # ]:           0 :     std::error_code error;
      30   [ #  #  #  # ]:           0 :     if (fs::exists(block_policy_path)) {
      31                 :           0 :         fs::remove(legacy_path, error);
      32         [ #  # ]:           0 :         if (error) {
      33   [ #  #  #  #  :           0 :             LogWarning("Failed to remove legacy fee estimates file %s: %s. Continuing anyway.", fs::PathToString(legacy_path), error.message());
                   #  # ]
      34                 :           0 :             return;
      35                 :             :         }
      36   [ #  #  #  # ]:           0 :         LogInfo("Removed legacy fee estimates file %s.", fs::PathToString(legacy_path));
      37                 :           0 :         return;
      38                 :             :     }
      39   [ #  #  #  # ]:           0 :     fs::create_directories(block_policy_path.parent_path(), error);
      40         [ #  # ]:           0 :     if (error) {
      41   [ #  #  #  #  :           0 :         LogWarning("Failed to create block policy fee estimates directory %s: %s. Continuing without migration.", fs::PathToString(block_policy_path.parent_path()), error.message());
             #  #  #  # ]
      42                 :           0 :         return;
      43                 :             :     }
      44                 :           0 :     fs::rename(legacy_path, block_policy_path, error);
      45         [ #  # ]:           0 :     if (error) {
      46   [ #  #  #  #  :           0 :         LogWarning("Failed to migrate fee estimates from %s to %s: %s. Continuing with fresh estimates.", fs::PathToString(legacy_path), fs::PathToString(block_policy_path), error.message());
             #  #  #  # ]
      47                 :           0 :         return;
      48                 :             :     }
      49   [ #  #  #  #  :           0 :     LogInfo("Migrated fee estimates from %s to %s.", fs::PathToString(legacy_path), fs::PathToString(block_policy_path));
                   #  # ]
      50                 :           2 : }
      51                 :             : 
      52                 :           3 : fs::path BlockPolicyFeeEstPath(const ArgsManager& argsman)
      53                 :             : {
      54   [ +  -  +  - ]:          15 :     return argsman.GetDataDirNet() / FEES_BASE_DIR / BLOCK_POLICY_ESTIMATES_FILENAME;
      55                 :             : }
      56                 :             : 
      57                 :           3 : fs::path MempoolPolicyEstimatorPath(const ArgsManager& argsman)
      58                 :             : {
      59   [ +  -  +  - ]:          15 :     return argsman.GetDataDirNet() / FEES_BASE_DIR / MEMPOOL_POLICY_ESTIMATOR_FILENAME;
      60                 :             : }
        

Generated by: LCOV version 2.0-1