Skip to content

Commit

Permalink
add panic for impossible scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed May 24, 2024
1 parent 38a6f13 commit fe82b13
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions x/fbridge/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) {
proposals := k.GetRoleProposals(ctx)
for _, proposal := range proposals {
if ctx.BlockTime().After(proposal.ExpiredAt) {
k.deleteRoleProposal(ctx, proposal.Id)
if err := k.deleteRoleProposal(ctx, proposal.Id); err != nil {
panic(err)
}
}
}
}
Expand All @@ -40,7 +42,9 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {
}
}

k.deleteRoleProposal(ctx, proposal.Id)
if err := k.deleteRoleProposal(ctx, proposal.Id); err != nil {
panic(err)
}
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions x/fbridge/keeper/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"encoding/binary"
"fmt"
"time"

sdk "github.com/Finschia/finschia-sdk/types"
Expand Down Expand Up @@ -102,7 +101,7 @@ func (k Keeper) updateRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress
case types.RoleGuardian:
roleMeta.Guardian++
if err := k.setBridgeSwitch(ctx, addr, types.StatusActive); err != nil {
return err
panic(err)
}
case types.RoleOperator:
roleMeta.Operator++
Expand Down Expand Up @@ -175,12 +174,14 @@ func (k Keeper) GetRoleProposal(ctx sdk.Context, id uint64) (proposal types.Role
return proposal, true
}

func (k Keeper) deleteRoleProposal(ctx sdk.Context, id uint64) {
func (k Keeper) deleteRoleProposal(ctx sdk.Context, id uint64) error {
store := ctx.KVStore(k.storeKey)
if _, found := k.GetRoleProposal(ctx, id); !found {
panic(fmt.Sprintf("role proposal #%d not found", id))
return sdkerrors.ErrNotFound.Wrapf("role proposal #%d not found", id)
}

store.Delete(types.ProposalKey(id))
return nil
}

// IterateProposals iterates over the all the role proposals and performs a callback function
Expand Down

0 comments on commit fe82b13

Please sign in to comment.