tx pool: Use class methods to hide raw map iterator impl details #13793

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:Mf1808-hideATMPiterators changing 3 files +46 −29
  1. MarcoFalke commented at 2:24 pm on July 29, 2018: member

    ATMP et al would often use map iterator implementation details such as end() or find(), which is acceptable in current code.

    However, this not only makes it impossible to turn the maps into private members in the future but also makes it harder to replace the maps with different data structures.

    This is required for and split off of #13804

  2. MarcoFalke added the label Refactoring on Jul 29, 2018
  3. MarcoFalke force-pushed on Jul 29, 2018
  4. MarcoFalke force-pushed on Jul 29, 2018
  5. in src/txmempool.cpp:370 in fa752b7480 outdated
    375-        const CAmount &delta = pos->second;
    376-        if (delta) {
    377+    CAmount delta{0};
    378+    ApplyDelta(hash, delta);
    379+    if (delta) {
    380             mapTx.modify(newit, update_fee_delta(delta));
    


    Empact commented at 11:17 pm on July 29, 2018:
    nit: whitespace
  6. in src/txmempool.cpp:393 in fa752b7480 outdated
    394@@ -397,11 +395,8 @@ void CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
    395     // to clean up the mess we're leaving here.
    396 
    397     // Update ancestors with information about this tx
    398-    for (const uint256 &phash : setParentTransactions) {
    399-        txiter pit = mapTx.find(phash);
    400-        if (pit != mapTx.end()) {
    401+    for (const auto& pit : GetSetIter(setParentTransactions)) {
    402             UpdateParent(newit, pit, true);
    


    Empact commented at 11:20 pm on July 29, 2018:
    nit: whitespace
  7. in src/txmempool.cpp:398 in fa752b7480 outdated
    394@@ -397,11 +395,8 @@ void CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
    395     // to clean up the mess we're leaving here.
    396 
    397     // Update ancestors with information about this tx
    398-    for (const uint256 &phash : setParentTransactions) {
    399-        txiter pit = mapTx.find(phash);
    400-        if (pit != mapTx.end()) {
    401+    for (const auto& pit : GetSetIter(setParentTransactions)) {
    


    Empact commented at 11:25 pm on July 29, 2018:
    nit: txiter instead of auto?
  8. DrahtBot commented at 2:50 pm on July 30, 2018: member
    • #13804 (Transaction Pool Layer by MarcoFalke)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  9. in src/txmempool.h:572 in fa752b7480 outdated
    564@@ -565,7 +565,12 @@ class CTxMemPool
    565     void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
    566     void ClearPrioritisation(const uint256 hash);
    567 
    568-public:
    569+    /** Get the transaction in the pool that spends the same prevout */
    570+    const CTransaction* GetConflictTx(const COutPoint& prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs);
    571+
    572+    /** Translate a set of hashes into a set of pool iterators to avoid repeated lookups */
    573+    setEntries GetSetIter(const std::set<uint256>& hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs);
    


    kallewoof commented at 6:47 pm on July 30, 2018:
    Nit: the name sounds like it’s a getter + setter operator. Maybe call it GetIterSet?

    MarcoFalke commented at 8:07 pm on July 30, 2018:
    Renamed to GetIterSet according to your feedback
  10. in src/validation.cpp:605 in fa752b7480 outdated
    601@@ -602,10 +602,8 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
    602     std::set<uint256> setConflicts;
    603     for (const CTxIn &txin : tx.vin)
    604     {
    605-        auto itConflicting = pool.mapNextTx.find(txin.prevout);
    606-        if (itConflicting != pool.mapNextTx.end())
    607-        {
    608-            const CTransaction *ptxConflicting = itConflicting->second;
    609+        const CTransaction* ptxConflicting = pool.GetConflictTx(txin.prevout);
    


    kallewoof commented at 6:48 pm on July 30, 2018:
    Nit: I think the convention is to not prefix variables with types anymore and to use snake_case.

    MarcoFalke commented at 6:57 pm on July 30, 2018:
    It is used in a couple of places further down, so I will keep the name for now.

    kallewoof commented at 7:03 pm on July 30, 2018:
    Weird, it looked like you renamed itConflicting to ptxConflicting, but ptxConflicting existed already. My bad.
  11. kallewoof commented at 6:51 pm on July 30, 2018: member
    utACK fa752b748058a0b48b151d2d3016dcfed2629087
  12. MarcoFalke force-pushed on Jul 30, 2018
  13. kallewoof commented at 8:13 pm on July 30, 2018: member
    utACK fa7b11eca5858d3c253dc12d146c50cde5763797
  14. in src/txmempool.cpp:877 in fa7b11eca5 outdated
    876+    return it == mapNextTx.end() ? nullptr : it->second;
    877+}
    878+
    879+CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>& hashes) const
    880+{
    881+    CTxMemPool::setEntries ret;
    


    laanwj commented at 1:57 pm on August 29, 2018:
    as the result is only ever used to iterate over, and the input is already unique, does this need to return a set? I guess a std::list would be a better match

    laanwj commented at 2:03 pm on August 29, 2018:
    OK I guess I’m wrong, there might be duplicate parents
  15. laanwj commented at 2:21 pm on August 29, 2018: member
    utACK fa7b11eca5858d3c253dc12d146c50cde5763797
  16. MarcoFalke force-pushed on Aug 29, 2018
  17. MarcoFalke commented at 2:59 pm on August 29, 2018: member
    Rebased
  18. MarcoFalke force-pushed on Sep 7, 2018
  19. MarcoFalke force-pushed on Sep 7, 2018
  20. tx pool: Use class methods to hide raw map iterator impl details faa1a74942
  21. MarcoFalke force-pushed on Sep 7, 2018
  22. laanwj merged this on Sep 10, 2018
  23. laanwj closed this on Sep 10, 2018

  24. laanwj referenced this in commit e0a4f9de7f on Sep 10, 2018
  25. MarcoFalke deleted the branch on Dec 29, 2020
  26. Munkybooty referenced this in commit 208626a527 on Jul 7, 2021
  27. 5tefan referenced this in commit 63fa38955b on Aug 10, 2021
  28. 5tefan referenced this in commit 7b6837b117 on Aug 11, 2021
  29. 5tefan referenced this in commit f719cafdcd on Aug 12, 2021
  30. 5tefan referenced this in commit 495cfa67f2 on Aug 12, 2021
  31. 5tefan referenced this in commit db302f912d on Aug 12, 2021
  32. UdjinM6 referenced this in commit 297cdf92b5 on Aug 13, 2021
  33. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me