Skip to content
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

delete output proposal bug #35

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
if isFinalized, err := k.isFinalized(ctx, bridgeId, output); err != nil {
return err
} else if isFinalized {
return types.ErrAlreadyFinalized
}

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
30 changes: 30 additions & 0 deletions x/ophost/keeper/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,33 @@ func Test_NextOutputIndex(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(101), index)
}

func Test_DeleteOutputProposal(t *testing.T) {
ctx, input := createDefaultTestInput(t)

output := types.Output{
OutputRoot: []byte{1, 2, 3},
L1BlockTime: ctx.BlockTime(),
L2BlockNumber: 100,
}
err := input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, output)
require.NoError(t, err)

err = input.OPHostKeeper.SetBridgeConfig(ctx, 1, types.BridgeConfig{
Challenger: "",
Proposer: "",
SubmissionInterval: time.Second * 10,
FinalizationPeriod: time.Second * 10,
SubmissionStartTime: ctx.BlockTime(),
Metadata: nil,
})
require.NoError(t, err)

// delete should fail due to already finalized error
err = input.OPHostKeeper.DeleteOutputProposal(ctx.WithBlockTime(ctx.BlockTime().Add(time.Second*11)), 1, 1)
require.ErrorIs(t, err, types.ErrAlreadyFinalized)

// delete should success
err = input.OPHostKeeper.DeleteOutputProposal(ctx.WithBlockTime(ctx.BlockTime().Add(time.Second*9)), 1, 1)
require.NoError(t, err)
}
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")
)
Loading