Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3

src/policy/fees.cpp

Before: src/policy/fees.cpp · After: src/policy/fees.cpp

File metadata
index a650a1326b0afc88f30783fa06d5761fae153242..da3962ca0e5dbf2e0b46d344181e0b0c1bda96cf 100644

Download original patch · Release notes

Diff rows 1–72 of 72. 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
@@ -423,7 +423,6 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
423
423
  // Read data file and do some very basic sanity checking
424
424
  // buckets and bucketMap are not updated yet, so don't access them
425
425
  // If there is a read failure, we'll just discard this entire object anyway
426
- size_t maxConfirms, maxPeriods;
427
426
 
428
427
  // The current version will store the decay with each individual TxConfirmStats and also keep a scale factor
429
428
  filein >> Using<EncodedDoubleFormatter>(decay);
@@ -444,10 +443,9 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
444
443
  throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
445
444
  }
446
445
  filein >> Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>(confAvg);
447
- maxPeriods = confAvg.size();
448
- maxConfirms = scale * maxPeriods;
446
+ const size_t maxPeriods = confAvg.size();
449
447
 
450
- if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) { // one week
448
+ if (maxPeriods == 0 || scale > (6 * 24 * 7) / maxPeriods) { // one week
451
449
  throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
452
450
  }
453
451
  for (unsigned int i = 0; i < maxPeriods; i++) {
@@ -470,6 +468,7 @@ void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
470
468
  // to match the number of confirms and buckets
471
469
  resizeInMemoryCounters(numBuckets);
472
470
 
471
+ const size_t maxConfirms = scale * maxPeriods;
473
472
  LogDebug(BCLog::ESTIMATEFEE, "Reading estimates: %u buckets counting confirms up to %u blocks\n",
474
473
  numBuckets, maxConfirms);
475
474
  }
@@ -567,12 +566,12 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath
567
566
 
568
567
  std::chrono::hours file_age = GetFeeEstimatorFileAge();
569
568
  if (file_age > MAX_FILE_AGE && !read_stale_estimates) {
570
- 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));
571
570
  return;
572
571
  }
573
572
 
574
573
  if (!Read(est_file)) {
575
- 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));
576
575
  }
577
576
  }
578
577
 
@@ -616,7 +615,7 @@ void CBlockPolicyEstimator::processTransaction(const NewMempoolTransactionInfo&
616
615
  // - the node is not behind
617
616
  // - the transaction is not dependent on any other transactions in the mempool
618
617
  // - it's not part of a package.
619
- 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;
620
619
 
621
620
  // Only want to be updating estimates when our blockchain is synced,
622
621
  // otherwise we'll miscalculate how many blocks its taking to get included.
@@ -959,19 +958,20 @@ void CBlockPolicyEstimator::Flush() {
959
958
  FlushFeeEstimates();
960
959
  }
961
960
 
962
- void CBlockPolicyEstimator::FlushFeeEstimates()
961
+ bool CBlockPolicyEstimator::FlushFeeEstimates() const
963
962
  {
964
963
  AutoFile est_file{fsbridge::fopen(m_estimation_filepath, "wb")};
965
964
  if (est_file.IsNull() || !Write(est_file)) {
966
- LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(m_estimation_filepath));
965
+ LogWarning("Failed to write fee estimates to %s. Continue anyway.", fs::PathToString(m_estimation_filepath));
967
966
  (void)est_file.fclose();
968
- return;
967
+ return false;
969
968
  }
970
969
  if (est_file.fclose() != 0) {
971
970
  LogError("Failed to close fee estimates file %s: %s. Continuing anyway.", fs::PathToString(m_estimation_filepath), SysErrorString(errno));
972
- return;
971
+ return false;
973
972
  }
974
973
  LogInfo("Flushed fee estimates to %s.", fs::PathToString(m_estimation_filepath.filename()));
974
+ return true;
975
975
  }
976
976
 
977
977
  bool CBlockPolicyEstimator::Write(AutoFile& fileout) const