PIVX Core  5.6.99
P2P Digital Currency
fees.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "policy/fees.h"
7 #include "policy/policy.h"
8 
10 #include "streams.h"
11 #include "txmempool.h"
12 #include "util/system.h"
13 
14 void TxConfirmStats::Initialize(std::vector<double>& defaultBuckets,
15  unsigned int maxConfirms, double _decay)
16 {
17  decay = _decay;
18  for (unsigned int i = 0; i < defaultBuckets.size(); i++) {
19  buckets.push_back(defaultBuckets[i]);
20  bucketMap[defaultBuckets[i]] = i;
21  }
22  confAvg.resize(maxConfirms);
23  curBlockConf.resize(maxConfirms);
24  unconfTxs.resize(maxConfirms);
25  for (unsigned int i = 0; i < maxConfirms; i++) {
26  confAvg[i].resize(buckets.size());
27  curBlockConf[i].resize(buckets.size());
28  unconfTxs[i].resize(buckets.size());
29  }
30 
31  oldUnconfTxs.resize(buckets.size());
32  curBlockTxCt.resize(buckets.size());
33  txCtAvg.resize(buckets.size());
34  curBlockVal.resize(buckets.size());
35  avg.resize(buckets.size());
36 }
37 
38 // Zero out the data for the current block
39 void TxConfirmStats::ClearCurrent(unsigned int nBlockHeight)
40 {
41  for (unsigned int j = 0; j < buckets.size(); j++) {
42  oldUnconfTxs[j] += unconfTxs[nBlockHeight%unconfTxs.size()][j];
43  unconfTxs[nBlockHeight%unconfTxs.size()][j] = 0;
44  for (unsigned int i = 0; i < curBlockConf.size(); i++)
45  curBlockConf[i][j] = 0;
46  curBlockTxCt[j] = 0;
47  curBlockVal[j] = 0;
48  }
49 }
50 
51 
52 void TxConfirmStats::Record(int blocksToConfirm, double val)
53 {
54  // blocksToConfirm is 1-based
55  if (blocksToConfirm < 1)
56  return;
57  unsigned int bucketindex = bucketMap.lower_bound(val)->second;
58  for (size_t i = blocksToConfirm; i <= curBlockConf.size(); i++) {
59  curBlockConf[i - 1][bucketindex]++;
60  }
61  curBlockTxCt[bucketindex]++;
62  curBlockVal[bucketindex] += val;
63 }
64 
66 {
67  for (unsigned int j = 0; j < buckets.size(); j++) {
68  for (unsigned int i = 0; i < confAvg.size(); i++)
69  confAvg[i][j] = confAvg[i][j] * decay + curBlockConf[i][j];
70  avg[j] = avg[j] * decay + curBlockVal[j];
71  txCtAvg[j] = txCtAvg[j] * decay + curBlockTxCt[j];
72  }
73 }
74 
75 // returns -1 on error conditions
76 double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
77  double successBreakPoint, bool requireGreater,
78  unsigned int nBlockHeight)
79 {
80  // Counters for a bucket (or range of buckets)
81  double nConf = 0; // Number of tx's confirmed within the confTarget
82  double totalNum = 0; // Total number of tx's that were ever confirmed
83  int extraNum = 0; // Number of tx's still in mempool for confTarget or longer
84 
85  int maxbucketindex = buckets.size() - 1;
86 
87  // requireGreater means we are looking for the lowest feerate such that all higher
88  // values pass, so we start at maxbucketindex (highest feerate) and look at succesively
89  // smaller buckets until we reach failure. Otherwise, we are looking for the highest
90  // feerate such that all lower values fail, and we go in the opposite direction.
91  unsigned int startbucket = requireGreater ? maxbucketindex : 0;
92  int step = requireGreater ? -1 : 1;
93 
94  // We'll combine buckets until we have enough samples.
95  // The near and far variables will define the range we've combined
96  // The best variables are the last range we saw which still had a high
97  // enough confirmation rate to count as success.
98  // The cur variables are the current range we're counting.
99  unsigned int curNearBucket = startbucket;
100  unsigned int bestNearBucket = startbucket;
101  unsigned int curFarBucket = startbucket;
102  unsigned int bestFarBucket = startbucket;
103 
104  bool foundAnswer = false;
105  unsigned int bins = unconfTxs.size();
106 
107  // Start counting from highest(default) or lowest feerate transactions
108  for (int bucket = startbucket; bucket >= 0 && bucket <= maxbucketindex; bucket += step) {
109  curFarBucket = bucket;
110  nConf += confAvg[confTarget - 1][bucket];
111  totalNum += txCtAvg[bucket];
112  for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
113  extraNum += unconfTxs[(nBlockHeight - confct)%bins][bucket];
114  extraNum += oldUnconfTxs[bucket];
115  // If we have enough transaction data points in this range of buckets,
116  // we can test for success
117  // (Only count the confirmed data points, so that each confirmation count
118  // will be looking at the same amount of data and same bucket breaks)
119  if (totalNum >= sufficientTxVal / (1 - decay)) {
120  double curPct = nConf / (totalNum + extraNum);
121 
122  // Check to see if we are no longer getting confirmed at the success rate
123  if (requireGreater && curPct < successBreakPoint)
124  break;
125  if (!requireGreater && curPct > successBreakPoint)
126  break;
127 
128  // Otherwise update the cumulative stats, and the bucket variables
129  // and reset the counters
130  else {
131  foundAnswer = true;
132  nConf = 0;
133  totalNum = 0;
134  extraNum = 0;
135  bestNearBucket = curNearBucket;
136  bestFarBucket = curFarBucket;
137  curNearBucket = bucket + step;
138  }
139  }
140  }
141 
142  double median = -1;
143  double txSum = 0;
144 
145  // Calculate the "average" feerate of the best bucket range that met success conditions
146  // Find the bucket with the median transaction and then report the average feerate from that bucket
147  // This is a compromise between finding the median which we can't since we don't save all tx's
148  // and reporting the average which is less accurate
149  unsigned int minBucket = bestNearBucket < bestFarBucket ? bestNearBucket : bestFarBucket;
150  unsigned int maxBucket = bestNearBucket > bestFarBucket ? bestNearBucket : bestFarBucket;
151  for (unsigned int j = minBucket; j <= maxBucket; j++) {
152  txSum += txCtAvg[j];
153  }
154  if (foundAnswer && txSum != 0) {
155  txSum = txSum / 2;
156  for (unsigned int j = minBucket; j <= maxBucket; j++) {
157  if (txCtAvg[j] < txSum)
158  txSum -= txCtAvg[j];
159  else { // we're in the right bucket
160  median = avg[j] / txCtAvg[j];
161  break;
162  }
163  }
164  }
165 
166  LogPrint(BCLog::ESTIMATEFEE, "%3d: For conf success %s %4.2f need feerate %s: %12.5g from buckets %8g - %8g Cur Bucket stats %6.2f%% %8.1f/(%.1f+%d mempool)\n",
167  confTarget, requireGreater ? ">" : "<", successBreakPoint,
168  requireGreater ? ">" : "<", median, buckets[minBucket], buckets[maxBucket],
169  100 * nConf / (totalNum + extraNum), nConf, totalNum, extraNum);
170 
171  return median;
172 }
173 
175 {
176  fileout << decay;
177  fileout << buckets;
178  fileout << avg;
179  fileout << txCtAvg;
180  fileout << confAvg;
181 }
182 
184 {
185  // Read data file into temporary variables and do some very basic sanity checking
186  std::vector<double> fileBuckets;
187  std::vector<double> fileAvg;
188  std::vector<std::vector<double> > fileConfAvg;
189  std::vector<double> fileTxCtAvg;
190  double fileDecay;
191  size_t maxConfirms;
192  size_t numBuckets;
193 
194  filein >> fileDecay;
195  if (fileDecay <= 0 || fileDecay >= 1)
196  throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
197  filein >> fileBuckets;
198  numBuckets = fileBuckets.size();
199  if (numBuckets <= 1 || numBuckets > 1000)
200  throw std::runtime_error("Corrupt estimates file. Must have between 2 and 1000 feerate buckets");
201  filein >> fileAvg;
202  if (fileAvg.size() != numBuckets)
203  throw std::runtime_error("Corrupt estimates file. Mismatch in feerate average bucket count");
204  filein >> fileTxCtAvg;
205  if (fileTxCtAvg.size() != numBuckets)
206  throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
207  filein >> fileConfAvg;
208  maxConfirms = fileConfAvg.size();
209  if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) // one week
210  throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
211  for (unsigned int i = 0; i < maxConfirms; i++) {
212  if (fileConfAvg[i].size() != numBuckets)
213  throw std::runtime_error("Corrupt estimates file. Mismatch in feerate conf average bucket count");
214  }
215  // Now that we've processed the entire feerate estimate data file and not
216  // thrown any errors, we can copy it to our data structures
217  decay = fileDecay;
218  buckets = fileBuckets;
219  avg = fileAvg;
220  confAvg = fileConfAvg;
221  txCtAvg = fileTxCtAvg;
222  bucketMap.clear();
223 
224  // Resize the current block variables which aren't stored in the data file
225  // to match the number of confirms and buckets
226  curBlockConf.resize(maxConfirms);
227  for (unsigned int i = 0; i < maxConfirms; i++) {
228  curBlockConf[i].resize(buckets.size());
229  }
230  curBlockTxCt.resize(buckets.size());
231  curBlockVal.resize(buckets.size());
232 
233  unconfTxs.resize(maxConfirms);
234  for (unsigned int i = 0; i < maxConfirms; i++) {
235  unconfTxs[i].resize(buckets.size());
236  }
237  oldUnconfTxs.resize(buckets.size());
238 
239  for (unsigned int i = 0; i < buckets.size(); i++)
240  bucketMap[buckets[i]] = i;
241 
242  LogPrint(BCLog::ESTIMATEFEE, "Reading estimates: %u buckets counting confirms up to %u blocks\n",
243  numBuckets, maxConfirms);
244 }
245 
246 unsigned int TxConfirmStats::NewTx(unsigned int nBlockHeight, double val)
247 {
248  unsigned int bucketindex = bucketMap.lower_bound(val)->second;
249  unsigned int blockIndex = nBlockHeight % unconfTxs.size();
250  unconfTxs[blockIndex][bucketindex]++;
251  return bucketindex;
252 }
253 
254 void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketindex)
255 {
256  //nBestSeenHeight is not updated yet for the new block
257  int blocksAgo = nBestSeenHeight - entryHeight;
258  if (nBestSeenHeight == 0) // the BlockPolicyEstimator hasn't seen any blocks yet
259  blocksAgo = 0;
260  if (blocksAgo < 0) {
261  LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error, blocks ago is negative for mempool tx\n");
262  return; //This can't happen because we call this with our best seen height, no entries can have higher
263  }
264 
265  if (blocksAgo >= (int)unconfTxs.size()) {
266  if (oldUnconfTxs[bucketindex] > 0)
267  oldUnconfTxs[bucketindex]--;
268  else
269  LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error, mempool tx removed from >25 blocks,bucketIndex=%u already\n",
270  bucketindex);
271  }
272  else {
273  unsigned int blockIndex = entryHeight % unconfTxs.size();
274  if (unconfTxs[blockIndex][bucketindex] > 0)
275  unconfTxs[blockIndex][bucketindex]--;
276  else
277  LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error, mempool tx removed from blockIndex=%u,bucketIndex=%u already\n",
278  blockIndex, bucketindex);
279  }
280 }
281 
282 // This function is called from CTxMemPool::removeUnchecked to ensure
283 // txs removed from the mempool for any reason are no longer
284 // tracked. Txs that were part of a block have already been removed in
285 // processBlockTx to ensure they are never double tracked, but it is
286 // of no harm to try to remove them again.
288 {
289  std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash);
290  if (pos != mapMemPoolTxs.end()) {
291  feeStats.removeTx(pos->second.blockHeight, nBestSeenHeight, pos->second.bucketIndex);
292  mapMemPoolTxs.erase(hash);
293  return true;
294  }
295  return false;
296 }
297 
299  : nBestSeenHeight(0), trackedTxs(0), untrackedTxs(0)
300 {
301  static_assert(MIN_FEERATE > 0, "Min feerate must be nonzero");
302  minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
303  std::vector<double> vfeelist;
304  for (double bucketBoundary = minTrackedFee.GetFeePerK(); bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) {
305  vfeelist.push_back(bucketBoundary);
306  }
307  vfeelist.push_back(INF_FEERATE);
308  feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY);
309 }
310 
311 void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate)
312 {
313  if(entry.HasZerocoins() || entry.IsShielded()) {
314  // Zerocoin spends/mints had fixed feerate. Skip them for the estimates.
315  return;
316  }
317 
318  unsigned int txHeight = entry.GetHeight();
319  uint256 hash = entry.GetTx().GetHash();
320  if (mapMemPoolTxs.count(hash)) {
321  LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error mempool tx %s already being tracked\n",
322  hash.ToString().c_str());
323  return;
324  }
325 
326  if (txHeight != nBestSeenHeight) {
327  // Ignore side chains and re-orgs; assuming they are random they don't
328  // affect the estimate. We'll potentially double count transactions in 1-block reorgs.
329  // Ignore txs if BlockPolicyEstimator is not in sync with chainActive.Tip().
330  // It will be synced next time a block is processed.
331  return;
332  }
333 
334  // Only want to be updating estimates when our blockchain is synced,
335  // otherwise we'll miscalculate how many blocks its taking to get included.
336  if (!validFeeEstimate) {
337  untrackedTxs++;
338  return;
339  }
340  trackedTxs++;
341 
342  // Feerates are stored and reported as PIV-per-kb:
343  CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
344 
345  mapMemPoolTxs[hash].blockHeight = txHeight;
346  mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK());
347 }
348 
349 bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry* entry)
350 {
351  if(entry->HasZerocoins() || entry->IsShielded()) {
352  // Zerocoin spends/mints had fixed feerate. Skip them for the estimates.
353  return false;
354  }
355 
356  if (!removeTx(entry->GetTx().GetHash())) {
357  // This transaction wasn't being tracked for fee estimation
358  return false;
359  }
360 
361  // How many blocks did it take for miners to include this transaction?
362  // blocksToConfirm is 1-based, so a transaction included in the earliest
363  // possible block has confirmation count of 1
364  int blocksToConfirm = nBlockHeight - entry->GetHeight();
365  if (blocksToConfirm <= 0) {
366  // This can't happen because we don't process transactions from a block with a height
367  // lower than our greatest seen height
368  LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error Transaction had negative blocksToConfirm\n");
369  return false;
370  }
371 
372  // Feerates are stored and reported as PIV-per-kb:
373  CFeeRate feeRate(entry->GetFee(), entry->GetTxSize());
374 
375  feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
376  return true;
377 }
378 
379 void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
380  std::vector<const CTxMemPoolEntry*>& entries)
381 {
382  if (nBlockHeight <= nBestSeenHeight) {
383  // Ignore side chains and re-orgs; assuming they are random
384  // they don't affect the estimate.
385  // And if an attacker can re-org the chain at will, then
386  // you've got much bigger problems than "attacker can influence
387  // transaction fees."
388  return;
389  }
390 
391  // Must update nBestSeenHeight in sync with ClearCurrent so that
392  // calls to removeTx (via processBlockTx) correctly calculate age
393  // of unconfirmed txs to remove from tracking.
394  nBestSeenHeight = nBlockHeight;
395 
396  // Clear the current block state and update unconfirmed circular buffer
397  feeStats.ClearCurrent(nBlockHeight);
398 
399  unsigned int countedTxs = 0;
400  // Repopulate the current block state
401  for (unsigned int i = 0; i < entries.size(); i++) {
402  if (processBlockTx(nBlockHeight, entries[i]))
403  countedTxs++;
404  }
405 
406  // Update all exponential averages with the current block state
408 
409  LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy after updating estimates for %u of %u txs in block, since last block %u of %u tracked, new mempool map size %u\n",
410  countedTxs, entries.size(), trackedTxs, trackedTxs + untrackedTxs, mapMemPoolTxs.size());
411 
412  trackedTxs = 0;
413  untrackedTxs = 0;
414 }
415 
417 {
418  // Return failure if trying to analyze a target we're not tracking
419  if (confTarget <= 0 || (unsigned int)confTarget > feeStats.GetMaxConfirms())
420  return CFeeRate(0);
421 
422  double median = feeStats.EstimateMedianVal(confTarget, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
423 
424  if (median < 0)
425  return CFeeRate(0);
426 
427  return CFeeRate(median);
428 }
429 
430 CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool)
431 {
432  if (answerFoundAtTarget)
433  *answerFoundAtTarget = confTarget;
434  // Return failure if trying to analyze a target we're not tracking
435  if (confTarget <= 0 || (unsigned int)confTarget > feeStats.GetMaxConfirms())
436  return CFeeRate(0);
437 
438  double median = -1;
439  while (median < 0 && (unsigned int)confTarget <= feeStats.GetMaxConfirms()) {
440  median = feeStats.EstimateMedianVal(confTarget++, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
441  }
442 
443  if (answerFoundAtTarget)
444  *answerFoundAtTarget = confTarget - 1;
445 
446  // If mempool is limiting txs , return at least the min feerate from the mempool
447  CAmount minPoolFee = pool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
448  if (minPoolFee > 0 && minPoolFee > median)
449  return CFeeRate(minPoolFee);
450 
451  if (median < 0)
452  return CFeeRate(0);
453 
454  return CFeeRate(median);
455 }
456 
458 {
459  fileout << nBestSeenHeight;
460  feeStats.Write(fileout);
461 }
462 
463 void CBlockPolicyEstimator::Read(CAutoFile& filein, int nFileVersion)
464 {
465  int nFileBestSeenHeight;
466  filein >> nFileBestSeenHeight;
467  feeStats.Read(filein);
468  nBestSeenHeight = nFileBestSeenHeight;
469  if (nFileVersion < 4029900) {
470  TxConfirmStats priStats;
471  priStats.Read(filein);
472  }
473 }
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:449
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:452
unsigned int untrackedTxs
Definition: fees.h:251
unsigned int nBestSeenHeight
Passed to constructor to avoid dependency on main.
Definition: fees.h:236
TxConfirmStats feeStats
Classes to track historical data on transaction confirmations.
Definition: fees.h:248
bool removeTx(const uint256 &hash)
Remove a transaction from the mempool tracking stats.
Definition: fees.cpp:287
void Write(CAutoFile &fileout)
Write estimation data to a file.
Definition: fees.cpp:457
CFeeRate estimateFee(int confTarget)
Return a feerate estimate.
Definition: fees.cpp:416
CBlockPolicyEstimator(const CFeeRate &minRelayFee)
Create new BlockPolicyEstimator and initialize stats tracking classes with default values.
Definition: fees.cpp:298
unsigned int trackedTxs
Definition: fees.h:250
CFeeRate minTrackedFee
Definition: fees.h:235
void Read(CAutoFile &filein, int nFileVersion)
Read estimation data from a file.
Definition: fees.cpp:463
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool)
Estimate feerate needed to get be included in a block within confTarget blocks.
Definition: fees.cpp:430
bool processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry *entry)
Process a transaction confirmed in a block.
Definition: fees.cpp:349
std::map< uint256, TxStatsInfo > mapMemPoolTxs
Definition: fees.h:245
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate)
Process a transaction accepted to the mempool.
Definition: fees.cpp:311
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry * > &entries)
Process all the transactions that have been included in a block.
Definition: fees.cpp:379
Fee rate in PIV per kilobyte: CAmount / kB.
Definition: feerate.h:20
CAmount GetFeePerK() const
Definition: feerate.h:29
const uint256 & GetHash() const
Definition: transaction.h:301
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:55
bool IsShielded() const
Definition: txmempool.h:97
const CTransaction & GetTx() const
Definition: txmempool.h:90
unsigned int GetHeight() const
Definition: txmempool.h:95
bool HasZerocoins() const
Definition: txmempool.h:96
size_t GetTxSize() const
Definition: txmempool.h:93
const CAmount & GetFee() const
Definition: txmempool.h:92
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:384
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
Definition: txmempool.cpp:1412
We will instantiate an instance of this class to track transactions that were included in a block.
Definition: fees.h:72
std::vector< double > buckets
Definition: fees.h:75
std::vector< double > curBlockVal
Definition: fees.h:95
std::map< double, unsigned int > bucketMap
Definition: fees.h:76
void Read(CAutoFile &filein)
Read saved state of estimation data from a file and replace all internal data structures and variable...
Definition: fees.cpp:183
void ClearCurrent(unsigned int nBlockHeight)
Clear the state of the curBlock variables to start counting for the new block.
Definition: fees.cpp:39
void removeTx(unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketIndex)
Remove a transaction from mempool tracking stats.
Definition: fees.cpp:254
double decay
Definition: fees.h:100
void Write(CAutoFile &fileout)
Write state of estimation data to a file.
Definition: fees.cpp:174
void Record(int blocksToConfirm, double val)
Record a new transaction data point in the current block stats.
Definition: fees.cpp:52
std::vector< double > txCtAvg
Definition: fees.h:81
double EstimateMedianVal(int confTarget, double sufficientTxVal, double minSuccess, bool requireGreater, unsigned int nBlockHeight)
Calculate a feerate estimate.
Definition: fees.cpp:76
std::vector< int > oldUnconfTxs
Definition: fees.h:107
std::vector< int > curBlockTxCt
Definition: fees.h:83
std::vector< std::vector< int > > curBlockConf
Definition: fees.h:89
void UpdateMovingAverages()
Update our estimates by decaying our historical moving average and updating with the data gathered fr...
Definition: fees.cpp:65
void Initialize(std::vector< double > &defaultBuckets, unsigned int maxConfirms, double decay)
Initialize the data structures.
Definition: fees.cpp:14
std::vector< double > avg
Definition: fees.h:93
std::vector< std::vector< double > > confAvg
Definition: fees.h:87
unsigned int GetMaxConfirms()
Return the max number of confirms we're tracking.
Definition: fees.h:156
std::vector< std::vector< int > > unconfTxs
Definition: fees.h:105
unsigned int NewTx(unsigned int nBlockHeight, double val)
Record a new transaction entering the mempool.
Definition: fees.cpp:246
std::string ToString() const
Definition: uint256.cpp:65
256-bit opaque blob.
Definition: uint256.h:138
#define LogPrint(category,...)
Definition: logging.h:163
@ ESTIMATEFEE
Definition: logging.h:49
ArgsManager gArgs
Definition: system.cpp:89