Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Oct 30, 2019

Fix #17139

@practicalswift
Copy link
Contributor

Concept ACK

src/init.cpp Outdated
for (int i=0; i<nScriptCheckThreads-1; i++)
threadGroup.create_thread([i]() { return ThreadScriptCheck(i); });
} else {
LogPrintf("Using the only thread for script verification\n");
Copy link
Member

@laanwj laanwj Oct 30, 2019

Choose a reason for hiding this comment

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

Concept ACK, my only comment would be that -par=0 and -par=1 do the same thing (right?), but log different messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not exactly:

gArgs.AddArg("-par=<n>", strprintf("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)",

Copy link
Member

@laanwj laanwj Oct 31, 2019

Choose a reason for hiding this comment

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

Wait, I'm not really talking about the input argument, but the already-processed value we end up with here.

It's doing the same thing in case of nScriptCheckThreads==0 and nScriptCheckThreads==1 so should log the same thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

After this code

bitcoin/src/init.cpp

Lines 1064 to 1071 in 08e2947

// -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency
nScriptCheckThreads = gArgs.GetArg("-par", DEFAULT_SCRIPTCHECK_THREADS);
if (nScriptCheckThreads <= 0)
nScriptCheckThreads += GetNumCores();
if (nScriptCheckThreads <= 1)
nScriptCheckThreads = 0;
else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS)
nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS;

is executed in AppInitParameterInteraction(), nScriptCheckThreads==1 is an impossible value.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, so it will never log Using 1 threads concurrently for script verification?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

src/init.cpp Outdated
for (int i=0; i<nScriptCheckThreads-1; i++)
threadGroup.create_thread([i]() { return ThreadScriptCheck(i); });
} else {
LogPrintf("Using the only thread for script verification\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Something feels a bit off with the wording here. What about "Using one thread for script verification"?

Copy link
Member

Choose a reason for hiding this comment

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

It's not just any thread though, it's the main thread. No additional threads are spawned. I think that's what he's trying to convey.

Copy link
Contributor

@practicalswift practicalswift Oct 31, 2019

Choose a reason for hiding this comment

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

What about:

"Validation concurrency disabled: using the main thread for script validation."

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't this the thread:

threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));

?

Copy link
Member

Choose a reason for hiding this comment

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

That spawns the scheduler thread, which is unrelated to script verification.

Copy link
Member

Choose a reason for hiding this comment

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

On -par=1, it will inline the calls into the current thread. See also:

git grep '\-par=' test

src/init.cpp Outdated
for (int i=0; i<nScriptCheckThreads-1; i++)
threadGroup.create_thread([i]() { return ThreadScriptCheck(i); });
} else {
LogPrintf("Using the only thread for script verification\n");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LogPrintf("Using the only thread for script verification\n");
LogPrintf("Script verification is done in the main thread\n");

Copy link
Member

@laanwj laanwj Oct 31, 2019

Choose a reason for hiding this comment

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

But script verification is always done in the main thread (as well), the other threads are only additional 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

"Script verification is done in the main thread only (no validation concurrency)"

Copy link
Member

@laanwj laanwj Oct 31, 2019

Choose a reason for hiding this comment

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

or "Script verification uses N additional threads" where N can be 0… it doesn't have to be a whole story

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, let's make it a one-line "fix"

Copy link
Member

Choose a reason for hiding this comment

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

shortest would be

LogPrintf("Script verification uses %d additional threads\m", std::max(nScriptCheckThreads-1, 0));

Copy link
Member Author

Choose a reason for hiding this comment

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

True, it is shorter than conditional operator ;)

Copy link
Contributor

@jnewbery jnewbery Oct 31, 2019

Choose a reason for hiding this comment

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

I don't think this should be nScriptCheckThreads-1. nScriptCheckThreads is the number of threads that are dedicated to script checking, so:

  • if nScriptCheckThreads >= 2, then log "Script verification uses {nScriptCheckThreads} additional threads"
  • if nScriptCheckThreads == 0, then script checking is done on the main thread so log "Script verification uses 0 additional threads"
  • nScriptCheckThreads cannot == 1 because of the logic in init.cpp

so you just want:

LogPrintf("Script verification uses %d dedicated threads\m", nScriptCheckThreads);

The log is already essentially correct. I think you just need to add the word 'dedicated' or 'additional' (I prefer 'dedicated').

