Skip to content

Commit

Permalink
Rename function, drop else claus, use realistic exponent in test case
Browse files Browse the repository at this point in the history
  • Loading branch information
UnbornAztecKing committed Jan 17, 2025
1 parent 1c24dd6 commit 69e6d40
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions protocol/streaming/full_node_streaming_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (sm *FullNodeStreamingManagerImpl) getNextAvailableSubscriptionId() uint32
return id
}

func doFilterSubaccountStreamUpdate(
func doFilterStreamUpdateBySubaccount(
orderBookUpdate *clobtypes.StreamUpdate_OrderbookUpdate,
subaccountIdNumbers []uint32,
logger log.Logger,
Expand All @@ -242,7 +242,7 @@ func doFilterSubaccountStreamUpdate(
// If a StreamUpdate_OrderUpdate contains no updates for subscribed subaccounts, drop message
// If a StreamUpdate_OrderUpdate contains updates for subscribed subaccounts, construct a new
// StreamUpdate_OrderUpdate with updates only for subscribed subaccounts
func FilterSubaccountStreamUpdates(
func FilterStreamUpdateBySubaccount(
updates []clobtypes.StreamUpdate,
subaccountIdNumbers []uint32,
logger log.Logger,
Expand All @@ -252,7 +252,7 @@ func FilterSubaccountStreamUpdates(
for _, update := range updates {
switch updateMessage := update.UpdateMessage.(type) {
case *clobtypes.StreamUpdate_OrderbookUpdate:
if doFilterSubaccountStreamUpdate(updateMessage, subaccountIdNumbers, logger) {
if doFilterStreamUpdateBySubaccount(updateMessage, subaccountIdNumbers, logger) {
filteredUpdates = append(filteredUpdates, update)
}
default:
Expand All @@ -262,9 +262,8 @@ func FilterSubaccountStreamUpdates(

if len(filteredUpdates) > 0 {
return &filteredUpdates
} else {
return nil
}
return nil
}

// Subscribe subscribes to the orderbook updates stream.
Expand Down Expand Up @@ -347,7 +346,7 @@ func (sm *FullNodeStreamingManagerImpl) Subscribe(
// to send through stream.
for updates := range subscription.updatesChannel {
if filterOrdersBySubAccountId {
filteredUpdates := FilterSubaccountStreamUpdates(updates, subaccountIdNumbers, sm.logger)
filteredUpdates := FilterStreamUpdateBySubaccount(updates, subaccountIdNumbers, sm.logger)
if filteredUpdates != nil {
updates = *filteredUpdates
}
Expand Down
4 changes: 2 additions & 2 deletions protocol/streaming/full_node_streaming_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func NewPriceUpdate(
MarketId: 1,
Price: pricestypes.MarketPrice{
Id: 1,
Exponent: 1_000_000,
Exponent: 6,
Price: 1,
},
Snapshot: true,
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestFilterStreamUpdates(t *testing.T) {

for name, testCase := range tests {
t.Run(name, func(t *testing.T) {
filteredUpdates := streaming.FilterSubaccountStreamUpdates(testCase.updates, testCase.subaccountIds, logger)
filteredUpdates := streaming.FilterStreamUpdateBySubaccount(testCase.updates, testCase.subaccountIds, logger)
if testCase.filteredUpdates != nil {
require.Equal(t, *filteredUpdates, *testCase.filteredUpdates)
} else {
Expand Down

0 comments on commit 69e6d40

Please sign in to comment.