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: consolidate MempoolAcceptResult processing #29619

Merged
merged 2 commits into from Mar 13, 2024

Conversation

glozow
Copy link
Member

@glozow glozow commented Mar 11, 2024

Every time we try to ProcessTransaction (i.e. submit a tx to mempool), we use the result to update a few net processing data structures. For example, after a failure, the {wtxid, txid, both, neither} (depending on reason) should be cached in m_recent_rejects so we don't try to download/validate it again.

There are 2 current places and at least 1 future place where we need to process MempoolAcceptResult:

Consolidate this code so it isn't repeated in 2 places and so we can reuse it in a future PR.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 11, 2024

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 instagibbs, achow101, dergoegge, TheCharlatan

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:

  • #29641 (scripted-diff: Use LogInfo/LogDebug over LogPrintf/LogPrint by maflcko)
  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
  • #28970 (p2p: opportunistically accept 1-parent-1-child packages by glozow)

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
Member

@dergoegge dergoegge 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

just inline nits for now

src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
src/net_processing.cpp Outdated Show resolved Hide resolved
@glozow
Copy link
Member Author

glozow commented Mar 11, 2024

Note to reviewers: this PR isn't supposed to change behavior at all. I have a spreadsheet here enumerating what we do on master, and this PR should match that.
For tests, p2p_orphan_handling.py was written to hit some of these codepaths. Unit/fuzz tests for this are pretty difficult to achieve right now, but I would like to add some in the future after modularization - see #28031 (e.g.ffa4d60).

Deduplicate code that exists in both tx processing and ProcessOrphanTx.
Additionally, this can be reused in a function that handles multiple
MempoolAcceptResults from package submission.
Deduplicate code that exists in both tx processing and ProcessOrphanTx.
Additionally, this can be reused in a function that handles multiple
MempoolAcceptResults from package submission.
@instagibbs
Copy link
Member

thanks for doing this! concept ACK

Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

ACK 07cd510

I can't find any behavior differences in this attempt, and it seems to be straight forwardly useful in the follow-up 1p1c PR.

Looking forward to making better unit test coverage; it's really quite lacking sadly.

RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
m_orphanage.AddChildrenToWorkSet(tx);

ProcessValidTx(pfrom.GetId(), ptx, result.m_replaced_transactions.value());
Copy link
Member

Choose a reason for hiding this comment

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

value_or here as well for belt and suspenders?

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding in the next PR, or will squash if I retouch 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

done in #28970

src/net_processing.cpp Show resolved Hide resolved
Copy link
Member

@achow101 achow101 left a comment

Choose a reason for hiding this comment

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

ACK 07cd510

Comment on lines -3129 to -3130
// We only add the txid if it differs from the wtxid, to
// avoid wasting entries in the rolling bloom filter.
Copy link
Member

Choose a reason for hiding this comment

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

In 07cd510 "[refactor] consolidate invalid MempoolAcceptResult processing"

This comment is lost.

Copy link
Member Author

Choose a reason for hiding this comment

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

added back in #28970

Copy link
Member

@dergoegge dergoegge 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 07cd510

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

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

ACK 07cd510

@@ -3037,6 +3046,63 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
return;
}

void PeerManagerImpl::ProcessInvalidTx(NodeId nodeid, const CTransactionRef& ptx, const TxValidationState& state,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The var names differ from the declaration for CTransactionsRef& and TxValidationState&. Is there a reason for the p in ptx?

Copy link
Member Author

Choose a reason for hiding this comment

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

p as in "pointer". I usually use CMutableTransaction mtx and CTransaction tx. Though I agree there's a mix...

@achow101 achow101 merged commit 264ca9d into bitcoin:master Mar 13, 2024
15 of 16 checks passed
@glozow glozow deleted the 2024-03-atmp-refactors branch March 13, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants