Remove CTxMemPool params from ATMP #23465

pull lsilva01 wants to merge 1 commits into bitcoin:master from lsilva01:remove_pool_params_atmp changing 3 files +33 −15
  1. lsilva01 commented at 4:43 am on November 8, 2021: contributor

    Remove CTxMemPool parameter from AcceptToMemoryPool function, as suggested in #23437 (comment) .

    This requires that CChainState has access to MockedTxPool in tx_pool.cpp as mentioned #23173 (review). So the MockedTxPool is attributed to CChainState::m_mempool before calling AcceptToMemoryPool.

    Requires #23437.

  2. DrahtBot commented at 5:01 am on November 8, 2021: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    No conflicts as of last run.

  3. lsilva01 force-pushed on Nov 8, 2021
  4. DrahtBot added the label P2P on Nov 8, 2021
  5. DrahtBot added the label RPC/REST/ZMQ on Nov 8, 2021
  6. DrahtBot added the label Utils/log/libs on Nov 8, 2021
  7. DrahtBot added the label Validation on Nov 8, 2021
  8. DrahtBot added the label Needs rebase on Nov 9, 2021
  9. lsilva01 force-pushed on Nov 13, 2021
  10. lsilva01 renamed this:
    Remove CChainParams and CTxMemPool params from ATMP
    Remove CTxMemPool params from ATMP
    on Nov 13, 2021
  11. lsilva01 force-pushed on Nov 13, 2021
  12. DrahtBot removed the label Needs rebase on Nov 13, 2021
  13. mjdietzx commented at 8:29 pm on November 15, 2021: contributor
    Code Review ACK 988cfd8914f12ce87fb6ac6499326e140e840c1d
  14. in src/validation.cpp:1157 in 988cfd8914 outdated
    1153@@ -1153,9 +1154,9 @@ CChainState::CChainState(
    1154     BlockManager& blockman,
    1155     ChainstateManager& chainman,
    1156     std::optional<uint256> from_snapshot_blockhash)
    1157-    : m_mempool(mempool),
    1158-      m_blockman(blockman),
    1159+    : m_blockman(blockman),
    


    stratospher commented at 8:44 am on November 25, 2021:
    Is there any particular reason for reordering the initialiser list?

    lsilva01 commented at 6:04 am on December 2, 2021:
    Member variables must be initialized in the order in which they are declared. Otherwise, CI will throw [-Werror = reorder]. See https://stackoverflow.com/questions/12222417/why-should-i-initialize-member-variables-in-the-order-theyre-declared-in

    stratospher commented at 6:33 am on December 4, 2021:
    Thanks!
  15. stratospher commented at 8:53 am on November 25, 2021: contributor
    Concept ACK. This PR removes CTxMemPool pool argument from AcceptToMemoryPool() since it can be obtained from CChainState active_chainstate.m_mempool
  16. in src/validation.h:596 in 988cfd8914 outdated
    590@@ -596,6 +591,10 @@ class CChainState
    591     /** Chain parameters for this chainstate */
    592     const CChainParams& m_params;
    593 
    594+    //! Optional mempool that is kept in sync with the chain.
    595+    //! Only the active chainstate has a mempool.
    596+    CTxMemPool* m_mempool;
    


    promag commented at 9:10 am on November 25, 2021:

    988cfd8914f12ce87fb6ac6499326e140e840c1d

    Instead of making this public, I think you should add a getter like CoinsTip() and an initialized like InitCoinsDB. Then you can revert what @stratospher asks in https://github.com/bitcoin/bitcoin/pull/23465/commits/988cfd8914f12ce87fb6ac6499326e140e840c1d#r756677595.


  17. promag commented at 9:16 am on November 25, 2021: member

    Code review ACK 988cfd8914f12ce87fb6ac6499326e140e840c1d.

    This change simplifies ATMP since chain params and the mempool are accessible from the chainstate.

    It also removes the intermediate AcceptToMemoryPoolWithTime causing all ATMP callers to explicit set accept_time, usually GetTime().

  18. DrahtBot added the label Needs rebase on Dec 1, 2021
  19. lsilva01 force-pushed on Dec 2, 2021
  20. DrahtBot removed the label Needs rebase on Dec 2, 2021
  21. lsilva01 force-pushed on Dec 2, 2021
  22. lsilva01 commented at 6:11 am on December 2, 2021: contributor

    I changed the approach. Now, the m_mempool remains private and the getter and setter were added, as suggested by @stratospher in #23448#pullrequestreview-816441509 and @promag in #23465 (review) .

    Not sure if this is idiomatic (c++ style). Otherwise, I can revert to original approach (with public m_mempool).

  23. in src/validation.h:216 in 358f94a281 outdated
    210@@ -211,7 +211,6 @@ struct PackageMempoolAcceptResult
    211  * Try to add a transaction to the mempool. This is an internal function and is exposed only for testing.
    212  * Client code should use ChainstateManager::ProcessTransaction()
    213  *
    214- * @param[in]  pool               Reference to the node's mempool.
    215  * @param[in]  active_chainstate  Reference to the active chainstate.
    216  * @param[in]  tx                 The transaction to submit for mempool acceptance.
    217  * @param[in]  accept_time        The timestamp for adding the transaction to the mempool. Usually
    


    MarcoFalke commented at 7:47 am on December 2, 2021:
    maybe remove the sentence that starts with “usually”? #23437 (review)

    lsilva01 commented at 7:50 pm on December 2, 2021:
    Done in 3f7d1c1
  24. in src/validation.h:667 in 358f94a281 outdated
    662+    }
    663+
    664+    /**
    665+     * Update the mempool
    666+     */
    667+    CTxMemPool* SetMempool(CTxMemPool* mempool)
    


    MarcoFalke commented at 7:48 am on December 2, 2021:
    Not a fan of adding test-only helpers to the real code. Might be better to move this to the test code.

    lsilva01 commented at 7:50 pm on December 2, 2021:
    Good catch. Done in 3f7d1c1
  25. lsilva01 force-pushed on Dec 2, 2021
  26. in src/test/fuzz/tx_pool.cpp:242 in 3f7d1c11c1 outdated
    238@@ -230,7 +239,10 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
    239         Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
    240                it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
    241 
    242-        const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(tx_pool, chainstate, tx, GetTime(), bypass_limits, /* test_accept= */ false));
    243+        DummyChainState& dummyChainState{ static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
    


    MarcoFalke commented at 10:54 am on December 3, 2021:
    there is already a chainstate symbol, so please use that. Also below it would be good to pass the same symbol to atmp, not the dummy one time and the “real” another time.

    lsilva01 commented at 11:42 pm on December 3, 2021:
    Done in 83b3697 . The same symbol is being passed to ATMP.
  27. lsilva01 force-pushed on Dec 3, 2021
  28. in src/validation.h:657 in 83b3697f39 outdated
    653@@ -656,6 +654,12 @@ class CChainState
    654         return m_coins_views->m_dbview;
    655     }
    656 
    657+    //! @returns A reference to the mempool.
    


    jnewbery commented at 12:17 pm on December 7, 2021:
    This is wrong. It’s returning a pointer, not a reference (and can’t return a reference, since m_mempool may be null).
  29. in src/validation.cpp:332 in 83b3697f39 outdated
    328@@ -329,11 +329,9 @@ void CChainState::MaybeUpdateMempoolForReorg(
    329     // been previously seen in a block.
    330     auto it = disconnectpool.queuedTx.get<insertion_order>().rbegin();
    331     while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
    332+        auto accepted = AcceptToMemoryPool(*this, *it, GetTime(), /* bypass_limits= */true, /* test_accept= */false);
    


    jnewbery commented at 12:20 pm on December 7, 2021:
    This is a behaviour chage. With this change, ATMP() is always called, even if fAddToMempol is false or the transaction is a coinbase.
  30. in src/test/fuzz/tx_pool.cpp:126 in 83b3697f39 outdated
    122@@ -114,7 +123,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
    123 {
    124     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
    125     const auto& node = g_setup->m_node;
    126-    auto& chainstate = node.chainman->ActiveChainstate();
    127+    auto& chainstate{ static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
    


    jnewbery commented at 12:28 pm on December 7, 2021:
    0    auto& chainstate{static_cast<DummyChainState&>(node.chainman->ActiveChainstate())};
    
  31. in src/test/fuzz/tx_pool.cpp:35 in 83b3697f39 outdated
    28@@ -29,6 +29,15 @@ struct MockedTxPool : public CTxMemPool {
    29     }
    30 };
    31 
    32+class DummyChainState final : public CChainState
    33+{
    34+public:
    35+    CTxMemPool* SetMempool(CTxMemPool* mempool)
    


    jnewbery commented at 12:29 pm on December 7, 2021:
    Why does this return a pointer to the CTxMemPool, which never gets used. Can it just return void?
  32. in src/test/fuzz/tx_pool.cpp:242 in 83b3697f39 outdated
    238@@ -230,7 +239,9 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
    239         Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
    240                it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
    241 
    242-        const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(tx_pool, chainstate, tx, GetTime(), bypass_limits, /* test_accept= */ false));
    243+        chainstate.SetMempool(&tx_pool);
    


    jnewbery commented at 12:30 pm on December 7, 2021:
    Does this still work if this line is moved up to l145 (i.e. immediately after the mempool is constructed). I think the test is easier to understand if the mempool pointer is set at the beginning and not updated.
  33. lsilva01 force-pushed on Dec 7, 2021
  34. lsilva01 force-pushed on Dec 7, 2021
  35. in src/validation.cpp:334 in d784d1e6e2 outdated
    330@@ -331,9 +331,7 @@ void CChainState::MaybeUpdateMempoolForReorg(
    331     while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
    332         // ignore validation errors in resurrected transactions
    333         if (!fAddToMempool || (*it)->IsCoinBase() ||
    334-            AcceptToMemoryPool(*m_mempool, *this, *it, GetTime(),
    335-                /* bypass_limits= */true, /* test_accept= */ false).m_result_type !=
    336-                    MempoolAcceptResult::ResultType::VALID) {
    337+            AcceptToMemoryPool(*this, *it, GetTime(), /* bypass_limits= */true, /* test_accept= */false).m_result_type != MempoolAcceptResult::ResultType::VALID) {
    


    jnewbery commented at 5:10 pm on December 7, 2021:
    I don’t understand why you keep changing the formatting on this line, where all you need to do is remove the m_mempool argument. 160 columns is too wide for many people to do a side-by-side diff.

    lsilva01 commented at 7:05 pm on December 7, 2021:
    Done in 2cc5a38
  36. lsilva01 force-pushed on Dec 7, 2021
  37. in src/validation.cpp:4578 in 2cc5a38f38 outdated
    4574@@ -4572,8 +4575,8 @@ bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mocka
    4575             }
    4576             if (nTime > nNow - nExpiryTimeout) {
    4577                 LOCK(cs_main);
    4578-                if (AcceptToMemoryPool(pool, active_chainstate, tx, nTime, /* bypass_limits= */ false,
    4579-                                               /* test_accept= */ false).m_result_type == MempoolAcceptResult::ResultType::VALID) {
    4580+                auto accepted = AcceptToMemoryPool(active_chainstate, tx, nTime, /* bypass_limits= */ false, /* test_accept= */ false);
    


    jonatack commented at 8:38 pm on December 7, 2021:
    0                const auto& accepted = AcceptToMemoryPool(active_chainstate, tx, nTime, /*bypass_limits=*/false, /*test_accept=*/false);
    
    • it may be preferable to use reference to const for read-only memoization of a MempoolAcceptResult class object
    • named arguments format compatible with clang-tidy verification

    Feel free to ignore.

  38. jonatack commented at 9:03 pm on December 7, 2021: member
    Approach ACK 2cc5a38f3890636e7707362ae0f1bcada82b505f, will review properly.
  39. lsilva01 force-pushed on Dec 7, 2021
  40. Remove CTxMemPool params from ATMP
    Co-authored-by: John Newbery <1063656+jnewbery@users.noreply.github.com>
    Co-authored-by: Jon Atack <jon@atack.com>
    f1f10c0514
  41. lsilva01 force-pushed on Dec 7, 2021
  42. jnewbery commented at 8:48 am on December 8, 2021: member
    utACK f1f10c0514fe81318c8b064f9dad0e2f9a2cd037
  43. MarcoFalke removed the label RPC/REST/ZMQ on Dec 8, 2021
  44. MarcoFalke removed the label P2P on Dec 8, 2021
  45. MarcoFalke removed the label Validation on Dec 8, 2021
  46. MarcoFalke removed the label Utils/log/libs on Dec 8, 2021
  47. MarcoFalke added the label Refactoring on Dec 8, 2021
  48. in src/validation.cpp:1100 in f1f10c0514
    1096                                        int64_t accept_time, bool bypass_limits, bool test_accept)
    1097     EXCLUSIVE_LOCKS_REQUIRED(cs_main)
    1098 {
    1099     const CChainParams& chainparams{active_chainstate.m_params};
    1100+    assert(active_chainstate.GetMempool() != nullptr);
    1101+    CTxMemPool& pool{*active_chainstate.GetMempool()};
    


    MarcoFalke commented at 8:54 am on December 8, 2021:
    0    CTxMemPool& pool{*Assert(active_chainstate.GetMempool())};
    

    nit: Can be written shorter

  49. in src/test/fuzz/tx_pool.cpp:34 in f1f10c0514
    28@@ -29,6 +29,15 @@ struct MockedTxPool : public CTxMemPool {
    29     }
    30 };
    31 
    32+class DummyChainState final : public CChainState
    33+{
    34+public:
    


    MarcoFalke commented at 8:55 am on December 8, 2021:
    0struct DummyChainState final : public CChainState {
    

    nit: Can be written shorter, but might be controversial to use struct here. I think in tests it is fine.


    jnewbery commented at 9:09 am on December 8, 2021:
    I’d prefer to declare this as a class, even if it requires an additional line for the access specifier (since it’s a class and not just a data structure).
  50. in src/test/fuzz/tx_pool.cpp:37 in f1f10c0514
    28@@ -29,6 +29,15 @@ struct MockedTxPool : public CTxMemPool {
    29     }
    30 };
    31 
    32+class DummyChainState final : public CChainState
    33+{
    34+public:
    35+    void SetMempool(CTxMemPool* mempool)
    36+    {
    37+        m_mempool = mempool;
    


    MarcoFalke commented at 8:56 am on December 8, 2021:

    nit: mempool is never null, so can use a reference

    0    void SetMempool(CTxMemPool& mempool)
    1    {
    2        m_mempool = &mempool;
    
  51. MarcoFalke approved
  52. MarcoFalke commented at 9:00 am on December 8, 2021: member

    left some nits in the test, but no blockers

    review ACK f1f10c0514fe81318c8b064f9dad0e2f9a2cd037 🔙

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3review ACK f1f10c0514fe81318c8b064f9dad0e2f9a2cd037 🔙
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUgHpQv/Zm11wrNJ2iGL1U2uf4cOLbafgx6DxBsY5Jf4VOBRhAaTSdluLEBEkhdY
     8eTLy4lrXuzAhrs9SS8ogJYEUT2JWn5vmfPjXdsPIyJPRVT1IEUoeelarH03oOHEe
     9+xW5ILkL7S8GlNGB+nUqXkq47Qw5jY+zr39v3tGvHJkrVHVhaDZOlFmPoXKDVrdv
    10TnsQcV8GL+4ZL9gyg6+tM26uSeDOaTId8L/4xtmzkzgcPcZqPsT/LyXxKmKDjY5s
    11KHyASsIIZG+Tb2M7HGAaZiPZelhhg1kyJqv0tq+woEfeE3qQ41U+r/if+kM10kmh
    12cKy4Jfw8lR7em5e2fVE2NDf0va6i1TVJz/8ZPYSS0C5IK8aeC+0OK2CE0GKjlP8k
    13n/F7rAU9BUOkerA4ccwq1T+l0FwN4yOa2d3EZobHHRDn8jSmITqwaXxZHIDyB7/3
    14lIHrKEoNBvdlF1ohlQNqXGSJQeb+wQ1l9EWLM0Gj/U/8WjZTyswSxAn1UBJOEabH
    15CzoLf3ep
    16=M0GN
    17-----END PGP SIGNATURE-----
    
  53. MarcoFalke merged this on Dec 8, 2021
  54. MarcoFalke closed this on Dec 8, 2021

  55. jonatack commented at 11:56 am on December 8, 2021: member
    Post-merge ACK, modulo that I’m not sure if the CChainState::GetMempool() getter adds value. I’ve proposed a follow-up to remove it that picks up some of Marco’s review feedback.
  56. lsilva01 deleted the branch on Dec 8, 2021
  57. sidhujag referenced this in commit ff6e1bdf71 on Dec 8, 2021
  58. RandyMcMillan referenced this in commit 1cd9ee7a8f on Dec 23, 2021
  59. Fabcien referenced this in commit 448a91fef4 on Nov 11, 2022
  60. DrahtBot locked this on Dec 8, 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-07-03 10:13 UTC

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