-
Notifications
You must be signed in to change notification settings - Fork 15
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
Review #190
Review #190
Conversation
This reverts commit e8640fa.
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.
Left some extra comments
k.SetCurrentEpochDays(ctx, genState.CurrentEpochDays) | ||
moduleAcc := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) | ||
k.accountKeeper.SetModuleAccount(ctx, moduleAcc) | ||
k.accountKeeper.GetModuleAccount(ctx, types.ModuleName) |
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.
The GetModuleAccount
function creates the module account if it does not exist. This is similar to what the mint
and auth
modules do. No need to get and set; get is enough.
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.
It will be applied on #202, Thanks 🙇
removedFromStaking := queuedStaking.Amount.Neg() | ||
queuedStaking.Amount = sdk.ZeroInt() | ||
removedFromStaking := queuedStaking.Amount.Neg() // make negative a positive | ||
staking.Amount = staking.Amount.Sub(removedFromStaking) |
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.
Changed to .Sub
for readability
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.
It will be applied on #202, Thank you.
k.DeleteQueuedStaking(ctx, coin.Denom, farmerAcc) | ||
k.DecreaseTotalStakings(ctx, coin.Denom, removedFromStaking) | ||
} | ||
|
||
if queuedStaking.Amount.IsPositive() { | ||
} else if queuedStaking.Amount.IsPositive() { | ||
k.SetQueuedStaking(ctx, coin.Denom, farmerAcc, queuedStaking) | ||
} else { | ||
k.DeleteQueuedStaking(ctx, coin.Denom, farmerAcc) |
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.
Joined conditions for readability. This required adding a call to .DeleteQueuedStaking
in the if
clause
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.
Fixed in 2b08a97 (not merged)
Apart from the comments and suggestions in the Files changed section; in general, more documentation (both inline and in the spec) are needed. This is not a simple module, and so the documentation requirements are greater. |
@migueldingli1997 Thank you for your valuable review and suggestion. Would it be better to commit the modifications you suggested on this PR? Or the suggestions and fix commit may be mixed, so should we just talk here and proceed with the fix in a separate PR? |
@dongsam Let's just talk here and proceed with any fixes that we agree upon in a separate PR :) |
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.
Appreciate for reviewing the farming module @migueldingli1997 ! They are so valuable feedbacks and suggestions.
@@ -17,6 +17,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { | |||
if !plan.GetTerminated() && ctx.BlockTime().After(plan.GetEndTime()) { | |||
if err := k.TerminatePlan(ctx, plan); err != nil { | |||
panic(err) | |||
// Consider deleting terminated plans |
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.
We've discussed about this internally before, and we decided not to delete terminated plans, to provide historical information.
@@ -19,9 +19,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { | |||
|
|||
k.SetParams(ctx, genState.Params) | |||
// TODO: what if CurrentEpochDays field was empty? | |||
// ^ If it is empty, it will default to zero and the following error comes up: 'current epoch days must be positive' |
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.
It'll be fixed through #192.
@@ -210,6 +210,7 @@ func (k Keeper) WithdrawRewards(ctx sdk.Context, farmerAcc sdk.AccAddress, staki | |||
|
|||
currentEpoch := k.GetCurrentEpoch(ctx, stakingCoinDenom) | |||
// TODO: handle if currentEpoch is 0 | |||
// ^ Ensure this is handled |
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.
It'll be fixed through #192.
// Consider adding totalRewards to list of events, so that this shows up when querying the transaction. | ||
// However I understand that WithdrawRewards itself does this for each denom one by one. |
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.
Sounds good to add total rewards withdrawn in both messages.
Let me fix this.
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.
Added event attribute in de9ca0c (not merged)
@@ -303,6 +306,8 @@ func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { | |||
farmingPoolBalances := make(map[string]sdk.Coins) // farmingPoolAddress => sdk.Coins | |||
allocCoins := make(map[string]map[uint64]sdk.Coins) // farmingPoolAddress => (planId => sdk.Coins) | |||
|
|||
// This complex function is lacking inline documentation |
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.
Let me add inline documentation around the code.
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.
Added comments in b83ea9a (not merged)
@@ -363,6 +369,8 @@ func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { | |||
func (k Keeper) AllocateRewards(ctx sdk.Context) error { | |||
unitRewardsByDenom := map[string]sdk.DecCoins{} // (staking coin denom) => (unit rewards) | |||
|
|||
// This complex function is lacking inline documentation |
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.
Let me add internal documentation around the code.
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.
Added comments in b83ea9a (not merged)
@@ -379,8 +387,7 @@ func (k Keeper) AllocateRewards(ctx sdk.Context) error { | |||
continue | |||
} | |||
|
|||
weightProportion := weight.Amount.QuoTruncate(totalWeight) | |||
allocCoins, _ := sdk.NewDecCoinsFromCoins(allocInfo.Amount...).MulDecTruncate(weightProportion).TruncateDecimal() | |||
allocCoins, _ := sdk.NewDecCoinsFromCoins(allocInfo.Amount...).MulDecTruncate(weight.Amount).TruncateDecimal() |
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.
If we don't need to calculate totalWeight
anymore(since it'll always be 1 because of the validation logic in msg/proposal handlers) , we can accept this change.
Let me fix this.
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.
Yep that's the context, since totalWeight
is expected to always be 1
👍
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.
Fixed in 4f0ea4a (not merged)
// ^ No need to check if balance has enough to pay for fee. Can just try to .SendCoins; it will error if insufficient tokens | ||
// If we want a specific error, the error returned by SendCoins can be replaced by the above error. |
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.
That's true. I'll fix this.
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.
Fixed in cdd32e3 (not merged now)
Co-authored-by: Dylan Frendo <ferendo@users.noreply.github.com>
// ^ No need to check if balance has enough to pay for fee. Can just try to .SendCoins; it will error if insufficient tokens | ||
// If we want a specific error, the error returned by SendCoins can be replaced by the above error. |
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.
Fixed in cdd32e3 (not merged now)
return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "lack of %s coins to pay private plan creation fee", diffs.String()) | ||
} | ||
// ^ No need to check if balance has enough to pay for fee. Can just try to .SendCoins; it will error if insufficient tokens | ||
// If we want a specific error, the error returned by SendCoins can be replaced by the above error. |
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.
Fixed in cdd32e3 (not merged now)
// Consider adding totalRewards to list of events, so that this shows up when querying the transaction. | ||
// However I understand that WithdrawRewards itself does this for each denom one by one. |
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.
Added event attribute in de9ca0c (not merged)
@@ -303,6 +306,8 @@ func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { | |||
farmingPoolBalances := make(map[string]sdk.Coins) // farmingPoolAddress => sdk.Coins | |||
allocCoins := make(map[string]map[uint64]sdk.Coins) // farmingPoolAddress => (planId => sdk.Coins) | |||
|
|||
// This complex function is lacking inline documentation |
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.
Added comments in b83ea9a (not merged)
@@ -336,9 +341,10 @@ func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { | |||
} | |||
|
|||
var allocInfos []AllocationInfo | |||
for farmingPool, coins := range allocCoins { | |||
// Renamed coins -> planCoins to make it more clear that it's a map (planId => sdk.Coins) not just sdk.Coins |
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.
Fixed in b83ea9a (not merged)
@@ -363,6 +369,8 @@ func (k Keeper) AllocationInfos(ctx sdk.Context) []AllocationInfo { | |||
func (k Keeper) AllocateRewards(ctx sdk.Context) error { | |||
unitRewardsByDenom := map[string]sdk.DecCoins{} // (staking coin denom) => (unit rewards) | |||
|
|||
// This complex function is lacking inline documentation |
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.
Added comments in b83ea9a (not merged)
@@ -379,8 +387,7 @@ func (k Keeper) AllocateRewards(ctx sdk.Context) error { | |||
continue | |||
} | |||
|
|||
weightProportion := weight.Amount.QuoTruncate(totalWeight) | |||
allocCoins, _ := sdk.NewDecCoinsFromCoins(allocInfo.Amount...).MulDecTruncate(weightProportion).TruncateDecimal() | |||
allocCoins, _ := sdk.NewDecCoinsFromCoins(allocInfo.Amount...).MulDecTruncate(weight.Amount).TruncateDecimal() |
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.
Fixed in 4f0ea4a (not merged)
k.DeleteQueuedStaking(ctx, coin.Denom, farmerAcc) | ||
k.DecreaseTotalStakings(ctx, coin.Denom, removedFromStaking) | ||
} | ||
|
||
if queuedStaking.Amount.IsPositive() { | ||
} else if queuedStaking.Amount.IsPositive() { | ||
k.SetQueuedStaking(ctx, coin.Denom, farmerAcc, queuedStaking) | ||
} else { | ||
k.DeleteQueuedStaking(ctx, coin.Denom, farmerAcc) |
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.
Fixed in 2b08a97 (not merged)
@@ -14,7 +14,7 @@ There are two types of farming plans in the `farming` module as below. | |||
A public farming plan can only be created through governance proposal meaning that the proposal must be first agreed and passed in order to create a public plan. | |||
### 2. Private Farming Plan | |||
|
|||
A private farming plan can be created with any account. The plan creator's account is used as `TerminationAddress`. There is a fee `PlanCreationFee` paid upon plan creation to prevent from spamming attack. | |||
A private farming plan can be created with any account. The plan creator's account is used as `TerminationAddress` (consider explaining what a TerminationAddress is used for here). There is a fee `PlanCreationFee` paid upon plan creation to prevent from spamming attack. |
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.
It will be added on #232, Thanks!
if clientCtx.Offline { | ||
return fmt.Errorf("cannot generate tx in offline mode with --all flag") | ||
} | ||
|
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.
I cherry-picked this commit on #232, Thanks for the suggestion.
Close the issue because all suggestions have been discussed or resolved. Thank you again :) |
Description
Code review of the entire module. Refer to the Files changed for most of the review comments.
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Linked to Github issue with discussion and accepted design OR link to spec that describes this work.Code follows the module structure standards.Wrote unit and integrationUpdated relevant documentation (docs/
) or specification (x/<module>/spec/
)Added relevantgodoc
comments.Files changed
in the Github PR explorerReviewCodecov Report
in the comment section below once CI passes