-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
MsgPruneAllowances
was 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
DefaultMinDepositRatio
constant 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
NewParams
function 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
MinDepositRatio
field is added to theParams
struct. This change is consistent with the new parameter added to theNewParams
function.104-104: The
DefaultMinDepositRatio
is used in theDefaultParams
function. This is consistent with the addition of theMinDepositRatio
field to theParams
struct.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
MinInitialDepositRatio
parameter 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
MinDepositRatio
has been added to the list of simulation parameters. This constant represents the minimum deposit ratio for proposals in the governance module.98-102: The
GenMinDepositRatio
function has been added to generate a random value for theMinDepositRatio
parameter. Currently, it returns a fixed value of0.001
. The commented-out code suggests that the function was intended to return a random value between0.001
and0.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
MinDepositRatio
parameter is being generated or retrieved from theAppParams
map. This is consistent with the handling of other simulation parameters.146-146: The
MinDepositRatio
parameter is being included in theParams
struct for theGenesisState
. Ensure that theParams
struct 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
strings
package 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
MinDepositRatio
is set, it checks if the deposit is equal to or greater thanMinDepositAmount * MinDepositRatio
for 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
params
andminDepositAmount
has 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
validateInitialDeposit
now checks if theinitialDeposit
is 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
MinDepositRatio
parameter 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
MinDepositRatio
parameter 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
MinDepositRatio
parameter 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
MinDepositRatio
parameter 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
MinDepositRatio
parameter and that the tests are still valid with this new deposit amount.proto/cosmos/gov/v1/gov.proto (2)
262-263: The
burn_vote_veto
field has been retained in theParams
message. No changes have been made to this field.265-270: A new field
min_deposit_ratio
has been added to theParams
message. This field represents the minimum deposit ratio that must be met when making a deposit. The field is of typestring
and uses thecosmos.Dec
scalar. Ensure that the new field is properly handled in the codebase where theParams
message 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_ratio
of typeprotoreflect.FieldDescriptor
has been added. Ensure that this field is correctly initialized and used throughout the codebase.5568-5571: The new field
fd_Params_min_deposit_ratio
is being initialized here. Ensure that the field name "min_deposit_ratio" exists inmd_Params
.5726-5734: The new field
MinDepositRatio
is being checked and its value is being processed here. Ensure that the functionf
can handle the value correctly.5777-5781: The new field
MinDepositRatio
is being checked here. Ensure that the comparisonx.MinDepositRatio != ""
is the intended behavior.5825-5829: The new field
MinDepositRatio
is being reset here. Ensure that settingx.MinDepositRatio
to an empty string is the intended behavior for reset.5894-5899: The new field
MinDepositRatio
is being processed here. Ensure that the functionprotoreflect.ValueOfString
can handle the value correctly.5951-5955: The new field
MinDepositRatio
is being set here. Ensure that the value is correctly cast to a string.6020-6024: The new field
MinDepositRatio
is being checked here. Ensure that the panic message is correct and that the field is indeed not mutable.6070-6074: The new field
MinDepositRatio
is being checked here. Ensure that returning an empty string is the intended behavior when the field is not set.6202-6208: The new field
MinDepositRatio
is being processed here. Ensure that the length ofx.MinDepositRatio
is correctly added ton
.6235-6246: The new field
MinDepositRatio
is being processed here. Ensure that the field is correctly copied intodAtA
and that the correct bytes are being set.6906-6941: The new field
MinDepositRatio
is being unmarshalled here. Ensure that the unmarshalling process is correct and that the field is correctly set inx
.7725-7733: The new field
MinDepositRatio
has been added to theParams
struct. Ensure that the protobuf tag is correct and that the JSON tag matches the intended JSON key.7861-7866: The new getter
GetMinDepositRatio
has been added. Ensure that it returns the correct value and that it is used correctly throughout the codebase.8003-8009: The new field
MinDepositRatio
is 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
DefaultMinDepositTokens
andDefaultMinDepositRatio
. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- proto/cosmos/gov/v1/gov.proto (1 hunks)
Files skipped from review due to trivial changes (1)
- proto/cosmos/gov/v1/gov.proto
|
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.
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
minDepositRatio
is 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:
Theamount
variable 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 whereamount
is less thanthreshold
. Ensure that this change doesn't introduce unexpected behavior in the rest of the codebase.
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.
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/gov
module 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/gov
module 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/gov
module and that it meets the new minimum deposit limit.
Makefile
Outdated
@@ -250,7 +250,7 @@ endif | |||
test-sim-nondeterminism: | |||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should not hard code a seed
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.
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
MinDepositRatio
which 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.md
make lint
andmake test
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.
I have...
!
in the type prefix if API or client breaking changeSummary by CodeRabbit
New Features:
MinDepositRatio
in thegov
module to enforce minimum deposit requirements, enhancing the governance system's security.x/distribution
tox/protocolpool
in thedistribution
module, improving fund management.PreviousProposer
to collections in thedistribution
module, optimizing data handling.upgrade
module, instead retrieving it from theParamStore
ofbaseapp
, simplifying version management.Refactor:
gov
module, simplifying the code and improving maintainability.Tests:
TestDepositAmount
to validate deposit amount logic, ensuring robustness of the new feature.Chores:
TestQueryDepositsWithoutInitialDeposit
from the codebase, improving code cleanliness.