8000 Remove mempool global by maflcko · Pull Request #19556 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove mempool global #19556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 7, 2020
Merged

Remove mempool global #19556

merged 3 commits into from
Sep 7, 2020

Conversation

maflcko
Copy link
Member
@maflcko maflcko commented Jul 19, 2020

This refactor unlocks some nice potential features, such as, but not limited to:

Even absent those features, the new code without the global should be easier to maintain, read and write tests for.

@hebasto
Copy link
Member
hebasto commented Jul 19, 2020

Concept ACK.

@jonatack
Copy link
Member

Concept/approach ACK.

@JeremyRubin
Copy link
Contributor

Concept ACK on this PR.

lite approach NACK on "Making the mempool optional for a "blocksonly" operation mode", it should be in it's own flag as there are some other reasons to keep a mempool around even in blocksonly.

@maflcko maflcko force-pushed the Mf1808-txpoolGlobal branch from fa3a019 to faab597 Compare July 19, 2020 18:26
@DrahtBot
Copy link
Contributor
DrahtBot commented Jul 20, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@naumenkogs
Copy link
Member

Concept ACK.

@jnewbery
Copy link
Contributor

Concept ACK

Copy link
@ariard ariard 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

As it has been raised above you may want to keep an empty mempool to test correctness of your transactions wrt to policy (testmempoolaccept). If user is willingly to run in blocksonly, turning on another flag doesn't seem a blocker if you're also willingly to disable fee-estimation.

@@ -18,16 +19,16 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)

// If this transaction is not in our mempool, then we can't be sure
// we will know about all its inputs.
if (!pool.exists(tx.GetHash())) {
if (!pool || !pool->exists(tx.GetHash())) {
Copy link

Choose a reason for hiding this comment

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

In fact I think you can do better than returning an UNKNOWN state if you check that all parents are part of coin cache and transaction doesn't explicitly signal you can return a FINAL state ?

@maflcko
Copy link
Member Author
maflcko commented Jul 21, 2020

... empty mempool to test correctness of your transactions wrt to policy (testmempoolaccept)

I don't modify testmempoolaccept behavior in this refactoring pull at all. If you think it should change, I suggest opening a separate behavior-changing pull reqeust. Though, with an empty mempool, a lot of the benefits of testmempoolaccept will be lost. So if the behavior is changed, I recommend that users will have to opt-in to the less-useful empty-mempool behavior.

In fact I think you can do better than returning an UNKNOWN state if you check that all parents are part of coin cache and transaction doesn't explicitly signal you can return a FINAL state ?

This function is only called by the wallet and I think it is not feasible to operate a wallet without a mempool, so accommodating that use case seems a bit overkill. Regardless, I suggest to handle this in a separate pull request from this refactor.

@ariard
Copy link
ariard commented Jul 21, 2020

I don't modify testmempoolaccept behavior in this refactoring pull at all.

I was aware of this PR not changing behavior , my comment was more an opinion on whether or not we should tight blocksonly and withoutmempool features under same flag in future works.

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.

Code review ACK faab597

Copy link
Member
@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK faab597, tested on Linux Mint 20 (x86_64).

@@ -5,9 +5,10 @@
#include <policy/rbf.h>
#include <util/rbf.h>

RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
namespace {
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool* const pool) NO_THREAD_SAFETY_ANALYSIS
Copy link
Member

Choose a reason for hiding this comment

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

fad153a
Could this function differ from

RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) { return IsRBFOptIn(tx, &pool); }

by name, not only by signature?

Copy link
Member Author

Choose a reason for hiding this comment

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

why? And, any suggestions I could take?

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 31, 2020
fa0572d Pass mempool reference to chainstate constructor (MarcoFalke)

Pull request description:

  Next step toward bitcoin#19556

  Instead of relying on the mempool global, each chainstate is given a reference to a mempool to keep up to date with the tip (block connections, disconnections, reorgs, ...)

ACKs for top commit:
  promag:
    Code review ACK fa0572d.
  darosior:
    ACK fa0572d
  hebasto:
    ACK fa0572d, reviewed and tested on Linux Mint 20 (x86_64).

Tree-SHA512: 12184d33ae5797438d03efd012a07ba3e4ffa0d817c7a0877743f3d7a7656fe279280c751554fc035ccd0058166153b6c6c308a98b2d6b13998922617ad95c4c
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Sep 5, 2020
fa9ee52 doc: Add doxygen comment to IsRBFOptIn (MarcoFalke)
faef4fc Remove mempool global from interfaces (MarcoFalke)
fa83168 refactor: Add IsRBFOptInEmptyMempool (MarcoFalke)

Pull request description:

  The chain interface has an `m_node` member, which has a pointer to the mempool global. Use the pointer instead of the global to prepare the removal of the mempool global. See bitcoin#19556

ACKs for top commit:
  jnewbery:
    utACK fa9ee52
  darosior:
    ACK fa9ee52
  hebasto:
    re-ACK fa9ee52, since my [previous](bitcoin#19848 (review)) review:

Tree-SHA512: 11b4c1446f0860a743fdaa67f95c52bf0262d0a4f888be0eaf07ee497448965d32be414111bf016bd568f2989cde923430e3a3889e224057b73c499f06de7199
MarcoFalke added 3 commits September 5, 2020 16:24
Can be reviewed with the git diff options

--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space --ignore-all-space
@maflcko maflcko force-pushed the Mf1808-txpoolGlobal branch from a43bc0a to fafb381 Compare September 5, 2020 14:27
@maflcko maflcko marked this pull request as ready for review September 5, 2020 14:28
@maflcko
Copy link
Member Author
maflcko commented Sep 5, 2020

This is now ready for review

Copy link
Member
@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK fafb381, I have reviewed the code and it looks OK, I agree it can be merged.

Hope these changes will make work on transit CTxMemPool::cs from RecursiveMutex to Mutex easier and more straightforward.

Copy link
Member
@darosior darosior left a comment

Choose a reason for hiding this comment

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

ACK fafb381

@jnewbery
Copy link
Contributor
jnewbery commented Sep 6, 2020

utACK fafb381

@@ -1368,10 +1360,18 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
assert(!node.connman);
node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));

// Make mempool generally available in the node context. For example the connection manager, wallet, or RPC threads,
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is outdated (the mempool is being constructed, not just made available). If you retouch the PR, can you update the comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. The comment should probably be removed because now that it is no longer a global, it is clear from the code where it is passed in.

@maflcko maflcko merged commit 0708705 into bitcoin:master Sep 7, 2020
@promag
Copy link
Contributor
promag commented Sep 7, 2020

Code review ACK fafb381.

@maflcko maflcko deleted the Mf1808-txpoolGlobal branch September 7, 2020 08:07
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 9, 2020
fafb381 Remove mempool global (MarcoFalke)
fa0359c Remove mempool global from p2p (MarcoFalke)
eeee110 Remove mempool global from init (MarcoFalke)

Pull request description:

  This refactor unlocks some nice potential features, such as, but not limited to:
  * Removing the fee estimates global (would avoid slightly fragile workarounds such as bitcoin#18766)
  * Making the mempool optional for a "blocksonly" operation mode

  Even absent those features, the new code without the global should be easier to maintain, read and write tests for.

ACKs for top commit:
  jnewbery:
    utACK fafb381
  hebasto:
    ACK fafb381, I have reviewed the code and it looks OK, I agree it can be merged.
  darosior:
    ACK fafb381

Tree-SHA512: a2e696dc377e2e81eaf9c389e6d13dde4a48d81f3538df88f4da502d3012dd61078495140ab5a5854f360a06249fe0e1f6a094c4e006d8b5cc2552a946becf26
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 8, 2021
Summary:
PR description:
Instead of relying on the implicit mempool global, pass a mempool pointer (which can be 0). This helps with testing, code clarity and unlocks the features described in [[bitcoin/bitcoin#19556 | #19556]]

This is a backport of [[bitcoin/bitcoin#19604 | core#19604]] [2/3]
bitcoin/bitcoin@fac674d

Depends on D9756

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9757
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 15, 2021
Summary:
> Next step toward [[bitcoin/bitcoin#19556 | core#19556]]
>
> Instead of relying on the mempool global, each chainstate is given a reference to a mempool to keep up to date with the tip (block connections, disconnections, reorgs, ...)

This is a backport of [[bitcoin/bitcoin#19826 | core#19826]]

Most differences from Core in validation.cpp are explained by D1667, D7203 & D7439.

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9780
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 15, 2021
Summary:
> GetTransaction implicitly and unconditionally asks the mempool global for a transaction. This is problematic for several reasons:
>
>  - gettxoutproof is for on-chain txs only and asking the mempool for on-chain txs is confusing and minimally wasteful
>  - Globals are confusing and make code harder to test with unit tests
>
> Fix both issues by passing in an optional mempool. This also helps with [[bitcoin/bitcoin#19556 | core#19556]]

This is a backport of [[bitcoin/bitcoin#19589 | core#19589]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9783
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 15, 2021
Summary:
> The chain interface has an m_node member, which has a pointer to the mempool global. Use the pointer instead of the global to prepare the removal of the mempool global. See [[bitcoin/bitcoin#19556 | core#19556]]

This is a backport of [[bitcoin/bitcoin#19848 | core#19848]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9784
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 15, 2021
Summary:
PR description:
> This refactor unlocks some nice potential features, such as, but not limited to:
>
> - Removing the fee estimates global (would avoid slightly fragile workarounds such as
>   Disable fee estimation in blocksonly mode (by removing the fee estimates global) #18766)
> - Making the mempool optional for a "blocksonly" operation mode
>
> Even absent those features, the new code without the global should be easier to maintain, read and write tests for.

This is a backport of [[bitcoin/bitcoin#19556 | core#19556]] [1/3]
bitcoin/bitcoin@eeee110

Depends on D9780, D9783 and D9784

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9788
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 15, 2021
Summary:
PR description:
> This refactor unlocks some nice potential features, such as, but not limited to:
>
> - Removing the fee estimates global (would avoid slightly fragile workarounds such as
>   Disable fee estimation in blocksonly mode (by removing the fee estimates global) #18766)
> - Making the mempool optional for a "blocksonly" operation mode
>
> Even absent those features, the new code without the global should be easier to maintain, read and write tests for.

This is a backport of [[bitcoin/bitcoin#19556 | core#19556]] [2/3]
bitcoin/bitcoin@fa0359c

Depends on D9788

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9789
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 15, 2021
Summary:
PR description:
> This refactor unlocks some nice potential features, such as, but not limited to:
>
> - Removing the fee estimates global (would avoid slightly fragile workarounds such as
>   Disable fee estimation in blocksonly mode (by removing the fee estimates global) #18766)
> - Making the mempool optional for a "blocksonly" operation mode
>
> Even absent those features, the new code without the global should be easier to maintain, read and write tests for.

This is a backport of [[bitcoin/bitcoin#19556 | core#19556]] [3/3]
bitcoin/bitcoin@fafb381

Depends on D9789

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9790
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 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.

0