mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Read and Write fee estimate file directly from CBlockPolicyEstimator
This commit is contained in:
parent
14e10aa842
commit
5ba81e54e0
@ -25,6 +25,7 @@
|
||||
#include "netbase.h"
|
||||
#include "net.h"
|
||||
#include "net_processing.h"
|
||||
#include "policy/fees.h"
|
||||
#include "policy/policy.h"
|
||||
#include "rpc/server.h"
|
||||
#include "rpc/register.h"
|
||||
@ -215,7 +216,7 @@ void Shutdown()
|
||||
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
|
||||
CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION);
|
||||
if (!est_fileout.IsNull())
|
||||
mempool.WriteFeeEstimates(est_fileout);
|
||||
::feeEstimator.Write(est_fileout);
|
||||
else
|
||||
LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
|
||||
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);
|
||||
// Allowed to fail as this file IS missing on first startup.
|
||||
if (!est_filein.IsNull())
|
||||
mempool.ReadFeeEstimates(est_filein);
|
||||
::feeEstimator.Read(est_filein);
|
||||
fFeeEstimatesInitialized = true;
|
||||
|
||||
// ********************************************************* Step 8: load wallet
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "policy/policy.h"
|
||||
|
||||
#include "amount.h"
|
||||
#include "clientversion.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "random.h"
|
||||
#include "streams.h"
|
||||
@ -173,7 +174,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
|
||||
return median;
|
||||
}
|
||||
|
||||
void TxConfirmStats::Write(CAutoFile& fileout)
|
||||
void TxConfirmStats::Write(CAutoFile& fileout) const
|
||||
{
|
||||
fileout << decay;
|
||||
fileout << buckets;
|
||||
@ -464,21 +465,40 @@ CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoun
|
||||
return CFeeRate(median);
|
||||
}
|
||||
|
||||
void CBlockPolicyEstimator::Write(CAutoFile& fileout)
|
||||
bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const
|
||||
{
|
||||
LOCK(cs_feeEstimator);
|
||||
fileout << nBestSeenHeight;
|
||||
feeStats.Write(fileout);
|
||||
try {
|
||||
LOCK(cs_feeEstimator);
|
||||
fileout << 139900; // version required to read: 0.13.99 or later
|
||||
fileout << CLIENT_VERSION; // version that wrote the file
|
||||
fileout << nBestSeenHeight;
|
||||
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)
|
||||
{
|
||||
LOCK(cs_feeEstimator);
|
||||
int nFileBestSeenHeight;
|
||||
filein >> nFileBestSeenHeight;
|
||||
feeStats.Read(filein);
|
||||
nBestSeenHeight = nFileBestSeenHeight;
|
||||
// if nVersionThatWrote < 139900 then another TxConfirmStats (for priority) follows but can be ignored.
|
||||
try {
|
||||
LOCK(cs_feeEstimator);
|
||||
int nVersionRequired, nVersionThatWrote, nFileBestSeenHeight;
|
||||
filein >> nVersionRequired >> nVersionThatWrote;
|
||||
if (nVersionRequired > CLIENT_VERSION)
|
||||
return error("CBlockPolicyEstimator::Read(): up-version (%d) fee estimate file", nVersionRequired);
|
||||
filein >> nFileBestSeenHeight;
|
||||
feeStats.Read(filein);
|
||||
nBestSeenHeight = nFileBestSeenHeight;
|
||||
// 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)
|
||||
|
@ -156,7 +156,7 @@ public:
|
||||
unsigned int GetMaxConfirms() const { return confAvg.size(); }
|
||||
|
||||
/** 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
|
||||
@ -226,10 +226,10 @@ public:
|
||||
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool) const;
|
||||
|
||||
/** Write estimation data to a file */
|
||||
void Write(CAutoFile& fileout);
|
||||
bool Write(CAutoFile& fileout) const;
|
||||
|
||||
/** Read estimation data from a file */
|
||||
void Read(CAutoFile& filein, int nFileVersion);
|
||||
bool Read(CAutoFile& filein);
|
||||
|
||||
private:
|
||||
CFeeRate minTrackedFee; //!< Passed to constructor to avoid dependency on main
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include "txmempool.h"
|
||||
|
||||
#include "clientversion.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "validation.h"
|
||||
@ -16,7 +15,6 @@
|
||||
#include "util.h"
|
||||
#include "utilmoneystr.h"
|
||||
#include "utiltime.h"
|
||||
#include "version.h"
|
||||
|
||||
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
|
||||
int64_t _nTime, unsigned int _entryHeight,
|
||||
@ -843,38 +841,6 @@ TxMempoolInfo CTxMemPool::info(const uint256& hash) const
|
||||
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)
|
||||
{
|
||||
{
|
||||
|
@ -617,10 +617,6 @@ public:
|
||||
TxMempoolInfo info(const uint256& hash) const;
|
||||
std::vector<TxMempoolInfo> infoAll() const;
|
||||
|
||||
/** Write/Read estimates to disk */
|
||||
bool WriteFeeEstimates(CAutoFile& fileout) const;
|
||||
bool ReadFeeEstimates(CAutoFile& filein);
|
||||
|
||||
size_t DynamicMemoryUsage() const;
|
||||
|
||||
boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
|
||||
|
Loading…
Reference in New Issue
Block a user