Skip to content

Conversation

@MudDev
Copy link

@MudDev MudDev commented Jan 13, 2026

This pull request refactors and improves the emission decay logic in the epixmint module, 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:

  • Refactored the emission decay logic by introducing the calculateDecayFactorAndBlocksPerYear helper 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:

  • Exported and enhanced the decay approximation function as 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:

  • Added comprehensive unit tests for 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.

@MudDev MudDev merged commit 68af41b into main Jan 13, 2026
3 of 13 checks passed
@github-actions github-actions bot added the tests label Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants