diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -603,11 +603,11 @@ fVerbose = request.params[1].get_bool(); } - uint256 hash = ParseHashV(request.params[0], "parameter 1"); + TxId txid(ParseHashV(request.params[0], "parameter 1")); LOCK(g_mempool.cs); - CTxMemPool::txiter it = g_mempool.mapTx.find(hash); + CTxMemPool::txiter it = g_mempool.mapTx.find(txid); if (it == g_mempool.mapTx.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool"); @@ -630,10 +630,10 @@ UniValue o(UniValue::VOBJ); for (CTxMemPool::txiter ancestorIt : setAncestors) { const CTxMemPoolEntry &e = *ancestorIt; - const uint256 &_hash = e.GetTx().GetId(); + const TxId &_txid = e.GetTx().GetId(); UniValue info(UniValue::VOBJ); entryToJSON(::g_mempool, info, e); - o.pushKV(_hash.ToString(), info); + o.pushKV(_txid.ToString(), info); } return o; } @@ -673,11 +673,11 @@ fVerbose = request.params[1].get_bool(); } - uint256 hash = ParseHashV(request.params[0], "parameter 1"); + TxId txid(ParseHashV(request.params[0], "parameter 1")); LOCK(g_mempool.cs); - CTxMemPool::txiter it = g_mempool.mapTx.find(hash); + CTxMemPool::txiter it = g_mempool.mapTx.find(txid); if (it == g_mempool.mapTx.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool"); @@ -699,10 +699,10 @@ UniValue o(UniValue::VOBJ); for (CTxMemPool::txiter descendantIt : setDescendants) { const CTxMemPoolEntry &e = *descendantIt; - const uint256 &_hash = e.GetTx().GetId(); + const TxId &_txid = e.GetTx().GetId(); UniValue info(UniValue::VOBJ); entryToJSON(::g_mempool, info, e); - o.pushKV(_hash.ToString(), info); + o.pushKV(_txid.ToString(), info); } return o; } @@ -726,11 +726,11 @@ HelpExampleRpc("getmempoolentry", "\"mytxid\"")); } - uint256 hash = ParseHashV(request.params[0], "parameter 1"); + TxId txid(ParseHashV(request.params[0], "parameter 1")); LOCK(g_mempool.cs); - CTxMemPool::txiter it = g_mempool.mapTx.find(hash); + CTxMemPool::txiter it = g_mempool.mapTx.find(txid); if (it == g_mempool.mapTx.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool"); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -297,10 +297,10 @@ LOCK(cs_main); - uint256 hash = ParseHashStr(request.params[0].get_str(), "txid"); + TxId txid(ParseHashStr(request.params[0].get_str(), "txid")); Amount nAmount = request.params[2].get_int64() * SATOSHI; - g_mempool.PrioritiseTransaction(hash, request.params[1].get_real(), + g_mempool.PrioritiseTransaction(txid, request.params[1].get_real(), nAmount); return true; } diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -189,7 +189,7 @@ pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); - uint256 txhash; + TxId txid; // Test with pre-forwarding tx 1, but not coinbase { @@ -258,18 +258,18 @@ pool.mapTx.find(block.vtx[2]->GetId())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 3); - txhash = block.vtx[2]->GetId(); + txid = block.vtx[2]->GetId(); block.vtx.clear(); block2.vtx.clear(); block3.vtx.clear(); // + 1 because of partialBlock; -1 because of block. - BOOST_CHECK_EQUAL(pool.mapTx.find(txhash)->GetSharedTx().use_count(), + BOOST_CHECK_EQUAL(pool.mapTx.find(txid)->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1 - 1); } // -1 because of block - BOOST_CHECK_EQUAL(pool.mapTx.find(txhash)->GetSharedTx().use_count(), + BOOST_CHECK_EQUAL(pool.mapTx.find(txid)->GetSharedTx().use_count(), SHARED_TX_OFFSET - 1); } @@ -284,7 +284,7 @@ pool.mapTx.find(block.vtx[1]->GetId())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 0); - uint256 txhash; + TxId txid; // Test with pre-forwarding coinbase + tx 2 with tx 1 in mempool { @@ -323,17 +323,17 @@ BlockMerkleRoot(block2, &mutated).ToString()); BOOST_CHECK(!mutated); - txhash = block.vtx[1]->GetId(); + txid = block.vtx[1]->GetId(); block.vtx.clear(); block2.vtx.clear(); // + 1 because of partialBlock; -1 because of block. - BOOST_CHECK_EQUAL(pool.mapTx.find(txhash)->GetSharedTx().use_count(), + BOOST_CHECK_EQUAL(pool.mapTx.find(txid)->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1 - 1); } // -1 because of block - BOOST_CHECK_EQUAL(pool.mapTx.find(txhash)->GetSharedTx().use_count(), + BOOST_CHECK_EQUAL(pool.mapTx.find(txid)->GetSharedTx().use_count(), SHARED_TX_OFFSET - 1); } diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -227,7 +227,7 @@ // extracts a transaction hash from CTxMemPoolEntry or CTransactionRef struct mempoolentry_txid { - typedef uint256 result_type; + typedef TxId result_type; result_type operator()(const CTxMemPoolEntry &entry) const { return entry.GetTx().GetId(); } @@ -396,7 +396,7 @@ public: SaltedTxidHasher(); - size_t operator()(const uint256 &txid) const { + size_t operator()(const TxId &txid) const { return SipHashUint256(k0, k1, txid); } }; @@ -646,7 +646,7 @@ void clear(); // lock free void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); - bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb); + bool CompareDepthAndScore(const TxId &txida, const TxId &txidb); void queryHashes(std::vector &vtxid) const; bool isSpent(const COutPoint &outpoint) const; unsigned int GetTransactionsUpdated() const; @@ -659,7 +659,7 @@ bool HasNoInputsOf(const CTransaction &tx) const; /** Affect CreateNewBlock prioritisation of transactions */ - void PrioritiseTransaction(const uint256 &hash, double dPriorityDelta, + void PrioritiseTransaction(const TxId &txid, double dPriorityDelta, const Amount nFeeDelta); void ApplyDeltas(const uint256 hash, double &dPriorityDelta, Amount &nFeeDelta) const; @@ -752,7 +752,7 @@ * Calculate the ancestor and descendant count for the given transaction. * The counts include the transaction itself. */ - void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, + void GetTransactionAncestry(const TxId &txid, size_t &ancestors, size_t &descendants) const; /** @returns true if the mempool is fully loaded */ @@ -771,13 +771,13 @@ return totalTxSize; } - bool exists(uint256 hash) const { + bool exists(const TxId &txid) const { LOCK(cs); - return mapTx.count(hash) != 0; + return mapTx.count(txid) != 0; } - CTransactionRef get(const uint256 &hash) const; - TxMempoolInfo info(const uint256 &hash) const; + CTransactionRef get(const TxId &txid) const; + TxMempoolInfo info(const TxId &txid) const; std::vector infoAll() const; CFeeRate estimateFee() const; diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -433,7 +433,7 @@ cachedInnerUsage += entry.DynamicMemoryUsage(); const CTransaction &tx = newit->GetTx(); - std::set setParentTransactions; + std::set setParentTransactions; for (const CTxIn &in : tx.vin) { mapNextTx.insert(std::make_pair(&in.prevout, &tx)); setParentTransactions.insert(in.prevout.GetTxId()); @@ -446,7 +446,7 @@ // the mess we're leaving here. // Update ancestors with information about this tx - for (const uint256 &phash : setParentTransactions) { + for (const TxId &phash : setParentTransactions) { txiter pit = mapTx.find(phash); if (pit != mapTx.end()) { UpdateParent(newit, pit, true); @@ -633,7 +633,7 @@ std::vector entries; for (const CTransactionRef &tx : reverse_iterate(disconnectpool.GetQueuedTx().get())) { - uint256 txid = tx->GetId(); + const TxId &txid = tx->GetId(); indexed_transaction_set::iterator i = mapTx.find(txid); if (i != mapTx.end()) { @@ -810,7 +810,7 @@ } for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) { - uint256 txid = it->second->GetId(); + const TxId &txid = it->second->GetId(); indexed_transaction_set::const_iterator it2 = mapTx.find(txid); const CTransaction &tx = it2->GetTx(); assert(it2 != mapTx.end()); @@ -821,14 +821,13 @@ assert(innerUsage == cachedInnerUsage); } -bool CTxMemPool::CompareDepthAndScore(const uint256 &hasha, - const uint256 &hashb) { +bool CTxMemPool::CompareDepthAndScore(const TxId &txida, const TxId &txidb) { LOCK(cs); - indexed_transaction_set::const_iterator i = mapTx.find(hasha); + indexed_transaction_set::const_iterator i = mapTx.find(txida); if (i == mapTx.end()) { return false; } - indexed_transaction_set::const_iterator j = mapTx.find(hashb); + indexed_transaction_set::const_iterator j = mapTx.find(txidb); if (j == mapTx.end()) { return true; } @@ -903,7 +902,7 @@ return ret; } -CTransactionRef CTxMemPool::get(const uint256 &txid) const { +CTransactionRef CTxMemPool::get(const TxId &txid) const { LOCK(cs); indexed_transaction_set::const_iterator i = mapTx.find(txid); if (i == mapTx.end()) { @@ -913,7 +912,7 @@ return i->GetSharedTx(); } -TxMempoolInfo CTxMemPool::info(const uint256 &txid) const { +TxMempoolInfo CTxMemPool::info(const TxId &txid) const { LOCK(cs); indexed_transaction_set::const_iterator i = mapTx.find(txid); if (i == mapTx.end()) { @@ -935,15 +934,14 @@ return std::max(::minRelayTxFee, GetMinFee(maxMempoolSize)); } -void CTxMemPool::PrioritiseTransaction(const uint256 &hash, - double dPriorityDelta, +void CTxMemPool::PrioritiseTransaction(const TxId &txid, double dPriorityDelta, const Amount nFeeDelta) { { LOCK(cs); - TXModifier &deltas = mapDeltas[hash]; + TXModifier &deltas = mapDeltas[txid]; deltas.first += dPriorityDelta; deltas.second += nFeeDelta; - txiter it = mapTx.find(hash); + txiter it = mapTx.find(txid); if (it != mapTx.end()) { mapTx.modify(it, update_fee_delta(deltas.second)); // Now update all ancestors' modified fees with descendants @@ -969,7 +967,7 @@ } } LogPrintf("PrioritiseTransaction: %s priority += %f, fee += %d\n", - hash.ToString(), dPriorityDelta, FormatMoney(nFeeDelta)); + txid.ToString(), dPriorityDelta, FormatMoney(nFeeDelta)); } void CTxMemPool::ApplyDeltas(const uint256 hash, double &dPriorityDelta, @@ -1227,7 +1225,7 @@ return maximum; } -void CTxMemPool::GetTransactionAncestry(const uint256 &txid, size_t &ancestors, +void CTxMemPool::GetTransactionAncestry(const TxId &txid, size_t &ancestors, size_t &descendants) const { LOCK(cs); auto it = mapTx.find(txid); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5663,7 +5663,7 @@ // wallet(s) having loaded it while we were processing // mempool transactions; consider these as valid, instead of // failed, but mark them as 'already there' - if (pool.exists(tx->GetHash())) { + if (pool.exists(tx->GetId())) { ++already_there; } else { ++failed; @@ -5677,7 +5677,7 @@ return false; } } - std::map mapDeltas; + std::map mapDeltas; file >> mapDeltas; for (const auto &i : mapDeltas) {