-
Notifications
You must be signed in to change notification settings - Fork 37.8k
refactor: CTxMempool constructor clean up #20222
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
Conversation
Concept ACK! Removing unnecessary interface functions, making constant values |
Concept ACK Very nice first-time contribution @ellemouton! Warm welcome as a contributor! :) |
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 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.
Concept ACK 😄 what a cool first contribution! Code looks good to me. Linter is failing on trailing whitespace in the CTxMemPool
constructor doxygen comments
a62501c
to
c65a593
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.
utACK c65a593
I've left two tiny style comments. Feel free to take or leave.
c65a593
to
70768e1
Compare
Use a ratio instead of a frequency that requires a double to int cast for determining how often a mempool sanity check should run.
70768e1
to
f15e780
Compare
…gument Since m_check_ratio is only set once and since the CTxMemPool object is no longer a global variable, m_check_ratio can be passed into the constructor of CTxMemPool. Since it is only read from after initialization, m_check_ratio can also be made a const and hence no longer needs to be guarded by the cs mutex.
Shorten the CTxMemPool initializer list using default initialization for members that dont depend on the constuctor parameters.
utACK f15e780 |
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.
utACK f15e780
Concept ACK It would be very interesting on why the original version of the mempool sanity check (introduced in #6776) used a random range of 2^32, needing rather complicated floating-point logic... I guess back then the motivation was to avoid a (potentially expensive) modulo operation? |
Thanks @theStack 😄 Yeah, good question. I will need to look into that a bit! |
@theStack That's exactly the reason. |
Correct me if I'm wrong, but |
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.
Code Review ACK f15e780
Agreed, |
ACK f15e780 👘 Show signature and timestampSignature:
Timestamp of file with hash |
f15e780 refactor: Clean up CTxMemPool initializer list (Elle Mouton) e331069 refactor: Make CTxMemPool::m_check_ratio a const and a constructor argument (Elle Mouton) 9d4b4b2 refactor: Avoid double to int cast for nCheckFrequency (Elle Mouton) Pull request description: This PR cleans up the CTxMemPool interface by including the ratio used to determine when a mempool sanity check should run in the constructor of CTxMempool instead of using nCheckFrequency which required a cast from a double to a uint32_t. Since nCheckFrequency (now called m_check_ratio) is set in the constructor and only every read from there after, it can be turned into a const and no longer needs to be guarded by the 'cs' lock. Since nCheckFrequency/m_check_ratio no longer needs to lock the 'cs' mutux, mutex lock line in the "CTxMempool::check" function can be moved below where the m_check_ratio variable is checked. Since the variable is 0 by default (meaning that "CTxMempool::check" will most likely not run its logic) this saves us from unnecessarily grabbing the lock. ACKs for top commit: jnewbery: utACK f15e780 MarcoFalke: ACK f15e780 👘 glozow: utACK bitcoin@f15e780 theStack: Code Review ACK f15e780 Tree-SHA512: d83f3b5311ca128847b621e5e999c7e1bf0f4e6261d4cc090fb13e229a0f7eecd66ad997f654f50a838baf708d1515740aa3bffc244909a001d01fd5ae398b68
Summary: PR description: > This PR cleans up the CTxMemPool interface by including the ratio used to determine when a mempool sanity check should run in the constructor of CTxMempool instead of using nCheckFrequency which required a cast from a double to a uint32_t. Since nCheckFrequency (now called m_check_ratio) is set in the constructor and only every read from there after, it can be turned into a const and no longer needs to be guarded by the 'cs' lock. > > Since nCheckFrequency/m_check_ratio no longer needs to lock the 'cs' mutux, mutex lock line in the "CTxMempool::check" function can be moved below where the m_check_ratio variable is checked. Since the variable is 0 by default (meaning that "CTxMempool::check" will most likely not run its logic) this saves us from unnecessarily grabbing the lock. Use a ratio instead of a frequency that requires a double to int cast for determining how often a mempool sanity check should run. This is a backport of [[bitcoin/bitcoin#20222 | core#20222]] [1/3] bitcoin/bitcoin@9d4b4b2 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10841
…gument Summary: Since m_check_ratio is only set once and since the CTxMemPool object is no longer a global variable, m_check_ratio can be passed into the constructor of CTxMemPool. Since it is only read from after initialization, m_check_ratio can also be made a const and hence no longer needs to be guarded by the cs mutex. This is a backport of [[bitcoin/bitcoin#20222 | core#20222]] [2/3] bitcoin/bitcoin@e331069 Depends on D10841 Test Plan: With TSAN: `ninja && ninja check check-functional` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10842
Summary: Shorten the CTxMemPool initializer list using default initialization for members that dont depend on the constuctor parameters. This is a backport of [[bitcoin/bitcoin#20222 | core#20222]] [3/3] bitcoin/bitcoin@f15e780 Depends on D10842 Test Plan: `ninja all check-all` eviewers: Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10843
This PR cleans up the CTxMemPool interface by including the ratio used to determine when a mempool sanity check should run in the constructor of CTxMempool instead of using nCheckFrequency which required a cast from a double to a uint32_t. Since nCheckFrequency (now called m_check_ratio) is set in the constructor and only every read from there after, it can be turned into a const and no longer needs to be guarded by the 'cs' lock.
Since nCheckFrequency/m_check_ratio no longer needs to lock the 'cs' mutux, mutex lock line in the "CTxMempool::check" function can be moved below where the m_check_ratio variable is checked. Since the variable is 0 by default (meaning that "CTxMempool::check" will most likely not run its logic) this saves us from unnecessarily grabbing the lock.