This is split out of D16224
Pass the pointer to the constructor, and move the responsibility of invoking the global to callsites (all of which will have access to the avalanche processor via the NodeContext in D16224)
The avalanche argument in the ctor is optional and defaults to nullptr, so we don't have to change all the callsites in tests where g_avalanche is currently not available.
Also add a `if (g_avalanche) check before dereferencing the pointer in `getblocktemplate` while we are touching the file. This is currently redundant because it is already done in `IsStakingRewardsActivated()` in the same `if ` statement, but in the future it won't be.