-
Notifications
You must be signed in to change notification settings - Fork 36.7k
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: Clean up nScriptCheckThreads #17342
refactor: Clean up nScriptCheckThreads #17342
Conversation
ACK 6775a18 -- agree regarding the confusion |
I think it would be much more straightforward if 0 (anything smaller than 1) was the disallowed value, not 1. Either that, or make the meaning the number of additional threads spawned, which can be 0. (Not that I disagree on adding documentation, but maybe it would be better to make this code less confusing instead, there is no deeper reason why it needs to be like this, the value isn't even exposed on the RPC interface) |
Turns out that a global int is not needed at all. We only need the bool-ness of whether any script checking threads have been spawned. I have a branch here: https://github.com/jnewbery/bitcoin/tree/2019-11-nScriptCheckThreads2 that changes the int for a bool, improves commenting everywhere and makes the code clearer. I fear it'd be NACKed by the "don't change code for purely cosmetic reasons" crowd, but if you prefer it, let me know. |
@jnewbery FWIW the other branch LGTM.
It's not cosmetic, it's a good refactor IMO. |
Refactor LGTM, we've both been in the group of people that were confused by this code at some point.
Wonder if we can take this a step further and not have any global at all, passing the flag into the ChainState constructor instead. |
6775a18
to
fa080f1
Compare
Thanks for the feedback everyone. I've changed this PR so it now refactors
Yes, it'd be great to remove more globals and make validation initialization take these as arguments, but I think that's too far to go in this PR. |
fa080f1
to
1856073
Compare
Tested that number of script threads started is the same before and after this PR: (
|
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.
Tested ACK 1856073.
This is not a breaking change since the configured -par
is clamped so existing configurations will work. Also verified that bitcoin-qt
does work if configured with 16 before this change - the setting nThreadsScriptVerif
remains 16 but the GUI also clamps to 15.
code review ACK 1856073 |
It's only needed for a hardcoded int, which we can define locally.
The global nScriptCheckThreads int is confusing and is only needed for its int-ness in AppInitMain. Move all `-par` parsing logic there and replace the int nScriptCheckThreads with a bool g_parallel_script_checks. Also tidy up logic and improve comments.
1856073
to
5506ecf
Compare
I wanted to remove the unused Thanks for the review! |
ACK 5506ecf |
ACK 5506ecf, only change was addressing my nits. |
Code review ACK 5506ecf |
Needs rebase |
ACK 5506ecf 🥐 Show signature and timestampSignature:
Timestamp of file with hash |
5506ecf [refactor] Replace global int nScriptCheckThreads with bool (John Newbery) d995762 [tests] Don't use TestingSetup in the checkqueue_tests (John Newbery) Pull request description: The meaning of this value is confusing. Refactor it and add comments. ACKs for top commit: sipa: ACK 5506ecf promag: ACK 5506ecf, only change was addressing my nits. laanwj: Code review ACK 5506ecf MarcoFalke: ACK 5506ecf 🥐 Tree-SHA512: 78536727c98d2c23f3c0f3f169131474fef9a4486ae65029011caf06eab30f6f70ff73a65b2fb04a5d969fc1150858d1c6ea4767f04d48c1eea6b829316d0e63
nScriptCheckThreads = 3; | ||
for (int i = 0; i < nScriptCheckThreads - 1; i++) | ||
// Start script-checking threads. Set g_parallel_script_checks to true so they are used. | ||
constexpr int script_check_threads = 2; |
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.
style-nit: compile time constants are generally ALL_UPPER_CASE
5506ecf [refactor] Replace global int nScriptCheckThreads with bool (John Newbery) d995762 [tests] Don't use TestingSetup in the checkqueue_tests (John Newbery) Pull request description: The meaning of this value is confusing. Refactor it and add comments. ACKs for top commit: sipa: ACK 5506ecf promag: ACK 5506ecf, only change was addressing my nits. laanwj: Code review ACK 5506ecf MarcoFalke: ACK 5506ecf 🥐 Tree-SHA512: 78536727c98d2c23f3c0f3f169131474fef9a4486ae65029011caf06eab30f6f70ff73a65b2fb04a5d969fc1150858d1c6ea4767f04d48c1eea6b829316d0e63
…ue_tests Summary: ~~It's only needed for a hardcoded int, which we can define locally.~~ Note from Backporter: Core's description of this is indeed somewhat confusing. nScriptCheckThreads is removed in the next commit. bitcoin/bitcoin@d995762 --- Partial backport of Core [[bitcoin/bitcoin#17342 | PR17342]] Test Plan: ninja check Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D7274
Summary: The global nScriptCheckThreads int is confusing and is only needed for its int-ness in AppInitMain. Move all `-par` parsing logic there and ~~replace~~ remove the int nScriptCheckThreads ~~with a bool g_parallel_script_checks.~~ (see D521) Also tidy up logic and improve comments. bitcoin/bitcoin@5506ecf --- Concludes backport of Core [[bitcoin/bitcoin#17342 | PR17342]] Depends on D7274 Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D7275
Summary: > test/functional/rpc_fundrawtransaction.py is fairly long to run and has no logging, so it can appear to be stalled. > > This commit adds info logging at each test to provide feedback on the test run. This is a backport of Core [[bitcoin/bitcoin#17342 | PR17342]] [1/2] bitcoin/bitcoin@94fcc08 Test Plan: `ninja && test/functional/test_runner.py rpc_fundr*` While the test is running, in another terminal: `tail -f test/tmp/test_runner_₿₵_🏃_20201102_112740/rpc_fundrawtransaction_475/test_framework.log` Reviewers: O1 Bitcoin ABC, #bitcoin_abc, jasonbcox Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D8234
5506ecf [refactor] Replace global int nScriptCheckThreads with bool (John Newbery) d995762 [tests] Don't use TestingSetup in the checkqueue_tests (John Newbery) Pull request description: The meaning of this value is confusing. Refactor it and add comments. ACKs for top commit: sipa: ACK 5506ecf promag: ACK 5506ecf, only change was addressing my nits. laanwj: Code review ACK 5506ecf MarcoFalke: ACK 5506ecf 🥐 Tree-SHA512: 78536727c98d2c23f3c0f3f169131474fef9a4486ae65029011caf06eab30f6f70ff73a65b2fb04a5d969fc1150858d1c6ea4767f04d48c1eea6b829316d0e63
partial bitcoin#15842, merge bitcoin#15849, bitcoin#17342, bitcoin#18710: Add local thread pool to CCheckQueue
The meaning of this value is confusing. Refactor it and add comments.