@@ -18,6 +18,7 @@ class CAutoFile;
18
18
class CFeeRate ;
19
19
class CTxMemPoolEntry ;
20
20
class CTxMemPool ;
21
+ class TxConfirmStats ;
21
22
22
23
/* * \class CBlockPolicyEstimator
23
24
* The BlockPolicyEstimator is used for estimating the feerate needed
@@ -60,113 +61,6 @@ class CTxMemPool;
60
61
* they've been outstanding.
61
62
*/
62
63
63
- /* *
64
- * We will instantiate an instance of this class to track transactions that were
65
- * included in a block. We will lump transactions into a bucket according to their
66
- * approximate feerate and then track how long it took for those txs to be included in a block
67
- *
68
- * The tracking of unconfirmed (mempool) transactions is completely independent of the
69
- * historical tracking of transactions that have been confirmed in a block.
70
- */
71
- class TxConfirmStats
72
- {
73
- private:
74
- // Define the buckets we will group transactions into
75
- std::vector<double > buckets; // The upper-bound of the range for the bucket (inclusive)
76
- std::map<double , unsigned int > bucketMap; // Map of bucket upper-bound to index into all vectors by bucket
77
-
78
- // For each bucket X:
79
- // Count the total # of txs in each bucket
80
- // Track the historical moving average of this total over blocks
81
- std::vector<double > txCtAvg;
82
- // and calculate the total for the current block to update the moving average
83
- std::vector<int > curBlockTxCt;
84
-
85
- // Count the total # of txs confirmed within Y blocks in each bucket
86
- // Track the historical moving average of theses totals over blocks
87
- std::vector<std::vector<double > > confAvg; // confAvg[Y][X]
88
- // and calculate the totals for the current block to update the moving averages
89
- std::vector<std::vector<int > > curBlockConf; // curBlockConf[Y][X]
90
-
91
- // Sum the total feerate of all tx's in each bucket
92
- // Track the historical moving average of this total over blocks
93
- std::vector<double > avg;
94
- // and calculate the total for the current block to update the moving average
95
- std::vector<double > curBlockVal;
96
-
97
- // Combine the conf counts with tx counts to calculate the confirmation % for each Y,X
98
- // Combine the total value with the tx counts to calculate the avg feerate per bucket
99
-
100
- double decay;
101
-
102
- // Mempool counts of outstanding transactions
103
- // For each bucket X, track the number of transactions in the mempool
104
- // that are unconfirmed for each possible confirmation value Y
105
- std::vector<std::vector<int > > unconfTxs; // unconfTxs[Y][X]
106
- // transactions still unconfirmed after MAX_CONFIRMS for each bucket
107
- std::vector<int > oldUnconfTxs;
108
-
109
- public:
110
- /* *
111
- * Create new TxConfirmStats. This is called by BlockPolicyEstimator's
112
- * constructor with default values.
113
- * @param defaultBuckets contains the upper limits for the bucket boundaries
114
- * @param maxConfirms max number of confirms to track
115
- * @param decay how much to decay the historical moving average per block
116
- */
117
- TxConfirmStats (const std::vector<double >& defaultBuckets, unsigned int maxConfirms, double decay);
118
-
119
- /* * Clear the state of the curBlock variables to start counting for the new block */
120
- void ClearCurrent (unsigned int nBlockHeight);
121
-
122
- /* *
123
- * Record a new transaction data point in the current block stats
124
- * @param blocksToConfirm the number of blocks it took this transaction to confirm
125
- * @param val the feerate of the transaction
126
- * @warning blocksToConfirm is 1-based and has to be >= 1
127
- */
128
- void Record (int blocksToConfirm, double val);
129
-
130
- /* * Record a new transaction entering the mempool*/
131
- unsigned int NewTx (unsigned int nBlockHeight, double val);
132
-
133
- /* * Remove a transaction from mempool tracking stats*/
134
- void removeTx (unsigned int entryHeight, unsigned int nBestSeenHeight,
135
- unsigned int bucketIndex);
136
-
137
- /* * Update our estimates by decaying our historical moving average and updating
138
- with the data gathered from the current block */
139
- void UpdateMovingAverages ();
140
-
141
- /* *
142
- * Calculate a feerate estimate. Find the lowest value bucket (or range of buckets
143
- * to make sure we have enough data points) whose transactions still have sufficient likelihood
144
- * of being confirmed within the target number of confirmations
145
- * @param confTarget target number of confirmations
146
- * @param sufficientTxVal required average number of transactions per block in a bucket range
147
- * @param minSuccess the success probability we require
148
- * @param requireGreater return the lowest feerate such that all higher values pass minSuccess OR
149
- * return the highest feerate such that all lower values fail minSuccess
150
- * @param nBlockHeight the current block height
151
- */
152
- double EstimateMedianVal (int confTarget, double sufficientTxVal,
153
- double minSuccess, bool requireGreater, unsigned int nBlockHeight) const ;
154
-
155
- /* * Return the max number of confirms we're tracking */
156
- unsigned int GetMaxConfirms () const { return confAvg.size (); }
157
-
158
- /* * Write state of estimation data to a file*/
159
- void Write (CAutoFile& fileout) const ;
160
-
161
- /* *
162
- * Read saved state of estimation data from a file and replace all internal data structures and
163
- * variables with this state.
164
- */
165
- void Read (CAutoFile& filein);
166
- };
167
-
168
-
169
-
170
64
/* * Track confirm delays up to 25 blocks, can't estimate beyond that */
171
65
static const unsigned int MAX_BLOCK_CONFIRMS = 25 ;
172
66
0 commit comments