diff --git a/protocol/x/clob/ante/clob.go b/protocol/x/clob/ante/clob.go index d2f9fafcda..dd678ba48b 100644 --- a/protocol/x/clob/ante/clob.go +++ b/protocol/x/clob/ante/clob.go @@ -110,17 +110,18 @@ func (cd ClobDecorator) AnteHandle( return next(ctx, tx, simulate) } - // HOTFIX: Ignore any short-term place orders in a transaction with a timeout height. - if timeoutHeight := GetTimeoutHeight(tx); timeoutHeight > 0 && ctx.IsCheckTx() { + // HOTFIX: Reject any short-term place orders in a transaction with a non-zero timeout height < good til block + if timeoutHeight := GetTimeoutHeight(tx); timeoutHeight > 0 && + timeoutHeight < uint64(msg.Order.GetGoodTilBlock()) && ctx.IsCheckTx() { log.InfoLog( ctx, - "Rejected short-term place order with non-zero timeout height", + "Rejected short-term place order with non-zero timeout height < goodTilBlock", timeoutHeightLogKey, timeoutHeight, ) return ctx, errorsmod.Wrap( sdkerrors.ErrInvalidRequest, - "a short term place order message may not have a non-zero timeout height, use goodTilBlock instead", + "timeout height (if non-zero) may not be less than `goodTilBlock` for a short-term place order", ) } diff --git a/protocol/x/clob/ante/clob_test.go b/protocol/x/clob/ante/clob_test.go index 141d330f05..60a0f8c39d 100644 --- a/protocol/x/clob/ante/clob_test.go +++ b/protocol/x/clob/ante/clob_test.go @@ -223,16 +223,16 @@ func TestClobDecorator_MsgPlaceOrder(t *testing.T) { expectedErr: sdkerrors.ErrInvalidRequest, }, // Test for hotfix. - "PlaceShortTermOrder is not called on keeper CheckTx if transaction timeout height is non-zero": { + "PlaceShortTermOrder is not called on keeper CheckTx if transaction timeout height < goodTilBlock": { msgs: []sdk.Msg{constants.Msg_PlaceOrder}, useWithIsCheckTxContext: true, useWithIsRecheckTxContext: false, isSimulate: false, expectedErr: errorsmod.Wrap( sdkerrors.ErrInvalidRequest, - "a short term place order message may not have a non-zero timeout height, use goodTilBlock instead", + "a short term place order message may not have a timeout height less than goodTilBlock", ), - timeoutHeight: 1, + timeoutHeight: uint64(constants.Msg_PlaceOrder.Order.GetGoodTilBlock() - 1), additionalAssertions: func(ctx sdk.Context, mck *mocks.ClobKeeper) { mck.AssertNotCalled( t, @@ -242,6 +242,22 @@ func TestClobDecorator_MsgPlaceOrder(t *testing.T) { ) }, }, + "Successfully places a short term order using a single message with timeout height >= goodTilBlock": { + msgs: []sdk.Msg{constants.Msg_PlaceOrder}, + setupMocks: func(ctx sdk.Context, mck *mocks.ClobKeeper) { + mck.On("PlaceShortTermOrder", + ctx, + constants.Msg_PlaceOrder, + ).Return( + satypes.BaseQuantums(0), + clobtypes.Success, + nil, + ) + }, + useWithIsCheckTxContext: true, + expectedErr: nil, + timeoutHeight: uint64(constants.Msg_PlaceOrder.Order.GetGoodTilBlock()), + }, } // Run tests.