v29.4-roots.1 · Commit 3: [PATCH 03/13] 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. The two line-number columns refer to before and after.
src/policy/fees.cpp
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
#include <uint256.h>
|
|
20
20
|
#include <util/fs.h>
|
|
21
21
|
#include <util/serfloat.h>
|
|
22
|
+
#include <util/syserror.h>
|
|
22
23
|
#include <util/time.h>
|
|
23
24
|
|
|
24
25
|
#include <algorithm>
|
|
@@ -422,7 +423,6 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
|
|
|
422
423
|
// Read data file and do some very basic sanity checking
|
|
423
424
|
// buckets and bucketMap are not updated yet, so don't access them
|
|
424
425
|
// If there is a read failure, we'll just discard this entire object anyway
|
|
425
|
-
size_t maxConfirms, maxPeriods;
|
|
426
426
|
|
|
427
427
|
// The current version will store the decay with each individual TxConfirmStats and also keep a scale factor
|
|
428
428
|
filein >> Using<EncodedDoubleFormatter>(decay);
|
|
@@ -443,10 +443,9 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
|
|
|
443
443
|
throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
|
|
444
444
|
}
|
|
445
445
|
filein >> Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>(confAvg);
|
|
446
|
-
maxPeriods = confAvg.size();
|
|
447
|
-
maxConfirms = scale * maxPeriods;
|
|
446
|
+
const size_t maxPeriods = confAvg.size();
|
|
448
447
|
|
|
449
|
-
if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) { // one week
|
|
448
|
+
if (maxPeriods == 0 || scale > (6 * 24 * 7) / maxPeriods) { // one week
|
|
450
449
|
throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
|
|
451
450
|
}
|
|
452
451
|
for (unsigned int i = 0; i < maxPeriods; i++) {
|
|
@@ -469,6 +468,7 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
|
|
|
469
468
|
// to match the number of confirms and buckets
|
|
470
469
|
resizeInMemoryCounters(numBuckets);
|
|
471
470
|
|
|
471
|
+
const size_t maxConfirms = scale * maxPeriods;
|
|
472
472
|
LogDebug(BCLog::ESTIMATEFEE, "Reading estimates: %u buckets counting confirms up to %u blocks\n",
|
|
473
473
|
numBuckets, maxConfirms);
|
|
474
474
|
}
|
|
@@ -566,12 +566,12 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath
|
|
|
566
566
|
|
|
567
567
|
std::chrono::hours file_age = GetFeeEstimatorFileAge();
|
|
568
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));
|
|
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
570
|
return;
|
|
571
571
|
}
|
|
572
572
|
|
|
573
573
|
if (!Read(est_file)) {
|
|
574
|
-
LogPrintf("Failed to read fee estimates from %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath));
|
|
574
|
+
LogWarning("Failed to read fee estimates from %s. Continue anyway.", fs::PathToString(m_estimation_filepath));
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
|
|
@@ -615,7 +615,7 @@ void CBlockPolicyEstimator::processTransaction(const NewMempoolTransactionInfo&
|
|
|
615
615
|
// - the node is not behind
|
|
616
616
|
// - the transaction is not dependent on any other transactions in the mempool
|
|
617
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;
|
|
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
619
|
|
|
620
620
|
// Only want to be updating estimates when our blockchain is synced,
|
|
621
621
|
// otherwise we'll miscalculate how many blocks its taking to get included.
|
|
@@ -950,13 +950,19 @@ void CBlockPolicyEstimator::Flush() {
|
|
|
950
950
|
FlushFeeEstimates();
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
-
void CBlockPolicyEstimator::FlushFeeEstimates()
|
|
953
|
+
bool CBlockPolicyEstimator::FlushFeeEstimates() const
|
|
954
954
|
{
|
|
955
955
|
AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
|
|
956
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));
|
|
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;
|
|
958
963
|
} else {
|
|
959
964
|
LogPrintf("Flushed fee estimates to %s.\n", fs::PathToString(m_estimation_filepath.filename()));
|
|
965
|
+
return true;
|
|
960
966
|
}
|
|
961
967
|
}
|
|
962
968
|
|