| 449 | } |
| 450 | |
| 451 | void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketindex, bool inBlock) |
| 452 | { |
| 453 | //nBestSeenHeight is not updated yet for the new block |
| 454 | int blocksAgo = nBestSeenHeight - entryHeight; |
| 455 | if (nBestSeenHeight == 0) // the BlockPolicyEstimator hasn't seen any blocks yet |
| 456 | blocksAgo = 0; |
| 457 | if (blocksAgo < 0) { |
| 458 | LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error, blocks ago is negative for mempool tx\n"); |
| 459 | return; //This can't happen because we call this with our best seen height, no entries can have higher |
| 460 | } |
| 461 | |
| 462 | if (blocksAgo >= (int)unconfTxs.size()) { |
| 463 | if (oldUnconfTxs[bucketindex] > 0) { |
| 464 | oldUnconfTxs[bucketindex]--; |
| 465 | } else { |
| 466 | LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error, mempool tx removed from >25 blocks,bucketIndex=%u already\n", |
| 467 | bucketindex); |
| 468 | } |
| 469 | } |
| 470 | else { |
| 471 | unsigned int blockIndex = entryHeight % unconfTxs.size(); |
| 472 | if (unconfTxs[blockIndex][bucketindex] > 0) { |
| 473 | unconfTxs[blockIndex][bucketindex]--; |
| 474 | } else { |
| 475 | LogPrint(BCLog::ESTIMATEFEE, "Blockpolicy error, mempool tx removed from blockIndex=%u,bucketIndex=%u already\n", |
| 476 | blockIndex, bucketindex); |
| 477 | } |
| 478 | } |
| 479 | if (!inBlock && (unsigned int)blocksAgo >= scale) { // Only counts as a failure if not confirmed for entire period |
| 480 | assert(scale != 0); |
| 481 | unsigned int periodsAgo = blocksAgo / scale; |
| 482 | for (size_t i = 0; i < periodsAgo && i < failAvg.size(); i++) { |
| 483 | failAvg[i][bucketindex]++; |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | // This function is called from CTxMemPool::removeUnchecked to ensure |
| 489 | // txs removed from the mempool for any reason are no longer |