Skip to content

Commit

Permalink
fix to delete output proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Apr 23, 2024
1 parent 6f061d6 commit d971bc5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion api/opinit/ophost/v1/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion proto/opinit/ophost/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ message MsgProposeOutputResponse {
////////////////////////////
// Challenger Messages

// MsgDeleteOutput is a message to delete unfinalized l2 output proposal.
// MsgDeleteOutput is a message to delete unfinalized l2 output proposals
// in [outputIndex, nextOutputIndex) range.
message MsgDeleteOutput {
option (cosmos.msg.v1.signer) = "challenger";
option (amino.name) = "ophost/MsgDeleteOutput";
Expand Down
11 changes: 9 additions & 2 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,18 @@ func (ms MsgServer) DeleteOutput(ctx context.Context, req *types.MsgDeleteOutput
return nil, errors.ErrUnauthorized.Wrap("invalid challenger")
}

// delete output proposal
if err := ms.DeleteOutputProposal(ctx, bridgeId, outputIndex); err != nil {
nextOutputIndex, err := ms.GetNextOutputIndex(ctx, bridgeId)
if err != nil {
return nil, err
}

// delete output proposals in [outputIndex, nextOutputIndex) range
for i := outputIndex; i < nextOutputIndex; i++ {
if err := ms.DeleteOutputProposal(ctx, bridgeId, i); err != nil {
return nil, err
}
}

// rollback next output index to the deleted output index
ms.NextOutputIndexes.Set(ctx, bridgeId, outputIndex)

Expand Down
7 changes: 7 additions & 0 deletions x/ophost/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func Test_DeleteOutput(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(1), proposeRes.OutputIndex)

proposeRes, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 200, []byte{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))
require.NoError(t, err)
require.Equal(t, uint64(2), proposeRes.OutputIndex)

// unauthorized
_, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[0], 1, 1))
require.Error(t, err)
Expand All @@ -125,6 +129,9 @@ func Test_DeleteOutput(t *testing.T) {
require.NoError(t, err)

// should return error; deleted
_, err = input.OPHostKeeper.GetOutputProposal(ctx, 1, 2)
require.Error(t, err)

_, err = input.OPHostKeeper.GetOutputProposal(ctx, 1, 1)
require.Error(t, err)

Expand Down
3 changes: 2 additions & 1 deletion x/ophost/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d971bc5

Please sign in to comment.