refactor: make CTxMemPool::GetIter strongly typed
This allows adding a GetIter(const Wtxid&) overload in a next commit, making it easier to visit this function from a variant. Co-authored-by: stickies-v <stickies-v@protonmail.com>
This commit is contained in:
1 parent
11d28f21bb
commit
fcf92fd640
4 files changed
+10
-10
No files matched your search
+2
-2
@@ -523,12 +523,12 @@ static RPCHelpMan getmempooldescendants()
|
|||||||
if (!request.params[1].isNull())
|
if (!request.params[1].isNull())
|
||||||
fVerbose = request.params[1].get_bool();
|
fVerbose = request.params[1].get_bool();
|
||||||
|
|
||||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
Txid txid{Txid::FromUint256(ParseHashV(request.params[0], "parameter 1"))};
|
||||||
|
|
||||||
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
|
|
||||||
const auto it{mempool.GetIter(hash)};
|
const auto it{mempool.GetIter(txid)};
|
||||||
if (!it) {
|
if (!it) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
|
|||||||
|
|
||||||
Package package_v3_v2{mempool_tx_v3, tx_v2_from_v3};
|
Package package_v3_v2{mempool_tx_v3, tx_v2_from_v3};
|
||||||
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), package_v3_v2, empty_ancestors), expected_error_str);
|
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), package_v3_v2, empty_ancestors), expected_error_str);
|
||||||
CTxMemPool::setEntries entries_mempool_v3{pool.GetIter(mempool_tx_v3->GetHash().ToUint256()).value()};
|
CTxMemPool::setEntries entries_mempool_v3{pool.GetIter(mempool_tx_v3->GetHash()).value()};
|
||||||
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), {tx_v2_from_v3}, entries_mempool_v3), expected_error_str);
|
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v2_from_v3, GetVirtualTransactionSize(*tx_v2_from_v3), {tx_v2_from_v3}, entries_mempool_v3), expected_error_str);
|
||||||
|
|
||||||
// mempool_tx_v3 mempool_tx_v2
|
// mempool_tx_v3 mempool_tx_v2
|
||||||
@@ -339,7 +339,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
|
|||||||
|
|
||||||
Package package_v2_v3{mempool_tx_v2, tx_v3_from_v2};
|
Package package_v2_v3{mempool_tx_v2, tx_v3_from_v2};
|
||||||
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), package_v2_v3, empty_ancestors), expected_error_str);
|
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), package_v2_v3, empty_ancestors), expected_error_str);
|
||||||
CTxMemPool::setEntries entries_mempool_v2{pool.GetIter(mempool_tx_v2->GetHash().ToUint256()).value()};
|
CTxMemPool::setEntries entries_mempool_v2{pool.GetIter(mempool_tx_v2->GetHash()).value()};
|
||||||
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), {tx_v3_from_v2}, entries_mempool_v2), expected_error_str);
|
BOOST_CHECK_EQUAL(*PackageTRUCChecks(tx_v3_from_v2, GetVirtualTransactionSize(*tx_v3_from_v2), {tx_v3_from_v2}, entries_mempool_v2), expected_error_str);
|
||||||
|
|
||||||
// mempool_tx_v3 mempool_tx_v2
|
// mempool_tx_v3 mempool_tx_v2
|
||||||
@@ -536,7 +536,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
|
|||||||
// Configuration where parent already has 2 other children in mempool (no sibling eviction allowed). This may happen as the result of a reorg.
|
// Configuration where parent already has 2 other children in mempool (no sibling eviction allowed). This may happen as the result of a reorg.
|
||||||
AddToMempool(pool, entry.FromTx(tx_v3_child2));
|
AddToMempool(pool, entry.FromTx(tx_v3_child2));
|
||||||
auto tx_v3_child3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 24}}, /*version=*/3);
|
auto tx_v3_child3 = make_tx({COutPoint{mempool_tx_v3->GetHash(), 24}}, /*version=*/3);
|
||||||
auto entry_mempool_parent = pool.GetIter(mempool_tx_v3->GetHash().ToUint256()).value();
|
auto entry_mempool_parent = pool.GetIter(mempool_tx_v3->GetHash()).value();
|
||||||
BOOST_CHECK_EQUAL(entry_mempool_parent->GetCountWithDescendants(), 3);
|
BOOST_CHECK_EQUAL(entry_mempool_parent->GetCountWithDescendants(), 3);
|
||||||
auto ancestors_2siblings{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_child3), m_limits)};
|
auto ancestors_2siblings{pool.CalculateMemPoolAncestors(entry.FromTx(tx_v3_child3), m_limits)};
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -154,7 +154,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256>& vHashes
|
|||||||
for (const auto& txid : descendants_to_remove) {
|
for (const auto& txid : descendants_to_remove) {
|
||||||
// This txid may have been removed already in a prior call to removeRecursive.
|
// This txid may have been removed already in a prior call to removeRecursive.
|
||||||
// Therefore we ensure it is not yet removed already.
|
// Therefore we ensure it is not yet removed already.
|
||||||
if (const std::optional<txiter> txiter = GetIter(txid)) {
|
if (const std::optional<txiter> txiter = GetIter(Txid::FromUint256(txid))) {
|
||||||
removeRecursive((*txiter)->GetTx(), MemPoolRemovalReason::SIZELIMIT);
|
removeRecursive((*txiter)->GetTx(), MemPoolRemovalReason::SIZELIMIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -984,9 +984,9 @@ const CTransaction* CTxMemPool::GetConflictTx(const COutPoint& prevout) const
|
|||||||
return it == mapNextTx.end() ? nullptr : it->second;
|
return it == mapNextTx.end() ? nullptr : it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const uint256& txid) const
|
std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const Txid& txid) const
|
||||||
{
|
{
|
||||||
auto it = mapTx.find(txid);
|
auto it = mapTx.find(txid.ToUint256());
|
||||||
if (it != mapTx.end()) return it;
|
if (it != mapTx.end()) return it;
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@@ -1007,7 +1007,7 @@ std::vector<CTxMemPool::txiter> CTxMemPool::GetIterVec(const std::vector<uint256
|
|||||||
std::vector<txiter> ret;
|
std::vector<txiter> ret;
|
||||||
ret.reserve(txids.size());
|
ret.reserve(txids.size());
|
||||||
for (const auto& txid : txids) {
|
for (const auto& txid : txids) {
|
||||||
const auto it{GetIter(txid)};
|
const auto it{GetIter(Txid::FromUint256(txid))};
|
||||||
if (!it) return {};
|
if (!it) return {};
|
||||||
ret.push_back(*it);
|
ret.push_back(*it);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -498,7 +498,7 @@ public:
|
|||||||
const CTransaction* GetConflictTx(const COutPoint& prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
const CTransaction* GetConflictTx(const COutPoint& prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
/** Returns an iterator to the given hash, if found */
|
/** Returns an iterator to the given hash, if found */
|
||||||
std::optional<txiter> GetIter(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
std::optional<txiter> GetIter(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
/** Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
|
/** Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
|
||||||
* Does not require that all of the hashes correspond to actual transactions in the mempool,
|
* Does not require that all of the hashes correspond to actual transactions in the mempool,
|
||||||
|
|||||||
Reference in new issue
Block a user