Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Oct 3, 2024
1 parent 1a9482b commit 46c33fe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
17 changes: 15 additions & 2 deletions protocol/mocks/MemClob.go

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

22 changes: 11 additions & 11 deletions protocol/x/clob/keeper/clob_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events"
"github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager"
"github.com/dydxprotocol/v4-chain/protocol/lib"
dydxlog "github.com/dydxprotocol/v4-chain/protocol/lib/log"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
)
Expand Down Expand Up @@ -238,18 +239,18 @@ func (k Keeper) validateClobPair(ctx sdk.Context, clobPair *types.ClobPair) erro
return nil
}

// maybeCreateOrderbook creates a new orderbook in the memclob.
func (k Keeper) maybeCreateOrderbook(ctx sdk.Context, clobPair types.ClobPair) {
// Create the corresponding orderbook in the memclob.
k.MemClob.MaybeCreateOrderbook(clobPair)
}

func (k Keeper) ApplySideEffectsForCNewlobPair(
func (k Keeper) ApplySideEffectsForNewClobPair(
ctx sdk.Context,
clobPair types.ClobPair,
) {
// TODO throw error if orderbook is not created.
k.MemClob.MaybeCreateOrderbook(clobPair)
if created := k.MemClob.MaybeCreateOrderbook(clobPair); !created {
dydxlog.ErrorLog(
ctx,
"ApplySideEffectsForNewClobPair: Orderbook already exists for CLOB pair",
"clob_pair", clobPair,
)
return
}
k.SetClobPairIdForPerpetual(clobPair)
}

Expand Down Expand Up @@ -285,8 +286,7 @@ func (k Keeper) InitMemClobOrderbooks(ctx sdk.Context) {
clobPairs := k.GetAllClobPairs(ctx)
for _, clobPair := range clobPairs {
// Create the corresponding orderbook in the memclob.
k.maybeCreateOrderbook(
ctx,
k.MemClob.MaybeCreateOrderbook(
clobPair,
)
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/x/clob/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (k Keeper) ProcessStagedFinalizeBlockEvents(ctx sdk.Context) {

switch event := stagedEvent.Event.(type) {
case *types.ClobStagedFinalizeBlockEvent_CreateClobPair:
k.ApplySideEffectsForCNewlobPair(ctx, *event.CreateClobPair)
k.ApplySideEffectsForNewClobPair(ctx, *event.CreateClobPair)
default:
dydxlog.ErrorLog(
ctx,
Expand Down
5 changes: 3 additions & 2 deletions protocol/x/clob/memclob/memclob.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ func (m *MemClobPriceTimePriority) CancelOrder(
// MaybeCreateOrderbook is used for updating memclob internal data structures to mark an orderbook as created.
func (m *MemClobPriceTimePriority) MaybeCreateOrderbook(
clobPair types.ClobPair,
) {
) (created bool) {
if _, exists := m.orderbooks[clobPair.GetClobPairId()]; exists {
return
return false
}
m.CreateOrderbook(clobPair)
return true
}

// CreateOrderbook is used for updating memclob internal data structures to mark an orderbook as created.
Expand Down
2 changes: 1 addition & 1 deletion protocol/x/clob/types/memclob.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type MemClob interface {
)
MaybeCreateOrderbook(
clobPair ClobPair,
)
) bool
GetOperationsToReplay(
ctx sdk.Context,
) (
Expand Down
8 changes: 0 additions & 8 deletions protocol/x/listing/keeper/listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,14 @@ func TestCreateClobPair(t *testing.T) {
tests := map[string]struct {
ticker string
isDeliverTx bool
isGenesis bool
}{
"deliverTx - true": {
ticker: "TEST-USD",
isDeliverTx: true,
isGenesis: false,
},
"deliverTx - false": {
ticker: "TEST-USD",
isDeliverTx: false,
isGenesis: false,
},
}

Expand All @@ -227,11 +224,6 @@ func TestCreateClobPair(t *testing.T) {
&mocks.BankKeeper{},
mockIndexerEventManager,
)
// if tc.isGenesis {
// ctx = ctx.WithBlockHeight(0)
// } else {
// ctx = ctx.WithBlockHeight(1)
// }
mockIndexerEventManager.On(
"AddTxnEvent",
mock.Anything,
Expand Down

0 comments on commit 46c33fe

Please sign in to comment.