Use unique_ptr:s for {fee,short,long}Stats (TxConfirmStats)

This commit is contained in:
practicalswift 2017-08-09 15:35:43 +02:00
parent 5a6f768896
commit fa6d1228e9
2 changed files with 12 additions and 18 deletions

View File

@ -548,16 +548,13 @@ CBlockPolicyEstimator::CBlockPolicyEstimator()
bucketMap[INF_FEERATE] = bucketIndex; bucketMap[INF_FEERATE] = bucketIndex;
assert(bucketMap.size() == buckets.size()); assert(bucketMap.size() == buckets.size());
feeStats = new TxConfirmStats(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE); feeStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats(buckets, bucketMap, MED_BLOCK_PERIODS, MED_DECAY, MED_SCALE));
shortStats = new TxConfirmStats(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE); shortStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats(buckets, bucketMap, SHORT_BLOCK_PERIODS, SHORT_DECAY, SHORT_SCALE));
longStats = new TxConfirmStats(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE); longStats = std::unique_ptr<TxConfirmStats>(new TxConfirmStats(buckets, bucketMap, LONG_BLOCK_PERIODS, LONG_DECAY, LONG_SCALE));
} }
CBlockPolicyEstimator::~CBlockPolicyEstimator() CBlockPolicyEstimator::~CBlockPolicyEstimator()
{ {
delete feeStats;
delete shortStats;
delete longStats;
} }
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate) void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate)
@ -690,16 +687,16 @@ CFeeRate CBlockPolicyEstimator::estimateRawFee(int confTarget, double successThr
double sufficientTxs = SUFFICIENT_FEETXS; double sufficientTxs = SUFFICIENT_FEETXS;
switch (horizon) { switch (horizon) {
case FeeEstimateHorizon::SHORT_HALFLIFE: { case FeeEstimateHorizon::SHORT_HALFLIFE: {
stats = shortStats; stats = shortStats.get();
sufficientTxs = SUFFICIENT_TXS_SHORT; sufficientTxs = SUFFICIENT_TXS_SHORT;
break; break;
} }
case FeeEstimateHorizon::MED_HALFLIFE: { case FeeEstimateHorizon::MED_HALFLIFE: {
stats = feeStats; stats = feeStats.get();
break; break;
} }
case FeeEstimateHorizon::LONG_HALFLIFE: { case FeeEstimateHorizon::LONG_HALFLIFE: {
stats = longStats; stats = longStats.get();
break; break;
} }
default: { default: {
@ -1002,12 +999,9 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein)
} }
// Destroy old TxConfirmStats and point to new ones that already reference buckets and bucketMap // Destroy old TxConfirmStats and point to new ones that already reference buckets and bucketMap
delete feeStats; feeStats = std::move(fileFeeStats);
delete shortStats; shortStats = std::move(fileShortStats);
delete longStats; longStats = std::move(fileLongStats);
feeStats = fileFeeStats.release();
shortStats = fileShortStats.release();
longStats = fileLongStats.release();
nBestSeenHeight = nFileBestSeenHeight; nBestSeenHeight = nFileBestSeenHeight;
historicalFirst = nFileHistoricalFirst; historicalFirst = nFileHistoricalFirst;

View File

@ -245,9 +245,9 @@ private:
std::map<uint256, TxStatsInfo> mapMemPoolTxs; std::map<uint256, TxStatsInfo> mapMemPoolTxs;
/** Classes to track historical data on transaction confirmations */ /** Classes to track historical data on transaction confirmations */
TxConfirmStats* feeStats; std::unique_ptr<TxConfirmStats> feeStats;
TxConfirmStats* shortStats; std::unique_ptr<TxConfirmStats> shortStats;
TxConfirmStats* longStats; std::unique_ptr<TxConfirmStats> longStats;
unsigned int trackedTxs; unsigned int trackedTxs;
unsigned int untrackedTxs; unsigned int untrackedTxs;