-
Notifications
You must be signed in to change notification settings - Fork 36.5k
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
Tidy up ProcessOrphanTx #19498
Tidy up ProcessOrphanTx #19498
Conversation
@jonatack @troygiorshev - you both concept ACKed this branch in #19364. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK on the doxygen comments. The pure refactoring changes seem ok. I hesitate with the commits where refactoring is mixed with behavior changes: are the behavior changes desirable in themselves or ignorable side effects; are the benefits worth the review and risk.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
There are no observable functional changes. The behavior changes are simply in the timing of how items are popped off the orphan_work_set list. They make the control flow of the function much easier to follow. After these changes either:
|
9c954f4
to
9f18dc3
Compare
rebased |
rebased |
9f18dc3
to
e26e8e8
Compare
rebased |
e26e8e8
to
eb30f87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost-ACK
+💯 to removing old outdated comments! 👏👏
Travis failure is unrelated
eb30f87
to
833bccc
Compare
Thanks for the review @troygiorshev . I've addressed your comment in the lastest force-push: https://github.com/bitcoin/bitcoin/compare/eb30f87e0972faae78df7c6116bc18f6fad7b353..833bccc522703f87d0d46b190a9a29bcb633c615 |
tACK 833bccc via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay tidy! thanks for the cleanup and docs, the code makes more sense.
is my understanding correct that there is a v. small change in behavior in ProcessOrphanTx
- previously, if an orphan taken off the orphan_work_set
was not accepted to mempool bc of missing additional parents & there are more orphans in the work set, the while loop would continue & process the next one. with these changes it will consider max of one orphan per run. seems like an edge case & acceptable shift, but would like to confirm my understanding.
src/net_processing.cpp
Outdated
/** Index from COutPoint into the mapOrphanTransactions. Used to remove | ||
* orphan transactions from the mapOrphanTransactions */ | ||
std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans); | ||
/** Orphan transactions listed in random order for random eviction */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1/3 nit on this comment, 2/3 for my understanding-
these orphans aren't listed exactly random right? AddOrphanTx
adds the entries to in the order they are seen, but EraseOrphanTx
introduces some randomness bc it deletes an entry by swapping out the last element (which I'm still trying to understand the point of).
seems the point of this data structure is to enable LimitOrphanTxSize
to easily choose a random orphan to erase by providing a vector interface?
if my understanding is correct, I think it'd be clearer to say "List of orphan transactions to enable random eviction"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these orphans aren't listed exactly random right?
if my understanding is correct, I think it'd be clearer to say "List of orphan transactions to enable random eviction"
You're correct. I've now fixed the comment. Thank you!
it deletes an entry by swapping out the last element (which I'm still trying to understand the point of)
This is because g_orphan_list
is a std::vector, which is a contiguous-memory container. It can't have gaps in the underlying array. The normal way to erase an element from the middle of the vector is to delete it and then shift all the following elements forward by one position. That's expensive, and would invalidate all of the list_pos
values that point back to a position in the vector. It's more efficient to copy the last element to the position of the element you want to delete, fix up the list_pos
of just that COrphanTx
, and then pop of the (now duplicate) last element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this sound right:
it seems to me that list_pos
is tracked for this reason. so the alternative would be if we removed list_pos
& used in the built in vector erase function. the tradeoff would be less efficiency.
the current design choice is to store this additional field on every COrphanTx
to reduce an O(n) operation on the g_orphan_list
vector, where n <= 100 | -maxorphantx
. but I don't have much idea of how often we erase orphans in practice. so small increase in memory for small decrease in processing time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the only reason we store list_pos
. Without it, we'd have to do a (relatively) expensive erase from the middle of the vector.
Concept ACK |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
There is a keyword that allows us to break out of loops. Use it. There's a small change in behaviour here: if we process multiple orphans that are still orphans, then we'll only call mempool.check() once at the end, instead of after processing each tx.
This starts empty, and is only added to if we're about to exit the function (so we never read from it).
Also rename orphan_state to state. Both the comment and the variable name are leftover from when this logic was part of ProcessMessage().
e59bbcd
to
001343f
Compare
Rebased |
ACK 001343f This is a rather straightforward PR now. |
utACK 001343f |
ACK 001343f 🌮 Show signature and timestampSignature:
Timestamp of file with hash |
001343f ProcessOrphanTx: Move AddToCompactExtraTransactions call into ProcessOrphanTx (John Newbery) 4fce726 ProcessOrphanTx: Remove aliases (John Newbery) e07c5d9 ProcessOrphanTx: Remove outdated commented (John Newbery) 4763b51 ProcessOrphanTx: remove useless setMisbehaving set (John Newbery) 55c79a9 ProcessOrphanTx: remove useless done variable (John Newbery) 6e8dd99 [net processing] Add doxygen comments for orphan data and function (John Newbery) Pull request description: Originally a follow-up to bitcoin#19364, this simplifies the logic in ProcessOrphanTx() and removes unused variables. ACKs for top commit: troygiorshev: ACK 001343f sipa: utACK 001343f MarcoFalke: ACK 001343f 🌮 Tree-SHA512: be558457f2e08ebb6bddcd49bdd75bd410c3650da44a76c688fc9f07822f94d5a1af93fa1342678052b2c8163cdb9745c352c7884325ab0a41fa593c3eb89116
Summary: PR description: > Originally a follow-up to #19364, this simplifies the logic in ProcessOrphanTx() and removes unused variables. This is a backport of [[bitcoin/bitcoin#19498 | core#19498]] [1/5] bitcoin/bitcoin@6e8dd99 Note: The `removed_txn` parameter does not exist in ProcessOrphanTx in Bitcoin ABC. This part of the logic was dropped in D1175, and was already unused by then. It seems to be related to RBF (see [[https://github.com/bitcoin/bitcoin/pull/21062/commits/f82baf0762f60c2ca5ffc339b095f9271d7c2f33#diff-d3c243938494b10666b44404a27af7d84b44a72b85a27431e0c89e181462ca6eR200|following comment]]). The last commit of this PR only deals with this parameter, so it is not relevant to Bitcoin ABC. Test Plan: proofreading Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D10412
Summary: > There is a keyword that allows us to break out of loops. Use it. > > There's a small change in behaviour here: if we process multiple orphans > that are still orphans, then we'll only call mempool.check() once at the > end, instead of after processing each tx. This is a backport of [[bitcoin/bitcoin#19498 | core#19498]] [2/5] bitcoin/bitcoin@55c79a9 Depends on D10412 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D10413
Summary: Original commit: > This starts empty, and is only added to if we're about to > exit the function (so we never read from it). In the Bitcoin ABC codebase, `setMisbehaving` was replaced with `rejectCountPerNode` in D2676, and in D6683 it stopped being used. This is a backport of [[bitcoin/bitcoin#19498 | core#19498]] [3/5] bitcoin/bitcoin@4763b51 Depends on D10413 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D10414
Summary: Also rename orphan_state to state. Both the comment and the variable name are leftover from when this logic was part of ProcessMessage(). This is a backport of [[bitcoin/bitcoin#19498 | core#19498]] [4/5] bitcoin/bitcoin@e07c5d9 Depends on D10414 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D10415
Summary: This is a backport of [[bitcoin/bitcoin#19498 | core#19498]] [5/5] bitcoin/bitcoin@4fce726 Depends on D10415 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Subscribers: majcosta Differential Revision: https://reviews.bitcoinabc.org/D10416
Originally a follow-up to #19364, this simplifies the logic in ProcessOrphanTx() and removes unused variables.