10
10
#include < logging.h>
11
11
#include < streams.h>
12
12
#include < txmempool.h>
13
+ #include < util/serfloat.h>
13
14
#include < util/system.h>
14
15
15
16
static const char * FEE_ESTIMATES_FILENAME = " fee_estimates.dat" ;
@@ -26,6 +27,25 @@ std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
26
27
assert (false );
27
28
}
28
29
30
+ namespace {
31
+
32
+ struct EncodedDoubleFormatter
33
+ {
34
+ template <typename Stream> void Ser (Stream &s, double v)
35
+ {
36
+ s << EncodeDouble (v);
37
+ }
38
+
39
+ template <typename Stream> void Unser (Stream& s, double & v)
40
+ {
41
+ uint64_t encoded;
42
+ s >> encoded;
43
+ v = DecodeDouble (encoded);
44
+ }
45
+ };
46
+
47
+ } // namespace
48
+
29
49
/* *
30
50
* We will instantiate an instance of this class to track transactions that were
31
51
* included in a block. We will lump transactions into a bucket according to their
@@ -356,12 +376,12 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
356
376
357
377
void TxConfirmStats::Write (CAutoFile& fileout) const
358
378
{
359
- fileout << decay;
379
+ fileout << Using<EncodedDoubleFormatter>( decay) ;
360
380
fileout << scale;
361
- fileout << m_feerate_avg;
362
- fileout << txCtAvg;
363
- fileout << confAvg;
364
- fileout << failAvg;
381
+ fileout << Using<VectorFormatter<EncodedDoubleFormatter>>( m_feerate_avg) ;
382
+ fileout << Using<VectorFormatter<EncodedDoubleFormatter>>( txCtAvg) ;
383
+ fileout << Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>( confAvg) ;
384
+ fileout << Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>( failAvg) ;
365
385
}
366
386
367
387
void TxConfirmStats::Read (CAutoFile& filein, int nFileVersion, size_t numBuckets)
@@ -372,7 +392,7 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
372
392
size_t maxConfirms, maxPeriods;
373
393
374
394
// The current version will store the decay with each individual TxConfirmStats and also keep a scale factor
375
- filein >> decay;
395
+ filein >> Using<EncodedDoubleFormatter>( decay) ;
376
396
if (decay <= 0 || decay >= 1 ) {
377
397
throw std::runtime_error (" Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)" );
378
398
}
@@ -381,15 +401,15 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
381
401
throw std::runtime_error (" Corrupt estimates file. Scale must be non-zero" );
382
402
}
383
403
384
- filein >> m_feerate_avg;
404
+ filein >> Using<VectorFormatter<EncodedDoubleFormatter>>( m_feerate_avg) ;
385
405
if (m_feerate_avg.size () != numBuckets) {
386
406
throw std::runtime_error (" Corrupt estimates file. Mismatch in feerate average bucket count" );
387
407
}
388
- filein >> txCtAvg;
408
+ filein >> Using<VectorFormatter<EncodedDoubleFormatter>>( txCtAvg) ;
389
409
if (txCtAvg.size () != numBuckets) {
390
410
throw std::runtime_error (" Corrupt estimates file. Mismatch in tx count bucket count" );
391
411
}
392
- filein >> confAvg;
412
+ filein >> Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>( confAvg) ;
393
413
maxPeriods = confAvg.size ();
394
414
maxConfirms = scale * maxPeriods;
395
415
@@ -402,7 +422,7 @@ void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets
402
422
}
403
423
}
404
424
405
- filein >> failAvg;
425
+ filein >> Using<VectorFormatter<VectorFormatter<EncodedDoubleFormatter>>>( failAvg) ;
406
426
if (maxPeriods != failAvg.size ()) {
407
427
throw std::runtime_error (" Corrupt estimates file. Mismatch in confirms tracked for failures" );
408
428
}
@@ -884,7 +904,7 @@ bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const
884
904
else {
885
905
fileout << historicalFirst << historicalBest;
886
906
}
887
- fileout << buckets;
907
+ fileout << Using<VectorFormatter<EncodedDoubleFormatter>>( buckets) ;
888
908
feeStats->Write (fileout);
889
909
shortStats->Write (fileout);
890
910
longStats->Write (fileout);
@@ -920,7 +940,7 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
920
940
throw std::runtime_error (" Corrupt estimates file. Historical block range for estimates is invalid" );
921
941
}
922
942
std::vector<double > fileBuckets;
923
- filein >> fileBuckets;
943
+ filein >> Using<VectorFormatter<EncodedDoubleFormatter>>( fileBuckets) ;
924
944
size_t numBuckets = fileBuckets.size ();
925
945
if (numBuckets <= 1 || numBuckets > 1000 ) {
926
946
throw std::runtime_error (" Corrupt estimates file. Must have between 2 and 1000 feerate buckets" );
0 commit comments