Merge bitcoin/bitcoin#34661: ipc mining: Prevent `Assertion m_node.chainman' failed`` errors on early startup

bbc8f1e0a7 ipc mining: Prevent ``Assertion `m_node.chainman' failed`` errors on early startup (Ryan Ofsky)
a7cabf92e4 init refactor: Only initialize node.notifications one time (Ryan Ofsky)
c8e332cb33 init refactor: Remove node.init accesss in AppInitInterfaces (Ryan Ofsky)

Pull request description:

  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 wait until chainstate data is loaded. It's probably the simplest possible fix but other alternatives like moving the wait to `Mining.createNewBlock` were discussed in the thread https://github.com/bitcoin/bitcoin/pull/34661#discussion_r2848176298 and could be implemented later without changes to clients.

ACKs for top commit:
  Sjors:
    utACK bbc8f1e0a7
  ismaelsadeeq:
    ACK bbc8f1e0a7
  achow101:
    ACK bbc8f1e0a7

Tree-SHA512: 3e2e4e28ccff364b2303efd06ce337a229c28609076638500acb29559f716a15ad99409c6970ce9ad91776d53e3f9d959f1bbbd144ea9a4a2fb578ddbf2da267
This commit is contained in:
Ava Chow committed 2026-02-27 15:07:57 -08:00
commit 5a6dd7c693
8 files changed
+84 -15

No files matched your search

+29
View File
@@ -147,6 +147,34 @@ class IPCMiningTest(BitcoinTestFramework):
asyncio.run(capnp.run(async_routine()))
def run_early_startup_test(self):
"""Make sure mining.createNewBlock safely returns on early startup as
soon as mining interface is available """
self.log.info("Running Mining interface early startup test")
node = self.nodes[0]
self.stop_node(node.index)
node.start()
async def async_routine():
while True:
try:
ctx, mining = await self.make_mining_ctx()
break
except (ConnectionRefusedError, FileNotFoundError):
# Poll quickly to connect as soon as socket becomes
# available but without using a lot of CPU
await asyncio.sleep(0.005)
opts = self.capnp_modules['mining'].BlockCreateOptions()
await mining.createNewBlock(ctx, opts)
asyncio.run(capnp.run(async_routine()))
# Reconnect nodes so next tests are happy
node.wait_for_rpc_connection()
self.connect_nodes(1, 0)
def run_block_template_test(self):
"""Test BlockTemplate interface methods."""
self.log.info("Running BlockTemplate interface test")
@@ -374,6 +402,7 @@ class IPCMiningTest(BitcoinTestFramework):
self.miniwallet = MiniWallet(self.nodes[0])
self.default_block_create_options = self.capnp_modules['mining'].BlockCreateOptions()
self.run_mining_interface_test()
self.run_early_startup_test()
self.run_block_template_test()
self.run_coinbase_and_submission_test()
self.run_ipc_option_override_test()