You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removes the `cs_main` lock usage from the nonce setup
in the miners.
The chain tip is only used for getting the Height of the tip,
so instead we can just retrieve the height directly. This requires
a change to the signature of `IncrementExtraNonce`.
The other item cs_main was protecting is the static `prevHeaderHash`;
this is only used to reset `nExtraNonce`. However, `nExtraNonce` is
thread-local, so the thread nonces will increment indefinitely, with the
occasional 0 thrown in. This is therefore unnecessary--and rarely may
result in a race:
- Thread 1: creates block template on block N-1
- Thread 2: accepts new block N
- Thread 3: creates block template on block N, resets local nonce
- Thread 1: resets local nonce
- Thread 4: creates block template on block N, resets local nonce
Thread 1 is doing useless work on the old block, this happens.
Threads 3 and 4 are doing the same work since they have the same nonce.
(If I understand right, and the nonces are used here mainly to give
the threads distinct works sets, I believe this means actually
incrementing `nExtraNonce` is unnecessary, since we take `cs_nonce` to
increment `nNonce_base` in order to give each thread a unique nonce.
We would need to rename `IncrementExtraNonce` to describe
what it's actually doing then.)
Removes one extraneous copy of the nonce into a thread local variable
(there were previously two, and I suspect the extra was already being
optimized away).
0 commit comments