From c2fddcaf87c4870a0ef4734284ee2872d9c83465 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Tue, 20 Feb 2024 08:06:06 -0500 Subject: [PATCH 1/2] cleanup: document magic number in fee_estimates.dat --- src/txmempool.cpp | 2 +- src/txmempool.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 1ecc59904..7d1a68a8b 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -890,7 +890,7 @@ CTxMemPool::WriteFeeEstimates(CAutoFile& fileout) const { try { LOCK(cs); - fileout << 139900; // version required to read: 0.13.99 or later + fileout << FEEFILE_MIN_BACKCOMPAT_VERSION; fileout << CLIENT_VERSION; // version that wrote the file minerPolicyEstimator->Write(fileout); } diff --git a/src/txmempool.h b/src/txmempool.h index 28510dabd..7243a656a 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -31,6 +31,11 @@ class CAutoFile; class CBlockIndex; +/** Minimum client version required to read fee_estimates.dat + * Clients with a lower version than this should ignore the file + */ +static const int FEEFILE_MIN_BACKCOMPAT_VERSION = 139900; // 0.13.99.0 + inline double AllowFreeThreshold() { return COIN * 144 / 250; From 7f3f0117f63f6dbaca43595b17ea54a5c88bf892 Mon Sep 17 00:00:00 2001 From: Patrick Lodder Date: Tue, 20 Feb 2024 09:03:47 -0500 Subject: [PATCH 2/2] mempool: ignore fee estimate files from older versions Do not load fee estimate files from before 1.14.7, because the previous min, max and spacing parametrization will override the newly introduced values from 35c29109 --- src/txmempool.cpp | 10 ++++++++++ src/txmempool.h | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 7d1a68a8b..fe8e68fd1 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -909,6 +909,16 @@ CTxMemPool::ReadFeeEstimates(CAutoFile& filein) filein >> nVersionRequired >> nVersionThatWrote; if (nVersionRequired > CLIENT_VERSION) return error("CTxMemPool::ReadFeeEstimates(): up-version (%d) fee estimate file", nVersionRequired); + + /* From 1.14.7, only accept fee estimate files created by a version equal to or higher than the + * minimum writer version. + * + * If in the future any of the MIN_FEERATE, MAX_FEERATE or FEE_SPACING in policy/fees.h change, + * or these values become configurable, this logic will need to be adapted. */ + if (nVersionThatWrote < FEEFILE_MIN_COMPAT_VERSION_WRITER) { + return error("CTxMemPool::ReadFeeEstimates(): cannot re-use fee estimate files from version %d, ignoring file (non-fatal)", nVersionThatWrote); + } + LOCK(cs); minerPolicyEstimator->Read(filein, nVersionThatWrote); } diff --git a/src/txmempool.h b/src/txmempool.h index 7243a656a..a0251f1e3 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -34,7 +34,15 @@ class CBlockIndex; /** Minimum client version required to read fee_estimates.dat * Clients with a lower version than this should ignore the file */ -static const int FEEFILE_MIN_BACKCOMPAT_VERSION = 139900; // 0.13.99.0 +static const int FEEFILE_MIN_BACKCOMPAT_VERSION = 1140700; // 1.14.7.0 + +/** Minimum client version required to read fee_estimates.dat + * Files created with a lower version than this are ignored + * + * Due to bucket spacing and min/max changes in 1.14.7, set this + * to 1.14.7.0 exactly. + */ +static const int FEEFILE_MIN_COMPAT_VERSION_WRITER = 1140700; // 1.14.7.0 inline double AllowFreeThreshold() {