feat(x/gov): implement a minimum amount per deposit#18146
Conversation
|
Which issue does this close? Where can I read more on the rationale for this? |
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
…s-sdk into facu/limit-deposits
WalkthroughThe changes mainly revolve around the Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Review Status
Actionable comments generated: 1
Files ignored due to filter (3)
- api/cosmos/feegrant/v1beta1/tx_grpc.pb.go
- x/feegrant/tx.pb.go
- x/gov/types/v1/gov.pb.go
Files selected for processing (17)
- CHANGELOG.md (1 hunks)
- api/cosmos/feegrant/v1beta1/tx.pulsar.go (2 hunks)
- api/cosmos/gov/v1/gov.pulsar.go (16 hunks)
- proto/cosmos/gov/v1/gov.proto (1 hunks)
- tests/e2e/gov/deposits.go (2 hunks)
- tests/e2e/gov/tx.go (5 hunks)
- tests/integration/bank/app_test.go (1 hunks)
- x/gov/abci_test.go (5 hunks)
- x/gov/keeper/deposit.go (4 hunks)
- x/gov/keeper/deposit_test.go (1 hunks)
- x/gov/keeper/msg_server.go (3 hunks)
- x/gov/keeper/msg_server_test.go (9 hunks)
- x/gov/migrations/v5/store.go (1 hunks)
- x/gov/simulation/genesis.go (3 hunks)
- x/gov/simulation/operations.go (2 hunks)
- x/gov/types/errors.go (1 hunks)
- x/gov/types/v1/params.go (4 hunks)
Files skipped from review due to trivial changes (7)
- tests/e2e/gov/deposits.go
- tests/integration/bank/app_test.go
- x/gov/keeper/deposit_test.go
- x/gov/keeper/msg_server.go
- x/gov/keeper/msg_server_test.go
- x/gov/migrations/v5/store.go
- x/gov/types/errors.go
Additional comments (Suppressed): 44
api/cosmos/feegrant/v1beta1/tx.pulsar.go (2)
2725-2730: The new hunk seems to be adding a comment indicating the version of the cosmos-sdk where
MsgPruneAllowanceswas introduced. Ensure that this versioning comment is accurate and necessary for the context of your project. If it is, the change is approved.2764-2769: Similar to the previous comment, this hunk is adding a versioning comment for
MsgPruneAllowancesResponse. Again, verify the accuracy and necessity of this comment for your project. If it is, the change is approved.x/gov/types/v1/params.go (4)
33-33: The new
DefaultMinDepositRatioconstant is introduced with a default value of "0.001". Ensure that this default value is appropriate for all use cases. If not, consider making it configurable.60-65: The
NewParamsfunction signature has been updated to include a new parameterminDepositRatio. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.82-82: The
MinDepositRatiofield is added to theParamsstruct. This change is consistent with the new parameter added to theNewParamsfunction.104-104: The
DefaultMinDepositRatiois used in theDefaultParamsfunction. This is consistent with the addition of theMinDepositRatiofield to theParamsstruct.x/gov/simulation/operations.go (3)
573-578: The new code introduces a minimum deposit ratio and calculates a threshold for the deposit amount. Ensure that the
GetMinDepositRatio()function is correctly implemented and returns a valid ratio. Also, verify that theToLegacyDec()andMul()functions are correctly converting and multiplying the values. TheTruncateInt()function should correctly truncate the decimal part of the result.580-582: The
MinInitialDepositRatioparameter is used here. Ensure that this parameter is correctly set and that theLegacyNewDecFromStr()function correctly converts it to a decimal.596-598: The new code checks if the deposit amount is less than the calculated threshold. This is a new condition that wasn't present in the old code. Ensure that this condition is correctly implemented and that it doesn't introduce any unexpected behavior.
x/gov/simulation/genesis.go (4)
28-31: The new constant
MinDepositRatiohas been added to the list of simulation parameters. This constant represents the minimum deposit ratio for proposals in the governance module.98-102: The
GenMinDepositRatiofunction has been added to generate a random value for theMinDepositRatioparameter. Currently, it returns a fixed value of0.001. The commented-out code suggests that the function was intended to return a random value between0.001and0.05, but this has been temporarily disabled. Please ensure that the function is updated to generate a random value as intended before merging the PR.- return sdkmath.LegacyMustNewDecFromStr("0.001") + return sdkmath.LegacyNewDec(int64(simulation.RandIntBetween(r, 1, 50))).Quo(sdkmath.LegacyNewDec(1000))
141-142: The
MinDepositRatioparameter is being generated or retrieved from theAppParamsmap. This is consistent with the handling of other simulation parameters.146-146: The
MinDepositRatioparameter is being included in theParamsstruct for theGenesisState. Ensure that theParamsstruct and any functions that use it have been updated to handle this new field.x/gov/keeper/deposit.go (4)
6-6: The import of the
stringspackage is new. Ensure that it is used in the code and is not an unnecessary import.75-122: The logic for validating the deposit amount and ratio has been significantly updated. The new logic checks if the deposit contains only valid denominations, and if the
MinDepositRatiois set, it checks if the deposit is equal to or greater thanMinDepositAmount * MinDepositRatiofor at least one denomination. If these conditions are not met, appropriate errors are returned. This is a significant change and should be thoroughly tested to ensure it works as expected.132-137: The logic for checking if the deposit has provided sufficient total funds to transition the proposal into the voting period has been simplified. The retrieval of the
paramsandminDepositAmounthas been removed from this section, presumably because it has been handled earlier in the code. Ensure that this change does not affect the functionality of this section.276-285: The function
validateInitialDepositnow checks if theinitialDepositis valid and not negative before proceeding with the rest of the validation. This is a good practice as it prevents further processing of invalid data.x/gov/abci_test.go (5)
98-104: The deposit amount for the proposal has been increased from 5 to 10000. Ensure that this change aligns with the new
MinDepositRatioparameter and that the tests are still valid with this new deposit amount.149-155: The deposit amount for the proposal has been increased from 5 to 10000. Ensure that this change aligns with the new
MinDepositRatioparameter and that the tests are still valid with this new deposit amount.172-178: The deposit amount for the proposal has been increased from 5 to 10000. Ensure that this change aligns with the new
MinDepositRatioparameter and that the tests are still valid with this new deposit amount.218-224: The deposit amount for the proposal has been increased from 5 to 10000. Ensure that this change aligns with the new
MinDepositRatioparameter and that the tests are still valid with this new deposit amount.241-247: The deposit amount for the proposal has been increased from 5 to 10000. Ensure that this change aligns with the new
MinDepositRatioparameter and that the tests are still valid with this new deposit amount.proto/cosmos/gov/v1/gov.proto (2)
262-263: The
burn_vote_vetofield has been retained in theParamsmessage. No changes have been made to this field.265-270: A new field
min_deposit_ratiohas been added to theParamsmessage. This field represents the minimum deposit ratio that must be met when making a deposit. The field is of typestringand uses thecosmos.Decscalar. Ensure that the new field is properly handled in the codebase where theParamsmessage is used.+ // The ratio representing the proportion of the deposit value minimum that must be met when making a deposit. + // Default value: 0.001. Meaning that for a chain with a min_deposit of 1000stake, a deposit of 1stake would be + // required. + // + // Since: cosmos-sdk 0.50 + string min_deposit_ratio = 16 [(cosmos_proto.scalar) = "cosmos.Dec"];api/cosmos/gov/v1/gov.pulsar.go (15)
5547-5550: The new field
fd_Params_min_deposit_ratioof typeprotoreflect.FieldDescriptorhas been added. Ensure that this field is correctly initialized and used throughout the codebase.5568-5571: The new field
fd_Params_min_deposit_ratiois being initialized here. Ensure that the field name "min_deposit_ratio" exists inmd_Params.5726-5734: The new field
MinDepositRatiois being checked and its value is being processed here. Ensure that the functionfcan handle the value correctly.5777-5781: The new field
MinDepositRatiois being checked here. Ensure that the comparisonx.MinDepositRatio != ""is the intended behavior.5825-5829: The new field
MinDepositRatiois being reset here. Ensure that settingx.MinDepositRatioto an empty string is the intended behavior for reset.5894-5899: The new field
MinDepositRatiois being processed here. Ensure that the functionprotoreflect.ValueOfStringcan handle the value correctly.5951-5955: The new field
MinDepositRatiois being set here. Ensure that the value is correctly cast to a string.6020-6024: The new field
MinDepositRatiois being checked here. Ensure that the panic message is correct and that the field is indeed not mutable.6070-6074: The new field
MinDepositRatiois being checked here. Ensure that returning an empty string is the intended behavior when the field is not set.6202-6208: The new field
MinDepositRatiois being processed here. Ensure that the length ofx.MinDepositRatiois correctly added ton.6235-6246: The new field
MinDepositRatiois being processed here. Ensure that the field is correctly copied intodAtAand that the correct bytes are being set.6906-6941: The new field
MinDepositRatiois being unmarshalled here. Ensure that the unmarshalling process is correct and that the field is correctly set inx.7725-7733: The new field
MinDepositRatiohas been added to theParamsstruct. Ensure that the protobuf tag is correct and that the JSON tag matches the intended JSON key.7861-7866: The new getter
GetMinDepositRatiohas been added. Ensure that it returns the correct value and that it is used correctly throughout the codebase.8003-8009: The new field
MinDepositRatiois being processed here. Ensure that the protobuf tag and the bytes are correct.tests/e2e/gov/tx.go (5)
59-70: The test case now includes a proposal with a minimum deposit calculated based on the
DefaultMinDepositTokensandDefaultMinDepositRatio. Ensure that the new deposit calculation logic is correctly implemented and that the test case is correctly testing the new deposit validation logic.130-133: The deposit amount in the proposal has been changed from 5431 to 10000. Ensure that this change aligns with the new deposit validation logic and that it does not affect other parts of the test suite.
198-201: The deposit amount in the proposal has been changed from 5431 to 15431. Ensure that this change aligns with the new deposit validation logic and that it does not affect other parts of the test suite.
224-230: The deposit amount in the proposal has been changed from 5431 to 10000. Ensure that this change aligns with the new deposit validation logic and that it does not affect other parts of the test suite.
249-255: The deposit amount in the proposal has been changed from 5431 to 10000. Ensure that this change aligns with the new deposit validation logic and that it does not affect other parts of the test suite.
Co-authored-by: Julien Robert <julien@rbrt.fr>
|
|
There was a problem hiding this comment.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- x/gov/simulation/operations.go (2 hunks)
Additional comments: 1
x/gov/simulation/operations.go (1)
- 570-581: The
minDepositRatiois parsed from a string value obtained fromparams.GetMinDepositRatio(). Ensure that the value ofparams.GetMinDepositRatio()is always a valid decimal string. If it's not guaranteed, consider adding error handling or validation for this value.595:
Theamountvariable is multiplied by 3. This is indicated as a hack to set it to three times the required amount. If this is a temporary solution, consider revisiting this to implement a more robust solution.597:
The condition for returning an error is modified to include the case whereamountis less thanthreshold. Ensure that this change doesn't introduce unexpected behavior in the rest of the codebase.
There was a problem hiding this comment.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- Makefile (1 hunks)
- x/gov/simulation/operations_test.go (3 hunks)
Files skipped from review due to trivial changes (1)
- Makefile
Additional comments: 3
x/gov/simulation/operations_test.go (3)
155-155: The initial deposit value has been updated. Ensure that this new value is consistent with the changes made in the
x/govmodule and that it meets the new minimum deposit limit.188-188: The initial deposit value has been updated. Ensure that this new value is consistent with the changes made in the
x/govmodule and that it meets the new minimum deposit limit.279-279: The deposit amount has been updated. Ensure that this new value is consistent with the changes made in the
x/govmodule and that it meets the new minimum deposit limit.
| @echo "Running non-determinism test..." | ||
| @cd ${CURRENT_DIR}/simapp && go test -mod=readonly -run TestAppStateDeterminism -Enabled=true \ | ||
| -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h | ||
| -NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h -Seed=6425865534782297734 |
There was a problem hiding this comment.
Can we get a comment on the reason of hard-coding the seed?
This makes running that sim not more random anymore right?
There was a problem hiding this comment.
yeah we should not hard code a seed
There was a problem hiding this comment.
sorry, I was testing and forgot to remove it!
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr> (cherry picked from commit 177e7f4) # Conflicts: # CHANGELOG.md # tests/e2e/gov/deposits.go # x/gov/keeper/deposit.go # x/gov/types/v1/gov.pb.go
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
…#19312) (#510) * feat(x/gov): implement a minimum amount per deposit (cosmos#18146) Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr> * Fix * Fix test * Fix e2e * Fix e2e * Fix test * update changelog * Include expedited proposal logic * Update deposit.go --------- Co-authored-by: MSalopek <matija.salopek994@gmail.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: Adam Tucker <adam@osmosis.team> Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
Description
This PR adds a new param to x/gov called
MinDepositRatiowhich dictates the least amount of tokens that a deposit must have to be accepted (given byMinDepositRatio*MinDeposit).Also only denoms that are present in MinDeposit will be accepted.
Lastly, when sending a proposal the deposit that this includes must also meet the conditions of a normal deposit (meaning there's a minimum amount to deposit along with a proposal submission).
Examples:
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...
!to the type prefix if API or client breaking changeCHANGELOG.mdmake lintandmake testReviewers 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.
I have...
!in the type prefix if API or client breaking changeSummary by CodeRabbit
New Features:
MinDepositRatioin thegovmodule to enforce minimum deposit requirements, enhancing the governance system's security.x/distributiontox/protocolpoolin thedistributionmodule, improving fund management.PreviousProposerto collections in thedistributionmodule, optimizing data handling.upgrademodule, instead retrieving it from theParamStoreofbaseapp, simplifying version management.Refactor:
govmodule, simplifying the code and improving maintainability.Tests:
TestDepositAmountto validate deposit amount logic, ensuring robustness of the new feature.Chores:
TestQueryDepositsWithoutInitialDepositfrom the codebase, improving code cleanliness.