-
Notifications
You must be signed in to change notification settings - Fork 28
feat(x/gov): change lazy dynamic deposit computation in favor of endblocker per-tick update #104
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
Closed
giunatale
wants to merge
1
commit into
giunatale/gov/dynamic-deposit
from
giunatale/dynamic-deposit/endblocker
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,7 @@ func (keeper Keeper) IncrementInactiveProposalsNumber(ctx sdk.Context) { | |
| inactiveProposalsNumber := keeper.GetInactiveProposalsNumber(ctx) + 1 | ||
| keeper.SetInactiveProposalsNumber(ctx, inactiveProposalsNumber) | ||
|
|
||
| currMinInitialDeposit := keeper.GetMinInitialDeposit(ctx) | ||
| keeper.SetLastMinInitialDeposit(ctx, currMinInitialDeposit, ctx.BlockTime()) | ||
| keeper.UpdateMinInitialDeposit(ctx, false) | ||
| } | ||
|
|
||
| // DecrementInactiveProposalsNumber decrements the number of inactive proposals by one | ||
|
|
@@ -48,8 +47,7 @@ func (keeper Keeper) DecrementInactiveProposalsNumber(ctx sdk.Context) { | |
| panic("number of inactive proposals should never be negative") | ||
| } | ||
|
|
||
| currMinInitialDeposit := keeper.GetMinInitialDeposit(ctx) | ||
| keeper.SetLastMinInitialDeposit(ctx, currMinInitialDeposit, ctx.BlockTime()) | ||
| keeper.UpdateMinInitialDeposit(ctx, false) | ||
| } | ||
|
|
||
| // SetLastMinInitialDeposit updates the last min initial deposit and last min | ||
|
|
@@ -80,18 +78,33 @@ func (keeper Keeper) GetLastMinInitialDeposit(ctx sdk.Context) (sdk.Coins, time. | |
| // GetMinInitialDeposit returns the (dynamic) minimum initial deposit currently required for | ||
| // proposal submission | ||
| func (keeper Keeper) GetMinInitialDeposit(ctx sdk.Context) sdk.Coins { | ||
| minInitialDeposit, _ := keeper.GetLastMinInitialDeposit(ctx) | ||
|
|
||
| if minInitialDeposit.Empty() { | ||
| // ValidateBasic prevents an empty FloorValue | ||
| // (and thus an empty deposit), if LastMinInitialDeposit is empty | ||
| // it means it was never set, so we return the floor value | ||
| return keeper.GetParams(ctx).MinInitialDepositThrottler.GetFloorValue() | ||
| } | ||
|
|
||
| return minInitialDeposit | ||
| } | ||
|
|
||
| // UpdateMinInitialDeposit updates the min initial deposit required for proposal submission | ||
| func (keeper Keeper) UpdateMinInitialDeposit(ctx sdk.Context, checkElapsedTime bool) { | ||
| params := keeper.GetParams(ctx) | ||
| minInitialDepositFloor := sdk.Coins(params.MinInitialDepositThrottler.FloorValue) | ||
| tick := params.MinInitialDepositThrottler.UpdatePeriod | ||
| lastMinInitialDeposit, lastMinInitialDepositTime := keeper.GetLastMinInitialDeposit(ctx) | ||
| if checkElapsedTime && ctx.BlockTime().Sub(lastMinInitialDepositTime).Nanoseconds() < tick.Nanoseconds() { | ||
| return | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here |
||
|
|
||
| minInitialDepositFloor := sdk.Coins(params.MinInitialDepositThrottler.FloorValue) | ||
| targetInactiveProposals := math.NewIntFromUint64(params.MinInitialDepositThrottler.TargetProposals) | ||
| k := params.MinInitialDepositThrottler.SensitivityTargetDistance | ||
| var a sdk.Dec | ||
|
|
||
| numInactiveProposals := math.NewIntFromUint64(keeper.GetInactiveProposalsNumber(ctx)) | ||
| lastMinInitialDeposit, lastMinInitialDepositTime := keeper.GetLastMinInitialDeposit(ctx) | ||
| // get number of ticks passed since last update | ||
| ticksPassed := ctx.BlockTime().Sub(lastMinInitialDepositTime).Nanoseconds() / tick.Nanoseconds() | ||
|
|
||
| if numInactiveProposals.GT(targetInactiveProposals) { | ||
| a = sdk.MustNewDecFromStr(params.MinInitialDepositThrottler.IncreaseRatio) | ||
| } else { | ||
|
|
@@ -109,26 +122,24 @@ func (keeper Keeper) GetMinInitialDeposit(ctx sdk.Context) sdk.Coins { | |
| c := a.Mul(b) | ||
| percChange = percChange.Add(c) | ||
| } | ||
| if ticksPassed != 0 { | ||
| percChange = percChange.Power(uint64(ticksPassed)) | ||
| } | ||
|
|
||
| minInitialDeposit := sdk.Coins{} | ||
| newMinInitialDeposit := sdk.Coins{} | ||
| minInitialDepositFloorDenomsSeen := make(map[string]bool) | ||
| for _, lastMinInitialDepositCoin := range lastMinInitialDeposit { | ||
| minInitialDepositFloorCoinAmt := minInitialDepositFloor.AmountOf(lastMinInitialDepositCoin.Denom) | ||
| if minInitialDepositFloorCoinAmt.IsZero() { | ||
| // minInitialDepositFloor was changed and this coin was removed, | ||
| // minInitialDepositFloor was changed since last update, | ||
| // and this coin was removed. | ||
| // reflect this also in the current min initial deposit, | ||
| // i.e. remove this coin | ||
| continue | ||
| } | ||
| minInitialDepositFloorDenomsSeen[lastMinInitialDepositCoin.Denom] = true | ||
| minInitialDepositCoinAmt := lastMinInitialDepositCoin.Amount.ToLegacyDec().Mul(percChange).TruncateInt() | ||
| if minInitialDepositCoinAmt.LT(minInitialDepositFloorCoinAmt) { | ||
| minInitialDeposit = append(minInitialDeposit, sdk.NewCoin(lastMinInitialDepositCoin.Denom, minInitialDepositFloorCoinAmt)) | ||
| newMinInitialDeposit = append(newMinInitialDeposit, sdk.NewCoin(lastMinInitialDepositCoin.Denom, minInitialDepositFloorCoinAmt)) | ||
| } else { | ||
| minInitialDeposit = append(minInitialDeposit, sdk.NewCoin(lastMinInitialDepositCoin.Denom, minInitialDepositCoinAmt)) | ||
| newMinInitialDeposit = append(newMinInitialDeposit, sdk.NewCoin(lastMinInitialDepositCoin.Denom, minInitialDepositCoinAmt)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -137,12 +148,12 @@ func (keeper Keeper) GetMinInitialDeposit(ctx sdk.Context) sdk.Coins { | |
| if _, seen := minInitialDepositFloorDenomsSeen[minInitialDepositFloorCoin.Denom]; !seen { | ||
| minInitialDepositCoinAmt := minInitialDepositFloorCoin.Amount.ToLegacyDec().Mul(percChange).TruncateInt() | ||
| if minInitialDepositCoinAmt.LT(minInitialDepositFloorCoin.Amount) { | ||
| minInitialDeposit = append(minInitialDeposit, minInitialDepositFloorCoin) | ||
| newMinInitialDeposit = append(newMinInitialDeposit, minInitialDepositFloorCoin) | ||
| } else { | ||
| minInitialDeposit = append(minInitialDeposit, sdk.NewCoin(minInitialDepositFloorCoin.Denom, minInitialDepositCoinAmt)) | ||
| newMinInitialDeposit = append(newMinInitialDeposit, sdk.NewCoin(minInitialDepositFloorCoin.Denom, minInitialDepositCoinAmt)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return minInitialDeposit | ||
| keeper.SetLastMinInitialDeposit(ctx, newMinInitialDeposit, ctx.BlockTime()) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is no additional case in the unit tests for this new condition, is it because it is already covered or is it a miss ?