-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(x/mint)!: avoid writing same minter and use millisecond precision for minting #20747
Conversation
WalkthroughWalkthroughThe updates across various files primarily focus on enhancing the precision of time calculations in the token minting process by shifting from seconds to milliseconds. Additionally, there are optimizations in data comparison logic for minter data to minimize unnecessary updates. The changes aim to improve the overall efficiency and accuracy of the minting module within the application. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant MintModule
participant HeaderService
User ->> App: Initiate Minting Operation
App ->> HeaderService: Get Current Time
HeaderService -->> App: Current UnixMilli Time
App ->> MintModule: Calculate Tokens to Mint
MintModule ->> App: Mint Tokens
App -->> User: Minting Successfully Completed
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- simapp/mint_fn.go (1 hunks)
- x/mint/epoch_hooks.go (2 hunks)
- x/mint/keeper/abci.go (2 hunks)
Additional context used
Path-based instructions (3)
x/mint/keeper/abci.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/mint/epoch_hooks.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/mint_fn.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (6)
x/mint/keeper/abci.go (2)
4-4
: Approved new import.The addition of the
bytes
package is justified as it is used for comparing byte slices to optimize the minting process.
22-22
: Optimization of minting logic.The use of marshaling and byte comparison before setting the minter is a good optimization, ensuring that updates to the minter are only made when necessary. This should enhance the efficiency of the
BeginBlocker
function.Also applies to: 31-34
x/mint/epoch_hooks.go (2)
4-4
: Approved new import.The addition of the
bytes
package is essential for the new logic that compares byte slices in theBeforeEpochStart
function.
24-24
: Optimization of epoch start logic.Adding logic to marshal the
minter
object and compare its state before and after potential modifications optimizes the process, preventing unnecessary updates. This is a thoughtful addition that aligns with the PR's goal to enhance efficiency.Also applies to: 31-34
simapp/mint_fn.go (2)
67-67
: Precision adjustment in time calculations.Switching from second-based to millisecond-based time calculations (
Unix()
toUnixMilli()
) is a critical update that supports the PR's objective of enhancing the minting process to accommodate faster block times.Also applies to: 71-71
74-75
: Updated minting calculation using millisecond precision.The update to use milliseconds in the minting calculation (
31536000000
instead of31536000
) aligns with the change to millisecond precision and is correctly implemented to ensure the minting amount is accurate.
…/avoidwritingminter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (4)
- x/mint/epoch_hooks.go (1 hunks)
- x/mint/keeper/abci.go (1 hunks)
- x/mint/keeper/keeper_test.go (2 hunks)
- x/mint/types/minter.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- x/mint/epoch_hooks.go
- x/mint/keeper/abci.go
Additional context used
Path-based instructions (2)
x/mint/types/minter.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/mint/keeper/keeper_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"
Additional comments not posted (2)
x/mint/types/minter.go (1)
85-99
: NewIsEqual
method forMinter
structThe addition of the
IsEqual
method in theMinter
struct is a crucial enhancement for comparing minter instances. This method checks all relevant fields (Inflation
,AnnualProvisions
, andData
) to ensure that twoMinter
instances are identical. This is aligned with the PR's aim to enhance the efficiency of data comparison in the minting process, potentially reducing unnecessary writes to the state.The implementation uses direct comparisons for
Inflation
andAnnualProvisions
and a byte-wise comparison forData
. This approach is efficient and appropriate for the types of data involved. The method is concise and adheres to the Uber Golang style guide.x/mint/keeper/keeper_test.go (1)
158-167
: Enhanced testing inTestBeginBlocker
The new test block in
TestBeginBlocker
is a significant addition. It tests the scenario where a mint function that performs no operations is used, and it verifies that the minter state remains unchanged after the operation. This is crucial for validating the new logic that prevents unnecessary state writes when no changes occur in the minter data.This test effectively uses a no-op mint function and asserts that the minter state before and after the function call is the same, ensuring that the minting logic is correctly optimized to avoid unnecessary writes. The test is well-structured and follows best practices in unit testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense!
Description
This PR is meant to be the last refactor before calling complete the rework on x/mint.
Next steps:
DefaultMintFn
(block based minting, kept for compatibility) and move to something likeExampleMintFn
(time based minting).Closes: #19761
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Improvements
New Features
Bug Fixes