returns -1 on error conditions
| 222 | |
| 223 | // returns -1 on error conditions |
| 224 | double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal, |
| 225 | double successBreakPoint, unsigned int nBlockHeight, |
| 226 | EstimationResult *result) const |
| 227 | { |
| 228 | // Counters for a bucket (or range of buckets) |
| 229 | double nConf = 0; // Number of tx's confirmed within the confTarget |
| 230 | double totalNum = 0; // Total number of tx's that were ever confirmed |
| 231 | int extraNum = 0; // Number of tx's still in mempool for confTarget or longer |
| 232 | double failNum = 0; // Number of tx's that were never confirmed but removed from the mempool after confTarget |
| 233 | const int periodTarget = (confTarget + scale - 1) / scale; |
| 234 | const int maxbucketindex = buckets.size() - 1; |
| 235 | |
| 236 | // We'll combine buckets until we have enough samples. |
| 237 | // The near and far variables will define the range we've combined |
| 238 | // The best variables are the last range we saw which still had a high |
| 239 | // enough confirmation rate to count as success. |
| 240 | // The cur variables are the current range we're counting. |
| 241 | unsigned int curNearBucket = maxbucketindex; |
| 242 | unsigned int bestNearBucket = maxbucketindex; |
| 243 | unsigned int curFarBucket = maxbucketindex; |
| 244 | unsigned int bestFarBucket = maxbucketindex; |
| 245 | |
| 246 | bool foundAnswer = false; |
| 247 | unsigned int bins = unconfTxs.size(); |
| 248 | bool newBucketRange = true; |
| 249 | bool passing = true; |
| 250 | EstimatorBucket passBucket; |
| 251 | EstimatorBucket failBucket; |
| 252 | |
| 253 | // Start counting from highest feerate transactions |
| 254 | for (int bucket = maxbucketindex; bucket >= 0; --bucket) { |
| 255 | if (newBucketRange) { |
| 256 | curNearBucket = bucket; |
| 257 | newBucketRange = false; |
| 258 | } |
| 259 | curFarBucket = bucket; |
| 260 | nConf += confAvg[periodTarget - 1][bucket]; |
| 261 | totalNum += txCtAvg[bucket]; |
| 262 | failNum += failAvg[periodTarget - 1][bucket]; |
| 263 | for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++) |
| 264 | extraNum += unconfTxs[(nBlockHeight - confct) % bins][bucket]; |
| 265 | extraNum += oldUnconfTxs[bucket]; |
| 266 | // If we have enough transaction data points in this range of buckets, |
| 267 | // we can test for success |
| 268 | // (Only count the confirmed data points, so that each confirmation count |
| 269 | // will be looking at the same amount of data and same bucket breaks) |
| 270 | if (totalNum >= sufficientTxVal / (1 - decay)) { |
| 271 | double curPct = nConf / (totalNum + failNum + extraNum); |
| 272 | |
| 273 | // Check to see if we are no longer getting confirmed at the success rate |
| 274 | if (curPct < successBreakPoint) { |
| 275 | if (passing == true) { |
| 276 | // First time we hit a failure record the failed bucket |
| 277 | unsigned int failMinBucket = std::min(curNearBucket, curFarBucket); |
| 278 | unsigned int failMaxBucket = std::max(curNearBucket, curFarBucket); |
| 279 | failBucket.start = failMinBucket ? buckets[failMinBucket - 1] : 0; |
| 280 | failBucket.end = buckets[failMaxBucket]; |
| 281 | failBucket.withinTarget = nConf; |
no test coverage detected