Browse Source

Read and Write fee estimate file directly from CBlockPolicyEstimator

0.15
Alex Morcos 8 years ago
parent
commit
5ba81e54e0
  1. 5
      src/init.cpp
  2. 28
      src/policy/fees.cpp
  3. 6
      src/policy/fees.h
  4. 34
      src/txmempool.cpp
  5. 4
      src/txmempool.h

5
src/init.cpp

@ -25,6 +25,7 @@
#include "netbase.h" #include "netbase.h"
#include "net.h" #include "net.h"
#include "net_processing.h" #include "net_processing.h"
#include "policy/fees.h"
#include "policy/policy.h" #include "policy/policy.h"
#include "rpc/server.h" #include "rpc/server.h"
#include "rpc/register.h" #include "rpc/register.h"
@ -215,7 +216,7 @@ void Shutdown()
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION); CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION);
if (!est_fileout.IsNull()) if (!est_fileout.IsNull())
mempool.WriteFeeEstimates(est_fileout); ::feeEstimator.Write(est_fileout);
else else
LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string()); LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
fFeeEstimatesInitialized = false; fFeeEstimatesInitialized = false;
@ -1550,7 +1551,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, CLIENT_VERSION); CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, CLIENT_VERSION);
// Allowed to fail as this file IS missing on first startup. // Allowed to fail as this file IS missing on first startup.
if (!est_filein.IsNull()) if (!est_filein.IsNull())
mempool.ReadFeeEstimates(est_filein); ::feeEstimator.Read(est_filein);
fFeeEstimatesInitialized = true; fFeeEstimatesInitialized = true;
// ********************************************************* Step 8: load wallet // ********************************************************* Step 8: load wallet

28
src/policy/fees.cpp

@ -7,6 +7,7 @@
#include "policy/policy.h" #include "policy/policy.h"
#include "amount.h" #include "amount.h"
#include "clientversion.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
#include "random.h" #include "random.h"
#include "streams.h" #include "streams.h"
@ -173,7 +174,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
return median; return median;
} }
void TxConfirmStats::Write(CAutoFile& fileout) void TxConfirmStats::Write(CAutoFile& fileout) const
{ {
fileout << decay; fileout << decay;
fileout << buckets; fileout << buckets;
@ -464,21 +465,40 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun
return CFeeRate(median); return CFeeRate(median);
} }
void CBlockPolicyEstimator::Write(CAutoFile& fileout) bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const
{ {
try {
LOCK(cs_feeEstimator); LOCK(cs_feeEstimator);
fileout << 139900; // version required to read: 0.13.99 or later
fileout << CLIENT_VERSION; // version that wrote the file
fileout << nBestSeenHeight; fileout << nBestSeenHeight;
feeStats.Write(fileout); feeStats.Write(fileout);
}
catch (const std::exception&) {
LogPrintf("CBlockPolicyEstimator::Write(): unable to read policy estimator data (non-fatal)\n");
return false;
}
return true;
} }
void CBlockPolicyEstimator::Read(CAutoFile& filein, int nFileVersion) bool CBlockPolicyEstimator::Read(CAutoFile& filein)
{ {
try {
LOCK(cs_feeEstimator); LOCK(cs_feeEstimator);
int nFileBestSeenHeight; int nVersionRequired, nVersionThatWrote, nFileBestSeenHeight;
filein >> nVersionRequired >> nVersionThatWrote;
if (nVersionRequired > CLIENT_VERSION)
return error("CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file", nVersionRequired);
filein >> nFileBestSeenHeight; filein >> nFileBestSeenHeight;
feeStats.Read(filein); feeStats.Read(filein);
nBestSeenHeight = nFileBestSeenHeight; nBestSeenHeight = nFileBestSeenHeight;
// if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored. // if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored.
}
catch (const std::exception&) {
LogPrintf("CBlockPolicyEstimator::Read(): unable to read policy estimator data (non-fatal)\n");
return false;
}
return true;
} }
FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee) FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee)

6
src/policy/fees.h

@ -156,7 +156,7 @@ public:
unsigned int GetMaxConfirms() const { return confAvg.size(); } unsigned int GetMaxConfirms() const { return confAvg.size(); }
/** Write state of estimation data to a file*/ /** Write state of estimation data to a file*/
void Write(CAutoFile& fileout); void Write(CAutoFile& fileout) const;
/** /**
* Read saved state of estimation data from a file and replace all internal data structures and * Read saved state of estimation data from a file and replace all internal data structures and
@ -226,10 +226,10 @@ public:
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool) const; CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool) const;
/** Write estimation data to a file */ /** Write estimation data to a file */
void Write(CAutoFile& fileout); bool Write(CAutoFile& fileout) const;
/** Read estimation data from a file */ /** Read estimation data from a file */
void Read(CAutoFile& filein, int nFileVersion); bool Read(CAutoFile& filein);
private: private:
CFeeRate minTrackedFee; //!< Passed to constructor to avoid dependency on main CFeeRate minTrackedFee; //!< Passed to constructor to avoid dependency on main

34
src/txmempool.cpp

@ -5,7 +5,6 @@
#include "txmempool.h" #include "txmempool.h"
#include "clientversion.h"
#include "consensus/consensus.h" #include "consensus/consensus.h"
#include "consensus/validation.h" #include "consensus/validation.h"
#include "validation.h" #include "validation.h"
@ -16,7 +15,6 @@
#include "util.h" #include "util.h"
#include "utilmoneystr.h" #include "utilmoneystr.h"
#include "utiltime.h" #include "utiltime.h"
#include "version.h"
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
int64_t _nTime, unsigned int _entryHeight, int64_t _nTime, unsigned int _entryHeight,
@ -843,38 +841,6 @@ TxMempoolInfo CTxMemPool::info(const uint256& hash) const
return GetInfo(i); return GetInfo(i);
} }
bool
CTxMemPool::WriteFeeEstimates(CAutoFile& fileout) const
{
try {
fileout << 139900; // version required to read: 0.13.99 or later
fileout << CLIENT_VERSION; // version that wrote the file
minerPolicyEstimator->Write(fileout);
}
catch (const std::exception&) {
LogPrintf("CTxMemPool::WriteFeeEstimates(): unable to write policy estimator data (non-fatal)\n");
return false;
}
return true;
}
bool
CTxMemPool::ReadFeeEstimates(CAutoFile& filein)
{
try {
int nVersionRequired, nVersionThatWrote;
filein >> nVersionRequired >> nVersionThatWrote;
if (nVersionRequired > CLIENT_VERSION)
return error("CTxMemPool::ReadFeeEstimates(): up-version (%d) fee estimate file", nVersionRequired);
minerPolicyEstimator->Read(filein, nVersionThatWrote);
}
catch (const std::exception&) {
LogPrintf("CTxMemPool::ReadFeeEstimates(): unable to read policy estimator data (non-fatal)\n");
return false;
}
return true;
}
void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta) void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
{ {
{ {

4
src/txmempool.h

@ -617,10 +617,6 @@ public:
TxMempoolInfo info(const uint256& hash) const; TxMempoolInfo info(const uint256& hash) const;
std::vector<TxMempoolInfo> infoAll() const; std::vector<TxMempoolInfo> infoAll() const;
/** Write/Read estimates to disk */
bool WriteFeeEstimates(CAutoFile& fileout) const;
bool ReadFeeEstimates(CAutoFile& filein);
size_t DynamicMemoryUsage() const; size_t DynamicMemoryUsage() const;
boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded; boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;

Loading…
Cancel
Save