diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -116,7 +116,7 @@ std::vector have_txn(txn_available.size()); { LOCK(pool->cs); - const std::vector> &vTxHashes = + const std::vector> &vTxHashes = pool->vTxHashes; for (size_t i = 0; i < vTxHashes.size(); i++) { uint64_t shortid = cmpctblock.GetShortID(vTxHashes[i].first); diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -360,7 +360,7 @@ std::string hashStr; const RetFormat rf = ParseDataFormat(hashStr, strURIPart); - uint256 hash; + TxHash hash; if (!ParseHashStr(hashStr, hash)) return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -441,19 +441,19 @@ LOCK(mempool.cs); UniValue o(UniValue::VOBJ); for (const CTxMemPoolEntry &e : mempool.mapTx) { - const uint256 &txid = e.GetTx().GetHash(); + const TxHash &txhash = e.GetTx().GetHash(); UniValue info(UniValue::VOBJ); entryToJSON(info, e); - o.push_back(Pair(txid.ToString(), info)); + o.push_back(Pair(txhash.ToString(), info)); } return o; } else { - std::vector vtxids; - mempool.queryHashes(vtxids); + std::vector vtxhashes; + mempool.queryHashes(vtxhashes); UniValue a(UniValue::VARR); - for (const uint256 &txid : vtxids) { - a.push_back(txid.ToString()); + for (const TxHash &txhash : vtxhashes) { + a.push_back(txhash.ToString()); } return a; diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -233,7 +233,7 @@ // extracts a TxMemPoolEntry's transaction hash struct mempoolentry_txid { - typedef uint256 result_type; + typedef TxHash result_type; result_type operator()(const CTxMemPoolEntry &entry) const { return entry.GetTx().GetHash(); } @@ -521,7 +521,7 @@ typedef indexed_transaction_set::nth_index<0>::type::iterator txiter; //!< All tx hashes/entries in mapTx, in random order - std::vector> vTxHashes; + std::vector> vTxHashes; struct CompareIteratorByHash { bool operator()(const txiter &a, const txiter &b) const { @@ -552,7 +552,7 @@ public: indirectmap mapNextTx; - std::map> mapDeltas; + std::map> mapDeltas; /** Create a new CTxMemPool. */ @@ -574,9 +574,9 @@ // to track size/count of descendant transactions. First version of // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and // then invoke the second version. - bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, + bool addUnchecked(const TxHash &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true); - bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, + bool addUnchecked(const TxHash &hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true); void removeRecursive( @@ -591,8 +591,8 @@ void clear(); // lock free void _clear(); - bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb); - void queryHashes(std::vector &vtxid); + bool CompareDepthAndScore(const TxHash &hasha, const TxHash &hashb); + void queryHashes(std::vector &vtxhash); bool isSpent(const COutPoint &outpoint); unsigned int GetTransactionsUpdated() const; void AddTransactionsUpdated(unsigned int n); @@ -604,11 +604,11 @@ bool HasNoInputsOf(const CTransaction &tx) const; /** Affect CreateNewBlock prioritisation of transactions */ - void PrioritiseTransaction(const uint256 hash, const std::string strHash, + void PrioritiseTransaction(const TxHash hash, const std::string strHash, double dPriorityDelta, const Amount nFeeDelta); - void ApplyDeltas(const uint256 hash, double &dPriorityDelta, + void ApplyDeltas(const TxHash hash, double &dPriorityDelta, Amount &nFeeDelta) const; - void ClearPrioritisation(const uint256 hash); + void ClearPrioritisation(const TxHash hash); public: /** @@ -632,8 +632,7 @@ * for). Note: hashesToUpdate should be the set of transactions from the * disconnected block that have been accepted back into the mempool. */ - void - UpdateTransactionsFromBlock(const std::vector &hashesToUpdate); + void UpdateTransactionsFromBlock(const std::vector &hashesToUpdate); /** * Try to calculate all in-mempool ancestors of entry. @@ -683,7 +682,7 @@ /** Returns false if the transaction is in the mempool and not within the * chain limit specified. */ - bool TransactionWithinChainLimit(const uint256 &txid, + bool TransactionWithinChainLimit(const TxHash &txhash, size_t chainLimit) const; unsigned long size() { @@ -696,7 +695,7 @@ return totalTxSize; } - bool exists(uint256 hash) const { + bool exists(TxHash hash) const { LOCK(cs); return mapTx.count(hash) != 0; } @@ -707,8 +706,8 @@ return it != mapTx.end() && outpoint.n < it->GetTx().vout.size(); } - CTransactionRef get(const uint256 &hash) const; - TxMempoolInfo info(const uint256 &hash) const; + CTransactionRef get(const TxHash &hash) const; + TxMempoolInfo info(const TxHash &hash) const; std::vector infoAll() const; /** @@ -758,7 +757,7 @@ * transaction again, if encountered in another transaction chain. */ void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, - const std::set &setExclude); + const std::set &setExclude); /** Update ancestors of hash to add/remove it as a descendant transaction. */ void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors); diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -79,7 +79,7 @@ // descendants. void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, - const std::set &setExclude) { + const std::set &setExclude) { setEntries stageEntries, setAllDescendants; stageEntries = GetMemPoolChildren(updateIt); @@ -130,7 +130,7 @@ // descendants to the parent. For each such descendant, also update the ancestor // state to include the parent. void CTxMemPool::UpdateTransactionsFromBlock( - const std::vector &vHashesToUpdate) { + const std::vector &vHashesToUpdate) { LOCK(cs); // For each entry in vHashesToUpdate, store the set of in-mempool, but not // in-vHashesToUpdate transactions, so that we don't have to recalculate @@ -139,15 +139,15 @@ // Use a set for lookups into vHashesToUpdate (these entries are already // accounted for in the state of their ancestors) - std::set setAlreadyIncluded(vHashesToUpdate.begin(), - vHashesToUpdate.end()); + std::set setAlreadyIncluded(vHashesToUpdate.begin(), + vHashesToUpdate.end()); // Iterate in reverse, so that whenever we are looking at at a transaction // we are sure that all in-mempool descendants have already been processed. // This maximizes the benefit of the descendant cache and guarantees that // setMemPoolChildren will be updated, an assumption made in // UpdateForDescendants. - for (const uint256 &hash : boost::adaptors::reverse(vHashesToUpdate)) { + for (const TxHash &hash : boost::adaptors::reverse(vHashesToUpdate)) { // we cache the in-mempool children to avoid duplicate updates setEntries setChildren; // calculate children from mapNextTx @@ -159,7 +159,7 @@ // First calculate the children, and update setMemPoolChildren to // include them, and update their setMemPoolParents to include this tx. for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) { - const uint256 &childHash = iter->second->GetHash(); + const TxHash &childHash = iter->second->GetHash(); txiter childIter = mapTx.find(childHash); assert(childIter != mapTx.end()); // We can skip updating entries we've encountered before or that are @@ -406,7 +406,7 @@ nTransactionsUpdated += n; } -bool CTxMemPool::addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, +bool CTxMemPool::addUnchecked(const TxHash &hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate) { NotifyEntryAdded(entry.GetSharedTx()); // Add to memory pool without checking anything. @@ -418,7 +418,7 @@ // Update transaction for any feeDelta created by PrioritiseTransaction // TODO: refactor so that the fee delta is calculated before inserting into // mapTx. - std::map>::const_iterator pos = + std::map>::const_iterator pos = mapDeltas.find(hash); if (pos != mapDeltas.end()) { const std::pair &deltas = pos->second; @@ -433,7 +433,7 @@ cachedInnerUsage += entry.DynamicMemoryUsage(); const CTransaction &tx = newit->GetTx(); - std::set setParentTransactions; + std::set setParentTransactions; for (unsigned int i = 0; i < tx.vin.size(); i++) { mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx)); setParentTransactions.insert(tx.vin[i].prevout.hash); @@ -446,7 +446,7 @@ // the mess we're leaving here. // Update ancestors with information about this tx - for (const uint256 &phash : setParentTransactions) { + for (const TxHash &phash : setParentTransactions) { txiter pit = mapTx.find(phash); if (pit != mapTx.end()) { UpdateParent(newit, pit, true); @@ -467,7 +467,7 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason) { NotifyEntryRemoved(it->GetSharedTx(), reason); - const uint256 txid = it->GetTx().GetHash(); + const TxHash txid = it->GetTx().GetHash(); for (const CTxIn &txin : it->GetTx().vin) { mapNextTx.erase(txin.prevout); } @@ -627,9 +627,9 @@ LOCK(cs); std::vector entries; for (const auto &tx : vtx) { - uint256 txid = tx->GetHash(); + TxHash txhash = tx->GetHash(); - indexed_transaction_set::iterator i = mapTx.find(txid); + indexed_transaction_set::iterator i = mapTx.find(txhash); if (i != mapTx.end()) entries.push_back(&*i); } // Before the txs in the new block have been removed from the mempool, @@ -797,8 +797,8 @@ } } for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) { - uint256 txid = it->second->GetHash(); - indexed_transaction_set::const_iterator it2 = mapTx.find(txid); + TxHash txhash = it->second->GetHash(); + indexed_transaction_set::const_iterator it2 = mapTx.find(txhash); const CTransaction &tx = it2->GetTx(); assert(it2 != mapTx.end()); assert(&tx == it->second); @@ -808,8 +808,8 @@ assert(innerUsage == cachedInnerUsage); } -bool CTxMemPool::CompareDepthAndScore(const uint256 &hasha, - const uint256 &hashb) { +bool CTxMemPool::CompareDepthAndScore(const TxHash &hasha, + const TxHash &hashb) { LOCK(cs); indexed_transaction_set::const_iterator i = mapTx.find(hasha); if (i == mapTx.end()) return false; @@ -854,15 +854,15 @@ return iters; } -void CTxMemPool::queryHashes(std::vector &vtxid) { +void CTxMemPool::queryHashes(std::vector &vtxhash) { LOCK(cs); auto iters = GetSortedDepthAndScore(); - vtxid.clear(); - vtxid.reserve(mapTx.size()); + vtxhash.clear(); + vtxhash.reserve(mapTx.size()); for (auto it : iters) { - vtxid.push_back(it->GetTx().GetHash()); + vtxhash.push_back(it->GetTx().GetHash()); } } @@ -886,16 +886,16 @@ return ret; } -CTransactionRef CTxMemPool::get(const uint256 &txid) const { +CTransactionRef CTxMemPool::get(const TxHash &txhash) const { LOCK(cs); - indexed_transaction_set::const_iterator i = mapTx.find(txid); + indexed_transaction_set::const_iterator i = mapTx.find(txhash); if (i == mapTx.end()) return nullptr; return i->GetSharedTx(); } -TxMempoolInfo CTxMemPool::info(const uint256 &txid) const { +TxMempoolInfo CTxMemPool::info(const TxHash &txhash) const { LOCK(cs); - indexed_transaction_set::const_iterator i = mapTx.find(txid); + indexed_transaction_set::const_iterator i = mapTx.find(txhash); if (i == mapTx.end()) return TxMempoolInfo(); return GetInfo(i); } @@ -955,7 +955,7 @@ return true; } -void CTxMemPool::PrioritiseTransaction(const uint256 hash, +void CTxMemPool::PrioritiseTransaction(const TxHash hash, const std::string strHash, double dPriorityDelta, const Amount nFeeDelta) { @@ -991,10 +991,10 @@ dPriorityDelta, FormatMoney(nFeeDelta)); } -void CTxMemPool::ApplyDeltas(const uint256 hash, double &dPriorityDelta, +void CTxMemPool::ApplyDeltas(const TxHash hash, double &dPriorityDelta, Amount &nFeeDelta) const { LOCK(cs); - std::map>::const_iterator pos = + std::map>::const_iterator pos = mapDeltas.find(hash); if (pos == mapDeltas.end()) return; const std::pair &deltas = pos->second; @@ -1002,7 +1002,7 @@ nFeeDelta += deltas.second; } -void CTxMemPool::ClearPrioritisation(const uint256 hash) { +void CTxMemPool::ClearPrioritisation(const TxHash hash) { LOCK(cs); mapDeltas.erase(hash); } @@ -1077,7 +1077,7 @@ return stage.size(); } -bool CTxMemPool::addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, +bool CTxMemPool::addUnchecked(const TxHash &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate) { LOCK(cs); setEntries setAncestors; @@ -1211,10 +1211,10 @@ nTxnRemoved, maxFeeRateRemoved.ToString()); } -bool CTxMemPool::TransactionWithinChainLimit(const uint256 &txid, +bool CTxMemPool::TransactionWithinChainLimit(const TxHash &txhash, size_t chainLimit) const { LOCK(cs); - auto it = mapTx.find(txid); + auto it = mapTx.find(txhash); return it == mapTx.end() || (it->GetCountWithAncestors() < chainLimit && it->GetCountWithDescendants() < chainLimit); } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -682,7 +682,7 @@ AssertLockHeld(cs_main); const CTransaction &tx = *ptx; - const uint256 txid = tx.GetHash(); + const TxHash txhash = tx.GetHash(); if (pfMissingInputs) { *pfMissingInputs = false; } @@ -714,7 +714,7 @@ } // Is it already in the memory pool? - if (pool.exists(txid)) { + if (pool.exists(txhash)) { return state.Invalid(false, REJECT_ALREADY_KNOWN, "txn-already-in-mempool"); } @@ -746,7 +746,7 @@ // Do we already have it? for (size_t out = 0; out < tx.vout.size(); out++) { - COutPoint outpoint(txid, out); + COutPoint outpoint(txhash, out); bool had_coin_in_cache = pcoinsTip->HaveCoinInCache(outpoint); if (view.HaveCoin(outpoint)) { if (!had_coin_in_cache) { @@ -815,7 +815,7 @@ // nModifiedFees includes any fee deltas from PrioritiseTransaction Amount nModifiedFees = nFees; double nPriorityDummy = 0; - pool.ApplyDeltas(txid, nPriorityDummy, nModifiedFees); + pool.ApplyDeltas(txhash, nPriorityDummy, nModifiedFees); Amount inChainInputValue; double dPriority = @@ -963,7 +963,7 @@ return error( "%s: BUG! PLEASE REPORT THIS! ConnectInputs failed against " "MANDATORY but not STANDARD flags %s, %s", - __func__, txid.ToString(), FormatStateMessage(state)); + __func__, txhash.ToString(), FormatStateMessage(state)); } if (!CheckInputs(tx, state, view, true, @@ -972,7 +972,7 @@ return error( "%s: ConnectInputs failed against MANDATORY but not " "STANDARD flags due to promiscuous mempool %s, %s", - __func__, txid.ToString(), FormatStateMessage(state)); + __func__, txhash.ToString(), FormatStateMessage(state)); } LogPrintf("Warning: -promiscuousmempool flags set to not include " @@ -987,14 +987,14 @@ IsCurrentForFeeEstimation() && pool.HasNoInputsOf(tx); // Store transaction in memory. - pool.addUnchecked(txid, entry, setAncestors, validForFeeEstimation); + pool.addUnchecked(txhash, entry, setAncestors, validForFeeEstimation); // Trim mempool and check if tx was trimmed. if (!fOverrideMempoolLimit) { LimitMempoolSize( pool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); - if (!pool.exists(txid)) { + if (!pool.exists(txhash)) { return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool full"); } @@ -1041,14 +1041,14 @@ /** Return transaction in txOut, and if it was found inside a block, its hash is * placed in hashBlock */ -bool GetTransaction(const Config &config, const uint256 &txid, +bool GetTransaction(const Config &config, const uint256 &txhash, CTransactionRef &txOut, uint256 &hashBlock, bool fAllowSlow) { CBlockIndex *pindexSlow = nullptr; LOCK(cs_main); - CTransactionRef ptx = mempool.get(txid); + CTransactionRef ptx = mempool.get(txhash); if (ptx) { txOut = ptx; return true; @@ -1056,7 +1056,7 @@ if (fTxIndex) { CDiskTxPos postx; - if (pblocktree->ReadTxIndex(txid, postx)) { + if (pblocktree->ReadTxIndex(txhash, postx)) { CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION); if (file.IsNull()) @@ -1071,15 +1071,15 @@ e.what()); } hashBlock = header.GetHash(); - if (txOut->GetHash() != txid) - return error("%s: txid mismatch", __func__); + if (txOut->GetHash() != txhash) + return error("%s: txhash mismatch", __func__); return true; } } // use coin database to locate block that contains transaction, and scan it if (fAllowSlow) { - const Coin &coin = AccessByTxid(*pcoinsTip, txid); + const Coin &coin = AccessByTxid(*pcoinsTip, txhash); if (!coin.IsSpent()) { pindexSlow = chainActive[coin.GetHeight()]; } @@ -1091,7 +1091,7 @@ CBlock block; if (ReadBlockFromDisk(block, pindexSlow, params)) { for (const auto &tx : block.vtx) { - if (tx->GetHash() == txid) { + if (tx->GetHash() == txhash) { txOut = tx; hashBlock = pindexSlow->GetBlockHash(); return true; @@ -1664,7 +1664,7 @@ size_t i = block.vtx.size(); while (i-- > 0) { const CTransaction &tx = *(block.vtx[i]); - uint256 txid = tx.GetHash(); + TxHash txhash = tx.GetHash(); // Check that all outputs are available and match the outputs in the // block itself exactly. @@ -1673,7 +1673,7 @@ continue; } - COutPoint out(txid, o); + COutPoint out(txhash, o); Coin coin; bool is_spent = view.SpendCoin(out, &coin); if (!is_spent || tx.vout[o] != coin.GetTxOut()) { @@ -2459,7 +2459,7 @@ if (!fBare) { // Resurrect mempool transactions from the disconnected block. - std::vector vHashUpdate; + std::vector vHashUpdate; for (const auto &it : block.vtx) { const CTransaction &tx = *it; // ignore validation errors in resurrected transactions @@ -3264,7 +3264,7 @@ if (!CheckCoinbase(*block.vtx[0], state, false)) { return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(), - strprintf("Coinbase check failed (txid %s) %s", + strprintf("Coinbase check failed (txhash %s) %s", block.vtx[0]->GetHash().ToString(), state.GetDebugMessage())); } @@ -3302,7 +3302,7 @@ if (!CheckRegularTransaction(*tx, state, false)) { return state.Invalid( false, state.GetRejectCode(), state.GetRejectReason(), - strprintf("Transaction check failed (txid %s) %s", + strprintf("Transaction check failed (txhash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage())); } } @@ -4963,7 +4963,7 @@ } if (ShutdownRequested()) return false; } - std::map mapDeltas; + std::map mapDeltas; file >> mapDeltas; for (const auto &i : mapDeltas) { @@ -4986,7 +4986,7 @@ void DumpMempool(void) { int64_t start = GetTimeMicros(); - std::map mapDeltas; + std::map mapDeltas; std::vector vinfo; {