Based on #36356. Together with it, this completes the "Remove remaining global states" TODO in #33758.
getmininginfo reports currentblockweight and currentblocktx from two process-wide statics, BlockAssembler::m_last_block_weight and m_last_block_num_txs, which every BlockAssembler::CreateNewBlock() call overwrites.
Like the getblocktemplate statics, they are shared by every node context in the process and nothing checks their locking. They also record templates that were not built for mining: the mempool fee estimator builds its own templates with BlockAssembler, so getmininginfo can report the fee estimator's template instead of the last mining template.
This PR:
- makes the two fields per-
BlockAssemblerinstance, still set at the same point inCreateNewBlock(); - has
BlockTemplateManager::CreateNewTemplate()record them in a member guarded bycs_main, whichgetmininginforeads.CreateNewTemplate()now holdscs_mainacross the build, asCreateNewBlock()already did internally, so concurrent builds cannot record their stats out of order; - adds a unit test showing that manager builds are recorded, that the latest one wins, and that a direct
BlockAssemblerbuild is ignored.
In short: the last global mining state moves out of BlockAssembler, and getmininginfo reports the last template built for mining rather than whatever the node assembled last.