-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update BlockTable.getLatest to throw an error and simplify logic #915
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ class AddressesController extends Controller { | |
): Promise<SubaccountResponseObject[]> { | ||
// TODO(IND-189): Use a transaction across all the DB queries | ||
const [subaccounts, latestBlock]: | ||
[SubaccountFromDatabase[], BlockFromDatabase | undefined] = await Promise.all([ | ||
[SubaccountFromDatabase[], BlockFromDatabase] = await Promise.all([ | ||
SubaccountTable.findAll( | ||
{ | ||
Comment on lines
82
to
87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Analysis chainThe change in the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining checks for `latestBlock` being undefined.
rg --type ts "latestBlock\s*?==\s*?undefined"
Length of output: 47 Script: #!/bin/bash
# Search for a broader pattern of checks involving `latestBlock` and `undefined`.
rg --type ts "latestBlock\s*?[=!]==?\s*?undefined"
Length of output: 288 Script: #!/bin/bash
# Check the context of the lines where `latestBlock` is being checked against `undefined`.
rg --type ts -C 3 "latestBlock\s*?[=!]==?\s*?undefined" indexer/services/comlink/src/controllers/api/v4/perpetual-positions-controller.ts
rg --type ts -C 3 "latestBlock\s*?[=!]==?\s*?undefined" indexer/packages/postgres/src/stores/block-table.ts
Length of output: 746 |
||
address, | ||
|
@@ -92,7 +92,7 @@ class AddressesController extends Controller { | |
BlockTable.getLatest(), | ||
]); | ||
|
||
if (subaccounts.length === 0 || latestBlock === undefined) { | ||
if (subaccounts.length === 0) { | ||
throw new NotFoundError(`No subaccounts found for address ${address}`); | ||
} | ||
|
||
|
@@ -175,7 +175,7 @@ class AddressesController extends Controller { | |
AssetPositionFromDatabase[], | ||
AssetFromDatabase[], | ||
MarketFromDatabase[], | ||
BlockFromDatabase | undefined, | ||
BlockFromDatabase, | ||
] = await Promise.all([ | ||
SubaccountTable.findById( | ||
subaccountId, | ||
|
@@ -197,7 +197,7 @@ class AddressesController extends Controller { | |
BlockTable.getLatest(), | ||
]); | ||
|
||
if (subaccount === undefined || latestBlock === undefined) { | ||
if (subaccount === undefined) { | ||
throw new NotFoundError( | ||
`No subaccount found with address ${address} and subaccountNumber ${subaccountNumber}`, | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1705,7 +1705,9 @@ describe('OrderRemoveHandler', () => { | |
const removedRedisOrder: RedisOrder = redisTestConstants.defaultRedisOrder; | ||
const expectedOrderUuid: string = redisTestConstants.defaultOrderUuid; | ||
|
||
const tableSpy = jest.spyOn(BlockTable, 'getLatest').mockResolvedValueOnce(undefined); | ||
const tableSpy = jest.spyOn(BlockTable, 'getLatest').mockImplementation(() => { | ||
throw new Error(); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock implementation of |
||
|
||
try { | ||
const orderRemoveJson: OrderRemoveV1 = { ...indexerExpiredOrderRemoved, removedOrderId }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script output indicates that there is still a check for
latestBlock === undefined
in theperpetual-positions-controller.ts
file. This check should be removed or replaced with appropriate error handling, given thatBlockTable.getLatest()
will now throw an error instead of returningundefined
.No output was produced for the
asset-positions-controller.ts
andaddresses-controller.ts
files, which suggests that there are no checks forlatestBlock === undefined
in these files, or the files do not exist or are not accessible. However, since we only have evidence of the check inperpetual-positions-controller.ts
, we will focus on that.Based on the provided information, the following issue has been identified:
perpetual-positions-controller.ts
file contains a check forlatestBlock === undefined
, which is no longer necessary and should be replaced with error handling to align with the new behavior ofBlockTable.getLatest()
.Analysis chain
The change to the
latestBlock
variable type fromBlockFromDatabase | undefined
toBlockFromDatabase
aligns with the PR's objective to ensure thatBlockTable.getLatest
always returns aBlockFromDatabase
object. This change will require that all usages oflatestBlock
in the codebase are updated to handle a thrown error instead of anundefined
check.Scripts Executed
The following scripts were executed for the analysis:
Script:
Length of output: 40307
Script:
Length of output: 654