Dash Core  0.12.2.1
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 
9 #include "amount.h"
10 #include "primitives/transaction.h"
11 #include "streams.h"
12 #include "txmempool.h"
13 #include "util.h"
14 
15 void TxConfirmStats::Initialize(std::vector<double>& defaultBuckets,
16  unsigned int maxConfirms, double _decay, std::string _dataTypeString)
17 {
18  decay = _decay;
19  dataTypeString = _dataTypeString;
20  for (unsigned int i = 0; i < defaultBuckets.size(); i++) {
21  buckets.push_back(defaultBuckets[i]);
22  bucketMap[defaultBuckets[i]] = i;
23  }
24  confAvg.resize(maxConfirms);
25  curBlockConf.resize(maxConfirms);
26  unconfTxs.resize(maxConfirms);
27  for (unsigned int i = 0; i < maxConfirms; i++) {
28  confAvg[i].resize(buckets.size());
29  curBlockConf[i].resize(buckets.size());
30  unconfTxs[i].resize(buckets.size());
31  }
32 
33  oldUnconfTxs.resize(buckets.size());
34  curBlockTxCt.resize(buckets.size());
35  txCtAvg.resize(buckets.size());
36  curBlockVal.resize(buckets.size());
37  avg.resize(buckets.size());
38 }
39 
40 // Zero out the data for the current block
41 void TxConfirmStats::ClearCurrent(unsigned int nBlockHeight)
42 {
43  for (unsigned int j = 0; j < buckets.size(); j++) {
44  oldUnconfTxs[j] += unconfTxs[nBlockHeight%unconfTxs.size()][j];
45  unconfTxs[nBlockHeight%unconfTxs.size()][j] = 0;
46  for (unsigned int i = 0; i < curBlockConf.size(); i++)
47  curBlockConf[i][j] = 0;
48  curBlockTxCt[j] = 0;
49  curBlockVal[j] = 0;
50  }
51 }
52 
53 
54 void TxConfirmStats::Record(int blocksToConfirm, double val)
55 {
56  // blocksToConfirm is 1-based
57  if (blocksToConfirm < 1)
58  return;
59  unsigned int bucketindex = bucketMap.lower_bound(val)->second;
60  for (size_t i = blocksToConfirm; i <= curBlockConf.size(); i++) {
61  curBlockConf[i - 1][bucketindex]++;
62  }
63  curBlockTxCt[bucketindex]++;
64  curBlockVal[bucketindex] += val;
65 }
66 
68 {
69  for (unsigned int j = 0; j < buckets.size(); j++) {
70  for (unsigned int i = 0; i < confAvg.size(); i++)
71  confAvg[i][j] = confAvg[i][j] * decay + curBlockConf[i][j];
72  avg[j] = avg[j] * decay + curBlockVal[j];
73  txCtAvg[j] = txCtAvg[j] * decay + curBlockTxCt[j];
74  }
75 }
76 
77 // returns -1 on error conditions
78 double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
79  double successBreakPoint, bool requireGreater,
80  unsigned int nBlockHeight)
81 {
82  // Counters for a bucket (or range of buckets)
83  double nConf = 0; // Number of tx's confirmed within the confTarget
84  double totalNum = 0; // Total number of tx's that were ever confirmed
85  int extraNum = 0; // Number of tx's still in mempool for confTarget or longer
86 
87  int maxbucketindex = buckets.size() - 1;
88 
89  // requireGreater means we are looking for the lowest fee/priority such that all higher
90  // values pass, so we start at maxbucketindex (highest fee) and look at successively
91  // smaller buckets until we reach failure. Otherwise, we are looking for the highest
92  // fee/priority such that all lower values fail, and we go in the opposite direction.
93  unsigned int startbucket = requireGreater ? maxbucketindex : 0;
94  int step = requireGreater ? -1 : 1;
95 
96  // We'll combine buckets until we have enough samples.
97  // The near and far variables will define the range we've combined
98  // The best variables are the last range we saw which still had a high
99  // enough confirmation rate to count as success.
100  // The cur variables are the current range we're counting.
101  unsigned int curNearBucket = startbucket;
102  unsigned int bestNearBucket = startbucket;
103  unsigned int curFarBucket = startbucket;
104  unsigned int bestFarBucket = startbucket;
105 
106  bool foundAnswer = false;
107  unsigned int bins = unconfTxs.size();
108 
109  // Start counting from highest(default) or lowest fee/pri transactions
110  for (int bucket = startbucket; bucket >= 0 && bucket <= maxbucketindex; bucket += step) {
111  curFarBucket = bucket;
112  nConf += confAvg[confTarget - 1][bucket];
113  totalNum += txCtAvg[bucket];
114  for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
115  extraNum += unconfTxs[(nBlockHeight - confct)%bins][bucket];
116  extraNum += oldUnconfTxs[bucket];
117  // If we have enough transaction data points in this range of buckets,
118  // we can test for success
119  // (Only count the confirmed data points, so that each confirmation count
120  // will be looking at the same amount of data and same bucket breaks)
121  if (totalNum >= sufficientTxVal / (1 - decay)) {
122  double curPct = nConf / (totalNum + extraNum);
123 
124  // Check to see if we are no longer getting confirmed at the success rate
125  if (requireGreater && curPct < successBreakPoint)
126  break;
127  if (!requireGreater && curPct > successBreakPoint)
128  break;
129 
130  // Otherwise update the cumulative stats, and the bucket variables
131  // and reset the counters
132  else {
133  foundAnswer = true;
134  nConf = 0;
135  totalNum = 0;
136  extraNum = 0;
137  bestNearBucket = curNearBucket;
138  bestFarBucket = curFarBucket;
139  curNearBucket = bucket + step;
140  }
141  }
142  }
143 
144  double median = -1;
145  double txSum = 0;
146 
147  // Calculate the "average" fee of the best bucket range that met success conditions
148  // Find the bucket with the median transaction and then report the average fee from that bucket
149  // This is a compromise between finding the median which we can't since we don't save all tx's
150  // and reporting the average which is less accurate
151  unsigned int minBucket = bestNearBucket < bestFarBucket ? bestNearBucket : bestFarBucket;
152  unsigned int maxBucket = bestNearBucket > bestFarBucket ? bestNearBucket : bestFarBucket;
153  for (unsigned int j = minBucket; j <= maxBucket; j++) {
154  txSum += txCtAvg[j];
155  }
156  if (foundAnswer && txSum != 0) {
157  txSum = txSum / 2;
158  for (unsigned int j = minBucket; j <= maxBucket; j++) {
159  if (txCtAvg[j] < txSum)
160  txSum -= txCtAvg[j];
161  else { // we're in the right bucket
162  median = avg[j] / txCtAvg[j];
163  break;
164  }
165  }
166  }
167 
168  LogPrint("estimatefee", "%3d: For conf success %s %4.2f need %s %s: %12.5g from buckets %8g - %8g Cur Bucket stats %6.2f%% %8.1f/(%.1f+%d mempool)\n",
169  confTarget, requireGreater ? ">" : "<", successBreakPoint, dataTypeString,
170  requireGreater ? ">" : "<", median, buckets[minBucket], buckets[maxBucket],
171  100 * nConf / (totalNum + extraNum), nConf, totalNum, extraNum);
172 
173  return median;
174 }
175 
177 {
178  fileout << decay;
179  fileout << buckets;
180  fileout << avg;
181  fileout << txCtAvg;
182  fileout << confAvg;
183 }
184 
186 {
187  // Read data file into temporary variables and do some very basic sanity checking
188  std::vector<double> fileBuckets;
189  std::vector<double> fileAvg;
190  std::vector<std::vector<double> > fileConfAvg;
191  std::vector<double> fileTxCtAvg;
192  double fileDecay;
193  size_t maxConfirms;
194  size_t numBuckets;
195 
196  filein >> fileDecay;
197  if (fileDecay <= 0 || fileDecay >= 1)
198  throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
199  filein >> fileBuckets;
200  numBuckets = fileBuckets.size();
201  if (numBuckets <= 1 || numBuckets > 1000)
202  throw std::runtime_error("Corrupt estimates file. Must have between 2 and 1000 fee/pri buckets");
203  filein >> fileAvg;
204  if (fileAvg.size() != numBuckets)
205  throw std::runtime_error("Corrupt estimates file. Mismatch in fee/pri average bucket count");
206  filein >> fileTxCtAvg;
207  if (fileTxCtAvg.size() != numBuckets)
208  throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
209  filein >> fileConfAvg;
210  maxConfirms = fileConfAvg.size();
211  if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) // one week
212  throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
213  for (unsigned int i = 0; i < maxConfirms; i++) {
214  if (fileConfAvg[i].size() != numBuckets)
215  throw std::runtime_error("Corrupt estimates file. Mismatch in fee/pri conf average bucket count");
216  }
217  // Now that we've processed the entire fee estimate data file and not
218  // thrown any errors, we can copy it to our data structures
219  decay = fileDecay;
220  buckets = fileBuckets;
221  avg = fileAvg;
222  confAvg = fileConfAvg;
223  txCtAvg = fileTxCtAvg;
224  bucketMap.clear();
225 
226  // Resize the current block variables which aren't stored in the data file
227  // to match the number of confirms and buckets
228  curBlockConf.resize(maxConfirms);
229  for (unsigned int i = 0; i < maxConfirms; i++) {
230  curBlockConf[i].resize(buckets.size());
231  }
232  curBlockTxCt.resize(buckets.size());
233  curBlockVal.resize(buckets.size());
234 
235  unconfTxs.resize(maxConfirms);
236  for (unsigned int i = 0; i < maxConfirms; i++) {
237  unconfTxs[i].resize(buckets.size());
238  }
239  oldUnconfTxs.resize(buckets.size());
240 
241  for (unsigned int i = 0; i < buckets.size(); i++)
242  bucketMap[buckets[i]] = i;
243 
244  LogPrint("estimatefee", "Reading estimates: %u %s buckets counting confirms up to %u blocks\n",
245  numBuckets, dataTypeString, maxConfirms);
246 }
247 
248 unsigned int TxConfirmStats::NewTx(unsigned int nBlockHeight, double val)
249 {
250  unsigned int bucketindex = bucketMap.lower_bound(val)->second;
251  unsigned int blockIndex = nBlockHeight % unconfTxs.size();
252  unconfTxs[blockIndex][bucketindex]++;
253  LogPrint("estimatefee", "adding to %s", dataTypeString);
254  return bucketindex;
255 }
256 
257 void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketindex)
258 {
259  //nBestSeenHeight is not updated yet for the new block
260  int blocksAgo = nBestSeenHeight - entryHeight;
261  if (nBestSeenHeight == 0) // the BlockPolicyEstimator hasn't seen any blocks yet
262  blocksAgo = 0;
263  if (blocksAgo < 0) {
264  LogPrint("estimatefee", "Blockpolicy error, blocks ago is negative for mempool tx\n");
265  return; //This can't happen because we call this with our best seen height, no entries can have higher
266  }
267 
268  if (blocksAgo >= (int)unconfTxs.size()) {
269  if (oldUnconfTxs[bucketindex] > 0)
270  oldUnconfTxs[bucketindex]--;
271  else
272  LogPrint("estimatefee", "Blockpolicy error, mempool tx removed from >25 blocks,bucketIndex=%u already\n",
273  bucketindex);
274  }
275  else {
276  unsigned int blockIndex = entryHeight % unconfTxs.size();
277  if (unconfTxs[blockIndex][bucketindex] > 0)
278  unconfTxs[blockIndex][bucketindex]--;
279  else
280  LogPrint("estimatefee", "Blockpolicy error, mempool tx removed from blockIndex=%u,bucketIndex=%u already\n",
281  blockIndex, bucketindex);
282  }
283 }
284 
286 {
287  std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash);
288  if (pos == mapMemPoolTxs.end()) {
289  LogPrint("estimatefee", "Blockpolicy error mempool tx %s not found for removeTx\n", hash.ToString());
290  return;
291  }
292  TxConfirmStats *stats = pos->second.stats;
293  unsigned int entryHeight = pos->second.blockHeight;
294  unsigned int bucketIndex = pos->second.bucketIndex;
295 
296  if (stats != NULL)
297  stats->removeTx(entryHeight, nBestSeenHeight, bucketIndex);
298  mapMemPoolTxs.erase(hash);
299 }
300 
302  : nBestSeenHeight(0)
303 {
304  minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
305  std::vector<double> vfeelist;
306  for (double bucketBoundary = minTrackedFee.GetFeePerK(); bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) {
307  vfeelist.push_back(bucketBoundary);
308  }
309  vfeelist.push_back(INF_FEERATE);
310  feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY, "FeeRate");
311 
313  std::vector<double> vprilist;
314  for (double bucketBoundary = minTrackedPriority; bucketBoundary <= MAX_PRIORITY; bucketBoundary *= PRI_SPACING) {
315  vprilist.push_back(bucketBoundary);
316  }
317  vprilist.push_back(INF_PRIORITY);
318  priStats.Initialize(vprilist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY, "Priority");
319 
320  feeUnlikely = CFeeRate(0);
322  priUnlikely = 0;
324 }
325 
327 {
328  if ((pri < minTrackedPriority && fee >= minTrackedFee) ||
329  (pri < priUnlikely && fee > feeLikely)) {
330  return true;
331  }
332  return false;
333 }
334 
336 {
337  if ((fee < minTrackedFee && pri >= minTrackedPriority) ||
338  (fee < feeUnlikely && pri > priLikely)) {
339  return true;
340  }
341  return false;
342 }
343 
344 void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool fCurrentEstimate)
345 {
346  unsigned int txHeight = entry.GetHeight();
347  uint256 hash = entry.GetTx().GetHash();
348  if (mapMemPoolTxs[hash].stats != NULL) {
349  LogPrint("estimatefee", "Blockpolicy error mempool tx %s already being tracked\n", hash.ToString());
350  return;
351  }
352 
353  if (txHeight < nBestSeenHeight) {
354  // Ignore side chains and re-orgs; assuming they are random they don't
355  // affect the estimate. We'll potentially double count transactions in 1-block reorgs.
356  return;
357  }
358 
359  // Only want to be updating estimates when our blockchain is synced,
360  // otherwise we'll miscalculate how many blocks its taking to get included.
361  if (!fCurrentEstimate)
362  return;
363 
364  if (!entry.WasClearAtEntry()) {
365  // This transaction depends on other transactions in the mempool to
366  // be included in a block before it will be able to be included, so
367  // we shouldn't include it in our calculations
368  return;
369  }
370 
371  // Fees are stored and reported as BTC-per-kb:
372  CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
373 
374  // Want the priority of the tx at confirmation. However we don't know
375  // what that will be and its too hard to continue updating it
376  // so use starting priority as a proxy
377  double curPri = entry.GetPriority(txHeight);
378  mapMemPoolTxs[hash].blockHeight = txHeight;
379 
380  LogPrint("estimatefee", "Blockpolicy mempool tx %s ", hash.ToString().substr(0,10));
381  // Record this as a priority estimate
382  if (entry.GetFee() == 0 || isPriDataPoint(feeRate, curPri)) {
383  mapMemPoolTxs[hash].stats = &priStats;
384  mapMemPoolTxs[hash].bucketIndex = priStats.NewTx(txHeight, curPri);
385  }
386  // Record this as a fee estimate
387  else if (isFeeDataPoint(feeRate, curPri)) {
388  mapMemPoolTxs[hash].stats = &feeStats;
389  mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK());
390  }
391  else {
392  LogPrint("estimatefee", "not adding");
393  }
394  LogPrint("estimatefee", "\n");
395 }
396 
397 void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry)
398 {
399  if (!entry.WasClearAtEntry()) {
400  // This transaction depended on other transactions in the mempool to
401  // be included in a block before it was able to be included, so
402  // we shouldn't include it in our calculations
403  return;
404  }
405 
406  // How many blocks did it take for miners to include this transaction?
407  // blocksToConfirm is 1-based, so a transaction included in the earliest
408  // possible block has confirmation count of 1
409  int blocksToConfirm = nBlockHeight - entry.GetHeight();
410  if (blocksToConfirm <= 0) {
411  // This can't happen because we don't process transactions from a block with a height
412  // lower than our greatest seen height
413  LogPrint("estimatefee", "Blockpolicy error Transaction had negative blocksToConfirm\n");
414  return;
415  }
416 
417  // Fees are stored and reported as BTC-per-kb:
418  CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
419 
420  // Want the priority of the tx at confirmation. The priority when it
421  // entered the mempool could easily be very small and change quickly
422  double curPri = entry.GetPriority(nBlockHeight);
423 
424  // Record this as a priority estimate
425  if (entry.GetFee() == 0 || isPriDataPoint(feeRate, curPri)) {
426  priStats.Record(blocksToConfirm, curPri);
427  }
428  // Record this as a fee estimate
429  else if (isFeeDataPoint(feeRate, curPri)) {
430  feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
431  }
432 }
433 
434 void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
435  std::vector<CTxMemPoolEntry>& entries, bool fCurrentEstimate)
436 {
437  if (nBlockHeight <= nBestSeenHeight) {
438  // Ignore side chains and re-orgs; assuming they are random
439  // they don't affect the estimate.
440  // And if an attacker can re-org the chain at will, then
441  // you've got much bigger problems than "attacker can influence
442  // transaction fees."
443  return;
444  }
445  nBestSeenHeight = nBlockHeight;
446 
447  // Only want to be updating estimates when our blockchain is synced,
448  // otherwise we'll miscalculate how many blocks its taking to get included.
449  if (!fCurrentEstimate)
450  return;
451 
452  // Update the dynamic cutoffs
453  // a fee/priority is "likely" the reason your tx was included in a block if >85% of such tx's
454  // were confirmed in 2 blocks and is "unlikely" if <50% were confirmed in 10 blocks
455  LogPrint("estimatefee", "Blockpolicy recalculating dynamic cutoffs:\n");
457  if (priLikely == -1)
459 
460  double feeLikelyEst = feeStats.EstimateMedianVal(2, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBlockHeight);
461  if (feeLikelyEst == -1)
463  else
464  feeLikely = CFeeRate(feeLikelyEst);
465 
467  if (priUnlikely == -1)
468  priUnlikely = 0;
469 
470  double feeUnlikelyEst = feeStats.EstimateMedianVal(10, SUFFICIENT_FEETXS, UNLIKELY_PCT, false, nBlockHeight);
471  if (feeUnlikelyEst == -1)
472  feeUnlikely = CFeeRate(0);
473  else
474  feeUnlikely = CFeeRate(feeUnlikelyEst);
475 
476  // Clear the current block states
477  feeStats.ClearCurrent(nBlockHeight);
478  priStats.ClearCurrent(nBlockHeight);
479 
480  // Repopulate the current block states
481  for (unsigned int i = 0; i < entries.size(); i++)
482  processBlockTx(nBlockHeight, entries[i]);
483 
484  // Update all exponential averages with the current block states
487 
488  LogPrint("estimatefee", "Blockpolicy after updating estimates for %u confirmed entries, new mempool map size %u\n",
489  entries.size(), mapMemPoolTxs.size());
490 }
491 
493 {
494  // Return failure if trying to analyze a target we're not tracking
495  if (confTarget <= 0 || (unsigned int)confTarget > feeStats.GetMaxConfirms())
496  return CFeeRate(0);
497 
498  double median = feeStats.EstimateMedianVal(confTarget, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
499 
500  if (median < 0)
501  return CFeeRate(0);
502 
503  return CFeeRate(median);
504 }
505 
506 CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool)
507 {
508  if (answerFoundAtTarget)
509  *answerFoundAtTarget = confTarget;
510  // Return failure if trying to analyze a target we're not tracking
511  if (confTarget <= 0 || (unsigned int)confTarget > feeStats.GetMaxConfirms())
512  return CFeeRate(0);
513 
514  double median = -1;
515  while (median < 0 && (unsigned int)confTarget <= feeStats.GetMaxConfirms()) {
517  }
518 
519  if (answerFoundAtTarget)
520  *answerFoundAtTarget = confTarget - 1;
521 
522  // If mempool is limiting txs , return at least the min fee from the mempool
523  CAmount minPoolFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
524  if (minPoolFee > 0 && minPoolFee > median)
525  return CFeeRate(minPoolFee);
526 
527  if (median < 0)
528  return CFeeRate(0);
529 
530  return CFeeRate(median);
531 }
532 
534 {
535  // Return failure if trying to analyze a target we're not tracking
536  if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms())
537  return -1;
538 
540 }
541 
542 double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool)
543 {
544  if (answerFoundAtTarget)
545  *answerFoundAtTarget = confTarget;
546  // Return failure if trying to analyze a target we're not tracking
547  if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms())
548  return -1;
549 
550  // If mempool is limiting txs, no priority txs are allowed
551  CAmount minPoolFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
552  if (minPoolFee > 0)
553  return INF_PRIORITY;
554 
555  double median = -1;
556  while (median < 0 && (unsigned int)confTarget <= priStats.GetMaxConfirms()) {
558  }
559 
560  if (answerFoundAtTarget)
561  *answerFoundAtTarget = confTarget - 1;
562 
563  return median;
564 }
565 
567 {
571 }
572 
574 {
575  int nFileBestSeenHeight;
576  filein >> nFileBestSeenHeight;
577  feeStats.Read(filein);
578  priStats.Read(filein);
579  nBestSeenHeight = nFileBestSeenHeight;
580 }
static const double PRI_SPACING
Definition: fees.h:211
std::vector< double > txCtAvg
Definition: fees.h:89
double priUnlikely
Definition: fees.h:287
double estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool)
Definition: fees.cpp:542
void processTransaction(const CTxMemPoolEntry &entry, bool fCurrentEstimate)
Definition: fees.cpp:344
std::vector< std::vector< int > > unconfTxs
Definition: fees.h:114
double EstimateMedianVal(int confTarget, double sufficientTxVal, double minSuccess, bool requireGreater, unsigned int nBlockHeight)
Definition: fees.cpp:78
std::vector< int > curBlockTxCt
Definition: fees.h:91
double minTrackedPriority
Passed to constructor to avoid dependency on main.
Definition: fees.h:269
CBlockPolicyEstimator(const CFeeRate &minRelayFee)
Definition: fees.cpp:301
unsigned int GetHeight() const
Definition: txmempool.h:119
double decay
Definition: fees.h:109
size_t GetTxSize() const
Definition: txmempool.h:117
std::string dataTypeString
Definition: fees.h:108
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE
Definition: policy.h:29
double AllowFreeThreshold()
Definition: txmempool.h:26
static FILE * fileout
Definition: util.cpp:210
void Record(int blocksToConfirm, double val)
Definition: fees.cpp:54
void Read(CAutoFile &filein)
Definition: fees.cpp:185
static const double UNLIKELY_PCT
Definition: fees.h:188
void ClearCurrent(unsigned int nBlockHeight)
Definition: fees.cpp:41
static const double MIN_FEERATE
Definition: fees.h:197
void UpdateMovingAverages()
Definition: fees.cpp:67
static const double INF_FEERATE
Definition: fees.h:199
static const double SUFFICIENT_PRITXS
Definition: fees.h:194
CFeeRate estimateFee(int confTarget)
Definition: fees.cpp:492
TxConfirmStats priStats
Definition: fees.h:283
const CAmount & GetFee() const
Definition: txmempool.h:116
static const double MAX_PRIORITY
Definition: fees.h:201
std::map< double, unsigned int > bucketMap
Definition: fees.h:84
int64_t CAmount
Definition: amount.h:14
void processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry &entry)
Definition: fees.cpp:397
CFeeRate estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool &pool)
Definition: fees.cpp:506
static int LogPrint(const char *category, const char *format)
Definition: util.h:126
CFeeRate feeLikely
Definition: fees.h:286
const CTransaction & GetTx() const
Definition: txmempool.h:110
CAmount GetFeePerK() const
Definition: amount.h:47
unsigned int GetMaxConfirms()
Definition: fees.h:166
unsigned int NewTx(unsigned int nBlockHeight, double val)
Definition: fees.cpp:248
std::string ToString() const
Definition: uint256.cpp:65
TxConfirmStats feeStats
Definition: fees.h:283
std::vector< double > avg
Definition: fees.h:101
void Initialize(std::vector< double > &defaultBuckets, unsigned int maxConfirms, double decay, std::string dataTypeString)
Definition: fees.cpp:15
std::vector< double > curBlockVal
Definition: fees.h:103
void removeTx(unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketIndex)
Definition: fees.cpp:257
static const double SUFFICIENT_FEETXS
Definition: fees.h:191
static const double DEFAULT_DECAY
Definition: fees.h:184
static const double MIN_SUCCESS_PCT
Definition: fees.h:187
CFeeRate feeUnlikely
Definition: fees.h:286
CFeeRate minTrackedFee
Definition: fees.h:268
const uint256 & GetHash() const
Definition: transaction.h:262
void removeTx(uint256 hash)
Definition: fees.cpp:285
static const double INF_PRIORITY
Definition: fees.h:202
bool isFeeDataPoint(const CFeeRate &fee, double pri)
Definition: fees.cpp:326
static const double MIN_PRIORITY
Definition: fees.h:200
bool isPriDataPoint(const CFeeRate &fee, double pri)
Definition: fees.cpp:335
static const double MAX_FEERATE
Definition: fees.h:198
unsigned int nBestSeenHeight
Set to AllowFreeThreshold.
Definition: fees.h:270
void Read(CAutoFile &filein)
Definition: fees.cpp:573
CFeeRate GetMinFee(size_t sizelimit) const
Definition: txmempool.cpp:1076
void processBlock(unsigned int nBlockHeight, std::vector< CTxMemPoolEntry > &entries, bool fCurrentEstimate)
Definition: fees.cpp:434
void Write(CAutoFile &fileout)
Definition: fees.cpp:176
std::vector< int > oldUnconfTxs
Definition: fees.h:116
double GetPriority(unsigned int currentHeight) const
Definition: txmempool.cpp:50
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Definition: util.cpp:441
bool WasClearAtEntry() const
Definition: txmempool.h:120
std::vector< std::vector< double > > confAvg
Definition: fees.h:95
std::vector< std::vector< int > > curBlockConf
Definition: fees.h:97
std::map< uint256, TxStatsInfo > mapMemPoolTxs
Definition: fees.h:280
void Write(CAutoFile &fileout)
Definition: fees.cpp:566
static const unsigned int MAX_BLOCK_CONFIRMS
Definition: fees.h:181
std::vector< double > buckets
Definition: fees.h:83
double estimatePriority(int confTarget)
Definition: fees.cpp:533
static const double FEE_SPACING
Definition: fees.h:208
double priLikely
Definition: fees.h:287