Skip to content

Possibly inconsistent locking of cs_main in mining code #5766

@domob1812

Description

@domob1812

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions