| 89 | } |
| 90 | |
| 91 | bool CTxMemPool::CheckTxInMemPool(const uint256 &txid, const CTxMemPoolEntry &memPoolEntry, CValidationState &state, int32_t index, |
| 92 | bool bRehearsalExecute) { |
| 93 | auto bm = MAKE_BENCHMARK("execute tx in mempool"); |
| 94 | CBlockIndex *pTip = chainActive.Tip(); |
| 95 | if (pTip == nullptr) |
| 96 | throw runtime_error("CheckTxInMemPool:: ChainActive.Tip() is null"); |
| 97 | |
| 98 | HeightType newHeight = pTip->height + 1; |
| 99 | // not within valid height |
| 100 | static int validHeight = SysCfg().GetTxCacheHeight(); |
| 101 | auto &tx = *memPoolEntry.GetTransaction(); |
| 102 | if (!tx.IsValidHeight(newHeight, validHeight)) { |
| 103 | LogPrint(BCLog::INFO, "valid_height(%d) of txid %s is invalid! new_height=%d\n", tx.valid_height, txid.GetHex(), newHeight); |
| 104 | return state.Invalid(false, REJECT_INVALID, "tx-invalid-height"); |
| 105 | } |
| 106 | |
| 107 | // already confirmed in block |
| 108 | if (cw->txCache.HasTx(txid)) { |
| 109 | LogPrint(BCLog::INFO, "txid %s confirmed in block\n", txid.GetHex()); |
| 110 | return state.Invalid(false, REJECT_INVALID, "tx-duplicate-confirmed"); |
| 111 | } |
| 112 | |
| 113 | auto spCW = std::make_shared<CCacheWrapper>(cw.get()); |
| 114 | |
| 115 | if (bRehearsalExecute) { //always true so far |
| 116 | const auto &bpRegid = GetBlockBpRegid(*chainActive.TipBlock()); |
| 117 | uint32_t fuelRate = GetElementForBurn(pTip); |
| 118 | uint32_t blockTime = pTip->GetBlockTime(); |
| 119 | uint32_t prevBlockTime = pTip->pprev != nullptr ? pTip->pprev->GetBlockTime() : pTip->GetBlockTime(); |
| 120 | CTxExecuteContext context(newHeight, index, fuelRate, blockTime, prevBlockTime, bpRegid, spCW.get(), &state, |
| 121 | TxExecuteContextType::VALIDATE_MEMPOOL); |
| 122 | |
| 123 | if (!tx.ExecuteFullTx(context)) { //rehearsal only within cache env |
| 124 | pCdMan->pLogCache->SetExecuteFail(newHeight, tx.GetHash(), |
| 125 | state.GetRejectCode(), state.GetRejectReason()); |
| 126 | return false; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | spCW->Flush(); |
| 131 | |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | void CTxMemPool::SetMemPoolCache() { |
| 136 | cw.reset(new CCacheWrapper(pCdMan)); |
nothing calls this directly
no test coverage detected