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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

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