|
7 | 7 | #include "policy/policy.h" |
8 | 8 |
|
9 | 9 | #include "amount.h" |
| 10 | +#include "clientversion.h" |
10 | 11 | #include "primitives/transaction.h" |
11 | 12 | #include "random.h" |
12 | 13 | #include "streams.h" |
@@ -173,7 +174,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal, |
173 | 174 | return median; |
174 | 175 | } |
175 | 176 |
|
176 | | -void TxConfirmStats::Write(CAutoFile& fileout) |
| 177 | +void TxConfirmStats::Write(CAutoFile& fileout) const |
177 | 178 | { |
178 | 179 | fileout << decay; |
179 | 180 | fileout << buckets; |
@@ -464,21 +465,40 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun |
464 | 465 | return CFeeRate(median); |
465 | 466 | } |
466 | 467 |
|
467 | | -void CBlockPolicyEstimator::Write(CAutoFile& fileout) |
| 468 | +bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const |
468 | 469 | { |
469 | | - LOCK(cs_feeEstimator); |
470 | | - fileout << nBestSeenHeight; |
471 | | - feeStats.Write(fileout); |
| 470 | + try { |
| 471 | + LOCK(cs_feeEstimator); |
| 472 | + fileout << 139900; // version required to read: 0.13.99 or later |
| 473 | + fileout << CLIENT_VERSION; // version that wrote the file |
| 474 | + fileout << nBestSeenHeight; |
| 475 | + feeStats.Write(fileout); |
| 476 | + } |
| 477 | + catch (const std::exception&) { |
| 478 | + LogPrintf("CBlockPolicyEstimator::Write(): unable to read policy estimator data (non-fatal)\n"); |
| 479 | + return false; |
| 480 | + } |
| 481 | + return true; |
472 | 482 | } |
473 | 483 |
|
474 | | -void CBlockPolicyEstimator::Read(CAutoFile& filein, int nFileVersion) |
| 484 | +bool CBlockPolicyEstimator::Read(CAutoFile& filein) |
475 | 485 | { |
476 | | - LOCK(cs_feeEstimator); |
477 | | - int nFileBestSeenHeight; |
478 | | - filein >> nFileBestSeenHeight; |
479 | | - feeStats.Read(filein); |
480 | | - nBestSeenHeight = nFileBestSeenHeight; |
481 | | - // if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored. |
| 486 | + try { |
| 487 | + LOCK(cs_feeEstimator); |
| 488 | + int nVersionRequired, nVersionThatWrote, nFileBestSeenHeight; |
| 489 | + filein >> nVersionRequired >> nVersionThatWrote; |
| 490 | + if (nVersionRequired > CLIENT_VERSION) |
| 491 | + return error("CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file", nVersionRequired); |
| 492 | + filein >> nFileBestSeenHeight; |
| 493 | + feeStats.Read(filein); |
| 494 | + nBestSeenHeight = nFileBestSeenHeight; |
| 495 | + // if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored. |
| 496 | + } |
| 497 | + catch (const std::exception&) { |
| 498 | + LogPrintf("CBlockPolicyEstimator::Read(): unable to read policy estimator data (non-fatal)\n"); |
| 499 | + return false; |
| 500 | + } |
| 501 | + return true; |
482 | 502 | } |
483 | 503 |
|
484 | 504 | FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee) |
|
0 commit comments