diff --git a/protocol/x/clob/abci_test.go b/protocol/x/clob/abci_test.go index 466489338a..b62b927f11 100644 --- a/protocol/x/clob/abci_test.go +++ b/protocol/x/clob/abci_test.go @@ -807,11 +807,11 @@ func TestEndBlocker_Success(t *testing.T) { for _, triggeredConditionalOrderId := range actualProcessProposerMatchesEvents. ConditionalOrderIdsTriggeredInLastBlock { // TODO(CLOB-746) Once R/W methods are created, substitute those methods here. - triggeredConditionalOrderMemstore := ks.ClobKeeper.GetTriggeredConditionalOrderPlacementMemStore(ctx) - untriggeredConditionalOrderMemstore := ks.ClobKeeper.GetUntriggeredConditionalOrderPlacementMemStore(ctx) - exists := triggeredConditionalOrderMemstore.Has(triggeredConditionalOrderId.ToStateKey()) + triggeredConditionalOrderStore := ks.ClobKeeper.GetTriggeredConditionalOrderPlacementStore(ctx) + untriggeredConditionalOrderStore := ks.ClobKeeper.GetUntriggeredConditionalOrderPlacementStore(ctx) + exists := triggeredConditionalOrderStore.Has(triggeredConditionalOrderId.ToStateKey()) require.True(t, exists) - exists = untriggeredConditionalOrderMemstore.Has(triggeredConditionalOrderId.ToStateKey()) + exists = untriggeredConditionalOrderStore.Has(triggeredConditionalOrderId.ToStateKey()) require.False(t, exists) } diff --git a/protocol/x/clob/keeper/keeper.go b/protocol/x/clob/keeper/keeper.go index 1bbd7872ee..4ea1edee3a 100644 --- a/protocol/x/clob/keeper/keeper.go +++ b/protocol/x/clob/keeper/keeper.go @@ -215,7 +215,6 @@ func (k Keeper) InitMemStore(ctx sdk.Context) { // Initialize all the necessary memory stores. for _, keyPrefix := range []string{ - types.OrderAmountFilledKeyPrefix, types.StatefulOrderKeyPrefix, } { // Retrieve an instance of the memstore. diff --git a/protocol/x/clob/keeper/order_state.go b/protocol/x/clob/keeper/order_state.go index 24ff70a22f..df6909323d 100644 --- a/protocol/x/clob/keeper/order_state.go +++ b/protocol/x/clob/keeper/order_state.go @@ -81,21 +81,9 @@ func (k Keeper) SetOrderFillAmount( orderId.ToStateKey(), orderFillStateBytes, ) - - // Retrieve an instance of the memStore. - memStore := prefix.NewStore( - ctx.KVStore(k.memKey), - []byte(types.OrderAmountFilledKeyPrefix), - ) - - // Write `orderFillStateBytes` to memStore. - memStore.Set( - orderId.ToStateKey(), - orderFillStateBytes, - ) } -// GetOrderFillAmount returns the total `fillAmount` and `prunableBlockHeight` from the memStore. +// GetOrderFillAmount returns the total `fillAmount` and `prunableBlockHeight` from state. func (k Keeper) GetOrderFillAmount( ctx sdk.Context, orderId types.OrderId, @@ -104,16 +92,15 @@ func (k Keeper) GetOrderFillAmount( fillAmount satypes.BaseQuantums, prunableBlockHeight uint32, ) { - memStore := ctx.KVStore(k.memKey) + store := ctx.KVStore(k.storeKey) - // Retrieve an instance of the memStore. - memPrefixStore := prefix.NewStore( - memStore, + prefixStore := prefix.NewStore( + store, []byte(types.OrderAmountFilledKeyPrefix), ) // Retrieve the `OrderFillState` bytes from the store. - orderFillStateBytes := memPrefixStore.Get( + orderFillStateBytes := prefixStore.Get( orderId.ToStateKey(), ) @@ -259,8 +246,8 @@ func (k Keeper) MigratePruneableOrders(ctx sdk.Context) { } } -// RemoveOrderFillAmount removes the fill amount of an Order from state and the memstore. -// This function is a no-op if no order fill amount exists in state and the mem store with `orderId`. +// RemoveOrderFillAmount removes the fill amount of an Order from state. +// This function is a no-op if no order fill amount exists in state with `orderId`. func (k Keeper) RemoveOrderFillAmount(ctx sdk.Context, orderId types.OrderId) { // Delete the fill amount from the state store. orderAmountFilledStore := prefix.NewStore( @@ -270,13 +257,6 @@ func (k Keeper) RemoveOrderFillAmount(ctx sdk.Context, orderId types.OrderId) { orderAmountFilledStore.Delete(orderId.ToStateKey()) - // Delete the fill amount from the mem store. - memStore := prefix.NewStore( - ctx.KVStore(k.memKey), - []byte(types.OrderAmountFilledKeyPrefix), - ) - memStore.Delete(orderId.ToStateKey()) - // If grpc stream is on, zero out the fill amount. if k.GetGrpcStreamingManager().Enabled() { allUpdates := types.NewOffchainUpdates() diff --git a/protocol/x/clob/keeper/order_state_test.go b/protocol/x/clob/keeper/order_state_test.go index 5b3a60557b..ee45daae15 100644 --- a/protocol/x/clob/keeper/order_state_test.go +++ b/protocol/x/clob/keeper/order_state_test.go @@ -582,10 +582,6 @@ func TestRemoveOrderFillAmount(t *testing.T) { string(constants.Order_Alice_Num1_Clob0_Id4_Buy10_Price45_GTB20.OrderId.ToStateKey()), types.OrderAmountFilledKeyPrefix + string(constants.Order_Alice_Num1_Clob0_Id4_Buy10_Price45_GTB20.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num1_Clob0_Id4_Buy10_Price45_GTB20.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num1_Clob0_Id4_Buy10_Price45_GTB20.OrderId.ToStateKey()), }, }, "SetOrderFillAmount twice and then RemoveOrderFillAmount removes the fill amount": { @@ -617,12 +613,6 @@ func TestRemoveOrderFillAmount(t *testing.T) { string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), types.OrderAmountFilledKeyPrefix + string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), }, }, "RemoveOrderFillAmount with non-existent order": { @@ -634,8 +624,6 @@ func TestRemoveOrderFillAmount(t *testing.T) { expectedMultiStoreWrites: []string{ types.OrderAmountFilledKeyPrefix + string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), }, }, "SetOrderFillAmount, RemoveOrderFillAmount, SetOrderFillAmount re-creates the fill amount": { @@ -668,12 +656,6 @@ func TestRemoveOrderFillAmount(t *testing.T) { string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), types.OrderAmountFilledKeyPrefix + string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), }, }, "RemoveOrderFillAmount does not delete fill amounts for other orders": { @@ -704,12 +686,6 @@ func TestRemoveOrderFillAmount(t *testing.T) { expectedMultiStoreWrites: []string{ types.OrderAmountFilledKeyPrefix + string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Bob_Num0_Id0_Clob1_Sell10_Price15_GTB20.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.Order_Bob_Num0_Id0_Clob1_Sell10_Price15_GTB20.OrderId.ToStateKey()), types.OrderAmountFilledKeyPrefix + string(constants.Order_Bob_Num0_Id0_Clob1_Sell10_Price15_GTB20.OrderId.ToStateKey()), types.OrderAmountFilledKeyPrefix + diff --git a/protocol/x/clob/keeper/orders_test.go b/protocol/x/clob/keeper/orders_test.go index e3b27261f3..3eb6427e22 100644 --- a/protocol/x/clob/keeper/orders_test.go +++ b/protocol/x/clob/keeper/orders_test.go @@ -144,14 +144,10 @@ func TestPlaceShortTermOrder(t *testing.T) { types.PrunableOrdersKeyPrefix, // Update taker order fill amount types.OrderAmountFilledKeyPrefix, - // Update taker order fill amount in memStore - types.OrderAmountFilledKeyPrefix, // Update prunable block height for maker fill amount types.PrunableOrdersKeyPrefix, // Update maker order fill amount types.OrderAmountFilledKeyPrefix, - // Update maker order fill amount in memStore - types.OrderAmountFilledKeyPrefix, }, expectedOpenInterests: map[uint32]*big.Int{ // positions fully closed @@ -396,14 +392,10 @@ func TestPlaceShortTermOrder(t *testing.T) { types.PrunableOrdersKeyPrefix, // Update taker order fill amount types.OrderAmountFilledKeyPrefix, - // Update taker order fill amount in memStore - types.OrderAmountFilledKeyPrefix, // Update prunable block height for maker fill amount types.PrunableOrdersKeyPrefix, // Update maker order fill amount types.OrderAmountFilledKeyPrefix, - // Update maker order fill amount in memStore - types.OrderAmountFilledKeyPrefix, }, expectedOpenInterests: map[uint32]*big.Int{ // 1 BTC + 0.01 BTC + 0.01 BTC filled @@ -754,14 +746,10 @@ func TestAddPreexistingStatefulOrder(t *testing.T) { indexer_manager.IndexerEventsCountKey, // Update block stats statstypes.BlockStatsKey, - // Update taker order fill amount to state and memStore. + // Update taker order fill amount to state. types.OrderAmountFilledKeyPrefix + string(constants.LongTermOrder_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTBT10.OrderId.ToStateKey()), - types.OrderAmountFilledKeyPrefix + - string(constants.LongTermOrder_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTBT10.OrderId.ToStateKey()), - // Update maker order fill amount to state and memStore. - types.OrderAmountFilledKeyPrefix + - string(constants.LongTermOrder_Dave_Num0_Id0_Clob0_Sell1BTC_Price50000_GTBT10.OrderId.ToStateKey()), + // Update maker order fill amount to state. types.OrderAmountFilledKeyPrefix + string(constants.LongTermOrder_Dave_Num0_Id0_Clob0_Sell1BTC_Price50000_GTBT10.OrderId.ToStateKey()), }, @@ -2434,11 +2422,9 @@ func TestPlaceConditionalOrdersTriggeredInLastBlock(t *testing.T) { longTermOrderPlacementBytes := ks.Cdc.MustMarshal(&longTermOrderPlacement) store := ks.ClobKeeper.GetTriggeredConditionalOrderPlacementStore(ctx) - memstore := ks.ClobKeeper.GetTriggeredConditionalOrderPlacementMemStore(ctx) orderKey := order.OrderId.ToStateKey() store.Set(orderKey, longTermOrderPlacementBytes) - memstore.Set(orderKey, longTermOrderPlacementBytes) } // Write to untriggered orders state @@ -2449,11 +2435,9 @@ func TestPlaceConditionalOrdersTriggeredInLastBlock(t *testing.T) { longTermOrderPlacementBytes := ks.Cdc.MustMarshal(&longTermOrderPlacement) store := ks.ClobKeeper.GetUntriggeredConditionalOrderPlacementStore(ctx) - memstore := ks.ClobKeeper.GetUntriggeredConditionalOrderPlacementMemStore(ctx) orderKey := order.OrderId.ToStateKey() store.Set(orderKey, longTermOrderPlacementBytes) - memstore.Set(orderKey, longTermOrderPlacementBytes) } // Assert expected order placement memclob calls. diff --git a/protocol/x/clob/keeper/stateful_order_state.go b/protocol/x/clob/keeper/stateful_order_state.go index 6afb569715..bba804d980 100644 --- a/protocol/x/clob/keeper/stateful_order_state.go +++ b/protocol/x/clob/keeper/stateful_order_state.go @@ -55,15 +55,12 @@ func (k Keeper) SetLongTermOrderPlacement( longTermOrderPlacementBytes := k.cdc.MustMarshal(&longTermOrderPlacement) // For setting long term order placements, always set conditional orders to the untriggered state store. - store, memStore := k.fetchStateStoresForOrder(ctx, order.OrderId) + store := k.fetchStateStoresForOrder(ctx, order.OrderId) orderKey := order.OrderId.ToStateKey() // Write the `LongTermOrderPlacement` to state. store.Set(orderKey, longTermOrderPlacementBytes) - // Write the `LongTermOrderPlacement` to memstore. - memStore.Set(orderKey, longTermOrderPlacementBytes) - if !found { // Increment the stateful order count. k.SetStatefulOrderCount( @@ -83,15 +80,15 @@ func (k Keeper) SetLongTermOrderPlacement( } } -// GetTriggeredConditionalOrderPlacement gets an triggered conditional order placement from the memstore. -// Returns false if no triggered conditional order exists in memstore with `orderId`. +// GetTriggeredConditionalOrderPlacement gets an triggered conditional order placement from the store. +// Returns false if no triggered conditional order exists in store with `orderId`. func (k Keeper) GetTriggeredConditionalOrderPlacement( ctx sdk.Context, orderId types.OrderId, ) (val types.LongTermOrderPlacement, found bool) { - memStore := k.GetTriggeredConditionalOrderPlacementMemStore(ctx) + store := k.GetTriggeredConditionalOrderPlacementStore(ctx) - b := memStore.Get(orderId.ToStateKey()) + b := store.Get(orderId.ToStateKey()) if b == nil { return val, false } @@ -100,15 +97,15 @@ func (k Keeper) GetTriggeredConditionalOrderPlacement( return val, true } -// GetUntriggeredConditionalOrderPlacement gets an untriggered conditional order placement from the memstore. -// Returns false if no untriggered conditional order exists in memstore with `orderId`. +// GetUntriggeredConditionalOrderPlacement gets an untriggered conditional order placement from the store. +// Returns false if no untriggered conditional order exists in store with `orderId`. func (k Keeper) GetUntriggeredConditionalOrderPlacement( ctx sdk.Context, orderId types.OrderId, ) (val types.LongTermOrderPlacement, found bool) { - memStore := k.GetUntriggeredConditionalOrderPlacementMemStore(ctx) + store := k.GetUntriggeredConditionalOrderPlacementStore(ctx) - b := memStore.Get(orderId.ToStateKey()) + b := store.Get(orderId.ToStateKey()) if b == nil { return val, false } @@ -127,9 +124,9 @@ func (k Keeper) GetLongTermOrderPlacement( // If this is a Short-Term order, panic. orderId.MustBeStatefulOrder() - _, memStore := k.fetchStateStoresForOrder(ctx, orderId) + store := k.fetchStateStoresForOrder(ctx, orderId) - b := memStore.Get(orderId.ToStateKey()) + b := store.Get(orderId.ToStateKey()) if b == nil { return val, false } @@ -148,15 +145,13 @@ func (k Keeper) DeleteLongTermOrderPlacement( // If this is a Short-Term order, panic. orderId.MustBeStatefulOrder() - store, memStore := k.fetchStateStoresForOrder(ctx, orderId) + store := k.fetchStateStoresForOrder(ctx, orderId) - // Note that since store reads/writes can cost gas we need to ensure that the number of operations is the - // same regardless of whether the memstore has the order or not. count := k.GetStatefulOrderCount(ctx, orderId.SubaccountId) orderKey := orderId.ToStateKey() - if memStore.Has(orderKey) { + if store.Has(orderKey) { if count == 0 { - log.ErrorLog(ctx, "Stateful order count is zero but order is in the memstore. Underflow", + log.ErrorLog(ctx, "Stateful order count is zero but order is in the store. Underflow", "orderId", cometbftlog.NewLazySprintf("%+v", orderId), ) } else { @@ -167,9 +162,6 @@ func (k Keeper) DeleteLongTermOrderPlacement( // Delete the `StatefulOrderPlacement` from state. store.Delete(orderKey) - // Delete the `StatefulOrderPlacement` from memstore. - memStore.Delete(orderKey) - // Set the count. k.SetStatefulOrderCount(ctx, orderId.SubaccountId, count) @@ -239,10 +231,9 @@ func (k Keeper) MustTriggerConditionalOrder( blockHeight := lib.MustConvertIntegerToUint32(ctx.BlockHeight()) - untriggeredConditionalOrderMemStore := k.GetUntriggeredConditionalOrderPlacementMemStore(ctx) untriggeredConditionalOrderStore := k.GetUntriggeredConditionalOrderPlacementStore(ctx) - bytes := untriggeredConditionalOrderMemStore.Get(orderId.ToStateKey()) + bytes := untriggeredConditionalOrderStore.Get(orderId.ToStateKey()) if bytes == nil { panic( fmt.Sprintf( @@ -262,17 +253,14 @@ func (k Keeper) MustTriggerConditionalOrder( TransactionIndex: nextStatefulOrderTransactionIndex, } - // Write the StatefulOrderPlacement to the Triggered state store/memstore. + // Write the StatefulOrderPlacement to the Triggered state store. longTermOrderPlacementBytes := k.cdc.MustMarshal(&longTermOrderPlacement) - triggeredConditionalOrderMemStore := k.GetTriggeredConditionalOrderPlacementMemStore(ctx) triggeredConditionalOrderStore := k.GetTriggeredConditionalOrderPlacementStore(ctx) orderKey := orderId.ToStateKey() triggeredConditionalOrderStore.Set(orderKey, longTermOrderPlacementBytes) - triggeredConditionalOrderMemStore.Set(orderKey, longTermOrderPlacementBytes) - // Delete the `StatefulOrderPlacement` from Untriggered state store/memstore. + // Delete the `StatefulOrderPlacement` from Untriggered state store. untriggeredConditionalOrderStore.Delete(orderKey) - untriggeredConditionalOrderMemStore.Delete(orderKey) } // MustAddOrderToStatefulOrdersTimeSlice adds a new `OrderId` to an existing time slice, or creates a new time slice @@ -367,9 +355,9 @@ func (k Keeper) IsConditionalOrderTriggered( ) (triggered bool) { // If this is not a conditional order, panic. orderId.MustBeConditionalOrder() - triggeredMemstore := k.GetTriggeredConditionalOrderPlacementMemStore(ctx) + store := k.GetTriggeredConditionalOrderPlacementStore(ctx) orderKey := orderId.ToStateKey() - return triggeredMemstore.Has(orderKey) + return store.Has(orderKey) } // RemoveExpiredStatefulOrdersTimeSlices iterates all time slices from 0 until the time specified by diff --git a/protocol/x/clob/keeper/stateful_order_state_test.go b/protocol/x/clob/keeper/stateful_order_state_test.go index cf72dd7edc..789a3bece4 100644 --- a/protocol/x/clob/keeper/stateful_order_state_test.go +++ b/protocol/x/clob/keeper/stateful_order_state_test.go @@ -167,18 +167,14 @@ func TestMustTriggerConditionalOrder(t *testing.T) { return orderPlacement, true } - triggeredConditionalOrderMemStore := ks.ClobKeeper.GetTriggeredConditionalOrderPlacementMemStore(ks.Ctx) triggeredConditionalOrderStore := ks.ClobKeeper.GetTriggeredConditionalOrderPlacementStore(ks.Ctx) - untriggeredConditionalOrderMemStore := ks.ClobKeeper.GetUntriggeredConditionalOrderPlacementMemStore(ks.Ctx) untriggeredConditionalOrderStore := ks.ClobKeeper.GetUntriggeredConditionalOrderPlacementStore(ks.Ctx) - // Verify that the triggered conditional order does not exist in untriggered memstore/store + // Verify that the triggered conditional order does not exist in untriggered store _, found = getOrderFromStore(conditionalOrder.OrderId, untriggeredConditionalOrderStore) require.False(t, found) - _, found = getOrderFromStore(conditionalOrder.OrderId, untriggeredConditionalOrderMemStore) - require.False(t, found) - // Verify that the triggered conditional order does exist in triggered memstore/store + // Verify that the triggered conditional order does exist in triggered store longTermOrderPlacement, found = getOrderFromStore(conditionalOrder.OrderId, triggeredConditionalOrderStore) require.True(t, found) require.Equal( @@ -191,8 +187,6 @@ func TestMustTriggerConditionalOrder(t *testing.T) { uint32(0), longTermOrderPlacement.PlacementIndex.BlockHeight, ) - _, found = getOrderFromStore(conditionalOrder.OrderId, triggeredConditionalOrderMemStore) - require.True(t, found) require.Equal( t, conditionalOrder, @@ -211,24 +205,18 @@ func TestMustTriggerConditionalOrder(t *testing.T) { traceDecoder.RequireKeyPrefixWrittenInSequence( t, []string{ - // Write the order to untriggered state and memStore and increment the stateful order + // Write the order to untriggered state and increment the stateful order // count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(conditionalOrder), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(conditionalOrder), types.StatefulOrderCountPrefix + orderToStringSubaccountId(conditionalOrder), types.NextStatefulOrderBlockTransactionIndexKey, - // Write to triggered state and memstore - types.TriggeredConditionalOrderKeyPrefix + - orderToStringId(conditionalOrder), + // Write to triggered state types.TriggeredConditionalOrderKeyPrefix + orderToStringId(conditionalOrder), - // Delete from state and memstore - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(conditionalOrder), + // Delete from state types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(conditionalOrder), }, @@ -338,92 +326,68 @@ func TestGetSetDeleteLongTermOrderState(t *testing.T) { traceDecoder.RequireKeyPrefixWrittenInSequence( t, []string{ - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id0_Clob0_Sell15_Price5_GTBT10), types.StatefulOrderCountPrefix + @@ -490,24 +454,18 @@ func TestGetSetDeleteLongTermOrderState_Replacements(t *testing.T) { traceDecoder.RequireKeyPrefixWrittenInSequence( t, []string{ - // Write the order to state and memStore and increment the stateful order count. + // Write the order to state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - // Write the order to state and memStore. We should not expect the stateful order + // Write the order to state. We should not expect the stateful order // count to change since this is a replacement. types.NextStatefulOrderBlockTransactionIndexKey, types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - // Delete the order from state and memStore and decrement the stateful order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), + // Delete the order from state and decrement the stateful order count. types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + @@ -623,19 +581,14 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { constants.Time_21st_Feb_2021, ) }, - expectedMultiStoreWrites: []string{ // Add first order to stateful order slice. types.StatefulOrdersTimeSlicePrefix + "2021-02-21T00:00:00.000000000", // Set first stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - // Place the first stateful order in state and memStore and increment the stateful order count. + // Place the first stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.StatefulOrderCountPrefix + @@ -645,12 +598,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set second stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - // Place the second stateful order in state and memStore and increment the stateful order count. + // Place the second stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.StatefulOrderCountPrefix + @@ -660,12 +609,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set third stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - // Place the third stateful order in state and memStore and increment the stateful order count. + // Place the third stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + @@ -708,19 +653,14 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15.OrderId, ) }, - expectedMultiStoreWrites: []string{ // Add first order to stateful order slice. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:15.000000000", // Set first stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - // Place the first stateful order in state and memStore and increment the stateful order count. + // Place the first stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.StatefulOrderCountPrefix + @@ -730,12 +670,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set second stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - // Place the second stateful order in state and memStore and increment the stateful order count. + // Place the second stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.StatefulOrderCountPrefix + @@ -745,38 +681,26 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set third stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - // Place the third stateful order in state and memStore and increment the stateful order count. + // Place the third stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), // Remove first order from stateful order slice, which removes the fill amount, stateful - // order placement from state and memStore, and decrement the stateful order count. + // order placement from state, and decrement the stateful order count. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:30.000000000", - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), // Remove second order from stateful order slice, which removes the fill amount, stateful - // order placement from state and memStore, and decrement the stateful order count. + // order placement from state, and decrement the stateful order count. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:15.000000000", types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + @@ -837,19 +761,14 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { constants.Time_21st_Feb_2021, ) }, - expectedMultiStoreWrites: []string{ // Add first order to stateful order slice. types.StatefulOrdersTimeSlicePrefix + "2021-02-21T00:00:00.000000000", // Set first stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - // Place the first stateful order in state and memStore and increment the stateful order count. + // Place the first stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.StatefulOrderCountPrefix + @@ -859,12 +778,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set second stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - // Place the second stateful order in state and memStore and increment the stateful order count. + // Place the second stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.StatefulOrderCountPrefix + @@ -873,12 +788,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { types.StatefulOrdersTimeSlicePrefix + "2021-02-21T00:00:00.000000000", types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - // Place the third stateful order in state and memStore and increment the stateful order count. + // Place the third stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.StatefulOrderCountPrefix + @@ -888,12 +799,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set fourth stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), - // Place the fourth stateful order in state and memStore and increment the stateful order count. + // Place the fourth stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), types.StatefulOrderCountPrefix + @@ -903,12 +810,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set fifth stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - // Place the fifth stateful order in state and memStore and increment the stateful order count. + // Place the fifth stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.StatefulOrderCountPrefix + @@ -918,12 +821,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set sixth stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Place the sixth stateful order in state and memStore and increment the stateful order count. + // Place the sixth stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + @@ -933,12 +832,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set seventh stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - // Place the seventh stateful order in state and memStore and increment the stateful order count. + // Place the seventh stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.StatefulOrderCountPrefix + @@ -984,12 +879,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set first stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - // Place the first stateful order in state and memStore and increment the stateful order count. + // Place the first stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.StatefulOrderCountPrefix + @@ -999,12 +890,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set second stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - // Place the second stateful order in state and memStore and increment the stateful order count. + // Place the second stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.StatefulOrderCountPrefix + @@ -1014,51 +901,35 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set third stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - // Place the third stateful order in state and memStore and increment the stateful order count. + // Place the third stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), // Remove first order from stateful order slice, which removes the fill amount, stateful - // order placement from state and memStore, and decrement the stateful order count. + // order placement from state, and decrement the stateful order count. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:15.000000000", types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), // Remove second order from stateful order slice, which removes the fill amount, stateful - // order placement from state and memStore, and decrement the stateful order count. + // order placement from state, and decrement the stateful order count. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:10.000000000", - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.StatefulOrderCountPrefix + orderToStringSubaccountId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), // Remove third order from stateful order slice, which removes the fill amount, stateful - // order placement from state and memStore, and decrement the stateful order count. + // order placement from state, and decrement the stateful order count. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:15.000000000", types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15), types.StatefulOrderCountPrefix + @@ -1103,20 +974,15 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { orders[2].OrderId, ) }, - expectedMultiStoreWrites: []string{ // Add first order to stateful order slice. types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:15.000000000", // Set first stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), - // Place the first stateful order in state and memStore and increment the stateful + // Place the first stateful order in state and increment the stateful // order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT15_StopLoss20), types.StatefulOrderCountPrefix + @@ -1126,12 +992,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set second stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), - // Place the second stateful order in state and memStore and increment the stateful order count. + // Place the second stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTBT20), types.StatefulOrderCountPrefix + @@ -1141,12 +1003,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set third stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Place the third stateful order in state and memStore and increment the stateful order count. + // Place the third stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + @@ -1156,12 +1014,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set fourth stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), - // Place the fourth stateful order in state and memStore and increment the stateful order count. + // Place the fourth stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id0_Clob0_Sell5_Price10_GTBT15_StopLoss15), types.StatefulOrderCountPrefix + @@ -1171,12 +1025,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set fifth stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), - // Place the fifth stateful order in state and memStore and increment the stateful order count. + // Place the fifth stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.UntriggeredConditionalOrderKeyPrefix + - orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.UntriggeredConditionalOrderKeyPrefix + orderToStringId(constants.ConditionalOrder_Alice_Num1_Id1_Clob0_Sell50_Price5_GTBT30_TakeProfit10), types.StatefulOrderCountPrefix + @@ -1185,12 +1035,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { types.StatefulOrdersTimeSlicePrefix + "1970-01-01T00:00:10.000000000", types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), - // Place the sixth stateful order in state and memStore and increment the stateful order count. + // Place the sixth stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num1_Id1_Clob0_Sell25_Price30_GTBT10), types.StatefulOrderCountPrefix + @@ -1200,12 +1046,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Set seventh stateful order fill amount to a non-zero value in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), - // Place the seventh stateful order in state and memStore and increment the stateful order count. + // Place the seventh stateful order in state and increment the stateful order count. types.NextStatefulOrderBlockTransactionIndexKey, - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), types.StatefulOrderCountPrefix + @@ -1215,12 +1057,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Remove seventh stateful order fill amount in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), - // Remove the seventh stateful order placement from state and memStore and decrement the stateful + // Remove the seventh stateful order placement from state and decrement the stateful // order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Bob_Num0_Id0_Clob0_Buy25_Price30_GTBT10), types.StatefulOrderCountPrefix + @@ -1230,12 +1068,8 @@ func TestGetAddAndRemoveStatefulOrderTimeSlice(t *testing.T) { // Remove third stateful order fill amount in state. types.OrderAmountFilledKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - types.OrderAmountFilledKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), - // Remove the third stateful order placement from state and memStore and decrement the stateful + // Remove the third stateful order placement from state and decrement the stateful // order count. - types.LongTermOrderPlacementKeyPrefix + - orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.LongTermOrderPlacementKeyPrefix + orderToStringId(constants.LongTermOrder_Alice_Num0_Id1_Clob1_Sell65_Price15_GTBT25), types.StatefulOrderCountPrefix + diff --git a/protocol/x/clob/keeper/stores.go b/protocol/x/clob/keeper/stores.go index e3b00d35d4..98f061067e 100644 --- a/protocol/x/clob/keeper/stores.go +++ b/protocol/x/clob/keeper/stores.go @@ -21,15 +21,6 @@ func (k Keeper) GetLongTermOrderPlacementStore(ctx sdk.Context) prefix.Store { ) } -// GetLongTermOrderPlacementMemStore fetches a state store used for creating, -// reading, updating, and deleting a stateful order placement from state. -func (k Keeper) GetLongTermOrderPlacementMemStore(ctx sdk.Context) prefix.Store { - return prefix.NewStore( - ctx.KVStore(k.memKey), - []byte(types.LongTermOrderPlacementKeyPrefix), - ) -} - // GetUntriggeredConditionalOrderPlacementStore fetches a state store used for creating, // reading, updating, and deleting untriggered conditional order placement from state. func (k Keeper) GetUntriggeredConditionalOrderPlacementStore(ctx sdk.Context) prefix.Store { @@ -39,15 +30,6 @@ func (k Keeper) GetUntriggeredConditionalOrderPlacementStore(ctx sdk.Context) pr ) } -// GetUntriggeredConditionalOrderPlacementMemStore fetches a state store used for creating, -// reading, updating, and deleting a stateful order placement from state. -func (k Keeper) GetUntriggeredConditionalOrderPlacementMemStore(ctx sdk.Context) prefix.Store { - return prefix.NewStore( - ctx.KVStore(k.memKey), - []byte(types.UntriggeredConditionalOrderKeyPrefix), - ) -} - // GetUncommittedStatefulOrderPlacementTransientStore fetches a state store used for creating, // reading, updating, and deleting a stateful order placement from transient state. func (k Keeper) GetUncommittedStatefulOrderPlacementTransientStore(ctx sdk.Context) prefix.Store { @@ -129,21 +111,17 @@ func (k Keeper) getTransientStore(ctx sdk.Context) storetypes.KVStore { func (k Keeper) fetchStateStoresForOrder( ctx sdk.Context, orderId types.OrderId, -) (store prefix.Store, memstore prefix.Store) { +) prefix.Store { orderId.MustBeStatefulOrder() if orderId.IsConditionalOrder() { triggered := k.IsConditionalOrderTriggered(ctx, orderId) if triggered { - store = k.GetTriggeredConditionalOrderPlacementStore(ctx) - memstore = k.GetTriggeredConditionalOrderPlacementMemStore(ctx) - return store, memstore + return k.GetTriggeredConditionalOrderPlacementStore(ctx) } - store = k.GetUntriggeredConditionalOrderPlacementStore(ctx) - memstore = k.GetUntriggeredConditionalOrderPlacementMemStore(ctx) - return store, memstore + return k.GetUntriggeredConditionalOrderPlacementStore(ctx) } else if orderId.IsLongTermOrder() { - return k.GetLongTermOrderPlacementStore(ctx), k.GetLongTermOrderPlacementMemStore(ctx) + return k.GetLongTermOrderPlacementStore(ctx) } panic( fmt.Sprintf( diff --git a/protocol/x/clob/types/keys.go b/protocol/x/clob/types/keys.go index 71a681832f..06f7a8eb4c 100644 --- a/protocol/x/clob/types/keys.go +++ b/protocol/x/clob/types/keys.go @@ -56,10 +56,7 @@ const ( // StatefulOrdersTimeSlicePrefix is the key to retrieve a unique list of the stateful orders that // expire at a given timestamp, sorted by order ID. StatefulOrdersTimeSlicePrefix = "ExpTm:" -) -// Store / Memstore -const ( // TriggeredConditionalOrderKeyPrefix is the key to retrieve an triggered conditional order and // information about when it was triggered. TriggeredConditionalOrderKeyPrefix = PlacedStatefulOrderKeyPrefix + "T:"