diff options
author | fanquake <fanquake@gmail.com> | 2023-10-06 11:18:45 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-10-06 11:36:51 +0100 |
commit | 1416d09cbabe80e57b8dad334d9571c2e8f2006e (patch) | |
tree | 8b5d071eb5069c9905abf4e87bbdf2b8b9868b67 /src/policy/fees.cpp | |
parent | 0df8f98d654291c08b9fe6cb11ec1685828f1504 (diff) | |
parent | 9077f214f55386af12419235deaff52b23446856 (diff) |
Merge bitcoin/bitcoin#28535: [24.x] Further backports
9077f214f55386af12419235deaff52b23446856 depends: fix unusable memory_resource in macos qt build (fanquake)
dccacf0bf7d5815036c64d4c040b5702ad890cd8 build, macos: Fix `qt` package build with new Xcode 15 linker (Hennadii Stepanov)
43596499b2c2b8cc0a51c0b9db9153047c266627 ci: Switch to `amd64` container in "ARM" task (Hennadii Stepanov)
805f98b79aa9e5ecda70516578296bd0a065a707 ci: Nuke Android APK task, Use credits for tsan (MarcoFalke)
cb5512da2336c9145a670c287f1abecc372906b9 test: ensure old fee_estimate.dat not read on restart and flushed (ismaelsadeeq)
01f8ee48efc1f46563f2841c0a7125b20b0df159 tx fees, policy: read stale fee estimates with a regtest-only option (ismaelsadeeq)
1c98029b3913a99e7bfe563d8ded2a5074e75fa1 tx fees, policy: do not read estimates of old fee_estimates.dat (ismaelsadeeq)
77979e0172d0bc86bfbc60f6a652e26c77722e29 tx fees, policy: periodically flush fee estimates to fee_estimates.dat (ismaelsadeeq)
67b6d99aead0d1b2030bc3e88256d279477894b5 Do not use std::vector = {} to release memory (Pieter Wuille)
defdc1502372863f700720e8d5cde69190371a64 ci: Use podman stop over podman kill (MarcoFalke)
7f1357de5136bd6f80758f1f31e6dba21acb9954 ci: Use podman for persistent workers (MarcoFalke)
0db69a3d500020e11fd67c55732e0d02eb606204 ci: Prune dangling images on RESTART_CI_DOCKER_BEFORE_RUN (MarcoFalke)
Pull request description:
Backports to the 24.x branch. Currently:
* https://github.com/bitcoin/bitcoin/pull/27622
* https://github.com/bitcoin/bitcoin/pull/27777
* https://github.com/bitcoin/bitcoin/pull/27834
* https://github.com/bitcoin/bitcoin/pull/27844
* https://github.com/bitcoin/bitcoin/pull/27886
* https://github.com/bitcoin/bitcoin/pull/28452
* https://github.com/bitcoin/bitcoin/pull/28543
* https://github.com/bitcoin/bitcoin/pull/28571
ACKs for top commit:
stickies-v:
ACK 9077f214f5
Tree-SHA512: abaafc9a048b67b494993134fd332457ea52695ec007b963c283f962ec40c3b6b3a7e98407481be55d3271a595088a0281cc84b79dad4f24d260381ea0153076
Diffstat (limited to 'src/policy/fees.cpp')
-rw-r--r-- | src/policy/fees.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 2b940be07e..54b63a5aa6 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -24,6 +24,7 @@ #include <algorithm> #include <cassert> +#include <chrono> #include <cmath> #include <cstddef> #include <cstdint> @@ -527,7 +528,7 @@ bool CBlockPolicyEstimator::_removeTx(const uint256& hash, bool inBlock) } } -CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath) +CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath, const bool read_stale_estimates) : m_estimation_filepath{estimation_filepath}, nBestSeenHeight{0}, firstRecordedHeight{0}, historicalFirst{0}, historicalBest{0}, trackedTxs{0}, untrackedTxs{0} { static_assert(MIN_BUCKET_FEERATE > 0, "Min feerate must be nonzero"); @@ -545,9 +546,22 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath shortStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE)); longStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE)); - // If the fee estimation file is present, read recorded estimations AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "rb")}; - if (est_file.IsNull() || !Read(est_file)) { + + // Whenever the fee estimation file is not present return early + if (est_file.IsNull()) { + LogPrintf("%s is not found. Continue anyway.\n", fs::PathToString(m_estimation_filepath)); + return; + } + + std::chrono::hours file_age = GetFeeEstimatorFileAge(); + // fee estimate file must not be too old to avoid wrong fee estimates. + if (file_age > MAX_FILE_AGE && !read_stale_estimates) { + LogPrintf("Fee estimation file %s too old (age=%lld > %lld hours) and will not be used to avoid serving stale estimates.\n", fs::PathToString(m_estimation_filepath), Ticks<std::chrono::hours>(file_age), Ticks<std::chrono::hours>(MAX_FILE_AGE)); + return; + } + + if (!Read(est_file)) { LogPrintf("Failed to read fee estimates from %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath)); } } @@ -903,10 +917,16 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, FeeCalculation void CBlockPolicyEstimator::Flush() { FlushUnconfirmed(); + FlushFeeEstimates(); +} +void CBlockPolicyEstimator::FlushFeeEstimates() +{ AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")}; if (est_file.IsNull() || !Write(est_file)) { LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath)); + } else { + LogPrintf("Flushed fee estimates to %s.\n", fs::PathToString(m_estimation_filepath.filename())); } } @@ -1010,6 +1030,13 @@ void CBlockPolicyEstimator::FlushUnconfirmed() { LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n", num_entries, (endclear - startclear)*0.000001); } +std::chrono::hours CBlockPolicyEstimator::GetFeeEstimatorFileAge() +{ + auto file_time = std::filesystem::last_write_time(m_estimation_filepath); + auto now = std::filesystem::file_time_type::clock::now(); + return std::chrono::duration_cast<std::chrono::hours>(now - file_time); +} + FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee) { CAmount minFeeLimit = std::max(CAmount(1), minIncrementalFee.GetFeePerK() / 2); |