Bitcoin Core 31.99.0
P2P Digital Currency
estimator_args.cpp
Go to the documentation of this file.
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
6
7#include <common/args.h>
8#include <util/log.h>
9
10#include <system_error>
11
12namespace {
13constexpr const char* FEES_BASE_DIR{"fees"};
14constexpr const char* BLOCK_POLICY_ESTIMATES_FILENAME{"block_policy_estimates.dat"};
15constexpr const char* LEGACY_FEE_ESTIMATES_FILENAME{"fee_estimates.dat"};
16constexpr const char* MEMPOOL_POLICY_ESTIMATOR_FILENAME{"mempool_policy_estimator.dat"};
17
18fs::path LegacyFeeEstPath(const ArgsManager& argsman)
19{
20 return argsman.GetDataDirNet() / LEGACY_FEE_ESTIMATES_FILENAME;
21}
22} // namespace
23
25{
26 const fs::path legacy_path{LegacyFeeEstPath(argsman)};
27 const fs::path block_policy_path{BlockPolicyFeeEstPath(argsman)};
28 if (!fs::exists(legacy_path)) return;
29 std::error_code error;
30 if (fs::exists(block_policy_path)) {
31 fs::remove(legacy_path, error);
32 if (error) {
33 LogWarning("Failed to remove legacy fee estimates file %s: %s. Continuing anyway.", fs::PathToString(legacy_path), error.message());
34 return;
35 }
36 LogInfo("Removed legacy fee estimates file %s.", fs::PathToString(legacy_path));
37 return;
38 }
39 fs::create_directories(block_policy_path.parent_path(), error);
40 if (error) {
41 LogWarning("Failed to create block policy fee estimates directory %s: %s. Continuing without migration.", fs::PathToString(block_policy_path.parent_path()), error.message());
42 return;
43 }
44 fs::rename(legacy_path, block_policy_path, error);
45 if (error) {
46 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 return;
48 }
49 LogInfo("Migrated fee estimates from %s to %s.", fs::PathToString(legacy_path), fs::PathToString(block_policy_path));
50}
51
52fs::path BlockPolicyFeeEstPath(const ArgsManager& argsman)
53{
54 return argsman.GetDataDirNet() / FEES_BASE_DIR / BLOCK_POLICY_ESTIMATES_FILENAME;
55}
56
58{
59 return argsman.GetDataDirNet() / FEES_BASE_DIR / MEMPOOL_POLICY_ESTIMATOR_FILENAME;
60}
fs::path GetDataDirNet() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Get data directory path with appended network identifier.
Definition: args.cpp:328
fs::path MempoolPolicyEstimatorPath(const ArgsManager &argsman)
void MaybeMigrateLegacyFeeEstimates(const ArgsManager &argsman)
Move a legacy fee_estimates.dat file to the current block policy fee estimator path,...
fs::path BlockPolicyFeeEstPath(const ArgsManager &argsman)
static bool exists(const path &p)
Definition: fs.h:96
static std::string PathToString(const path &path)
Convert path object to a byte string.
Definition: fs.h:162
#define LogWarning(...)
Definition: log.h:126
#define LogInfo(...)
Definition: log.h:125