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

feat: support multiple coins for funding #179

Merged
merged 31 commits into from
May 3, 2024

Conversation

troykessler
Copy link
Member

@troykessler troykessler commented May 2, 2024

This PR adjust the funding module so funders can fund pools in multiple coins.

Summary by CodeRabbit

  • Documentation

    • Updated API documentation to enhance clarity in descriptions and adjust data types for funding processes.
  • New Features

    • Introduced enhancements in funding processes, allowing for multiple coin types and denominations.
    • Added new message types for creating, updating, and managing funders and funding pools.
  • Refactor

    • Major updates to internal logic to support a variety of coin types in funding calculations.
    • Adjusted test utilities and integration tests to align with new funding structures.
  • Tests

    • Expanded test scenarios to cover new functionalities and ensure robust handling of multiple coin types.
  • Chores

    • Implemented necessary imports and updated functions across various modules to support the new features.

@troykessler troykessler self-assigned this May 2, 2024
Copy link

coderabbitai bot commented May 2, 2024

Walkthrough

The updates primarily focus on transitioning from single to multiple coin types across various modules, enhancing flexibility in funding operations. This includes changes from simple numeric values to lists of coins in funding-related fields, and adjustments in message structures and logic to support these enhancements in the blockchain's handling of transactions and balances.

Changes

File Path Change Summary
docs/static/openapi.yml and proto/kyve/query/v1beta1 Updated fields from string or uint64 to array for multiple coin types; added items and properties for denom and amount.
proto/kyve/funders/v1beta1, x/funders/keeper, x/bundles/keeper Extensive changes to support lists of coins, new imports, and updated logic for funding and defunding processes.
testutil/integration, x/delegation/keeper, x/funders/keeper/msg_server_defund_pool_test.go Adjustments in testing utilities and test cases to handle new coin types and operations.
app/upgrades/v1_5/upgrade.go, x/funders/spec/01_concepts.md, x/funders/spec/03_messages.md Documentation and upgrade logic updates to reflect the new funding mechanisms and message types.

🐇✨
In the land of code, where the bits align,
A rabbit hopped, leaving changes behind.
Coins aplenty, now in arrays,
For funders' delight, in the blockchain's maze.
Hop, skip, a commit, then merge,
Celebrate the update, as new features emerge! 🎉
🐇✨


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7de4ce3 and 9ab9dc2.
Files selected for processing (7)
  • app/upgrades/v1_5/upgrade.go (1 hunks)
  • x/bundles/keeper/logic_bundles.go (1 hunks)
  • x/funders/keeper/logic_funders.go (5 hunks)
  • x/funders/keeper/msg_server_fund_pool_test.go (9 hunks)
  • x/funders/spec/01_concepts.md (1 hunks)
  • x/funders/spec/03_messages.md (1 hunks)
  • x/funders/types/params.go (1 hunks)
Files not summarized due to errors (1)
  • x/funders/keeper/msg_server_fund_pool_test.go: Error: Message exceeds token limit
Files not reviewed due to errors (1)
  • x/funders/keeper/msg_server_fund_pool_test.go (no review received)
Files skipped from review due to trivial changes (1)
  • app/upgrades/v1_5/upgrade.go
Files skipped from review as they are similar to previous changes (2)
  • x/bundles/keeper/logic_bundles.go
  • x/funders/types/params.go
Additional Context Used
LanguageTool (27)
x/funders/spec/01_concepts.md (11)

Near line 11: It seems like there are too many consecutive spaces here.
Context: ...ed and therefore have a strong interest in further archiving the data. Once a va...


Near line 13: Consider a shorter alternative to avoid wordiness.
Context: ...ting the funds equally from each funder in order to guarantee a steady pool economy. ## F...


Near line 18: Possible spelling mistake found.
Context: ...nomy. ## Funding Slots Currently, the KYVE protocol allows at most 50 funders per ...


Near line 20: Consider adding a comma after this introductory phrase.
Context: ...han the current lowest funder. By doing so the funds of the lowest funder will be ...


