Skip to content

Commit

Permalink
more msgBatchCancels in code
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfung-dydx committed Feb 29, 2024
1 parent ef75e27 commit f6d3e69
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 7 deletions.
6 changes: 5 additions & 1 deletion protocol/app/module/interface_registry.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package module

import (
"cosmossdk.io/x/tx/signing"
"fmt"

"cosmossdk.io/x/tx/signing"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -76,6 +77,9 @@ func NewInterfaceRegistry(addrPrefix string, valAddrPrefix string) (types.Interf
// https://github.com/cosmos/cosmos-sdk/issues/18722 is fixed, replace this with the cosmos.msg.v1.signing
// annotation on the protos.
CustomGetSigners: map[protoreflect.FullName]signing.GetSignersFunc{
"dydxprotocol.clob.MsgBatchCancel": getLegacyMsgSignerFn(
[]string{"subaccount_id", "owner"},
),
"dydxprotocol.clob.MsgCancelOrder": getLegacyMsgSignerFn(
[]string{"order_id", "subaccount_id", "owner"},
),
Expand Down
3 changes: 3 additions & 0 deletions protocol/app/process/other_msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package process

import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/lib/ante"
Expand All @@ -23,6 +25,7 @@ func DecodeOtherMsgsTx(decoder sdk.TxDecoder, txBytes []byte) (*OtherMsgsTx, err
// Decode.
tx, err := decoder(txBytes)
if err != nil {
fmt.Println("GUHH")
return nil, errorsmod.Wrapf(ErrDecodingTxBytes, "OtherMsgsTx Error: %+v", err)
}

Expand Down
10 changes: 9 additions & 1 deletion protocol/app/process/other_msgs_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package process_test

import (
errorsmod "cosmossdk.io/errors"
"testing"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/process"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
Expand Down Expand Up @@ -87,6 +88,13 @@ func TestDecodeOtherMsgsTx(t *testing.T) {
"Msg type *types.MsgCancelOrder is not allowed in OtherTxs",
),
},
"Error: batch cancel order is not allowed": {
txBytes: constants.Msg_BatchCancel_TxBtyes,
expectedErr: errorsmod.Wrap(
process.ErrUnexpectedMsgType,
"Msg type *types.MsgBatchCancel is not allowed in OtherTxs",
),
},
"Valid: single msg": {
txBytes: constants.Msg_Send_TxBytes,
expectedMsgs: []sdk.Msg{constants.Msg_Send},
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/process/utils_disallow_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func IsDisallowClobOrderMsgInOtherTxs(targetMsg sdk.Msg) bool {
order := msg.GetOrder()
orderId := order.GetOrderId()
return !orderId.IsStatefulOrder() // not stateful -> returns true -> disallow
case *clobtypes.MsgBatchCancel:
return true
}
return false
}
2 changes: 1 addition & 1 deletion protocol/app/process/utils_disallow_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestIsDisallowClobOrderMsgInOtherTxs(t *testing.T) {
for _, msg := range allMsgSamples {
result := process.IsDisallowClobOrderMsgInOtherTxs(msg)
switch msg.(type) {
case *clobtypes.MsgCancelOrder, *clobtypes.MsgPlaceOrder:
case *clobtypes.MsgCancelOrder, *clobtypes.MsgPlaceOrder, *clobtypes.MsgBatchCancel:
// The sample msgs are short-term orders, so we expect these to be disallowed.
require.True(t, result) // true -> disallow
default:
Expand Down
15 changes: 15 additions & 0 deletions protocol/testutil/constants/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func init() {
_ = TestTxBuilder.SetMsgs(Msg_CancelOrder)
Msg_CancelOrder_TxBtyes, _ = TestEncodingCfg.TxConfig.TxEncoder()(TestTxBuilder.GetTx())

_ = TestTxBuilder.SetMsgs(Msg_BatchCancel)
Msg_BatchCancel_TxBtyes, _ = TestEncodingCfg.TxConfig.TxEncoder()(TestTxBuilder.GetTx())

_ = TestTxBuilder.SetMsgs(Msg_Send)
Msg_Send_TxBytes, _ = TestEncodingCfg.TxConfig.TxEncoder()(TestTxBuilder.GetTx())

Expand Down Expand Up @@ -54,6 +57,18 @@ var (
}
Msg_PlaceOrder_TxBtyes []byte

Msg_BatchCancel = &clobtypes.MsgBatchCancel{
SubaccountId: Alice_Num0,
ShortTermCancels: []clobtypes.OrderBatch{
{
ClobPairId: 0,
ClientIds: []uint32{0},
},
},
GoodTilBlock: 5,
}
Msg_BatchCancel_TxBtyes []byte

Msg_PlaceOrder_LongTerm = &clobtypes.MsgPlaceOrder{
Order: LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15,
}
Expand Down
4 changes: 3 additions & 1 deletion protocol/testutil/encoding/utils.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package encoding

import (
"github.com/dydxprotocol/v4-chain/protocol/testutil/ante"
"testing"

"github.com/dydxprotocol/v4-chain/protocol/testutil/ante"

feegrantmodule "cosmossdk.io/x/feegrant/module"
"cosmossdk.io/x/upgrade"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -73,6 +74,7 @@ func GetTestEncodingCfg() testutil.TestEncodingConfig {
&clobtypes.MsgProposedOperations{},
&clobtypes.MsgPlaceOrder{},
&clobtypes.MsgCancelOrder{},
&clobtypes.MsgBatchCancel{},

// Perpetuals.
&perpetualtypes.MsgAddPremiumVotes{},
Expand Down
1 change: 0 additions & 1 deletion protocol/x/clob/ante/clob.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (cd ClobDecorator) AnteHandle(
return next(ctx, tx, simulate)
}

fmt.Println("msg batch cancellll", msg)
ctx = log.AddPersistentTagsToLogger(ctx,
log.Handler, log.MsgBatchCancel,
)
Expand Down
2 changes: 0 additions & 2 deletions protocol/x/clob/keeper/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (k Keeper) BatchCancelShortTermOrder(
)
}
}
fmt.Println("good good")
subaccountId := msg.GetSubaccountId()
oneCancelSucceeded := false
for _, batchOrder := range msg.GetShortTermCancels() {
Expand All @@ -97,7 +96,6 @@ func (k Keeper) BatchCancelShortTermOrder(
GoodTilBlock: goodTilBlock,
},
}
fmt.Println("running st order cancel", msgCancelOrder)
// Run the short term order. If it errors, just log silently.
err := k.CancelShortTermOrder(
ctx,
Expand Down

0 comments on commit f6d3e69

Please sign in to comment.