v29.4-roots.3 · Commit 3: [PATCH 03/30] policy: restore conservative relay and network controls
src/policy/fees.cpp
Before: src/policy/fees.cpp · After: src/policy/fees.cpp
File metadata
index e85b2f2caaa8c0aadc33d31129a6970567d1f16e..82448342f2d715874e3e472e84a40517794bae7c 100644
Download original patch · Release notes
Diff rows 1–76 of 76. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/policy/fees.cpp
CHANGED
|
@@ -19,6 +19,7 @@
|
|
| 19 |
#include <uint256.h>
|
| 20 |
#include <util/fs.h>
|
| 21 |
#include <util/serfloat.h>
|
|
|
|
| 22 |
#include <util/time.h>
|
| 23 |
|
| 24 |
#include <algorithm>
|
|
@@ -422,7 +423,6 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
|
|
| 422 |
// Read data file and do some very basic sanity checking
|
| 423 |
// buckets and bucketMap are not updated yet, so don't access them
|
| 424 |
// If there is a read failure, we'll just discard this entire object anyway
|
| 425 |
-
size_t maxConfirms, maxPeriods;
|
| 426 |
|
| 427 |
// The current version will store the decay with each individual TxConfirmStats and also keep a scale factor
|
| 428 |
filein >> Using<EncodedDoubleFormatter>(decay);
|
|
@@ -443,10 +443,9 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
|
|
| 443 |
throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
|
| 444 |
}
|
| 445 |
filein >> Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>(confAvg);
|
| 446 |
-
maxPeriods = confAvg.size();
|
| 447 |
-
maxConfirms = scale * maxPeriods;
|
| 448 |
|
| 449 |
-
if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) { // one week
|
| 450 |
throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
|
| 451 |
}
|
| 452 |
for (unsigned int i = 0; i < maxPeriods; i++) {
|
|
@@ -469,6 +468,7 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
|
|
| 469 |
// to match the number of confirms and buckets
|
| 470 |
resizeInMemoryCounters(numBuckets);
|
| 471 |
|
|
|
|
| 472 |
LogDebug(BCLog::ESTIMATEFEE, "Reading estimates: %u buckets counting confirms up to %u blocks\n",
|
| 473 |
numBuckets, maxConfirms);
|
| 474 |
}
|
|
@@ -566,12 +566,12 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath
|
|
| 566 |
|
| 567 |
std::chrono::hours file_age = GetFeeEstimatorFileAge();
|
| 568 |
if (file_age > MAX_FILE_AGE && !read_stale_estimates) {
|
| 569 |
-
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));
|
| 570 |
return;
|
| 571 |
}
|
| 572 |
|
| 573 |
if (!Read(est_file)) {
|
| 574 |
-
LogPrintf("Failed to read fee estimates from %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath));
|
| 575 |
}
|
| 576 |
}
|
| 577 |
|
|
@@ -615,7 +615,7 @@ void CBlockPolicyEstimator::processTransaction(const NewMempoolTransactionInfo&
|
|
| 615 |
// - the node is not behind
|
| 616 |
// - the transaction is not dependent on any other transactions in the mempool
|
| 617 |
// - it's not part of a package.
|
| 618 |
-
const bool validForFeeEstimation = !tx.m_mempool_limit_bypassed && !tx.m_submitted_in_package && tx.m_chainstate_is_current && tx.m_has_no_mempool_parents;
|
| 619 |
|
| 620 |
// Only want to be updating estimates when our blockchain is synced,
|
| 621 |
// otherwise we'll miscalculate how many blocks its taking to get included.
|
|
@@ -950,13 +950,19 @@ void CBlockPolicyEstimator::Flush() {
|
|
| 950 |
FlushFeeEstimates();
|
| 951 |
}
|
| 952 |
|
| 953 |
-
void CBlockPolicyEstimator::FlushFeeEstimates()
|
| 954 |
{
|
| 955 |
AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
|
| 956 |
if (est_file.IsNull() || !Write(est_file)) {
|
| 957 |
-
LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 958 |
} else {
|
| 959 |
LogPrintf("Flushed fee estimates to %s.\n", fs::PathToString(m_estimation_filepath.filename()));
|
|
|
|
| 960 |
}
|
| 961 |
}
|
| 962 |
|
|
|
|
| 19 |
#include <uint256.h>
|
| 20 |
#include <util/fs.h>
|
| 21 |
#include <util/serfloat.h>
|
| 22 |
+
#include <util/syserror.h>
|
| 23 |
#include <util/time.h>
|
| 24 |
|
| 25 |
#include <algorithm>
|
|
|
|
| 423 |
// Read data file and do some very basic sanity checking
|
| 424 |
// buckets and bucketMap are not updated yet, so don't access them
|
| 425 |
// If there is a read failure, we'll just discard this entire object anyway
|
|
|
|
| 426 |
|
| 427 |
// The current version will store the decay with each individual TxConfirmStats and also keep a scale factor
|
| 428 |
filein >> Using<EncodedDoubleFormatter>(decay);
|
|
|
|
| 443 |
throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
|
| 444 |
}
|
| 445 |
filein >> Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>(confAvg);
|
| 446 |
+
const size_t maxPeriods = confAvg.size();
|
|
|
|
| 447 |
|
| 448 |
+
if (maxPeriods == 0 || scale > (6 * 24 * 7) / maxPeriods) { // one week
|
| 449 |
throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
|
| 450 |
}
|
| 451 |
for (unsigned int i = 0; i < maxPeriods; i++) {
|
|
|
|
| 468 |
// to match the number of confirms and buckets
|
| 469 |
resizeInMemoryCounters(numBuckets);
|
| 470 |
|
| 471 |
+
const size_t maxConfirms = scale * maxPeriods;
|
| 472 |
LogDebug(BCLog::ESTIMATEFEE, "Reading estimates: %u buckets counting confirms up to %u blocks\n",
|
| 473 |
numBuckets, maxConfirms);
|
| 474 |
}
|
|
|
|
| 566 |
|
| 567 |
std::chrono::hours file_age = GetFeeEstimatorFileAge();
|
| 568 |
if (file_age > MAX_FILE_AGE && !read_stale_estimates) {
|
| 569 |
+
LogWarning("Fee estimation file %s too old (age=%lld > %lld hours) and will not be used to avoid serving stale estimates.", fs::PathToString(m_estimation_filepath), Ticks<std::chrono::hours>(file_age), Ticks<std::chrono::hours>(MAX_FILE_AGE));
|
| 570 |
return;
|
| 571 |
}
|
| 572 |
|
| 573 |
if (!Read(est_file)) {
|
| 574 |
+
LogWarning("Failed to read fee estimates from %s. Continue anyway.", fs::PathToString(m_estimation_filepath));
|
| 575 |
}
|
| 576 |
}
|
| 577 |
|
|
|
|
| 615 |
// - the node is not behind
|
| 616 |
// - the transaction is not dependent on any other transactions in the mempool
|
| 617 |
// - it's not part of a package.
|
| 618 |
+
const bool validForFeeEstimation = tx.m_ignore_rejects.empty() && !tx.m_submitted_in_package && tx.m_chainstate_is_current && tx.m_has_no_mempool_parents;
|
| 619 |
|
| 620 |
// Only want to be updating estimates when our blockchain is synced,
|
| 621 |
// otherwise we'll miscalculate how many blocks its taking to get included.
|
|
|
|
| 950 |
FlushFeeEstimates();
|
| 951 |
}
|
| 952 |
|
| 953 |
+
bool CBlockPolicyEstimator::FlushFeeEstimates() const
|
| 954 |
{
|
| 955 |
AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
|
| 956 |
if (est_file.IsNull() || !Write(est_file)) {
|
| 957 |
+
LogWarning("Failed to write fee estimates to %s. Continue anyway.", fs::PathToString(m_estimation_filepath));
|
| 958 |
+
(void)est_file.fclose();
|
| 959 |
+
return false;
|
| 960 |
+
} else if (est_file.fclose() != 0) {
|
| 961 |
+
LogWarning("Failed to close fee estimates file %s: %s. Continuing anyway.", fs::PathToString(m_estimation_filepath), SysErrorString(errno));
|
| 962 |
+
return false;
|
| 963 |
} else {
|
| 964 |
LogPrintf("Flushed fee estimates to %s.\n", fs::PathToString(m_estimation_filepath.filename()));
|
| 965 |
+
return true;
|
| 966 |
}
|
| 967 |
}
|
| 968 |
|