Skip to content

Conversation

lsilva01
Copy link
Contributor

@lsilva01 lsilva01 commented Nov 4, 2021

This PR refactors AcceptToMemoryPool.

. Remove AcceptToMemoryPoolWithTime (after #23173, this function is no longer needed).
. Remove the CChainParams chainparams parameter from ATMP as they can be inferred from the current chain state.
. Update the tx_pool test with new function signature.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 4, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23546 (scripted-diff: Use clang-tidy syntax for C++ named arguments (tests only) by MarcoFalke)
  • #23465 (Remove CTxMemPool params from ATMP by lsilva01)

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.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

I also have a branch that does this (amongst other things) here: https://github.com/jnewbery/bitcoin/tree/2021-09-process-transaction-2. Feel free to take anything you find useful from that branch.

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, good cleanup.

@lsilva01
Copy link
Contributor Author

lsilva01 commented Nov 5, 2021

@jnewbery and @glozow thanks for reviews.
I addressed your suggestions in 034e827.

As these changes are already implemented in another branch, with more other commits, I can close this PR if it's better.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments inline

As these changes are already implemented in another branch, with more other commits, I can close this PR if it's better.

No, please continue with this PR! Just feel free to take anything from the other branch that you find useful.

@theStack
Copy link
Contributor

theStack commented Nov 5, 2021

Concept ACK

@theStack
Copy link
Contributor

theStack commented Nov 7, 2021

Possible follow-up idea that came to my mind while reviewing this PR: couldn't we simplify the interface of AcceptToMemoryPool by getting rid of both the CChainParams and CTxMemPool parameters, since those can be deduced from the chainstate anyway? The change would look something like

-MempoolAcceptResult AcceptToMemoryPool(const CChainParams& chainparams, CTxMemPool& pool,
-                                       CChainState& active_chainstate, const CTransactionRef& tx,
+MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, const CTransactionRef& tx,
                                        int64_t accept_time, bool bypass_limits, bool test_accept)
     EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 {
+    const CChainParams& chainparams{active_chainstate.m_params};
+    assert(active_chainstate.m_mempool != nullptr);
+    CTxMemPool& pool{*active_chainstate.m_mempool};
     std::vector<COutPoint> coins_to_uncache;
     MemPoolAccept::ATMPArgs args { chainparams, accept_time, bypass_limits, coins_to_uncache,
                                    test_accept, /* m_allow_bip125_replacement */ true };

I couldn't think of a case where passing chainparams or a mempool instance that doesn't belong to the active chainstate makes much sense. Drawback though: currently the member m_mempool is protected and thus not accessible from outside, that one would need to move to the public section, like it was done for m_params in the last commit of this PR.

@lsilva01
Copy link
Contributor Author

lsilva01 commented Nov 8, 2021

Thanks for the review @theStack . I opened PR #23465 to test your suggestion.
It seems to work fine.

@jnewbery
Copy link
Contributor

#23173 is merged. Please rebase and I'll review.

@jnewbery
Copy link
Contributor

Please update the PR description now that #23173 is merged.

@maflcko maflcko changed the title refactor, mempool: refactor AcceptToMemoryPool refactor: AcceptToMemoryPool Nov 22, 2021
@maflcko maflcko requested review from glozow and jnewbery November 22, 2021 09:26
@lsilva01
Copy link
Contributor Author

@theStack and @stratospher thanks for the review.
The commit were squashed, as suggested.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 4ec8b96

@jnewbery
Copy link
Contributor

jnewbery commented Dec 1, 2021

utACK 4ec8b96

Happy to rereview this once it's rebased.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 123f5de

@jnewbery
Copy link
Contributor

jnewbery commented Dec 1, 2021

reACK 123f5de

@glozow
Copy link
Member

glozow commented Dec 1, 2021

light code review ACK 123f5de

* @param[in] tx The transaction to submit for mempool acceptance.
* @param[in] accept_time The timestamp for adding the transaction to the mempool. Usually
* the current system time, but may be different.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think we need to explain what the argument means at the call site.

@maflcko maflcko merged commit 1c06e1a into bitcoin:master Dec 1, 2021
@lsilva01 lsilva01 deleted the remove_atmp_time branch December 1, 2021 17:00
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 2, 2021
maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Dec 8, 2021
f1f10c0 Remove CTxMemPool params from ATMP (lsilva01)

Pull request description:

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

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

  Requires #23437.

ACKs for top commit:
  jnewbery:
    utACK f1f10c0
  MarcoFalke:
    review ACK f1f10c0 🔙

Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 8, 2021
f1f10c0 Remove CTxMemPool params from ATMP (lsilva01)

Pull request description:

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

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

  Requires bitcoin#23437.

ACKs for top commit:
  jnewbery:
    utACK f1f10c0
  MarcoFalke:
    review ACK f1f10c0 🔙

Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
RandyMcMillan pushed a commit to RandyMcMillan/mempool-tab that referenced this pull request Dec 23, 2021
93134c7 Remove calls to global Params() in tx_pool test (lsilva01)
bfdb258 Remove AcceptToMemoryPoolWithTime (lsilva01)

Pull request description:

  This PR refactors AcceptToMemoryPool.

  . Remove `AcceptToMemoryPoolWithTime` (after #23173, this function is no longer needed).
  . Remove the `CChainParams chainparams` parameter from ATMP as they can be inferred from the current chain state.
  . Update the `tx_pool` test with new function signature.

ACKs for top commit:
  jnewbery:
    reACK 93134c7
  glozow:
    light code review ACK 93134c7
  theStack:
    re-ACK 93134c7

Tree-SHA512: b672d9f091f5fcb4d163c0a443aa469b2ce6f37201136803201c620c3fa329ffb41abd50c5b528787fd1c47e8e09af5ec20ddaa0a4235352c9c619e5691dddb6
RandyMcMillan pushed a commit to RandyMcMillan/mempool-tab that referenced this pull request Dec 23, 2021
efbb49e Remove CTxMemPool params from ATMP (lsilva01)

Pull request description:

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

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

  Requires #23437.

ACKs for top commit:
  jnewbery:
    utACK efbb49e
  MarcoFalke:
    review ACK efbb49e 🔙

Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 13, 2022
Summary:
This is a backport of [[bitcoin/bitcoin#23437 | core#23437]]
bitcoin/bitcoin@9360778

The fuzzer part of the first commit and the second commit are not applicable, due  to missing fuzzer backports.
Depends on D12236

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D12238
@bitcoin bitcoin locked and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants