Skip to content

Commit

Permalink
fix(x/protocolpool): fix potential panic and missing error handling (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Halimao authored Jan 10, 2024
1 parent dee20ad commit 8d71191
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions x/protocolpool/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) error
}
for _, budget := range data.Budget {
// Validate StartTime
if budget.StartTime.IsZero() || budget.StartTime == nil {
if budget.StartTime == nil || budget.StartTime.IsZero() {
budget.StartTime = &currentTime
}
// ignore budget with start time < currentTime
if budget.StartTime != nil && budget.StartTime.Before(currentTime) {
if budget.StartTime.Before(currentTime) {
continue
}

Expand Down
7 changes: 3 additions & 4 deletions x/protocolpool/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (k Keeper) withdrawContinuousFund(ctx context.Context, recipient sdk.AccAdd
if errors.Is(err, collections.ErrNotFound) {
return sdk.Coin{}, fmt.Errorf("no continuous fund found for recipient: %s", recipient.String())
}
return sdk.Coin{}, fmt.Errorf("get continuous fund failed for recipient: %s", recipient.String())
}
if cf.Expiry != nil && cf.Expiry.Before(sdkCtx.HeaderInfo().Time) {
return sdk.Coin{}, fmt.Errorf("cannot withdraw continuous funds: continuous fund expired for recipient: %s", recipient.String())
Expand Down Expand Up @@ -412,10 +413,8 @@ func (k Keeper) validateContinuousFund(ctx context.Context, msg types.MsgCreateC

// Validate expiry
currentTime := sdk.UnwrapSDKContext(ctx).BlockTime()
if msg.Expiry != nil {
if msg.Expiry.Compare(currentTime) == -1 {
return fmt.Errorf("expiry time cannot be less than the current block time")
}
if msg.Expiry != nil && msg.Expiry.Compare(currentTime) == -1 {
return fmt.Errorf("expiry time cannot be less than the current block time")
}

return nil
Expand Down
6 changes: 2 additions & 4 deletions x/protocolpool/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ func (k MsgServer) CancelContinuousFund(ctx context.Context, msg *types.MsgCance

// withdraw funds if any are allocated
withdrawnFunds, err := k.withdrawRecipientFunds(ctx, recipient)
if err != nil {
if !errorspkg.Is(err, types.ErrNoRecipientFund) {
return nil, fmt.Errorf("error while withdrawing already allocated funds for recipient %s: %v", msg.RecipientAddress, err)
}
if err != nil && !errorspkg.Is(err, types.ErrNoRecipientFund) {
return nil, fmt.Errorf("error while withdrawing already allocated funds for recipient %s: %v", msg.RecipientAddress, err)
}

if err := k.ContinuousFund.Remove(ctx, recipient); err != nil {
Expand Down

0 comments on commit 8d71191

Please sign in to comment.