0

What is cs_main? Why is it called cs_main?

This question was asked during the May 12th 2021 Bitcoin Core PR review club hosted by John Newbery on a Carl Dong PR to de-globalize ChainstateManager.

(The lock on cs_main was discussed in this StackExchange question.)

0

What is cs_main?

cs_main is a recursive mutex which is used to ensure that validation is carried out in an atomic way. It guards access to validation specific variables (such as CChainState and CNode) or mempool variables (in net_processing). The lock of cs_main is in validation.cpp.

Why is it called cs_main?

cs_main was the mutex ("critical section") that protected data in Satoshi's original main.cpp. In theory it could be renamed today as main.cpp has since been refactored into smaller files but every time you rename something in a header file, everyone needs to recompile any file that includes that header.

A long-term goal is to separate out those different bits of data that are protected by cs_main, so that eventually cs_main only protects the data inside validation.

These were answered by John Newbery and other participants of the May 12th 2021 Bitcoin Core PR review club.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.