@sipa has corrected my misunderstanding below.

Copy link
Member

@sipa sipa Oct 31, 2019

Choose a reason for hiding this comment

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

That's not correct; it should be LogPrintf("Script verification uses %d dedicated threads\m", nScriptCheckThreads - 1); then, as nScriptCheckThreads includes the main thread.

Copy link
Member

Choose a reason for hiding this comment

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

@sipa The std::max(nScriptCheckThreads-1, 0) bound is there because nScriptCheckThreads might be zero at this point.

@hebasto hebasto force-pushed the 20191030-fix-par-log branch from 3ee5d33 to 417c910 Compare October 31, 2019 16:46
Co-authored-by: Wladimir J. van der Laan <laanwj@protonmail.com>
@hebasto hebasto force-pushed the 20191030-fix-par-log branch from 417c910 to 8a0ca5e Compare October 31, 2019 16:59
@hebasto
Copy link
Member Author

hebasto commented Oct 31, 2019

All comments have been addressed.

@jnewbery
Copy link
Contributor

Tested ACK 8a0ca5e

If we wanted to be completely explicit we could log "Script verification uses main thread and %d dedicated threads\n"

@laanwj
Copy link
Member

laanwj commented Nov 1, 2019

ACK 8a0ca5e

If we wanted to be completely explicit we could log "Script verification uses main thread and %d dedicated threads\n"

I know bitcoin core is lacking in user documentation, but I don't think the debug log is the place for it 😄
The value is now correct, which is good for troubleshooting.

laanwj added a commit that referenced this pull request Nov 1, 2019
8a0ca5e log: Fix log message for -par=1 (Hennadii Stepanov)

Pull request description:

  Fix #17139

ACKs for top commit:
  jnewbery:
    Tested ACK 8a0ca5e
  laanwj:
    ACK 8a0ca5e

Tree-SHA512: 09f5416c00cd3e4f85cd9040267dc825d5c5623f8903e9d2373013686dce7f6b3ba573648787adc1d58e6f1d5012e26c78700d585273d4b508cb25312b3fa06b
@laanwj laanwj merged commit 8a0ca5e into bitcoin:master Nov 1, 2019
@hebasto hebasto deleted the 20191030-fix-par-log branch November 1, 2019 10:12
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 1, 2019
8a0ca5e log: Fix log message for -par=1 (Hennadii Stepanov)

Pull request description:

  Fix bitcoin#17139

ACKs for top commit:
  jnewbery:
    Tested ACK 8a0ca5e
  laanwj:
    ACK 8a0ca5e

Tree-SHA512: 09f5416c00cd3e4f85cd9040267dc825d5c5623f8903e9d2373013686dce7f6b3ba573648787adc1d58e6f1d5012e26c78700d585273d4b508cb25312b3fa06b
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Apr 7, 2020
- doc: fix git add argument bitcoin#18513
- build: Fix libevent linking for bench_bitcoin binary bitcoin#18397
- script: fix SCRIPT_ERR_SIG_PUSHONLY error string bitcoin#18412
- doc: Comment fix merkle.cpp bitcoin#18379
- log: Fix UB with bench on genesis block bitcoin#15283
- test: Fix mining to an invalid target + ensure that a new block has the correct hash internally bitcoin#18350
- Fix missing header in sync.h bitcoin#18357
- refactor: Fix implicit value conversion in formatPingTime bitcoin#18260
- Fix .gitignore policy in build_msvc directory bitcoin#18108
- build: Fix behavior when ALLOW_HOST_PACKAGES unset bitcoin#18051
- test: Fix p2p_invalid_messages failing in Python 3.8 because of warning bitcoin#17931
- qa: Fix double-negative arg test bitcoin#17893
- build: Fix configure report about qr bitcoin#17547
- log: Fix log message for -par=1 bitcoin#17325
- bench: Fix negative values and zero for -evals flag bitcoin#17267
- depends: fix boost mac cross build with clang 9+ bitcoin#17231
- doc: Fix broken bitcoin-cli examples bitcoin#17119
- doc: fix Makefile target in benchmarking.md bitcoin#17081
- contrib: fix minor typos in makeseeds.py bitcoin#17042
- test: Fix Python Docstring to include all Args. bitcoin#17030
- doc: Fix some misspellings bitcoin#17351
- doc: Doxygen-friendly script/descriptor.h comments bitcoin#16947
- doc: Fix doxygen errors bitcoin#17945
- doc: Doxygen-friendly CuckooCache comments bitcoin#16986
- doc: Add to Doxygen documentation guidelines bitcoin#17873
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Apr 7, 2020
- doc: fix git add argument bitcoin#18513
- build: Fix libevent linking for bench_bitcoin binary bitcoin#18397
- script: fix SCRIPT_ERR_SIG_PUSHONLY error string bitcoin#18412
- doc: Comment fix merkle.cpp bitcoin#18379
- log: Fix UB with bench on genesis block bitcoin#15283
- test: Fix mining to an invalid target + ensure that a new block has the correct hash internally bitcoin#18350
- Fix missing header in sync.h bitcoin#18357
- refactor: Fix implicit value conversion in formatPingTime bitcoin#18260
- Fix .gitignore policy in build_msvc directory bitcoin#18108
- build: Fix behavior when ALLOW_HOST_PACKAGES unset bitcoin#18051
- test: Fix p2p_invalid_messages failing in Python 3.8 because of warning bitcoin#17931
- qa: Fix double-negative arg test bitcoin#17893
- build: Fix configure report about qr bitcoin#17547
- log: Fix log message for -par=1 bitcoin#17325
- bench: Fix negative values and zero for -evals flag bitcoin#17267
- depends: fix boost mac cross build with clang 9+ bitcoin#17231
- doc: Fix broken bitcoin-cli examples bitcoin#17119
- doc: fix Makefile target in benchmarking.md bitcoin#17081
- contrib: fix minor typos in makeseeds.py bitcoin#17042
- test: Fix Python Docstring to include all Args. bitcoin#17030
- doc: Fix some misspellings bitcoin#17351
- doc: Doxygen-friendly script/descriptor.h comments bitcoin#16947
- doc: Fix doxygen errors bitcoin#17945
- doc: Doxygen-friendly CuckooCache comments bitcoin#16986
- doc: Add to Doxygen documentation guidelines bitcoin#17873
- depends: Consistent use of package variable bitcoin#17928
- init: Replace URL_WEBSITE with PACKAGE_URL bitcoin#18503
- doc: Add missed copyright headers bitcoin#17691
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
8a0ca5e log: Fix log message for -par=1 (Hennadii Stepanov)

Pull request description:

  Fix bitcoin#17139

ACKs for top commit:
  jnewbery:
    Tested ACK 8a0ca5e
  laanwj:
    ACK 8a0ca5e

Tree-SHA512: 09f5416c00cd3e4f85cd9040267dc825d5c5623f8903e9d2373013686dce7f6b3ba573648787adc1d58e6f1d5012e26c78700d585273d4b508cb25312b3fa06b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2021
8a0ca5e log: Fix log message for -par=1 (Hennadii Stepanov)

Pull request description:

  Fix bitcoin#17139

ACKs for top commit:
  jnewbery:
    Tested ACK 8a0ca5e
  laanwj:
    ACK 8a0ca5e

Tree-SHA512: 09f5416c00cd3e4f85cd9040267dc825d5c5623f8903e9d2373013686dce7f6b3ba573648787adc1d58e6f1d5012e26c78700d585273d4b508cb25312b3fa06b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 28, 2021
8a0ca5e log: Fix log message for -par=1 (Hennadii Stepanov)

Pull request description:

  Fix bitcoin#17139

ACKs for top commit:
  jnewbery:
    Tested ACK 8a0ca5e
  laanwj:
    ACK 8a0ca5e

Tree-SHA512: 09f5416c00cd3e4f85cd9040267dc825d5c5623f8903e9d2373013686dce7f6b3ba573648787adc1d58e6f1d5012e26c78700d585273d4b508cb25312b3fa06b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 29, 2021
8a0ca5e log: Fix log message for -par=1 (Hennadii Stepanov)

Pull request description:

  Fix bitcoin#17139

ACKs for top commit:
  jnewbery:
    Tested ACK 8a0ca5e
  laanwj:
    ACK 8a0ca5e

Tree-SHA512: 09f5416c00cd3e4f85cd9040267dc825d5c5623f8903e9d2373013686dce7f6b3ba573648787adc1d58e6f1d5012e26c78700d585273d4b508cb25312b3fa06b
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

log, doc: Confusing log message
7 participants