Skip to content

Commit d94adc7

Browse files
committed
Merge bitcoin/bitcoin#29702: fees: Remove CLIENT_VERSION serialization
fa1c5cc fees: Log non-fatal errors as [warning], instead of info-level (MarcoFalke) ddddbac fees: Pin required version to 149900 (MarcoFalke) fa5126a fees: Pin "version that wrote" to 0 (MarcoFalke) Pull request description: Coupling the fees serialization with CLIENT_VERSION is problematic, because: * `CLIENT_VERSION` may change, even though the serialization format does not change. This is harmless, but still confusing. * If a serialization format change was backported (unlikely), it may lead to incorrect results. * `CLIENT_VERSION` is changed at a different time during the release process than any serialization format change. This is harmless for releases of Bitcoin Core, but may be confusing when using the development branch. * It is harder to reason about a global `CLIENT_VERSION` when changing the format, than to reason about a versioning local to the module. Fix all issues by pinning the current version number in the module locally. In the future it can then be modified locally to the module, if needed. ACKs for top commit: hodlinator: re-ACK fa1c5cc TheCharlatan: Re-ACK fa1c5cc Tree-SHA512: 93870176ed50cc5a734576d66398a6036b31632228a9e05db1fa5452229e35ba4126f003e7db246aeb9891764ed47bde4470c674ec2bce7fd3ddd97e43944627
2 parents 7290bc6 + fa1c5cc commit d94adc7

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/policy/fees.cpp

+20-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <policy/fees.h>
77

8-
#include <clientversion.h>
98
#include <common/system.h>
109
#include <consensus/amount.h>
1110
#include <kernel/mempool_entry.h>
@@ -32,6 +31,10 @@
3231
#include <stdexcept>
3332
#include <utility>
3433

34+
// The current format written, and the version required to read. Must be
35+
// increased to at least 289900+1 on the next breaking change.
36+
constexpr int CURRENT_FEES_FILE_VERSION{149900};
37+
3538
static constexpr double INF_FEERATE = 1e99;
3639

3740
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
@@ -168,7 +171,7 @@ class TxConfirmStats
168171
* Read saved state of estimation data from a file and replace all internal data structures and
169172
* variables with this state.
170173
*/
171-
void Read(AutoFile& filein, int nFileVersion, size_t numBuckets);
174+
void Read(AutoFile& filein, size_t numBuckets);
172175
};
173176

174177

@@ -414,7 +417,7 @@ void TxConfirmStats::Write(AutoFile& fileout) const
414417
fileout << Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>(failAvg);
415418
}
416419

417-
void TxConfirmStats::Read(AutoFile& filein, int nFileVersion, size_t numBuckets)
420+
void TxConfirmStats::Read(AutoFile& filein, size_t numBuckets)
418421
{
419422
// Read data file and do some very basic sanity checking
420423
// buckets and bucketMap are not updated yet, so don't access them
@@ -961,8 +964,8 @@ bool CBlockPolicyEstimator::Write(AutoFile& fileout) const
961964
{
962965
try {
963966
LOCK(m_cs_fee_estimator);
964-
fileout << 149900; // version required to read: 0.14.99 or later
965-
fileout << CLIENT_VERSION; // version that wrote the file
967+
fileout << CURRENT_FEES_FILE_VERSION;
968+
fileout << int{0}; // Unused dummy field. Written files may contain any value in [0, 289900]
966969
fileout << nBestSeenHeight;
967970
if (BlockSpan() > HistoricalBlockSpan()/2) {
968971
fileout << firstRecordedHeight << nBestSeenHeight;
@@ -976,7 +979,7 @@ bool CBlockPolicyEstimator::Write(AutoFile& fileout) const
976979
longStats->Write(fileout);
977980
}
978981
catch (const std::exception&) {
979-
LogPrintf("CBlockPolicyEstimator::Write(): unable to write policy estimator data (non-fatal)\n");
982+
LogWarning("Unable to write policy estimator data (non-fatal)");
980983
return false;
981984
}
982985
return true;
@@ -986,20 +989,20 @@ bool CBlockPolicyEstimator::Read(AutoFile& filein)
986989
{
987990
try {
988991
LOCK(m_cs_fee_estimator);
989-
int nVersionRequired, nVersionThatWrote;
990-
filein >> nVersionRequired >> nVersionThatWrote;
991-
if (nVersionRequired > CLIENT_VERSION) {
992-
throw std::runtime_error(strprintf("up-version (%d) fee estimate file", nVersionRequired));
992+
int nVersionRequired, dummy;
993+
filein >> nVersionRequired >> dummy;
994+
if (nVersionRequired > CURRENT_FEES_FILE_VERSION) {
995+
throw std::runtime_error{strprintf("File version (%d) too high to be read.", nVersionRequired)};
993996
}
994997

995998
// Read fee estimates file into temporary variables so existing data
996999
// structures aren't corrupted if there is an exception.
9971000
unsigned int nFileBestSeenHeight;
9981001
filein >> nFileBestSeenHeight;
9991002

1000-
if (nVersionRequired < 149900) {
1001-
LogPrintf("%s: incompatible old fee estimation data (non-fatal). Version: %d\n", __func__, nVersionRequired);
1002-
} else { // New format introduced in 149900
1003+
if (nVersionRequired < CURRENT_FEES_FILE_VERSION) {
1004+
LogWarning("Incompatible old fee estimation data (non-fatal). Version: %d", nVersionRequired);
1005+
} else { // nVersionRequired == CURRENT_FEES_FILE_VERSION
10031006
unsigned int nFileHistoricalFirst, nFileHistoricalBest;
10041007
filein >> nFileHistoricalFirst >> nFileHistoricalBest;
10051008
if (nFileHistoricalFirst > nFileHistoricalBest || nFileHistoricalBest > nFileBestSeenHeight) {
@@ -1015,9 +1018,9 @@ bool CBlockPolicyEstimator::Read(AutoFile& filein)
10151018
std::unique_ptr<TxConfirmStats> fileFeeStats(new TxConfirmStats(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE));
10161019
std::unique_ptr<TxConfirmStats> fileShortStats(new TxConfirmStats(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE));
10171020
std::unique_ptr<TxConfirmStats> fileLongStats(new TxConfirmStats(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE));
1018-
fileFeeStats->Read(filein, nVersionThatWrote, numBuckets);
1019-
fileShortStats->Read(filein, nVersionThatWrote, numBuckets);
1020-
fileLongStats->Read(filein, nVersionThatWrote, numBuckets);
1021+
fileFeeStats->Read(filein, numBuckets);
1022+
fileShortStats->Read(filein, numBuckets);
1023+
fileLongStats->Read(filein, numBuckets);
10211024

10221025
// Fee estimates file parsed correctly
10231026
// Copy buckets from file and refresh our bucketmap
@@ -1038,7 +1041,7 @@ bool CBlockPolicyEstimator::Read(AutoFile& filein)
10381041
}
10391042
}
10401043
catch (const std::exception& e) {
1041-
LogPrintf("CBlockPolicyEstimator::Read(): unable to read policy estimator data (non-fatal): %s\n",e.what());
1044+
LogWarning("Unable to read policy estimator data (non-fatal): %s", e.what());
10421045
return false;
10431046
}
10441047
return true;

0 commit comments

Comments
 (0)