Near line 26: Possible spelling mistake found.
Context: ...Funding To ease the process of funding KYVE pools we introduced the concept of mult...


Near line 26: Possible missing comma found.
Context: ...ng To ease the process of funding KYVE pools we introduced the concept of multiple c...


Near line 27: Possible spelling mistake found.
Context: ...introduced the concept of multiple coin fundings. This implies that funders can not only...


Near line 29: Possible spelling mistake found.
Context: ...y pool, the protocol validators and the delegators who not only receive $KYVE as rewards ...


Near line 35: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...t to contribute and how much funds they want to distribute per validated and archived b...


Near line 36: Consider a shorter alternative to avoid wordiness.
Context: ... and promotes competition between pools in order to attract validators who typically choose...


Near line 37: Possible missing comma found.
Context: ...ition between pools in order to attract validators who typically choose the pool with the ...

x/funders/spec/03_messages.md (16)

Near line 7: Possible spelling mistake found.
Context: # Messages ## MsgCreateFunder MsgCreateFunder creates the funder wit...


Near line 8: Possible spelling mistake found.
Context: ... 3 --> # Messages ## MsgCreateFunder MsgCreateFunder creates the funder with all relevant in...


Near line 9: This word is normally spelled with a hyphen.
Context: ...ut the funder, this includes a moniker (human readable name), an identity (keybase.io identity...


Near line 13: Possible spelling mistake found.
Context: ... exists or if the moniker is empty. ## MsgUpdateFunder MsgUpdateFunder can update all propert...


Near line 14: Possible spelling mistake found.
Context: ... moniker is empty. ## MsgUpdateFunder MsgUpdateFunder can update all properties of the funder...


Near line 17: Possible spelling mistake found.
Context: ...funder except the funder's address. ## MsgFundPool MsgFundPool commits funds from the fun...


Near line 18: Possible spelling mistake found.
Context: ... the funder's address. ## MsgFundPool MsgFundPool commits funds from the funder to a spec...


Near line 20: Possible spelling mistake found.
Context: ... but they have to be whitelisted by the KYVE protocol. For each coin the funder fund...


Near line 24: Possible spelling mistake found.
Context: ... bundle to the protocol validators. ## MsgDefundPool MsgDefundPool can withdraw remaining f...


Near line 25: Possible spelling mistake found.
Context: ...protocol validators. ## MsgDefundPool MsgDefundPool can withdraw remaining funds on the pro...


Near line 31: Possible spelling mistake found.
Context: ...in, else the transaction will fail. ## MsgUpdateParams MsgUpdateParams is a gov transaction a...


Near line 32: Possible spelling mistake found.
Context: ...saction will fail. ## MsgUpdateParams MsgUpdateParams is a gov transaction and can be only ca...


Near line 33: Consider replacing this word to strengthen your wording.
Context: ...s MsgUpdateParams is a gov transaction and can be only called by the governance au...


Near line 34: Possible spelling mistake found.
Context: ...his transaction someone has to create a MsgUpdateParams governance proposal. This will update ...


Near line 36: An apostrophe may be missing.
Context: ... This will update the parameters of the funders module, containing the coin whitelist a...


Near line 36: Possible spelling mistake found.
Context: ..., containing the coin whitelist and the MinFundingMultiple parameter.

Additional comments not posted (8)
x/funders/spec/03_messages.md (5)

9-9: Hyphenate "human readable name" to "human-readable name" for grammatical correctness.


20-20: Add a comma after "funds" for clarity.


26-26: Rephrase "can be also withdrawn" to "can also be withdrawn" for better readability.


33-33: Correct the message name from MsgDisablePool to MsgUpdateParams.


36-36: Expand "param" to "parameter" for clarity.

x/funders/keeper/logic_funders.go (3)

22-31: Refactor GetTotalActiveFunding to handle multiple coin types efficiently.


Line range hint 37-78: The implementation of ChargeFundersOfPool correctly handles fund transfers and event emissions.


170-202: The implementation of ensureFreeSlot correctly handles the addition of new funding and the removal of the lowest funding.


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

@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: 20

Out of diff range and nitpick comments (8)
x/funders/keeper/msg_server_defund_pool.go (1)

Line range hint 33-53: Add a check for zero defund amount to avoid unnecessary operations.

+	if msg.Amounts.IsZero() {
+		return &types.MsgDefundPoolResponse{}, nil
+	}
x/delegation/keeper/keeper_suite_test.go (1)

31-39: Clarify that direct modifications to funding.AmountsPerBundle in tests might not reflect production behavior.

x/funders/keeper/msg_server_update_params_test.go (1)

[!TIP]
Codebase Verification

The output from the executed script shows various instances where CoinWhitelist is used across the codebase, particularly in tests and keeper logic. However, there is no evidence of checks for uniqueness of entries in the whitelist during updates or additions, which was the concern raised in the review comment.

The review comment suggested that the test "Update multiple coin whitelist entries" should include a check to ensure that all entries are unique and do not duplicate existing entries in the whitelist. The script output does not show any usage of a method or function that would check for such uniqueness, such as a Contains method or similar logic.

Given this information, it appears that the review comment is valid, and the test does not currently include a check for the uniqueness of whitelist entries. This could potentially allow duplicate entries in the whitelist, which would be a flaw in maintaining the integrity of the whitelist.

Conclusion

The review comment is correct in pointing out the absence of a check for the uniqueness of entries in the whitelist during updates. This is a potential issue that needs to be addressed to ensure the integrity of the whitelist is maintained.

  • The test in msg_server_update_params_test.go should be updated to include a check for uniqueness of the whitelist entries.
  • Similar checks should be considered in other parts of the codebase where the whitelist is updated.
Analysis chain

Line range hint 288-331: The test "Update multiple coin whitelist entries" should include a check to ensure that all entries are unique and do not duplicate existing entries in the whitelist. This is crucial for maintaining the integrity of the whitelist.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all whitelist entries are unique in similar update operations across the codebase.
rg --type go 'CoinWhitelist' | grep -v 'Contains'

Length of output: 6320

x/funders/keeper/logic_funders_test.go (1)

Line range hint 37-89: Ensure consistent use of coin denominations and weights in test setup.

The test setup initializes a whitelist of coins with varying denominations and weights. It's crucial to ensure that these values are consistent and meaningful across tests to avoid confusion and potential bugs. Consider standardizing these values or clearly documenting their intended use cases.

docs/static/openapi.yml (4)

249-249: Ensure the description for protocol_self_delegation_unbonding is complete and accurate.

The description seems to be truncated or incomplete. It would be beneficial to provide a full and clear description for better understanding and documentation quality.


257-257: Ensure the description for protocol_delegation_unbonding is complete and accurate.

Similar to the previous comment, the description appears to be incomplete. Providing a full description will enhance clarity and documentation quality.


4662-4664: Clarify the description for min_funding_multiple.

The description for min_funding_multiple seems to be cut off. Providing a complete sentence will improve clarity and ensure that the documentation is informative.


8643-8650: Clarify the description for score.

The description for score seems to be cut off. Providing a complete sentence will improve clarity and ensure that the documentation is informative.

x/bundles/keeper/logic_bundles_test.go Show resolved Hide resolved
proto/kyve/funders/v1beta1/funders.proto Outdated Show resolved Hide resolved
x/funders/types/funders.go Outdated Show resolved Hide resolved
x/funders/keeper/msg_server_fund_pool_test.go Outdated Show resolved Hide resolved
x/funders/types/params.go Show resolved Hide resolved
x/funders/keeper/msg_server_defund_pool_test.go Outdated Show resolved Hide resolved
x/funders/keeper/msg_server_defund_pool_test.go Outdated Show resolved Hide resolved
proto/kyve/funders/v1beta1/funders.proto Outdated Show resolved Hide resolved
proto/kyve/query/v1beta1/funders.proto Show resolved Hide resolved
x/funders/keeper/logic_funders.go Show resolved Hide resolved
x/funders/keeper/logic_funders.go Show resolved Hide resolved
x/funders/spec/02_state.md Outdated Show resolved Hide resolved
x/funders/spec/02_state.md Outdated Show resolved Hide resolved
x/funders/types/errors.go Outdated Show resolved Hide resolved
x/funders/types/message_defund_pool.go Outdated Show resolved Hide resolved
x/funders/types/message_fund_pool.go Outdated Show resolved Hide resolved
Copy link

@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: 3

proto/kyve/funders/v1beta1/params.proto Outdated Show resolved Hide resolved
x/funders/spec/04_params.md Show resolved Hide resolved
x/funders/spec/02_state.md Outdated Show resolved Hide resolved
Copy link

@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

x/funders/keeper/msg_server_fund_pool_test.go Show resolved Hide resolved
x/funders/types/funders.go Show resolved Hide resolved
Copy link

@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: 3

x/funders/spec/02_state.md Show resolved Hide resolved
x/funders/spec/02_state.md Show resolved Hide resolved
# Conflicts:
#	testutil/integration/helpers.go
#	testutil/integration/integration.go
#	x/delegation/keeper/keeper_suite_test.go
#	x/query/types/account.pb.go
Copy link

@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

x/funders/keeper/logic_funders.go Show resolved Hide resolved
Copy link

@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 (8)
x/delegation/keeper/msg_server_undelegate_test.go (8)

42-42: Consider adding a comment explaining the purpose of CreatePool in the test setup.


42-42: Ensure that the UploadInterval parameter is appropriate for the test scenario, as it affects the timing of operations.


42-42: Add a comment explaining the significance of the InflationShareWeight parameter in the context of this test.


42-42: Confirm that the Version parameter in the pool creation is set to a meaningful value for the test scenario.


42-42: Validate the Runtime parameter in the pool creation to ensure it matches the expected value for the test scenario.


42-42: Check the consistency of the StartKey parameter in the pool creation with the expected setup for the test.


42-42: Ensure that the Name parameter in the pool creation is set appropriately for the test context.


42-42: Verify that the UploadInterval parameter is set correctly for the test scenario, as it affects the timing of operations.

Copy link

@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 (2)
x/funders/keeper/logic_funders_test.go (2)

159-159: Consider renaming T_KYVE to i.M for clarity, as T_KYVE might be misleading when used with i.BCoins().


553-553: Clarification needed: Why is the variable named Dummy1? Consider using a more descriptive name.

mbreithecker
mbreithecker previously approved these changes May 3, 2024
@mbreithecker mbreithecker merged commit 6e0aba8 into main May 3, 2024
5 checks passed
@mbreithecker mbreithecker deleted the troy/funding-multiple-coins branch May 3, 2024 15:31
Copy link

@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: 3

of funders. Funders are special actors who provide liquidity to a pool
and basically pay for the rewards the validators earn for their work.
Funders would usually be stakeholders of the data that is being archived and
therefore have a strong interest in further archiving the data. Once a valid
Copy link

Choose a reason for hiding this comment

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

It seems like there are too many consecutive spaces here.

- therefore have a strong interest  in further archiving the data.
+ therefore have a strong interest in further archiving the data.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
therefore have a strong interest in further archiving the data. Once a valid
therefore have a strong interest in further archiving the data. Once a valid


Currently, the KYVE protocol allows at most 50 funders per pool to limit
gas consumption. If the slots are full and a funder wants to join anyway he
has to fund more than the current lowest funder. By doing so the funds of the
Copy link

Choose a reason for hiding this comment

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

Consider adding a comma after this introductory phrase.

- By doing so the funds of the
+ By doing so, the funds of the

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
has to fund more than the current lowest funder. By doing so the funds of the
has to fund more than the current lowest funder. By doing so, the funds of the


## Multiple Coin Funding

To ease the process of funding KYVE pools we introduced the concept of multiple
Copy link

Choose a reason for hiding this comment

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

Possible missing comma found.

- To ease the process of funding KYVE pools we introduced the concept of multiple
+ To ease the process of funding KYVE pools, we introduced the concept of multiple

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
To ease the process of funding KYVE pools we introduced the concept of multiple
To ease the process of funding KYVE pools, we introduced the concept of multiple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants