Coverage Report

Created: 2026-09-14 20:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/tmp/bitcoin/src/policy/fees/estimator_args.cpp
Line
Count
Source
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
fs::path LegacyFeeEstPath(const ArgsManager& argsman)
19
1.07k
{
20
1.07k
    return argsman.GetDataDirNet() / LEGACY_FEE_ESTIMATES_FILENAME;
21
1.07k
}
22
} // namespace
23
24
void MaybeMigrateLegacyFeeEstimates(const ArgsManager& argsman)
25
1.07k
{
26
1.07k
    const fs::path legacy_path{LegacyFeeEstPath(argsman)};
27
1.07k
    const fs::path block_policy_path{BlockPolicyFeeEstPath(argsman)};
28
1.07k
    if (!fs::exists(legacy_path)) return;
29
3
    std::error_code error;
30
3
    if (fs::exists(block_policy_path)) {
31
1
        fs::remove(legacy_path, error);
32
1
        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
0
        }
36
1
        LogInfo("Removed legacy fee estimates file %s.", fs::PathToString(legacy_path));
37
1
        return;
38
1
    }
39
2
    fs::create_directories(block_policy_path.parent_path(), error);
40
2
    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
0
    }
44
2
    fs::rename(legacy_path, block_policy_path, error);
45
2
    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
0
    }
49
2
    LogInfo("Migrated fee estimates from %s to %s.", fs::PathToString(legacy_path), fs::PathToString(block_policy_path));
50
2
}
51
52
fs::path BlockPolicyFeeEstPath(const ArgsManager& argsman)
53
2.14k
{
54
2.14k
    return argsman.GetDataDirNet() / FEES_BASE_DIR / BLOCK_POLICY_ESTIMATES_FILENAME;
55
2.14k
}
56
57
fs::path MempoolPolicyEstimatorPath(const ArgsManager& argsman)
58
1.07k
{
59
1.07k
    return argsman.GetDataDirNet() / FEES_BASE_DIR / MEMPOOL_POLICY_ESTIMATOR_FILENAME;
60
1.07k
}