Skip to content

Commit 8d71191

Browse files
authored
fix(x/protocolpool): fix potential panic and missing error handling (#18995)
1 parent dee20ad commit 8d71191

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

x/protocolpool/keeper/genesis.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) error
2828
}
2929
for _, budget := range data.Budget {
3030
// Validate StartTime
31-
if budget.StartTime.IsZero() || budget.StartTime == nil {
31+
if budget.StartTime == nil || budget.StartTime.IsZero() {
3232
budget.StartTime = &currentTime
3333
}
3434
// ignore budget with start time < currentTime
35-
if budget.StartTime != nil && budget.StartTime.Before(currentTime) {
35+
if budget.StartTime.Before(currentTime) {
3636
continue
3737
}
3838

x/protocolpool/keeper/keeper.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func (k Keeper) withdrawContinuousFund(ctx context.Context, recipient sdk.AccAdd
111111
if errors.Is(err, collections.ErrNotFound) {
112112
return sdk.Coin{}, fmt.Errorf("no continuous fund found for recipient: %s", recipient.String())
113113
}
114+
return sdk.Coin{}, fmt.Errorf("get continuous fund failed for recipient: %s", recipient.String())
114115
}
115116
if cf.Expiry != nil && cf.Expiry.Before(sdkCtx.HeaderInfo().Time) {
116117
return sdk.Coin{}, fmt.Errorf("cannot withdraw continuous funds: continuous fund expired for recipient: %s", recipient.String())
@@ -412,10 +413,8 @@ func (k Keeper) validateContinuousFund(ctx context.Context, msg types.MsgCreateC
412413

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

421420
return nil

x/protocolpool/keeper/msg_server.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,8 @@ func (k MsgServer) CancelContinuousFund(ctx context.Context, msg *types.MsgCance
190190

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

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

0 commit comments

Comments
 (0)