Skip to content
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

refactor: Simplify CTxMempool/BlockAssembler fields, remove some external mapTx access #28391

Merged
merged 15 commits into from
Nov 13, 2023

Conversation

TheCharlatan
Copy link
Contributor

@TheCharlatan TheCharlatan commented Sep 2, 2023

Motivation

Overview of things done in this PR:

  • Make vTxHashes a vector of transaction references instead of a pair of transaction hash and iterator. The trade off here is that the data is retrieved on the fly with GetEntry instead of being cached in vTxHashes.
  • Introduce GetEntry helper method to replace the more involved GetIter where applicable
  • Replace mapTx access with CTxMemPool helper methods
  • Simplify checkChainLimits call in node/interfaces.cpp
  • Make CTxMemPoolEntrys lockPointsmutable such that they can be changed with a const iterator directly instead of going through mapTx
  • Make BlockAssembler's inBlock and failedTx sets of transaction hashes.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 2, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK stickies-v, glozow, maflcko
Concept ACK Sjors
Stale ACK ismaelsadeeq

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28368 (Fee Estimator updates from Validation Interface/CScheduler thread by ismaelsadeeq)
  • #28335 (RFC: Remove boost usage from kernel api / headers by TheCharlatan)

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.

@TheCharlatan TheCharlatan changed the title refactor: Simplify CTxMempool / Miner fields, remove some external mapTx usage refactor: Simplify CTxMempool/BlockAssembler fields, remove some external mapTx usage Sep 2, 2023
@TheCharlatan TheCharlatan changed the title refactor: Simplify CTxMempool/BlockAssembler fields, remove some external mapTx usage refactor: Simplify CTxMempool/BlockAssembler fields, remove some external mapTx access Sep 3, 2023
@DrahtBot DrahtBot removed the CI failed label Sep 4, 2023
@TheCharlatan TheCharlatan marked this pull request as ready for review September 5, 2023 06:22
@glozow
Copy link
Member

glozow commented Sep 5, 2023

Concept ACK fwiw
As additional motivation, I imagine this would also make it easier to change the internal implementation of CTxMemPool without touching all these files.

Copy link
Member

@ismaelsadeeq ismaelsadeeq 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 on the changes on in this PR.

This refactor all seems relevant.
The commits are really atomic and easier to review. 💯

src/node/interfaces.cpp Outdated Show resolved Hide resolved
src/test/blockencodings_tests.cpp Show resolved Hide resolved
@TheCharlatan
Copy link
Contributor Author

glozow and others added 10 commits November 10, 2023 16:44
The behavior is the same as CalculateMemPoolAncestors. The only
difference is the string returned, and the string is discarded anyway
since checkChainLimits only cares about pass/fail.
Allows calling UpdateLockPoints() with a (const) txiter. Note that this
was already possible for caller using mapTx.modify(txiter). The point
here is to not be accessing mapTx when doing so.
vTxHashes exposes a complex mapTx iterator type that its external users
don't need. Directly populate it with CTransactionRef instead.
-BEGIN VERIFY SCRIPT-
git grep -l "vTxHashesIdx" src | xargs sed -i "s/vTxHashesIdx/idx_randomized/g"
git grep -l "vTxHashes" src | xargs sed -i "s/vTxHashes/txns_randomized/g"
-END VERIFY SCRIPT-
Use the helper function instead of reaching into the mapTx member
object.
@TheCharlatan
Copy link
Contributor Author

Copy link
Contributor

@stickies-v stickies-v 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 4dd94ca

@glozow
Copy link
Member

glozow commented Nov 10, 2023

reACK 4dd94ca

@DrahtBot DrahtBot removed the request for review from glozow November 10, 2023 17:00
@maflcko
Copy link
Member

maflcko commented Nov 11, 2023

re-ACK 4dd94ca 👝

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: re-ACK 4dd94ca18f6fc843137ffca3e6d3e97e4f19377b 👝
bfX5G2mlfoBXb55qisEcFZjk5n7/wUwHbMjlDI8yW0PZkGts+ABxmKmEYnMVoT8uNoolCpfL0MahaEHSXhgUCQ==

@DrahtBot DrahtBot removed the request for review from maflcko November 11, 2023 16:22
@fanquake fanquake merged commit dd5f571 into bitcoin:master Nov 13, 2023
16 checks passed

std::vector<CTxMemPoolEntryRef> ret;
ret.reserve(mapTx.size());
for (const auto& it : GetSortedDepthAndScore()) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason that we are invoking GetSortedDepthAndScore() here, ie do any of the callers rely on a particular sort order?

(I'm planning to eliminate this function in #28676, so just want to understand if this behavior needs to be preserved for some reason.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is supposed to mimic infoAll, which was originally used in this patchset to retrieve mempool information instead of directly accessing mapTx. Looking at its usage you are right, the way I read this too there were no order promises made prior to this patch. I opened #29019 to instead just iterate through mapTx.

glozow added a commit to bitcoin-core/gui that referenced this pull request Dec 18, 2023
…mits` error message to wallet

8dec9c5 wallet, mempool: propagete `checkChainLimits` error message to wallet (ismaelsadeeq)

Pull request description:

  * Requested in [#28391 comment](bitcoin/bitcoin#28391 (comment))

  * The error message is static when a new transaction is created and package limit is reached.
  `Transaction has too long of a mempool chain`
  While the [`CTxMempool::CheckPackageLimits`](https://github.com/bitcoin/bitcoin/blob/5800c558eb5efb4839ed00d6967e43306d68e1c3/src/txmempool.cpp#L199) provide explicit information about the error message.
  * This PR updates [`CTxMempool::CheckPackageLimits`](https://github.com/bitcoin/bitcoin/blob/5800c558eb5efb4839ed00d6967e43306d68e1c3/src/txmempool.cpp#L199) return type to `util::Result<void>`, `CheckPackageLimits` now returns void when package limit is not hit, and returns the error string whenever package limit is hit instead of using out parameter `errString`.
  * The PR updates [`checkChainLimits`](https://github.com/bitcoin/bitcoin/blob/5800c558eb5efb4839ed00d6967e43306d68e1c3/src/node/interfaces.cpp#L703) return type to `util::Result<void>`.

  * Now the wallet `CreateTransactionInternal` will have access to the package limit error string whenever its hit.
  * Also Updated functional test to reflect the error message from `CTxMempool::CheckPackageLimits` output.

ACKs for top commit:
  glozow:
    utACK 8dec9c5
  Sjors:
    utACK 8dec9c5
  TheCharlatan:
    Re-ACK 8dec9c5

Tree-SHA512: ddeac18aeba6f8e3be0e3fe76bf3db655352e3b415169f1f83ea1e8976a2f3e3de021c8da6880eb8382ab52d545e418e3f4d57adcc68ecb4f390339710ee6f30
@glozow
Copy link
Member

glozow commented Jan 5, 2024

Should we backport 453b481?

glozow pushed a commit to glozow/bitcoin that referenced this pull request Jan 9, 2024
Instead of reaching into the mapTx data structure, use a helper method
that provides the required vector of CTxMemPoolEntry pointers.

Github-Pull: bitcoin#28391
Rebased-From: 453b481
@glozow glozow mentioned this pull request Jan 9, 2024
glozow pushed a commit to glozow/bitcoin that referenced this pull request Jan 18, 2024
Instead of reaching into the mapTx data structure, use a helper method
that provides the required vector of CTxMemPoolEntry pointers.

Github-Pull: bitcoin#28391
Rebased-From: 453b481
glozow pushed a commit to glozow/bitcoin that referenced this pull request Jan 19, 2024
Instead of reaching into the mapTx data structure, use a helper method
that provides the required vector of CTxMemPoolEntry pointers.

Github-Pull: bitcoin#28391
Rebased-From: 453b481
fanquake added a commit that referenced this pull request Feb 16, 2024
11f3a7e Use hardened runtime on macOS release builds. (Mark Friedenbach)
ac1b9a5 [test] import descriptor wallet with reorged parent + IsFromMe child in mempool (glozow)
ecb8ebc [test] rescan legacy wallet with reorged parent + IsFromMe child in mempool (Gloria Zhao)
438ac29 snapshots: don't core dump when running -checkblockindex after `loadtxoutset` (Mark Friedenbach)
7ec3455 [log] mempool loading (glozow)
fe0f8fe net: create I2P sessions with both ECIES-X25519 and ElGamal encryption (Jon Atack)
fc62271 [refactor] Add helper for iterating through mempool entries (stickies-v)

Pull request description:

  Backports for 26.x. Includes:
  - 453b481 from #28391
    - #29179
  - #29200
  - #29227
  - #28791
  - #29127

ACKs for top commit:
  stickies-v:
    ACK 11f3a7e

Tree-SHA512: 20ef871ec768f2328056d83f958e595b36ae9b8baa8a6e8b0e1f02c3df4b16965a8e05dcb4323afbcc9ecc4bdde10931232512022c39ee7e12baf9795bf25bf1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done or Closed or Rethinking
Development

Successfully merging this pull request may close these issues.

None yet

9 participants