Skip to content

Commit

Permalink
Fix bug with socks subaccount subscription with best effort canceled …
Browse files Browse the repository at this point in the history
…logic. (#2718)

(cherry picked from commit a601005)

# Conflicts:
#	indexer/services/socks/__tests__/lib/subscriptions.test.ts
#	indexer/services/socks/src/lib/subscription.ts
  • Loading branch information
vincentwschau authored and mergify[bot] committed Feb 18, 2025
1 parent a0de470 commit 74ff12c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,23 @@ router.get(
options: { gt: 0 },
},
},
goodTilBlockAfter: {
in: 'query',
optional: true,
isInt: {
options: { gt: 0 },
},
},
goodTilBlockTimeBeforeOrAt: {
in: 'query',
optional: true,
isISO8601: true,
},
goodTilBlockTimeAfter: {
in: 'query',
optional: true,
isISO8601: true,
},
returnLatestOrders: {
in: 'query',
isBoolean: true,
Expand Down
10 changes: 10 additions & 0 deletions indexer/services/socks/__tests__/lib/subscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,25 @@ describe('Subscriptions', () => {
const initialResponseUrlPatterns: Record<Channel, string[] | undefined> = {
[Channel.V4_ACCOUNTS]: [
'/v4/addresses/.+/subaccountNumber/.+',
<<<<<<< HEAD
'/v4/orders?.+subaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED,BEST_EFFORT_CANCELED',
=======
'/v4/orders?.+subaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED',
'/v4/orders?.+subaccountNumber.+BEST_EFFORT_CANCELED.+goodTilBlockAfter=[0-9]+',
>>>>>>> a6010055 (Fix bug with socks subaccount subscription with best effort canceled logic. (#2718))
],
[Channel.V4_CANDLES]: ['/v4/candles/perpetualMarkets/.+?resolution=.+'],
[Channel.V4_MARKETS]: ['/v4/perpetualMarkets'],
[Channel.V4_ORDERBOOK]: ['/v4/orderbooks/perpetualMarket/.+'],
[Channel.V4_TRADES]: ['/v4/trades/perpetualMarket/.+'],
[Channel.V4_PARENT_ACCOUNTS]: [
'/v4/addresses/.+/parentSubaccountNumber/.+',
<<<<<<< HEAD
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED,BEST_EFFORT_CANCELED',
=======
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+OPEN,UNTRIGGERED,BEST_EFFORT_OPENED',
'/v4/orders/parentSubaccountNumber?.+parentSubaccountNumber.+BEST_EFFORT_CANCELED.+goodTilBlockAfter=[0-9]+',
>>>>>>> a6010055 (Fix bug with socks subaccount subscription with best effort canceled logic. (#2718))
],
[Channel.V4_BLOCK_HEIGHT]: ['v4/height'],
};
Expand Down
24 changes: 24 additions & 0 deletions indexer/services/socks/src/lib/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,19 @@ export class Subscriptions {
},
transformResponse: (res) => res,
}),
<<<<<<< HEAD
blockHeightRefresher.getLatestBlockHeight(),
=======
axiosRequest({
method: RequestMethod.GET,
url: `${COMLINK_URL}/v4/orders?address=${address}&subaccountNumber=${subaccountNumber}&status=BEST_EFFORT_CANCELED&goodTilBlockAfter=${Math.max(numBlockHeight - 20, 1)}`,
timeout: config.INITIAL_GET_TIMEOUT_MS,
headers: {
'cf-ipcountry': country,
},
transformResponse: (res) => res,
}),
>>>>>>> a6010055 (Fix bug with socks subaccount subscription with best effort canceled logic. (#2718))
]);

return JSON.stringify({
Expand All @@ -588,6 +600,12 @@ export class Subscriptions {
blockHeight,
});
} catch (error) {
logger.error({
at: 'getInitialResponseForSubaccountSubscription',
message: 'Error on getting initial response for subaccount subscription',
id,
error,
});
// The subaccounts API endpoint returns a 404 for subaccounts that are not indexed, however
// such subaccounts can be subscribed to and events can be sent when the subaccounts are
// indexed to an existing subscription.
Expand Down Expand Up @@ -657,6 +675,12 @@ export class Subscriptions {
blockHeight,
});
} catch (error) {
logger.error({
at: 'getInitialResponseForParentSubaccountSubscription',
message: 'Error on getting initial response for subaccount subscription',
id,
error,
});
// The subaccounts API endpoint returns a 404 for subaccounts that are not indexed, however
// such subaccounts can be subscribed to and events can be sent when the subaccounts are
// indexed to an existing subscription.
Expand Down

0 comments on commit 74ff12c

Please sign in to comment.