Problem
createNewBlock() returns nullptr only when the node is shutting down (WaitTipChanged returns nullopt on interrupt and nothing else). The mining RPCs wrapped the result in CHECK_NONFATAL, reporting an expected shutdown condition as "Internal bug detected".
Fix
getblocktemplate and generateblock now throw "Shutting down" (RPC_CLIENT_NOT_CONNECTED), matching how getblocktemplate's longpoll path already reports the same condition. generateBlocks stops mining and returns the blocks found so far, matching its existing interrupt handling.
Testing
Add regression coverage: a longpoll getblocktemplate interrupted by shutdown must error with "Shutting down". Without the fix this raced ~50/50 between the correct error and the internal-bug error, because the IsRPCRunning() check runs before RPC is disabled during shutdown.
Fixes #34262