Skip to content

Commit

Permalink
Reject short-term orders with 0 < TimeoutHeight < GoodTilBlock. (back…
Browse files Browse the repository at this point in the history
…port #1854) (#1855)

Co-authored-by: vincentwschau <[email protected]>
  • Loading branch information
mergify[bot] and vincentwschau authored Jul 5, 2024
1 parent dac2239 commit e8cf1f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
9 changes: 5 additions & 4 deletions protocol/x/clob/ante/clob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}

Expand Down
22 changes: 19 additions & 3 deletions protocol/x/clob/ante/clob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down

0 comments on commit e8cf1f3

Please sign in to comment.