re: #34661 (review)
The comment in bbc8f1e ipc mining: Prevent Assertion `m_node.chainman' failed errors on early startup is better. But it doesn’t explain why it’s safe for internal consumers.
For RPC IIRC all methods are blocked until we’ve made some (enough?) progress in initialization. The new BlockTemplateCache in #33421 should be fine initially, because it doesn’t introduce new accessors. Once it’s expanded to fee estimation, that code needs to be careful though?
I guess I don’t really see it as a goal to for internal interface pointers to be safe to use at all time. I think basically all node code including RPC methods need to be aware of initialization and shutdown and check for null objects, check for interrupts appropriately, and only external clients shouldn’t need to do this.
From my perspective even making the makeMining method blocking for external clients is potentially too restrictive and was not my first choice. My initial attempt at fixing this crash was to leave makeMining alone and update all the mining interface methods individually to handle the chainstate not being loaded yet, and return false, or null, or wait inside as appropriate inside each method. However, implementing this turned into a bigger change (especially trying to integrate the chainstate wait with mining methods that were already waiting), so I decided to take the simpler approach of leaving all the methods alone except Init.makeMining.
I still think we may want to go back a version of the other approach, if for example we want to give mining clients the ability to show progress messages on node startup or disconnect cleanly while chain data is being loaded.