[ADD] contextual version
Version is contextual: it depends on state at a given block height. It is also expensive to compute, as it requires iteration over all node accounts. During BeginBlock
the version is computed and cached in both the mgr
and Keeper
objects to avoid unnecessary re-computation during block processing, and to allow new version checks to be added without consuming gas/breaking consensus.
However the cached version is local to the running thorchain
module. In querier, which has it's own mgr
and Keeper
, the version must be re-computed. Additionally, any other code which needs to determine version cheaply is unable to do so unless it has access to the main mgr
or Keeper
instance.
This patch stores the version in the Keeper
during BeginBlock
, making it accessible cheaply to the querier, etc. It is cheap to store and cheap to lookup (only set/updated when version changes; string lookup during gets will be cached under the hood). And the lookup uses an InfiniteGasMeter
to access without consuming gas, allowing new version checks to be added while maintaining consensus.