Clean up the deterministic emissions #9
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors and improves the emission decay logic in the
epixmintmodule, focusing on determinism, safety, and testability. The main changes include centralizing and simplifying the decay calculation logic, exporting the decay approximation function for testing, introducing safeguards against performance and overflow issues, and adding comprehensive tests for decay behavior and edge cases.Refactoring and Centralization:
calculateDecayFactorAndBlocksPerYearhelper function, which centralizes the calculation of decay factors and blocks per year for use in both emission rate functions. This reduces code duplication and ensures consistent logic.Deterministic and Safe Decay Calculation:
ApproximateDecayWithDec, adding parameter validation (ensuring base is between 0 and 1), capping the exponent at a maximum number of years (MaxDecayYears), and improving documentation for clarity and safety. This ensures deterministic and safe calculations across all architectures.Testing Improvements:
ApproximateDecayWithDec, covering standard cases, fractional exponents, negative bases, zero bases, negative exponents, exponent capping, and determinism. This ensures the function behaves correctly in all scenarios and remains robust against edge cases.