Is it possible (not feasible) to mine bitcoins with Bitcoin Core v0.21.1? Before you tell me, yes, I'm aware CPU mining is dead in 2021 and attempting to do so will likely just burn CPU time for no good reason.
However, my question is not whether mining is feasible, but whether it is possible with the (currently) latest version of Bitcoin Core, v0.21.1. From my understanding, it was possible in 2016, but the internal miner was &quot;removed&quot; in v0.13.0. Looking at the code, it's unclear to me whether it's still possible; miner.cpp is still present, for example. All that seems to remain is the &quot;-generate&quot; option. Does this option actually allow mining on mainnet?
If the answer is no: Isn't Bitcoin Core meant to be the reference implementation of Bitcoin? And given that, isn't it a bit odd that the reference implementation does contain one of the core components of Bitcoin, that is, the mining system? I understand it's pointless to do so, but as the reference implementation, shouldn't Bitcoin Core provide this feature regardless?
The setgenerate built-in background miner was removed.
There is however still a test-only on-demand miner, which will try to mine N blocks whenever requested by RPC (see generatetoaddress /generatetodescriptor/generateblock RPCs in recent Bitcoin Core versions). It is many times less efficient than even the built-in CPU miner was. Its only purpose is in functional tests (which use the &quot;regtest&quot; network that is permanently at very low difficulty).
The code you see in miner.cpp is additionally used as a backend for the getblocktemplate RPC, which is how pools and external miners communicate with bitcoind. It doesn't actually do any mining (as in hashing) itself, but provides block templates for others to do so, based on transactions in the mempool and the chain's tip block hash.
The -generate option to bitcoin-cli is just a wrapper around the internal generatetoaddress RPC, which is slightly more convenient (it requests an address from the wallet, and then miner to it). It is in theory usable on mainnet, but it obviously won't ever actually find anything (except with extremely small probability).