Skip to content
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

Add local cache inside the takerfee #8148

Merged
merged 7 commits into from
May 13, 2024

Conversation

ValarDragon
Copy link
Member

@ValarDragon ValarDragon commented Apr 26, 2024

What is the purpose of the change

Remove parameter unmarshal time from charging TakerFee from poolmanager

Testing and Verifying

Covered by existing unit tests

Documentation and Release Note

  • Changelog entry added to Unreleased section of CHANGELOG.md? - DONE

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

Summary by CodeRabbit

  • New Features
    • Added new fields to enhance fee management in the trading platform.
  • Enhancements
    • Improved the fee retrieval process to ensure more efficient and accurate fee handling.

@ValarDragon ValarDragon added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v24.x backport patches to v24.x branch labels Apr 26, 2024
Copy link
Contributor

coderabbitai bot commented Apr 26, 2024

Warning

Rate Limit Exceeded

@ValarDragon has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 28 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between ef97dc5 and 5327f96.

Walkthrough

The changes in the poolmanager package aim to enhance the management of default taker fees within the blockchain's transaction fee structure. These improvements involve introducing new fields to the Keeper struct and updating the fee retrieval process to utilize raw bytes and JSON unmarshalling for more efficient handling of taker fees.

Changes

File Path Change Summary
x/poolmanager/keeper.go Added defaultTakerFeeBz and defaultTakerFeeVal to Keeper
x/poolmanager/taker_fee.go Updated GetDefaultTakerFee to use new fields for fee retrieval
CHANGELOG.md Removed deserialization time for GetDefaultTakerFee()

Poem

🐇✨🌟
In the realm of code, where the bits align,
A rabbit hopped through, refining design.
Bytes and Decs, in fields they lay,
Enhancing fees, in a smarter way.
Hop, skip, a commit, then merge,
In blockchain's weave, new efficiencies surge.
🌟✨🐇


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Comment on lines 18 to 24
defaultTakerFeeBz := k.paramSpace.GetRaw(ctx, types.KeyDefaultTakerFee)
if !bytes.Equal(defaultTakerFeeBz, k.defaultTakerFeeBz) {
var defaultTakerFeeValue sdk.Dec
json.Unmarshal(defaultTakerFeeBz, &defaultTakerFeeValue)
k.defaultTakerFeeVal = defaultTakerFeeValue
}
return k.defaultTakerFeeVal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure thread safety in caching mechanism.

The caching mechanism in GetDefaultTakerFee does not appear to be thread-safe. Consider using synchronization techniques like mutexes to protect the shared state (defaultTakerFeeBz and defaultTakerFeeVal) from concurrent access issues.

Comment on lines +38 to +39
defaultTakerFeeBz []byte
defaultTakerFeeVal sdk.Dec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialization of new fields in Keeper struct.

The new fields defaultTakerFeeBz and defaultTakerFeeVal in the Keeper struct are not initialized in the NewKeeper constructor. This might lead to nil pointer dereferences or unexpected behavior. Ensure these fields are properly initialized when a new Keeper instance is created.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Out of diff range and nitpick comments (9)
CHANGELOG.md (9)

Line range hint 1002-1002: Heading levels should only increment by one level at a time.


Line range hint 1014-1014: Heading levels should only increment by one level at a time.


Line range hint 1023-1023: Heading levels should only increment by one level at a time.


Line range hint 1028-1028: Heading levels should only increment by one level at a time.


Line range hint 1080-1080: Heading levels should only increment by one level at a time.


Line range hint 341-341: Trailing punctuation in heading.


Line range hint 604-604: Bare URL used.


Line range hint 662-662: Bare URL used.


Line range hint 1243-1243: No empty links.

@PaddyMc PaddyMc added the A:backport/v25.x backport patches to v25.x branch label Apr 27, 2024
@@ -34,6 +34,9 @@ type Keeper struct {
poolModules []types.PoolModuleI

paramSpace paramtypes.Subspace

defaultTakerFeeBz []byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to initialize this value somewhere right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no its intended to be set to nil until initialization!

k.paramSpace.Get(ctx, types.KeyDefaultTakerFee, &defaultTakerFee)
return defaultTakerFee
defaultTakerFeeBz := k.paramSpace.GetRaw(ctx, types.KeyDefaultTakerFee)
if !bytes.Equal(defaultTakerFeeBz, k.defaultTakerFeeBz) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here for the value for k.defaultTakerFeeBz

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended to be nil!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still wrong though, which was highlighted as I was stepping through with debugger. Don't we want to set k.defaultTakerFeeBz to defaultTakerFeeBz at the end? Otherwise this will always hit the if statement. Its not "wrong", but we are forced to unmarshal the value every time which defeats the purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, whoops

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Out of diff range and nitpick comments (9)
CHANGELOG.md (9)

Line range hint 1016-1016: Correct the heading level for better document structure.

- #### [v6.4.0]
+ ### [v6.4.0]

Line range hint 1028-1028: Correct the heading level for better document structure.

- #### [v6.3.1]
+ ### [v6.3.1]

Line range hint 1037-1037: Correct the heading level for better document structure.

- #### [v6.3.0]
+ ### [v6.3.0]

Line range hint 1042-1042: Correct the heading level for better document structure.

- #### [v6.2.0]
+ ### [v6.2.0]

Line range hint 1094-1094: Correct the heading level for better document structure.

- #### [v6.1.0]
+ ### [v6.1.0]

Line range hint 355-355: Remove the trailing punctuation in the heading for consistency.

- ## [v4.0.0]
+ ## [v4.0.0]

Line range hint 618-618: Convert the bare URL to a markdown link for better readability.

- See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) For more details
+ See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) for more details

Line range hint 676-676: Convert the bare URL to a markdown link for better readability.

- Upgrade instructions for node operators can be found [here](https://github.com/osmosis-labs/osmosis/blob/v5.x/networks/osmosis-1/upgrades/v5/guide.md)
+ Upgrade instructions for node operators can be found [here](https://github.com/osmosis-labs/osmosis/blob/v5.x/networks/osmosis-1/upgrades/v5/guide.md).

Line range hint 1257-1257: Ensure all links are functional and not empty.

Please verify that the link provided is correct and accessible.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Out of diff range and nitpick comments (1)
x/poolmanager/taker_fee.go (1)

Line range hint 107-107: Prioritize optimization of chargeTakerFee.

The TODO comment in chargeTakerFee mentions the need to optimize this function for gas and CPU usage. Given the critical nature of fee handling in transaction systems, prioritizing this optimization could lead to significant performance improvements.

x/poolmanager/taker_fee.go Show resolved Hide resolved
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label May 11, 2024
@PaddyMc PaddyMc removed the Stale label May 13, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Out of diff range and nitpick comments (9)
CHANGELOG.md (9)

Line range hint 1025-1025: Correct the heading level to maintain a proper hierarchical structure.

- ### [v6.4.0]
+ ## [v6.4.0]

Line range hint 1037-1037: Correct the heading level to maintain a proper hierarchical structure.

- ### SDK fork updates
+ ## SDK fork updates

Line range hint 1046-1046: Correct the heading level to maintain a proper hierarchical structure.

- ### Minor improvements & Bug Fixes
+ ## Minor improvements & Bug Fixes

Line range hint 1051-1051: Correct the heading level to maintain a proper hierarchical structure.

- ### Features
+ ## Features

Line range hint 1103-1103: Correct the heading level to maintain a proper hierarchical structure.

- ### SDK fork updates
+ ## SDK fork updates

Line range hint 364-364: Remove the trailing punctuation in the heading for consistency.

- ## [v6.0.0].
+ ## [v6.0.0]

Line range hint 627-627: Convert the bare URL to a markdown link for better readability.

- See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) For more details
+ See: [SDK v0.43.0 Release Notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) for more details

Line range hint 685-685: Convert the bare URL to a markdown link for better readability.

- [wasmd-v.022.0-osmo-v7.2](https://github.com/osmosis-labs/wasmd/releases/tag/v0.22.0-osmo-v7.2) Upgrade SDK and IAVL dependencies to use fast storage
+ [wasmd-v.022.0-osmo-v7.2](https://github.com/osmosis-labs/wasmd/releases/tag/v0.22.0-osmo-v7.2) upgrade SDK and IAVL dependencies to use fast storage

Line range hint 1266-1266: Ensure there are no empty links in the document.

- [v1.0.2](https://github.com/osmosis-labs/osmosis/releases/tag/v1.0.2) - 2021-06-18
+ [v1.0.2](https://github.com/osmosis-labs/osmosis/releases/tag/v1.0.2) - 2021-06-18 This release improves the CLI UX of creating and querying gauges.

@ValarDragon ValarDragon merged commit b8fd642 into main May 13, 2024
1 check passed
@ValarDragon ValarDragon deleted the dev/add_poolmanager_takerfee_cache branch May 13, 2024 18:31
mergify bot pushed a commit that referenced this pull request May 13, 2024
* Add local cache inside the takerfee

* add error handling

* Add Changelog

* Fix cache per @adam's comment

* Update x/poolmanager/taker_fee.go

(cherry picked from commit b8fd642)

# Conflicts:
#	CHANGELOG.md
mergify bot pushed a commit that referenced this pull request May 13, 2024
* Add local cache inside the takerfee

* add error handling

* Add Changelog

* Fix cache per @adam's comment

* Update x/poolmanager/taker_fee.go

(cherry picked from commit b8fd642)
PaddyMc pushed a commit that referenced this pull request May 14, 2024
* Add local cache inside the takerfee

* add error handling

* Add Changelog

* Fix cache per @adam's comment

* Update x/poolmanager/taker_fee.go

(cherry picked from commit b8fd642)

Co-authored-by: Dev Ojha <[email protected]>
PaddyMc added a commit that referenced this pull request May 14, 2024
* Add local cache inside the takerfee (#8148)

* Add local cache inside the takerfee

* add error handling

* Add Changelog

* Fix cache per @adam's comment

* Update x/poolmanager/taker_fee.go

(cherry picked from commit b8fd642)

# Conflicts:
#	CHANGELOG.md

* chore: fix merge errors

---------

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: PaddyMc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v24.x backport patches to v24.x branch A:backport/v25.x backport patches to v25.x branch C:x/poolmanager V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants