-
Notifications
You must be signed in to change notification settings - Fork 115
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
Get funding index maps for vault positions in chunks. #2525
Conversation
Co-authored-by: Adam Fraser <[email protected]>
Co-authored-by: Adam Fraser <[email protected]>
…eposit (backport #2330) (#2353) Co-authored-by: jerryfan01234 <[email protected]>
Co-authored-by: jerryfan01234 <[email protected]>
Co-authored-by: vincentwschau <[email protected]>
… (backport #2364) (#2367) Co-authored-by: vincentwschau <[email protected]>
Co-authored-by: dydxwill <[email protected]>
…#2368) (#2374) Co-authored-by: dydxwill <[email protected]>
… (backport #2376) (#2378) Co-authored-by: vincentwschau <[email protected]>
…2410) Co-authored-by: roy-dydx <[email protected]>
Co-authored-by: roy-dydx <[email protected]>
Co-authored-by: vincentwschau <[email protected]>
Co-authored-by: dydxwill <[email protected]>
Co-authored-by: dydxwill <[email protected]>
Co-authored-by: vincentwschau <[email protected]>
Co-authored-by: jerryfan01234 <[email protected]>
Co-authored-by: vincentwschau <[email protected]>
…port #2454) (#2466) Co-authored-by: vincentwschau <[email protected]>
…2474) Co-authored-by: jerryfan01234 <[email protected]>
Co-authored-by: jerryfan01234 <[email protected]>
Co-authored-by: Mohammed Affan <[email protected]>
Co-authored-by: vincentwschau <[email protected]>
Co-authored-by: Adam Fraser <[email protected]>
Co-authored-by: dydxwill <[email protected]>
…2497) Co-authored-by: dydxwill <[email protected]>
Co-authored-by: Mohammed Affan <[email protected]>
…ossing (backport #2494) (#2506) Co-authored-by: Mohammed Affan <[email protected]>
Co-authored-by: Adam Fraser <[email protected]>
…essed. (backport #2513) (#2514) Co-authored-by: vincentwschau <[email protected]>
Co-authored-by: jerryfan01234 <[email protected]>
WalkthroughThe changes in this pull request involve modifications to several files, primarily focusing on enhancing the functionality and performance of the funding index updates retrieval process. Key updates include the addition of a maximum height variable in the SQL query logic, a new configuration parameter for vault settings, improved logging and performance measurement in the vault controller, and the introduction of methods for efficient data retrieval. These changes collectively refine the data handling and observability of the vault-related operations. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 5
🧹 Outside diff range and nitpick comments (2)
indexer/services/comlink/src/config.ts (1)
66-66
: LGTM. Consider adding a comment for clarity.The addition of
VAULT_FETCH_FUNDING_INDEX_BLOCK_WINDOWS
aligns with the PR objective of chunking data retrieval for vault positions. The implementation is consistent with the existing code style.Consider adding a brief comment explaining the purpose and impact of this configuration parameter. For example:
// Defines the block window size for chunked retrieval of funding index data for vaults VAULT_FETCH_FUNDING_INDEX_BLOCK_WINDOWS: parseInteger({default: 250_000 }),indexer/packages/postgres/src/stores/funding-index-updates-table.ts (1)
245-245
: LGTM! Consider a minor optimization.The introduction of
maxheight
and its use in the SQL query is a good optimization that aligns with the PR's objective of chunking data retrieval. This should improve query performance by limiting the range of data fetched.Consider using
Math.max()
for clarity:const maxheight: number = Math.max(...heightNumbers);This change would make the intent more explicit and potentially more performant for larger arrays.
Also applies to: 259-259
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- indexer/packages/postgres/src/stores/funding-index-updates-table.ts (2 hunks)
- indexer/services/comlink/src/config.ts (1 hunks)
- indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (7 hunks)
🧰 Additional context used
🔇 Additional comments (2)
indexer/packages/postgres/src/stores/funding-index-updates-table.ts (1)
Line range hint
1-300
: Overall assessment: Changes are well-implemented and align with PR objectives.The modifications to the
findFundingIndexMaps
function effectively implement the chunking strategy for funding index map retrieval. The changes are focused and don't introduce any apparent risks to other parts of the codebase. This implementation should contribute to reducing the number of rows scanned during queries, as intended in the PR objectives.To ensure there are no unintended side effects, please run the existing unit tests for this file and confirm that all tests pass.
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (1)
1-1
: Approved: Correctly importinglogger
andstats
The import statement correctly brings in
logger
andstats
from@dydxprotocol-indexer/base
, which are used for logging and performance measurement.
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- indexer/services/comlink/src/config.ts (1 hunks)
- indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- indexer/services/comlink/src/config.ts
🧰 Additional context used
🔇 Additional comments (7)
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (7)
1-1
: New import added for logging.The
logger
import from '@dydxprotocol-indexer/base' has been added. This is a good practice for improving the observability of the application.
74-79
: Performance timing added for fetching vaults.The addition of
stats.timing
is a good practice for monitoring the performance of thegetVaultMapping
function. This will help in identifying potential bottlenecks.
Line range hint
81-107
: Performance timing added for fetching ticks, positions, and equity.Similar to the previous comment, performance timing has been added for fetching ticks, positions, and equity. This is a good practice for monitoring the performance of these operations.
Line range hint
338-392
: Performance timing added for fetching subaccount positions.Performance timing has been added for fetching subaccount positions. This is consistent with the previous additions and will help in monitoring the performance of this operation.
Line range hint
394-413
: New function call and performance timing for funding index maps.A new function
getFundingIndexMapsChunked
has been introduced to fetch funding index maps. Performance timing has also been added for this operation. This change appears to be aimed at improving efficiency in retrieving funding index maps.
579-603
: New functiongetFundingIndexMapsChunked
introduced.This function retrieves funding index maps in chunks to reduce database load. It uses the
getHeightWindows
function to process updated heights in batches. This is a good optimization for handling large datasets.
605-631
: New helper functiongetHeightWindows
introduced.This function separates an array of heights into chunks based on a window size. It's used by
getFundingIndexMapsChunked
to optimize database queries. The implementation looks correct and efficient.
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts
Outdated
Show resolved
Hide resolved
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (7 hunks)
🧰 Additional context used
🔇 Additional comments (4)
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (4)
74-79
: Ensurestats.timing
is called even if an error occursIf
getVaultMapping()
throws an error, thestats.timing
call will be skipped, and the timing metric won't be recorded. Wrap the code in atry...finally
block to ensure that timing is always recorded.
104-107
: Ensure timing metrics are recorded on errorsThe
stats.timing
call will be skipped if an error occurs before it's reached. Enclose the preceding code in atry...finally
block to guarantee timing metrics are captured even when exceptions are thrown.
389-392
: Record timing metrics even if fetching positions failsIf an error occurs during the fetching of positions, the
stats.timing
call won't execute. To ensure timing is always recorded, use atry...finally
block around the fetching logic.
409-413
: Ensure funding fetch timing is recorded on errorsThe timing metric for fetching funding will not be recorded if an error occurs before
stats.timing
is called. Wrap the fetching code in atry...finally
block to ensure the timing is always captured.
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts
Outdated
Show resolved
Hide resolved
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts
Outdated
Show resolved
Hide resolved
@Mergifyio backport release/indexer/v7.x |
✅ Backports have been created
|
(cherry picked from commit 0a28594)
#2527) Co-authored-by: vincentwschau <[email protected]>
Changelist
Chunk the funding index maps to get for each vault subaccount to reduce the amount of rows scanned. Heights to get funding index maps for will be separated into chunks that cover 250k blocks each (number of blocks per chunk can be configured).
Updated funding index map query to limit searches to both a min and max block height.
Additional fixes:
Test Plan
Existing unit tests.
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit
New Features
Improvements