Mining blocks on a blockchain equipped with a proof of work consensus protocol is known to be resource-consuming. A miner bears the operational cost, mainly electricity consumption and IT gear, of mining, and is compensated by a capital gain when a block is discovered. In this talk we quantify the profitability of mining when the possible event of ruin is also taken into consideration. This is done by formulating a tractable stochastic model and using tools from actuarial ruin theory and analysis, including the explicit solution of a certain type of advanced functional differential equation. The expected profit at a future time point is determined for the situation when the miner follows the protocol as well as when he/she withholds blocks. The obtained explicit expressions allow to analyze the sensitivity with respect to the different model ingredients and to identify conditions under which selfish mining is a strategic advantage. We also investigate the advantage of joining a mining pool, which leads to analogies with reinsurance.