Possibly inconsistent locking of `cs_main` in mining code #5766

issue domob1812 opened this issue on February 7, 2015
  1. domob1812 commented at 8:06 AM on February 7, 2015: contributor

    Looking at the code in rpcmining.cpp with respect to locking of cs_main when creating new blocks, I observe two things:

    1. The code for setgenerate locks cs_main only very briefly for calling IncrementExtraNonce. Does that mean that in theory, a block could have arrived between the call to CreateNewBlock and IncrementExtraNonce, thus making IncrementExtraNonce write out a wrong height into the coinbase? I realise that this is only for regtest mode and thus a non-issue, but it seems "wrong" nevertheless.

    2. The code for getblocktemplate, on the other hand, locks cs_main over most of its length. Because of this, the usage of pindexPrevNew (with a comment "to avoid races") seems unnecessary. Or do I miss anything here?

    None of these is an issue I would consider "critical" - but both seem a bit inconsistent to me. Unless I miss some details here, the code in its current form seems, at least, confusing about how locking "should" be done.

  2. laanwj added the label Mining on May 18, 2015
  3. laanwj closed this on Mar 6, 2018

  4. MarcoFalke locked this on Sep 8, 2021
Contributors
Labels

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me