ipc mining: Prevent `Assertion m_node.chainman' failed`` errors on early startup

This fixes ``Assertion `m_node.chainman' failed`` errors first reported
https://github.com/bitcoin/bitcoin/issues/33994#issuecomment-3602551596 when
IPC mining methods are called before ChainstateManager is loaded.

The fix works by making the `Init.makeMining` method block until chainstate
data is loaded.
This commit is contained in:
Ryan Ofsky
2026-02-24 08:31:38 -05:00
parent a7cabf92e4
commit bbc8f1e0a7
6 changed files with 52 additions and 5 deletions

View File

@@ -1017,5 +1017,17 @@ public:
namespace interfaces {
std::unique_ptr<Node> MakeNode(node::NodeContext& context) { return std::make_unique<node::NodeImpl>(context); }
std::unique_ptr<Chain> MakeChain(node::NodeContext& context) { return std::make_unique<node::ChainImpl>(context); }
std::unique_ptr<Mining> MakeMining(node::NodeContext& context) { return std::make_unique<node::MinerImpl>(context); }
std::unique_ptr<Mining> MakeMining(node::NodeContext& context, bool wait_loaded)
{
if (wait_loaded) {
node::KernelNotifications& kernel_notifications(*Assert(context.notifications));
util::SignalInterrupt& interrupt(*Assert(context.shutdown_signal));
WAIT_LOCK(kernel_notifications.m_tip_block_mutex, lock);
kernel_notifications.m_tip_block_cv.wait(lock, [&]() EXCLUSIVE_LOCKS_REQUIRED(kernel_notifications.m_tip_block_mutex) {
return kernel_notifications.m_state.chainstate_loaded || interrupt;
});
if (interrupt) return nullptr;
}
return std::make_unique<node::MinerImpl>(context);
}
} // namespace interfaces