From 0cbcfedfea3afb2205e2157f95a7d5c92fa421f6 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:26:43 +0900 Subject: [PATCH] allow gov and proposer to delete invalid output root (#120) --- x/ophost/keeper/msg_server.go | 6 +++--- x/ophost/keeper/msg_server_test.go | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/x/ophost/keeper/msg_server.go b/x/ophost/keeper/msg_server.go index 9af1bf8..b530dc9 100644 --- a/x/ophost/keeper/msg_server.go +++ b/x/ophost/keeper/msg_server.go @@ -183,9 +183,9 @@ func (ms MsgServer) DeleteOutput(ctx context.Context, req *types.MsgDeleteOutput return nil, err } - // permission check - if bridgeConfig.Challenger != challenger { - return nil, errors.ErrUnauthorized.Wrap("invalid challenger") + // gov, current propoer or current challenger can delete output. + if ms.authority != challenger && bridgeConfig.Proposer != challenger && bridgeConfig.Challenger != challenger { + return nil, errors.ErrUnauthorized.Wrapf("invalid challenger; expected %s, %s or %s, got %s", ms.authority, bridgeConfig.Proposer, bridgeConfig.Challenger, challenger) } nextOutputIndex, err := ms.GetNextOutputIndex(ctx, bridgeId) diff --git a/x/ophost/keeper/msg_server_test.go b/x/ophost/keeper/msg_server_test.go index ba1943c..3b2a812 100644 --- a/x/ophost/keeper/msg_server_test.go +++ b/x/ophost/keeper/msg_server_test.go @@ -119,10 +119,10 @@ func Test_DeleteOutput(t *testing.T) { require.NoError(t, err) // unauthorized - _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[0], 1, 1)) + _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[2], 1, 1)) require.Error(t, err) - // valid + // valid by challenger _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[1], 1, 1)) require.NoError(t, err) @@ -140,6 +140,18 @@ func Test_DeleteOutput(t *testing.T) { // invalid output index: nextoutputindex is 2 now _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[1], 1, 2)) require.Error(t, err) + + // valid delete by gov + _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(input.OPHostKeeper.GetAuthority(), 1, 1)) + require.NoError(t, err) + + // should be able to resubmit the same output + _, err = ms.ProposeOutput(ctx, types.NewMsgProposeOutput(addrsStr[0], 1, 1, 100, []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) + + // valid delete by proposer + _, err = ms.DeleteOutput(ctx, types.NewMsgDeleteOutput(addrsStr[0], 1, 1)) + require.NoError(t, err) } func Test_InitiateTokenDeposit(t *testing.T) {