Skip to content

Commit

Permalink
delete output proposal only if it is not finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cha committed Mar 23, 2024
1 parent 9061c8f commit b5f8449
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions x/ophost/keeper/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ func (k Keeper) GetOutputProposal(ctx context.Context, bridgeId, outputIndex uin
}

func (k Keeper) DeleteOutputProposal(ctx context.Context, bridgeId, outputIndex uint64) error {
output, err := k.GetOutputProposal(ctx, bridgeId, outputIndex)
if err != nil {
return err
}

Check warning on line 28 in x/ophost/keeper/output.go

View check run for this annotation

Codecov / codecov/patch

x/ophost/keeper/output.go#L27-L28

Added lines #L27 - L28 were not covered by tests
if isFinal, err := k.isFinalized(ctx, bridgeId, output); err != nil {
return err

Check warning on line 30 in x/ophost/keeper/output.go

View check run for this annotation

Codecov / codecov/patch

x/ophost/keeper/output.go#L30

Added line #L30 was not covered by tests
} else if isFinal {
return types.ErrAlreadyFinalized
}

Check warning on line 33 in x/ophost/keeper/output.go

View check run for this annotation

Codecov / codecov/patch

x/ophost/keeper/output.go#L32-L33

Added lines #L32 - L33 were not covered by tests

return k.OutputProposals.Remove(ctx, collections.Join(bridgeId, outputIndex))
}

Expand All @@ -35,6 +45,10 @@ func (k Keeper) IsFinalized(ctx context.Context, bridgeId, outputIndex uint64) (
return false, err
}

return k.isFinalized(ctx, bridgeId, output)
}

func (k Keeper) isFinalized(ctx context.Context, bridgeId uint64, output types.Output) (bool, error) {
bridgeConfig, err := k.GetBridgeConfig(ctx, bridgeId)
if err != nil {
return false, err
Expand Down
5 changes: 3 additions & 2 deletions x/ophost/types/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
ErrInvalidSequence = errorsmod.Register(ModuleName, 6, "invalid sequence")
ErrInvalidL2BlockNumber = errorsmod.Register(ModuleName, 7, "invalid l2 block number")
ErrNotFinalized = errorsmod.Register(ModuleName, 8, "output has not finalized")
ErrFailedToVerifyWithdrawal = errorsmod.Register(ModuleName, 9, "failed to verify withdrawal tx")
ErrWithdrawalAlreadyFinalized = errorsmod.Register(ModuleName, 10, "withdrawal already finalized")
ErrAlreadyFinalized = errorsmod.Register(ModuleName, 9, "output has already finalized")
ErrFailedToVerifyWithdrawal = errorsmod.Register(ModuleName, 10, "failed to verify withdrawal tx")
ErrWithdrawalAlreadyFinalized = errorsmod.Register(ModuleName, 11, "withdrawal already finalized")
)

0 comments on commit b5f8449

Please sign in to comment.