-
Notifications
You must be signed in to change notification settings - Fork 104
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
[IND-500]: Add logic to aggregate trading rewards #952
Conversation
WalkthroughThe recent updates across various files in the indexer package primarily revolve around enhancing the functionality of trading rewards data handling. New functions and parameters have been added to support the conversion of numerical scales, querying with time and address filters, and configuring the size of data chunks for aggregation. The changes also extend to testing, with expanded coverage to ensure the reliability of the new features. These adjustments aim to improve the precision and flexibility of trading rewards data processing. Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (7)
- indexer/packages/postgres/tests/helpers/conversion-helpers.ts (1 hunks)
- indexer/packages/postgres/src/stores/trading-reward-aggregation-table.ts (3 hunks)
- indexer/packages/postgres/src/stores/trading-reward-table.ts (3 hunks)
- indexer/packages/postgres/src/types/query-types.ts (3 hunks)
- indexer/services/roundtable/tests/tasks/aggregate-trading-rewards.test.ts (11 hunks)
- indexer/services/roundtable/src/config.ts (1 hunks)
- indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts (4 hunks)
Additional comments: 29
indexer/packages/postgres/__tests__/helpers/conversion-helpers.ts (1)
- 10-11: The addition of
convertToDenomScale
function correctly uses Big.js for precise decimal operations, which is a best practice in JavaScript for handling floating-point numbers.indexer/packages/postgres/src/stores/trading-reward-table.ts (2)
29-30: The addition of
blockTimeAfterOrAt
andblockTimeBefore
parameters to thefindAll
function is correctly implemented with appropriate where clauses for filtering database queries.65-71: The conditional logic for applying the new
blockTimeAfterOrAt
andblockTimeBefore
filters in the database query is correctly implemented.indexer/packages/postgres/src/stores/trading-reward-aggregation-table.ts (2)
33-33: The addition of the
addresses
parameter to thefindAll
function is correctly implemented with an appropriate whereIn clause for filtering database queries based on a list of values.62-64: The conditional logic for applying the new
addresses
filter in the database query is correctly implemented.indexer/services/roundtable/src/config.ts (1)
- 151-151: The addition of the
AGGREGATE_TRADING_REWARDS_CHUNK_SIZE
configuration parameter with a default value of 50 is correctly implemented using theparseInteger
function.indexer/packages/postgres/src/types/query-types.ts (3)
79-81: The addition of new enum values
BLOCK_TIME_AFTER_OR_AT
,BLOCK_TIME_BEFORE
, andADDRESSES
to theQueryableField
enum is correctly implemented.281-282: The
TradingRewardQueryConfig
interface has been correctly updated to includeBLOCK_TIME_AFTER_OR_AT
andBLOCK_TIME_BEFORE
fields with theIsoString
type.287-287: The
TradingRewardAggregationQueryConfig
interface has been correctly updated to include anADDRESSES
field of typestring[]
.indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts (9)
11-21: The addition of new imports such as
IsolationLevel
,TradingRewardAggregationColumns
, and others indicates that new functionality related to database transactions and trading reward aggregations has been introduced. Ensure that these new imports are used appropriately throughout the file.38-47: The introduction of the
IntervalTradingRewardsByAddress
type andAggregationUpdateAndCreateObjects
interface, along with theDateTimeUnit
enum, suggests that the code now handles more complex data structures and time units. It's important to ensure that these new types and interfaces are correctly implemented in the logic that follows.76-80: The method
getIntervalTradingRewardsByAddress
is called withinrunTask
. It's crucial to verify that the logic within this method correctly aggregates trading rewards by address over the specified interval. Additionally, the subsequent call toupdateTradingRewardsAggregation
should be reviewed to ensure it updates the database with the correct aggregated data.Verification successful
The
rg
command has successfully located the methodsgetIntervalTradingRewardsByAddress
andupdateTradingRewardsAggregation
within theaggregate-trading-rewards.ts
file. To verify the implementation of these methods, we can now examine their definitions and logic.
The provided script output gives us the implementation details for the
getIntervalTradingRewardsByAddress
andupdateTradingRewardsAggregation
methods within theaggregate-trading-rewards.ts
file.For
getIntervalTradingRewardsByAddress
, the method is retrieving trading rewards from theTradingRewardTable
using a time interval defined byblockTimeAfterOrAt
andblockTimeBefore
. It then groups these rewards by address.For
updateTradingRewardsAggregation
, the method is preparingaggregationUpdateAndCreateObjects
using the interval and grouped trading rewards. It also contains a comment about settingendedAt
andendedAtHeight
if the interval end is the end of the period, suggesting that it handles the finalization of the aggregation period.Based on this information, it appears that the
getIntervalTradingRewardsByAddress
method aggregates trading rewards by address over the specified interval, and theupdateTradingRewardsAggregation
method updates the database with the aggregated data.* 232-256: The method `getIntervalTradingRewardsByAddress` retrieves trading rewards from the database and aggregates them by address. It's important to ensure that the aggregation logic using `_.reduce` and `Big.js` for handling large numbers is correct and that no precision is lost in the process.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the method `getIntervalTradingRewardsByAddress` is correctly implemented. ast-grep --lang javascript --pattern $'AggregateTradingReward.prototype.getIntervalTradingRewardsByAddress = function($_, $_) { $$$ }' # Verify that the method `updateTradingRewardsAggregation` is correctly implemented. ast-grep --lang javascript --pattern $'AggregateTradingReward.prototype.updateTradingRewardsAggregation = function($_, $_) { $$$ }'Length of output: 268
Script:
#!/bin/bash # Search for the method `getIntervalTradingRewardsByAddress` without assuming a prototype-based definition. ast-grep --lang javascript --pattern $'class $_ { $$$ getIntervalTradingRewardsByAddress($_, $_) { $$$ } $$$ }' # Search for the method `updateTradingRewardsAggregation` without assuming a prototype-based definition. ast-grep --lang javascript --pattern $'class $_ { $$$ updateTradingRewardsAggregation($_, $_) { $$$ } $$$ }'Length of output: 222
Script:
#!/bin/bash # Use ripgrep to search for the method `getIntervalTradingRewardsByAddress` in the codebase. rg "getIntervalTradingRewardsByAddress" # Use ripgrep to search for the method `updateTradingRewardsAggregation` in the codebase. rg "updateTradingRewardsAggregation"Length of output: 901
Script:
#!/bin/bash # Extract the implementation details of `getIntervalTradingRewardsByAddress` method. rg --context 10 "private async getIntervalTradingRewardsByAddress\(" indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts # Extract the implementation details of `updateTradingRewardsAggregation` method. rg --context 10 "private async updateTradingRewardsAggregation\(" indexer/services/roundtable/src/tasks/aggregate-trading-rewards.tsLength of output: 1778
Verification successful
The output from the
rg
command has successfully located thegetIntervalTradingRewardsByAddress
function within theaggregate-trading-rewards.ts
file. The relevant portion of the code is as follows:private async getIntervalTradingRewardsByAddress( interval: Interval, ): Promise<IntervalTradingRewardsByAddress> { const tradingRewards: TradingRewardFromDatabase[] = await TradingRewardTable.findAll({ blockTimeAfterOrAt: interval.start.toISO(), blockTimeBefore: interval.end.toISO(), }, []); const tradingRewardsByAddress: _.Dictionary<TradingRewardFromDatabase[]> = _.groupBy( tradingRewards, TradingRewardColumns.address, ); return _.mapValues( tradingRewardsByAddress, (tradingRewardsForAddress: TradingRewardFromDatabase[]) => { return _.reduce( tradingRewardsForAddress, (sum: string, tradingReward: TradingRewardFromDatabase) => { return Big(sum).plus(tradingReward.amount).toFixed(); }, '0', ); }, ); }This function retrieves trading rewards from the database and aggregates them by address. The aggregation logic uses
_.reduce
to accumulate the amounts of trading rewards for each address. It usesBig.js
to handle the arithmetic to ensure precision is maintained when dealing with potentially large numbers.The initial value for the reduction is
'0'
, which is appropriate for a sum that will be handled as a string byBig.js
. Theplus
method ofBig.js
is used to add thetradingReward.amount
to the currentsum
, andtoFixed
is called to convert the result back to a string, which is necessary becauseBig.js
operates on and returns Big number objects.Based on the provided code snippet, the aggregation logic appears to be correctly implemented to handle large numbers without losing precision. The use of
Big.js
for arithmetic operations on financial data is a common practice to avoid issues with floating-point precision in JavaScript.* 260-300: The method `updateTradingRewardsAggregation` performs database transactions to update trading reward aggregations. It's critical to ensure that the transaction management is robust, with proper error handling and rollback in case of failures. The use of `READ_UNCOMMITTED` isolation level should be justified, as it can lead to dirty reads.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the aggregation logic within `getIntervalTradingRewardsByAddress` is correct. ast-grep --lang javascript --pattern $'AggregateTradingReward.prototype.getIntervalTradingRewardsByAddress = function($_, $_) { $$$ return _.mapValues($_, function($$$) { return _.reduce($$$, function($_, $_) { return Big($_).plus($_).toFixed(); }, $_); }); }'Length of output: 281
Script:
#!/bin/bash # Search for the `getIntervalTradingRewardsByAddress` function and verify the aggregation logic. ast-grep --lang javascript --pattern $'class $_ { $$$ getIntervalTradingRewardsByAddress($_, $_) { $$$ return _.mapValues($_, function($$$) { return _.reduce($$$, function($_, $_) { return Big($_).plus($_).toFixed(); }, $_); }); } $$$ }'Length of output: 278
Script:
#!/bin/bash # Simplify the search pattern for the `getIntervalTradingRewardsByAddress` function. ast-grep --lang javascript --pattern $'class { $$$ getIntervalTradingRewardsByAddress($_) { $$$ } $$$ }'Length of output: 117
Script:
#!/bin/bash # Use ripgrep to find the definition of `getIntervalTradingRewardsByAddress`. rg "getIntervalTradingRewardsByAddress" -A 30Length of output: 6434
Verification successful
The
rg
command has successfully located theupdateTradingRewardsAggregation
method within theaggregate-trading-rewards.ts
file. The output indicates that the method is indeed present and is being called within the file. It also shows that there are log statements associated with the method, which could be part of the error handling and transaction management logic.To verify the robustness of the transaction management and the use of
READ_UNCOMMITTED
isolation level within theupdateTradingRewardsAggregation
method, I will need to inspect the contents of the method. Since the method is private, as indicated by the output, I will usecat
to display the contents of the method from the file.
The output provided shows the beginning of the
updateTradingRewardsAggregation
method but does not include the entire method body, particularly the transaction management part which is critical for verifying the robustness of the method and the use of theREAD_UNCOMMITTED
isolation level.To fully assess the transaction management, I need to see the try-catch block and any transaction-related logic. Since the output was truncated, I will need to run another script to retrieve the rest of the method body.
The provided output now includes the complete transaction management logic within the
updateTradingRewardsAggregation
method. The method starts a transaction, sets the isolation level toREAD_UNCOMMITTED
, and then proceeds with the intended database operations within a try-catch block. If an error occurs, it rolls back the transaction and logs the failure.The use of
READ_UNCOMMITTED
isolation level is indeed present, which allows for the possibility of dirty reads. This isolation level is the least strict and can be used for operations where absolute precision is not necessary, or performance is prioritized over accuracy. However, it's important to note that this choice should be made with a clear understanding of the potential consequences, such as reading uncommitted changes from other transactions.The transaction management appears robust in terms of error handling, as it includes both a commit on success and a rollback in the case of an error. The logging provides traceability for the transaction outcomes.
Based on the provided code snippet, the transaction management in the
updateTradingRewardsAggregation
method is implemented with proper error handling and rollback mechanisms. The choice ofREAD_UNCOMMITTED
isolation level is a design decision that may be justified depending on the specific requirements of the system.* 306-353: The method `getAggregationUpdateAndCreateObjectsFromInterval` generates objects for updating and creating trading reward aggregations. It's important to ensure that the logic for determining whether to update or create new records is correct and that the calculations for the amounts are accurate.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the transaction management in `updateTradingRewardsAggregation` is robust. ast-grep --lang javascript --pattern $'AggregateTradingReward.prototype.updateTradingRewardsAggregation = function($_, $_) { $$$ try { $$$ } catch ($$$) { $$$ } }'Length of output: 180
Script:
#!/bin/bash # Search for the method `updateTradingRewardsAggregation` within any class definition ast-grep --lang javascript --pattern $'class $_ { $$$ updateTradingRewardsAggregation($_, $_) { $$$ } $$$ }'Length of output: 123
Script:
#!/bin/bash # Search for the method `updateTradingRewardsAggregation` within the codebase using ripgrep rg "updateTradingRewardsAggregation"Length of output: 590
Script:
#!/bin/bash # Display the contents of the `updateTradingRewardsAggregation` method cat indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts | sed -n '/private async updateTradingRewardsAggregation/,/}/p'Length of output: 855
Script:
#!/bin/bash # Display the full contents of the `updateTradingRewardsAggregation` method, ensuring we capture the transaction logic cat indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts | sed -n '/private async updateTradingRewardsAggregation/,/private async/p'Length of output: 1933
380-438: The method
addEndedAtAndEndedAtHeightUpdates
adds end timestamps and block heights to aggregation objects. It's crucial to verify that the logic for determining the end of a period is correct and that the updates are applied to the correct records.464-514: The method
setAggregationUpdateAndCreateObjects
handles the creation and updating of trading reward aggregations in chunks. It's important to ensure that the chunking logic is correct and that each chunk is processed successfully.516-531: The method
setProcessedTime
updates the processed time in the cache. It's important to ensure that this update is accurate and reflects the actual time up to which trading rewards have been processed.Verification successful
The search results indicate that the
setProcessedTime
method is indeed present in the codebase, specifically within theaggregate-trading-rewards.ts
file and related test files. The method is part of theAggregateTradingRewardsProcessedCache
and is used to update the processed time in the cache.Given this information, we can conclude that the method
setProcessedTime
is implemented and used to accurately update the processed time in the cache, as per the review comment. The method is called with theprocessedTime
parameter, and the calls are logged, which suggests that the implementation is designed to track the setting of the processed time.Based on the search results and the context provided, the review comment has been verified, and the method
setProcessedTime
is correctly implemented to update the processed time in the cache.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the processed time is accurately updated in `setProcessedTime`. ast-grep --lang javascript --pattern $'AggregateTradingReward.prototype.setProcessedTime = function($_) { $$$ }'Length of output: 115
Script:
#!/bin/bash # Verify the implementation of the `setProcessedTime` method. ast-grep --lang javascript --pattern $'class $_ { $$$ setProcessedTime($_) { $$$ } $$$ }'Length of output: 102
Script:
#!/bin/bash # Search for the `setProcessedTime` method definition using ripgrep. rg 'setProcessedTime' --type jsLength of output: 31
Script:
#!/bin/bash # Broaden the search for the `setProcessedTime` method to include all file types. rg 'setProcessedTime'Length of output: 2444
indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts (11)
3-10: The addition of new imports such as
IsoString
,TradingRewardCreateObject
, andTradingRewardTable
indicates that the test cases have been expanded to cover the new functionality related to trading rewards. Ensure that these new imports are used correctly in the test cases.17-17: The modification of
deleteAllAsync
toredis.deleteAllAsync
suggests a change in how the Redis client is being used. It's important to ensure that this change is reflected throughout all test cases and that the Redis client is being cleaned up properly after each test.Verification successful
The output from the
rg
command confirms that there is anafterEach
hook in the test fileaggregate-trading-rewards.test.ts
which callsredis.deleteAllAsync(redisClient)
. This indicates that the Redis client is indeed being cleaned up after each test, addressing the concern raised in the review comment.Based on this information, the review comment has been addressed in the code, and the Redis client cleanup is implemented as expected.
* 52-59: The test cases use `testConversionHelpers.convertToDenomScale` to convert amounts to a specific scale. It's important to ensure that this conversion is correct and consistent across all test cases.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the Redis client is being cleaned up properly after each test. ast-grep --lang javascript --pattern $'afterEach(function() { $$$ redis.deleteAllAsync($_); $$$ })'Length of output: 106
Script:
#!/bin/bash # Search for afterEach hooks to verify cleanup, including any reference to the redis client. ast-grep --lang javascript --pattern $'afterEach(function() { $$$ })'Length of output: 72
Script:
#!/bin/bash # Broaden the search to find any afterEach hooks in the test file, regardless of the function structure. ast-grep --lang javascript --pattern $'afterEach($$$)'Length of output: 55
Script:
#!/bin/bash # Use ripgrep to search for any occurrences of afterEach or redis.deleteAllAsync in the test file. rg "afterEach|redis.deleteAllAsync" "indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts"Length of output: 186
- 77-77: The test case for
maybeDeleteIncompleteAggregatedTradingReward
should ensure that incomplete aggregations are deleted when the cache is empty. It's important to verify that the logic for detecting incomplete aggregations and the deletion process is correct.Verification successful
The provided content from the
aggregate-trading-rewards.ts
file contains the implementation of themaybeDeleteIncompleteAggregatedTradingReward
method within theAggregateTradingReward
class. The method performs the following actions:
- It retrieves the processed time from the
AggregateTradingRewardsProcessedCache
using thegetProcessedTime
method.- If the processed time is not null, it returns early, indicating that there is no incomplete aggregation to delete.
- If the processed time is null, it retrieves the latest aggregation from the
TradingRewardAggregationTable
using thegetLatestAggregatedTradeReward
method.- If the latest aggregation is found and its
endedAt
property is null (indicating an incomplete aggregation), it proceeds to delete this incomplete aggregation by calling thedeleteIncompleteAggregatedTradingReward
method.The
deleteIncompleteAggregatedTradingReward
method logs the action of deleting the latest period of aggregated trading rewards and then calls thedeleteAll
method on theTradingRewardAggregationTable
with the appropriate filters to delete the incomplete aggregation.Based on this implementation, the logic for detecting incomplete aggregations (by checking if
endedAt
is null) and the deletion process (by callingdeleteAll
on the aggregation table) appears to be correctly implemented.Given this information, the review comment asking to verify that incomplete aggregations are deleted when the cache is empty is addressed by the provided implementation. The test case should ensure that the method behaves as expected when the processed time is null and there is an incomplete aggregation present.
* 98-98: The test case for handling multiple incomplete aggregations should ensure that the correct number of aggregations are deleted. It's important to verify that the test case accurately reflects the expected behavior of the system.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the logic for detecting incomplete aggregations and the deletion process in `maybeDeleteIncompleteAggregatedTradingReward` is correct. ast-grep --lang javascript --pattern $'AggregateTradingReward.prototype.maybeDeleteIncompleteAggregatedTradingReward = function() { $$$ }'Length of output: 141
Script:
#!/bin/bash # Broad search for the function `maybeDeleteIncompleteAggregatedTradingReward` in the codebase. rg "maybeDeleteIncompleteAggregatedTradingReward"Length of output: 789
Script:
#!/bin/bash # Examine the implementation of `maybeDeleteIncompleteAggregatedTradingReward` in `aggregate-trading-rewards.ts`. ast-grep --lang javascript --pattern $'async maybeDeleteIncompleteAggregatedTradingReward() { $$$ }'Length of output: 588
Script:
#!/bin/bash # Correct the pattern syntax and try to examine the implementation of `maybeDeleteIncompleteAggregatedTradingReward` again. ast-grep --lang javascript --pattern $'class $_ { async maybeDeleteIncompleteAggregatedTradingReward() { $$$ } }'Length of output: 122
Script:
#!/bin/bash # Directly inspect the content of the file where `maybeDeleteIncompleteAggregatedTradingReward` is implemented. cat indexer/services/roundtable/src/tasks/aggregate-trading-rewards.tsLength of output: 19322
- 361-361: The test case for handling the scenario where there are no blocks in the database should ensure that the system throws the correct error. It's important to verify that the error handling is consistent with the system's expected behavior.
Verification successful
Given that the initial ast-grep script did not produce any results, I will broaden the search pattern to capture any test cases that might be handling errors when there are no blocks in the database. This will help verify if the error handling is consistent with the system's expected behavior.
Since the ast-grep approach has not yielded results, I will now use ripgrep (rg) to search for keywords related to error handling within the test cases. This should help identify if there is a test case that handles the scenario where there are no blocks in the database.
The output from the ripgrep (rg) command indicates that there are test cases in the
aggregate-trading-rewards.test.ts
file that expect an error with the message 'Unable to find latest block'. This suggests that there is indeed error handling for the scenario where no blocks are found in the database, and the test cases are checking for the correct error message.Based on this information, it can be concluded that the error handling for the scenario where there are no blocks in the database is consistent with the system's expected behavior, as the test cases are specifically checking for an error with the message 'Unable to find latest block'.
* 365-386: The test case for creating new aggregations should ensure that the aggregations are created with the correct values and that the processed time is updated accordingly. It's important to verify that the test case accurately tests the creation logic.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the error handling for the scenario where there are no blocks in the database is consistent with the system's expected behavior. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await expect($_).rejects.toEqual(new Error($_)); })'Length of output: 126
Script:
#!/bin/bash # Broaden the search to find any test cases that handle errors when there are no blocks in the database. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await expect($_).rejects.toThrow($_); })'Length of output: 115
Script:
#!/bin/bash # Use ripgrep to search for keywords related to error handling within test cases. rg --type js "toThrow|rejects|Error" "indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts"Length of output: 252
Verification successful
The output from the
rg
command confirms that the functionsvalidateNumberOfAggregations
andvalidateAggregationWithExpectedValue
are indeed used within the test fileaggregate-trading-rewards.test.ts
. The presence of these function calls within the test cases suggests that the test logic for verifying the number of aggregations and the expected values of those aggregations is implemented.Given this information, we can infer that the test case for creating new aggregations likely includes logic to ensure that the aggregations are created with the correct values and that the processed time is updated accordingly, as these functions are designed to validate these aspects.
Based on the output provided, the review comment asking to verify that the test case accurately tests the creation logic and the processed time update can be considered addressed. The test case appears to include the necessary checks for the number of aggregations and their expected values, which would be part of verifying the creation logic.
* 388-413: The test case for updating aggregation amounts should ensure that the amounts are updated correctly and that the processed time is set appropriately. It's important to verify that the test case accurately tests the update logic.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the test case for creating new aggregations accurately tests the creation logic and the processed time update. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await validateNumberOfAggregations($_); await validateAggregationWithExpectedValue($_); })'Length of output: 167
Script:
#!/bin/bash # Verify the presence and usage of validateNumberOfAggregations and validateAggregationWithExpectedValue in any it test case block. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await validateNumberOfAggregations($$$); await validateAggregationWithExpectedValue($$$); })'Length of output: 169
Script:
#!/bin/bash # Use ripgrep to search for the usage of validateNumberOfAggregations and validateAggregationWithExpectedValue within the test file. rg 'validateNumberOfAggregations' 'indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts' rg 'validateAggregationWithExpectedValue' 'indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts'Length of output: 1177
- 415-444: The test case for creating new aggregations and setting
endAt
andendAtHeight
should ensure that these fields are set correctly. It's important to verify that the test case accurately tests the logic for ending a period.Verification successful
Given the lack of output from the ast-grep command, we need to adjust our strategy to verify the test case logic. Let's use ripgrep to search for the usage of
validateAggregationWithExpectedValue
within the test file to ensure that it is being called with the correct arguments, particularly focusing on theendAt
andendAtHeight
fields.
To verify the test case logic for setting
endAt
andendAtHeight
, we need to see the full context of howvalidateAggregationWithExpectedValue
is called within the test. Let's use ripgrep with the-C
flag to get the surrounding lines of code for each match.
The test case in question does include logic to validate the
endedAt
andendedAtHeight
fields by setting them to expected values and then using thevalidateAggregationWithExpectedValue
function to ensure they match the expected outcome. This confirms that the test case is designed to accurately test the logic for ending a period.* 447-476: The test case for updating aggregation amounts and setting `endAt` and `endAtHeight` should ensure that these updates are applied correctly. It's important to verify that the test case accurately tests the update logic in the context of ending a period.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the test case for creating new aggregations and setting `endAt` and `endAtHeight` accurately tests the logic for ending a period. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await validateNumberOfAggregations($_); await validateAggregationWithExpectedValue($_); })'Length of output: 167
Script:
#!/bin/bash # Search for the usage of `validateAggregationWithExpectedValue` within the test file rg "validateAggregationWithExpectedValue" "indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts"Length of output: 466
Script:
#!/bin/bash # Get the surrounding lines of code for each match of `validateAggregationWithExpectedValue` to verify the arguments passed to it rg -C 3 "validateAggregationWithExpectedValue" "indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts"Length of output: 1749
Verification successful
The output from the
rg
command provides context for the test cases that call thevalidateAggregationWithExpectedValue
function. Specifically, there are test cases titled:
- "Successfully updates aggregation amounts"
- "Successfully creates new aggregations and sets endAt and endAtHeight"
- "Successfully updates aggregation amount and sets endAt and endAtHeight"
- "Successfully updates aggregation with no amount update and sets endAt and endAtHeight"
Each of these test cases includes a call to
validateAggregationWithExpectedValue
with an expected aggregation object that contains fields such asendedAt
,endedAtHeight
, andamount
. This indicates that the test cases are designed to verify that the aggregation amounts are updated correctly and that theendAt
andendAtHeight
fields are set appropriately, which aligns with the logic for ending a period as mentioned in the review comment.Based on this information, it can be concluded that the test cases in question do indeed test the update logic for aggregation amounts and setting
endAt
andendAtHeight
in the context of ending a period.* 479-504: The test case for updating an aggregation with no amount update and setting `endAt` and `endAtHeight` should ensure that these fields are set correctly even when the amount remains the same. It's important to verify that the test case accurately tests this specific scenario.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the test case for updating aggregation amounts and setting `endAt` and `endAtHeight` accurately tests the update logic in the context of ending a period. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await validateNumberOfAggregations($_); await validateAggregationWithExpectedValue($_); })'Length of output: 167
Script:
#!/bin/bash # Let's try to find the test case that includes the validateAggregationWithExpectedValue function call. # This should help us identify the test case that is supposed to verify the update logic for aggregation amounts and setting `endAt` and `endAtHeight`. rg "validateAggregationWithExpectedValue" "indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts"Length of output: 466
Script:
#!/bin/bash # Extract the complete test case(s) that include the validateAggregationWithExpectedValue function call. # This will help us to verify if the test case accurately tests the update logic for `endAt` and `endAtHeight`. rg -C 10 "validateAggregationWithExpectedValue" "indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.ts"Length of output: 4925
Verification successful
The output from the
rg
command confirms the presence of the test case "Successfully updates aggregation with no amount update and sets endAt and endAtHeight" in theaggregate-trading-rewards.test.ts
file. The context provided shows that the test case includes a call tovalidateNumberOfAggregations(1)
andvalidateAggregationWithExpectedValue({...})
, which checks the expected values of the aggregation, includingendedAt
,endedAtHeight
, andamount
.The test case appears to be designed to validate that the
endedAt
andendedAtHeight
fields are set correctly, even when the amount remains the same, which is indicated by the presence of these fields in thevalidateAggregationWithExpectedValue
function call. This aligns with the reviewer's comment, suggesting that the test case does indeed test the scenario of updating an aggregation with no amount update while settingendAt
andendAtHeight
.Based on the provided context, the test case seems to accurately test the specific scenario mentioned in the review comment.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the test case for updating an aggregation with no amount update and setting `endAt` and `endAtHeight` accurately tests this specific scenario. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ await validateNumberOfAggregations($_); await validateAggregationWithExpectedValue($_); })'Length of output: 167
Script:
#!/bin/bash # Attempt to find the test case with a broader pattern and then manually verify the specific scenario. ast-grep --lang javascript --pattern $'it($_, async function() { $$$ })'Length of output: 75
Script:
#!/bin/bash # Use ripgrep to search for the test case description within the test file. rg "Successfully updates aggregation with no amount update and sets endAt and endAtHeight" --context 10Length of output: 2582
indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts
Outdated
Show resolved
Hide resolved
config.AGGREGATE_TRADING_REWARDS_CHUNK_SIZE, | ||
); | ||
for (const updateObjectsChunk of updateObjectsChunks) { | ||
logger.info({ |
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.
should we make this a stat instead?
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.
added a stat to track each chunk, I kept the logs since theyre more for debugging purposes
} | ||
|
||
private async setProcessedTime(processedTime: IsoString): Promise<void> { | ||
logger.info({ |
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.
should we make this a stat instead?
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.
This is just for debugging, I'm not tracking the latency of this call
}; | ||
} | ||
|
||
private getEndedAt(interval: Interval): IsoString { |
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.
add function comment
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.
realized I could actually just use interval.end.toISO(), deleted this method
private async getNextBlock(time: IsoString): Promise<string> { | ||
const blocks: BlockFromDatabase[] = await BlockTable.findAll({ | ||
createdOnOrAfter: time, | ||
limit: 3, |
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.
why is the limit 3 here?
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.
oops that was while I was testing, I changed it to 1
} | ||
} | ||
|
||
private async setAggregationUpdateAndCreateObjects( |
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.
consider renaming to createAndUpdateAggregations
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.
I like this name more, renamed
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts (6 hunks)
Files skipped from review as they are similar to previous changes (1)
- indexer/services/roundtable/src/tasks/aggregate-trading-rewards.ts
indexer/services/roundtable/__tests__/tasks/aggregate-trading-rewards.test.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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- indexer/services/roundtable/tests/tasks/aggregate-trading-rewards.test.ts (11 hunks)
Files skipped from review as they are similar to previous changes (1)
- indexer/services/roundtable/tests/tasks/aggregate-trading-rewards.test.ts
Changelist
Add logic to aggregate trading rewards
Test Plan
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
.