Skip to content
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

Storing more fee vault info and linking to send packets #25

Merged
merged 7 commits into from
Aug 19, 2024

Conversation

mvpoyatt
Copy link
Contributor

@mvpoyatt mvpoyatt commented Aug 15, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced fee management with new properties totalRecvFeesDeposited and totalAckFeesDeposited for tracking overall fees in packet handling.
    • Introduced a new function postBlockFeeHook for improved fee processing capabilities.
  • Bug Fixes

    • Improved logic for managing fee transactions, ensuring accurate aggregation of fee entries associated with send packets.
  • Documentation

    • Updated GraphQL schema to reflect changes in the fee management structure, enhancing clarity in gas-related fields.
  • Style

    • Minor formatting adjustments for code consistency across various files.

@mvpoyatt mvpoyatt requested a review from Inkvi August 15, 2024 21:30
Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

This update enhances the fee management system for packet handling by modifying database schemas, GraphQL types, and event declarations. New properties track total received and acknowledged fees, while the focus shifts from sending to receiving gas parameters. The logic for managing fee deposits has been refined, resulting in improved clarity and functionality throughout the system.

Changes

Files Change Summary
db/migrations/...-Data.js, schema.graphql, src/model/generated/... Introduced new fields for tracking total received and acknowledged fees. Renamed gas properties to reflect receiving operations instead of sending.
src/handlers/... Updated functions to manage new fee properties, improving transaction handling and ensuring accurate tracking of fee transactions associated with send packets.

Poem

🐇 Twirling in the fields so bright,
New fees track both left and right.
Gas limits shift, and prices too,
Enhancing how we handle through.
With every hop, we cheer and play,
For clearer paths in our fee ballet! 🌼✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 7243809 and 9bf8214.

Files selected for processing (9)
  • db/migrations/1723751676020-Data.js (1 hunks)
  • schema.graphql (2 hunks)
  • src/abi/fee.ts (1 hunks)
  • src/handlers/backfill.ts (1 hunks)
  • src/handlers/fees.ts (1 hunks)
  • src/handlers/index.ts (3 hunks)
  • src/handlers/packets.ts (1 hunks)
  • src/model/generated/sendPacket.model.ts (1 hunks)
  • src/model/generated/sendPacketFeeDeposited.model.ts (1 hunks)
Additional comments not posted (12)
src/model/generated/sendPacketFeeDeposited.model.ts (1)

23-23: Property renaming approved.

The renaming of sendGasLimit to recvGasLimit and sendGasPrice to recvGasPrice reflects a semantic shift towards receiving operations. Ensure that related documentation and usage throughout the codebase are updated accordingly.

Consider verifying that all instances of these properties in the codebase have been updated to reflect the new naming convention.

Also applies to: 27-27

Verification successful

Property Renaming Verified Successfully

The renaming of sendGasLimit to recvGasLimit and sendGasPrice to recvGasPrice has been successfully reflected in the codebase. The new property names are being used in multiple files, confirming the update.

  • src/model/generated/sendPacketFeeDeposited.model.ts
  • src/handlers/index.ts
  • src/handlers/fees.ts
  • src/handlers/backfill.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of renamed properties in the codebase.

# Test: Search for the old property names. Expect: No occurrences.
rg --type ts 'sendGasLimit|sendGasPrice'

Length of output: 42


Script:

#!/bin/bash
# Description: Verify all instances of new property names in the codebase.

# Test: Search for the new property names. Expect: Occurrences found.
rg --type ts 'recvGasLimit|recvGasPrice'

Length of output: 663

src/handlers/fees.ts (1)

19-20: Parameter renaming approved.

The update to recvGasLimit and recvGasPrice in handleSendPacketFee aligns with the semantic shift towards receiving operations. Ensure that the changes are consistently applied throughout the codebase.

Consider verifying that all related logic and documentation reflect these changes.

Verification successful

Parameter renaming is consistently applied.

The new parameter names recvGasLimit and recvGasPrice are used consistently across the codebase in relevant files, confirming that the renaming aligns with the intended semantic shift.

  • src/handlers/index.ts
  • src/model/generated/sendPacketFeeDeposited.model.ts
  • src/handlers/fees.ts
  • src/handlers/backfill.ts

No occurrences of the old parameter names were found, indicating a thorough update.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of renamed parameters in the codebase.

# Test: Search for the old parameter names. Expect: No occurrences.
rg --type ts 'sendGasLimit|sendGasPrice'

Length of output: 42


Script:

#!/bin/bash
# Description: Verify all instances of the new parameter names in the codebase.

# Search for the new parameter names to ensure consistent usage.
rg --type ts 'recvGasLimit|recvGasPrice' -A 3

Length of output: 1910

db/migrations/1723751676020-Data.js (1)

1-32: Migration script approved.

The migration script correctly updates the database schema to reflect the renaming of columns and the addition of new columns and indexes. The down method is well-structured to reverse these changes.

Ensure that this migration is tested in a staging environment to verify its correctness and impact on existing data.

src/model/generated/sendPacket.model.ts (2)

102-104: Ensure consistent usage of totalAckFeesDeposited.

The property totalAckFeesDeposited is indexed and non-nullable, which is appropriate for performance and integrity. Verify that all assignments and usages of this property throughout the codebase are consistent with its intended purpose.

Verification successful

Consistent Usage of totalAckFeesDeposited Verified

The property totalAckFeesDeposited is consistently used across the codebase. It is properly initialized, updated, and declared in line with its definition as an indexed, non-nullable bigint. No inconsistencies were found in its usage.

  • Files Involved:
    • schema.graphql: Defined as non-nullable BigInt.
    • src/handlers/packets.ts: Initialized.
    • src/handlers/index.ts: Updated with arithmetic operations.
    • src/handlers/backfill.ts: Updated with arithmetic operations.
    • src/model/generated/sendPacket.model.ts: Declared as non-nullable bigint.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `totalAckFeesDeposited`.

# Test: Search for occurrences of `totalAckFeesDeposited` in the codebase.
rg --type typescript -A 5 $'totalAckFeesDeposited'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify consistent usage of `totalAckFeesDeposited`.

# Test: Search for occurrences of `totalAckFeesDeposited` in the codebase.
rg -A 5 'totalAckFeesDeposited'

Length of output: 2469


98-100: Ensure consistent usage of totalRecvFeesDeposited.

The property totalRecvFeesDeposited is indexed and non-nullable, which is appropriate for performance and integrity. Verify that all assignments and usages of this property throughout the codebase are consistent with its intended purpose.

Verification successful

Consistent Usage of totalRecvFeesDeposited Verified

The property totalRecvFeesDeposited is used consistently across the codebase. It is appropriately indexed and non-nullable, with assignments and calculations aligning with its intended purpose of tracking received fees.

  • Files Checked:
    • schema.graphql
    • src/model/generated/sendPacket.model.ts
    • src/handlers/backfill.ts
    • src/handlers/packets.ts
    • src/handlers/index.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of `totalRecvFeesDeposited`.

# Test: Search for occurrences of `totalRecvFeesDeposited` in the codebase.
rg --type typescript -A 5 $'totalRecvFeesDeposited'

Length of output: 85


Script:

#!/bin/bash
# Description: Verify consistent usage of `totalRecvFeesDeposited`.

# Test: Search for occurrences of `totalRecvFeesDeposited` in the codebase.
rg -A 5 'totalRecvFeesDeposited'

Length of output: 2263

src/abi/fee.ts (1)

8-8: Verify the impact of removing indexed from channelId and sequence.

The removal of the indexed keyword from channelId and sequence in the SendPacketFeeDeposited event may affect event filtering and retrieval. Ensure that this change aligns with the intended behavior and does not disrupt existing functionality.

src/handlers/backfill.ts (1)

167-167: Ensure correct accumulation for totalAckFeesDeposited.

The logic for updating totalAckFeesDeposited is correct, but verify that the initial value is set appropriately elsewhere in the code.

Verification successful

Initialization of totalAckFeesDeposited is Correct

The totalAckFeesDeposited variable is initialized to BigInt(0) in src/handlers/packets.ts, ensuring that it starts with a correct initial value before accumulation. This confirms that the accumulation logic is based on a properly initialized variable.

  • Initialization Location:
    • src/handlers/packets.ts: totalAckFeesDeposited: BigInt(0),
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify initialization of `totalAckFeesDeposited`.

# Test: Search for initialization and usage of `totalAckFeesDeposited`.
rg --type typescript -A 5 $'totalAckFeesDeposited'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify initialization of `totalAckFeesDeposited`.

# Test: Search for initialization and usage of `totalAckFeesDeposited` without specifying a file type.
rg -A 5 'totalAckFeesDeposited'

Length of output: 2469

schema.graphql (2)

56-57: Additions to SendPacket: Ensure proper usage and initialization.

The fields totalRecvFeesDeposited and totalAckFeesDeposited have been added to the SendPacket type. Ensure these fields are correctly initialized and used in the application logic to reflect accurate fee management.

Verification successful

Fields Properly Initialized and Used

The fields totalRecvFeesDeposited and totalAckFeesDeposited are correctly initialized and used in the codebase. They are initialized to BigInt(0) in src/handlers/packets.ts and updated with specific logic in src/handlers/backfill.ts and src/handlers/index.ts. This confirms their proper integration into the application logic for fee management.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify initialization and usage of the new fields in the codebase.

# Test: Search for the usage of the new fields. Expect: Proper initialization and usage.
rg --type js 'totalRecvFeesDeposited|totalAckFeesDeposited'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify initialization and usage of the new fields in the codebase in TypeScript files.

# Test: Search for the usage of the new fields in TypeScript files.
rg --type ts 'totalRecvFeesDeposited|totalAckFeesDeposited'

Length of output: 993


Script:

#!/bin/bash
# Description: Verify initialization and usage of the new fields in other potential contexts.

# Test: Search for the usage of the new fields in any GraphQL-related files or other relevant contexts.
rg 'totalRecvFeesDeposited|totalAckFeesDeposited'

Length of output: 1098


357-358: Field Renaming in SendPacketFeeDeposited: Verify consistency.

The fields sendGasLimit and sendGasPrice have been renamed to recvGasLimit and recvGasPrice. Ensure that all references to these fields in the codebase have been updated to prevent inconsistencies.

Verification successful

Field Renaming Verified: Consistency Confirmed

The fields sendGasLimit and sendGasPrice have been successfully renamed to recvGasLimit and recvGasPrice across the codebase. The new field names are used consistently in the relevant TypeScript files.

  • Verified usage in:
    • src/handlers/index.ts
    • src/handlers/fees.ts
    • src/handlers/backfill.ts
    • src/model/generated/sendPacketFeeDeposited.model.ts

No instances of the old field names were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency of renamed fields in the codebase.

# Test: Search for old field names to ensure they are not used. Expect: No results.
rg --type js 'sendGasLimit|sendGasPrice'

Length of output: 42


Script:

#!/bin/bash
# Description: Verify consistency of renamed fields across the codebase.

# Search for old field names in TypeScript files and documentation.
rg --type ts 'sendGasLimit|sendGasPrice'
rg --type md 'sendGasLimit|sendGasPrice'

# Verify usage of new field names in JavaScript and TypeScript files.
rg --type js 'recvGasLimit|recvGasPrice'
rg --type ts 'recvGasLimit|recvGasPrice'

Length of output: 792

src/handlers/index.ts (2)

177-179: Integration of postBlockFeeHook: Verify workflow integration.

The postBlockFeeHook function is integrated into the handler function. Ensure that this integration does not disrupt the existing workflow and that the sequence of operations is logical.

Verification successful

Integration of postBlockFeeHook Verified: Logical Workflow Sequence

The integration of postBlockFeeHook within the handler function in src/handlers/index.ts follows a logical sequence. It is executed after processing entities and other hooks, ensuring a coherent workflow. No disruptions detected.

  • File: src/handlers/index.ts
  • Lines: 177-179
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `postBlockFeeHook` in the workflow.

# Test: Check the sequence of operations in the `handler` function. Expect: Logical sequence without disruptions.
rg --type js 'handler'

Length of output: 22


Script:

#!/bin/bash
# Search for the definition and implementation of the `handler` function in TypeScript files.
ast-grep --lang typescript --pattern 'function handler($_) { $$$ }'

# Search for the usage of `postBlockFeeHook` within TypeScript files to verify its integration.
rg 'postBlockFeeHook' --type ts -A 5

Length of output: 8088


273-306: Review postBlockFeeHook: Ensure correct logic and error handling.

The postBlockFeeHook function processes sendPacketFees and updates SendPacket instances. Ensure that:

  • The logic for updating fees is correct.
  • Error handling is sufficient, especially when a SendPacket is not found.
  • The limit of 20 fee transactions per packet is appropriate and justified.
Verification successful

Review postBlockFeeHook: Logic is correct, consider improving error handling

The postBlockFeeHook function correctly updates fees for SendPacket instances and handles cases where packets are not found or have reached the transaction limit by logging messages. However, you might want to consider more robust error handling mechanisms beyond logging, such as throwing exceptions or implementing alternative error handling strategies.

  • Located in src/handlers/index.ts lines 273-306.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic and error handling in `postBlockFeeHook`.

# Test: Check for error messages and logic flow. Expect: Correct logic and sufficient error handling.
rg --type js 'postBlockFeeHook'

Length of output: 31


Script:

#!/bin/bash
# Search for the definition of the `postBlockFeeHook` function in TypeScript files.
ast-grep --lang typescript --pattern 'async function postBlockFeeHook($_, $_) { $$$ }'

Length of output: 2392

src/handlers/packets.ts (1)

45-46: Initialization of Fee Properties: Verify correctness.

The properties totalRecvFeesDeposited and totalAckFeesDeposited are initialized to BigInt(0) in handleSendPacket. Ensure these initializations are correct and align with the intended fee tracking logic.

Verification successful

Initialization of Fee Properties: Verified Correctness

The properties totalRecvFeesDeposited and totalAckFeesDeposited are correctly initialized to BigInt(0) in src/handlers/packets.ts. This initialization aligns with their intended use for accumulating fees, as demonstrated by their usage in src/handlers/index.ts and src/handlers/backfill.ts. No issues found with the initialization logic.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify initialization of fee properties in `handleSendPacket`.

# Test: Check for correct initialization and usage of fee properties. Expect: Proper initialization and logical usage.
rg --type js 'handleSendPacket'

Length of output: 31


Script:

#!/bin/bash
# Use ast-grep to search for the handleSendPacket function in the codebase.
ast-grep --pattern 'function handleSendPacket($_) { $$$ }'

Length of output: 60


Script:

#!/bin/bash
# Search for references to totalRecvFeesDeposited and totalAckFeesDeposited to understand their usage.
rg 'totalRecvFeesDeposited|totalAckFeesDeposited' -A 5

Length of output: 2864

Comment on lines 166 to 167
sendPacket.totalRecvFeesDeposited = sendPacket.totalAckFeesDeposited + BigInt(sendPacketFee.recvGasLimit * sendPacketFee.recvGasPrice);
sendPacket.totalAckFeesDeposited = sendPacket.totalAckFeesDeposited + BigInt(sendPacketFee.ackGasLimit * sendPacketFee.ackGasPrice);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the logic for updating totalRecvFeesDeposited.

The logic for updating totalRecvFeesDeposited seems incorrect. It should accumulate the recvGasLimit * recvGasPrice rather than adding it to totalAckFeesDeposited.

- sendPacket.totalRecvFeesDeposited = sendPacket.totalAckFeesDeposited + BigInt(sendPacketFee.recvGasLimit * sendPacketFee.recvGasPrice);
+ sendPacket.totalRecvFeesDeposited = sendPacket.totalRecvFeesDeposited + BigInt(sendPacketFee.recvGasLimit * sendPacketFee.recvGasPrice);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sendPacket.totalRecvFeesDeposited = sendPacket.totalAckFeesDeposited + BigInt(sendPacketFee.recvGasLimit * sendPacketFee.recvGasPrice);
sendPacket.totalAckFeesDeposited = sendPacket.totalAckFeesDeposited + BigInt(sendPacketFee.ackGasLimit * sendPacketFee.ackGasPrice);
sendPacket.totalRecvFeesDeposited = sendPacket.totalRecvFeesDeposited + BigInt(sendPacketFee.recvGasLimit * sendPacketFee.recvGasPrice);
sendPacket.totalAckFeesDeposited = sendPacket.totalAckFeesDeposited + BigInt(sendPacketFee.ackGasLimit * sendPacketFee.ackGasPrice);

Comment on lines 169 to 172
if (sendPacket.feesDeposited.length < 20) {
sendPacket.feesDeposited = sendPacket.feesDeposited.concat(sendPacketFee);
} else {
console.log(`Send packet ${sendPacket.id} already has 20 associated fee transactions`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making the fee transaction limit configurable.

The current logic limits fee transactions to 20 per packet. Consider making this limit configurable to allow flexibility based on different use cases.

- if (sendPacket.feesDeposited.length < 20) {
+ const MAX_FEE_TRANSACTIONS = 20; // Consider moving this to a configuration file
+ if (sendPacket.feesDeposited.length < MAX_FEE_TRANSACTIONS) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (sendPacket.feesDeposited.length < 20) {
sendPacket.feesDeposited = sendPacket.feesDeposited.concat(sendPacketFee);
} else {
console.log(`Send packet ${sendPacket.id} already has 20 associated fee transactions`);
const MAX_FEE_TRANSACTIONS = 20; // Consider moving this to a configuration file
if (sendPacket.feesDeposited.length < MAX_FEE_TRANSACTIONS) {
sendPacket.feesDeposited = sendPacket.feesDeposited.concat(sendPacketFee);
} else {
console.log(`Send packet ${sendPacket.id} already has 20 associated fee transactions`);

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9bf8214 and d3d8df0.

Files selected for processing (4)
  • abi/fee.json (1 hunks)
  • src/handlers/backfill.ts (1 hunks)
  • src/handlers/index.ts (3 hunks)
  • src/handlers/packets.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/handlers/backfill.ts
  • src/handlers/index.ts
Additional comments not posted (9)
abi/fee.json (8)

15-27: New error types enhance error handling.

The introduction of IncorrectFeeSent, NoFeeSent, and SenderNotDispatcher error types improves the contract's robustness by providing specific feedback for fee-related issues.


29-69: Enhanced event tracking for OpenChannelFeeDeposited.

The event now includes additional parameters, improving the observability of contract interactions.


72-88: OwnershipTransferred event parameters are correctly defined.

The event parameters remain unchanged and are correctly defined.


91-119: Enhanced event tracking for SendPacketFeeDeposited.

The event now includes additional parameters, improving the observability of contract interactions.


121-152: Refined fee validation in depositOpenChannelFee.

The function now includes expected and sent parameters, reflecting a more precise fee validation mechanism.


154-180: Improved fee processing in depositSendPacketFee.

The function now includes parameters for channelId, sequence, gasLimits, and gasPrices, allowing for more granular control over fee calculations.


183-194: owner function definition is correct.

The function remains unchanged and is correctly defined.


196-220: Function definitions are correct.

The functions renounceOwnership, transferOwnership, and withdrawFeesToOwner remain unchanged and are correctly defined.

src/handlers/packets.ts (1)

45-46: Enhanced fee tracking in handleSendPacket.

The new properties totalRecvFeesDeposited and totalAckFeesDeposited are correctly initialized, improving fee management.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d3d8df0 and 14d7499.

Files selected for processing (1)
  • src/handlers/backfill.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/handlers/backfill.ts

Inkvi
Inkvi previously approved these changes Aug 16, 2024
if (!sendPacket.feesDeposited) {
sendPacket.feesDeposited = [sendPacketFee];
}
// Store up to 20 fee transactions per packet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is 20 coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it up. Seemed like more fees than anyone would realistically add but also small enough to prevent a single row in the table from getting too bloated. Could probably be as high as 100ish without any problems though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to store individual fees? What if we just store a sum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Inkvi let me know what you think of new solution

db/migrations/1723751676020-Data.js Outdated Show resolved Hide resolved
src/handlers/index.ts Outdated Show resolved Hide resolved
src/handlers/index.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 14d7499 and 9967534.

Files selected for processing (1)
  • src/handlers/index.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/handlers/index.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9967534 and 185b289.

Files selected for processing (6)
  • db/migrations/1723751676020-Data.js (1 hunks)
  • schema.graphql (2 hunks)
  • src/handlers/backfill.ts (1 hunks)
  • src/handlers/index.ts (3 hunks)
  • src/model/generated/sendPacket.model.ts (2 hunks)
  • src/model/generated/sendPacketFeeDeposited.model.ts (3 hunks)
Files skipped from review as they are similar to previous changes (6)
  • db/migrations/1723751676020-Data.js
  • schema.graphql
  • src/handlers/backfill.ts
  • src/handlers/index.ts
  • src/model/generated/sendPacket.model.ts
  • src/model/generated/sendPacketFeeDeposited.model.ts

@Inkvi Inkvi dismissed their stale review August 16, 2024 18:22

There is still a concern about handling and storing fees correctly

schema.graphql Show resolved Hide resolved
src/handlers/backfill.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
db/migrations/1723836233391-Data.js (1)

10-11: Ensure Default Values or Migration Scripts for New Columns

The columns total_recv_fees_deposited and total_ack_fees_deposited are added as NOT NULL without default values or migration scripts for existing records. This could lead to issues with existing data. Please ensure that default values are set or migration scripts are included to handle these new columns properly.

  • File: db/migrations/1723836233391-Data.js
  • Lines: 10-11
Analysis chain

Check for default values or migration scripts for new columns.

The new columns total_recv_fees_deposited and total_ack_fees_deposited are added as NOT NULL. Ensure that there are default values or migration scripts to populate these columns for existing records.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the handling of new columns in the codebase.

# Test: Search for the initialization of new columns. Expect: Migration scripts or default values handling.
rg --type sql 'total_recv_fees_deposited|total_ack_fees_deposited'

Length of output: 217


Script:

#!/bin/bash
# Description: Search for references to the new columns in all file types to verify default values or migration scripts.

# Search for initialization or handling of the new columns in the codebase.
rg 'total_recv_fees_deposited|total_ack_fees_deposited' -A 5

Length of output: 3010

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 185b289 and 9607d40.

Files selected for processing (5)
  • db/migrations/1723836233391-Data.js (1 hunks)
  • schema.graphql (2 hunks)
  • src/handlers/backfill.ts (1 hunks)
  • src/handlers/index.ts (3 hunks)
  • src/model/generated/sendPacket.model.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • schema.graphql
  • src/handlers/index.ts
  • src/model/generated/sendPacket.model.ts
Additional comments not posted (7)
db/migrations/1723836233391-Data.js (5)

5-7: Verify the impact of dropping indexes.

Dropping indexes can affect query performance. Ensure that these indexes are not critical for read operations in the existing application logic.

Verification successful

Indexes are not critical for current application logic.

The dropped indexes are only referenced within migration files and are not used elsewhere in the codebase. This suggests they are not critical for read operations in the existing application logic.

  • IDX_36524a30939bb522f1eda95267
  • IDX_b05770c7b9f6fba9a0b12814e9
  • IDX_9415c52ccc157e1a37c9f3f623
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the dropped indexes in the codebase.

# Test: Search for the usage of the dropped indexes. Expect: No critical dependencies on these indexes.
rg --type sql 'IDX_36524a30939bb522f1eda95267|IDX_b05770c7b9f6fba9a0b12814e9|IDX_9415c52ccc157e1a37c9f3f623'

Length of output: 259


Script:

#!/bin/bash
# Description: Verify the usage of the dropped indexes in the entire codebase without filtering by file type.

# Test: Search for the usage of the dropped indexes. Expect: No critical dependencies on these indexes.
rg 'IDX_36524a30939bb522f1eda95267|IDX_b05770c7b9f6fba9a0b12814e9|IDX_9415c52ccc157e1a37c9f3f623'

Length of output: 2586


14-18: Ensure the new indexes support query performance.

The creation of new indexes should be validated to ensure they support the queries executed by the application. Check if these indexes align with the most common query patterns.


12-13: Review the change from foreign key constraint to unique constraint.

The change from a foreign key constraint to a unique constraint on send_packet_id could affect data integrity. Ensure that this change aligns with the business logic and does not introduce data consistency issues.


8-9: Ensure the renaming of columns aligns with the new logic.

The renaming of send_gas_limit to recv_gas_limit and send_gas_price to recv_gas_price should be consistent with the updated logic in the application. Verify that all related code has been updated accordingly.


22-38: Verify the reversibility of the migration.

Ensure that the down method correctly reverses the changes made in the up method. This includes restoring indexes, constraints, and column names.

Verification successful

Reversibility Verification of Migration

The down method correctly reverses the changes made in the up method. Here's a detailed comparison:

  • Indexes:

    • The up method drops indexes IDX_36524a30939bb522f1eda95267, IDX_b05770c7b9f6fba9a0b12814e9, and IDX_9415c52ccc157e1a37c9f3f623. The down method recreates these indexes.
  • Column Renames:

    • The up method renames columns send_gas_limit to recv_gas_limit and send_gas_price to recv_gas_price. The down method reverses these renames.
  • Columns:

    • The up method adds columns total_recv_fees_deposited and total_ack_fees_deposited. The down method drops these columns.
  • Constraints:

    • The up method alters constraints, dropping FK_9415c52ccc157e1a37c9f3f6235 and adding UQ_9415c52ccc157e1a37c9f3f6235. The down method reverses these changes.

The migration appears to be correctly reversible.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the reversibility of the migration.

# Test: Check that the `down` method restores the database state accurately.
# No specific command can be executed, but ensure logical consistency between `up` and `down` methods.
echo "Review the `down` method to ensure all changes from `up` are reversed."

Length of output: 286


Script:

#!/bin/bash
# Locate the `up` method in the migration file to compare with the `down` method.
ast-grep --lang javascript --pattern $'async up($_) {
  $$$
}'

Length of output: 508


Script:

#!/bin/bash
# Correct the pattern to locate the `up` method in the migration file.
ast-grep --lang javascript --pattern 'async up($$) {
  $$$
}'

Length of output: 508


Script:

#!/bin/bash
# Simplify the pattern to locate the `up` method in the migration file.
ast-grep --lang javascript --pattern 'up($_) { $$$ }'

Length of output: 492


Script:

#!/bin/bash
# Use ripgrep to locate the `up` method in the migration file.
rg 'async up' -A 20

Length of output: 60299

src/handlers/backfill.ts (2)

166-167: Correct the logic for updating totalRecvFeesDeposited.

The logic for updating totalRecvFeesDeposited seems incorrect. It should accumulate the recvGasLimit * recvGasPrice rather than adding it to totalAckFeesDeposited.


169-173: Ensure initialization of feesDeposited is consistent.

The initialization of feesDeposited as an array should be consistent with the data model. Verify that this change aligns with the intended functionality and does not introduce data consistency issues.

Verification successful

Initialization of feesDeposited is consistent with the data model.

The feesDeposited property is consistently initialized as an array across the codebase, aligning with its definition in the data models. This ensures data consistency and adheres to the intended functionality.

  • src/handlers/index.ts: Proper initialization and usage as an array.
  • src/handlers/backfill.ts: Proper initialization and usage as an array.
  • src/model/generated/channelOpenInit.model.ts: Defined as an array type.
  • src/model/generated/sendPacket.model.ts: Defined as an array type.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization of `feesDeposited` in the codebase.

# Test: Search for the usage of `feesDeposited`. Expect: Consistent handling as an array.
rg --type typescript 'feesDeposited'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the initialization of `feesDeposited` in the codebase.

# Test: Search for the usage of `feesDeposited`. Expect: Consistent handling as an array.
rg --glob '*.ts' 'feesDeposited'

Length of output: 716

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
src/handlers/index.ts (1)

Line range hint 1-49:
Improve logging for missing SendPacket instances.

Consider enhancing the log message when a SendPacket is not found to include more context, such as the chainId, srcChannelId, and sequence. This will aid in debugging.

// Example enhancement
console.warn(`SendPacket not found for chainId: ${sendPacketFee.chainId}, srcChannelId: ${sendPacketFee.srcChannelId}, sequence: ${sendPacketFee.sequence}`);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9607d40 and 1c0dc71.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (1)
  • src/handlers/index.ts (2 hunks)
Additional comments not posted (1)
src/handlers/index.ts (1)

177-178: Verify the integration of postBlockFeeHook.

The addition of postBlockFeeHook enhances fee processing. Ensure that this integration does not introduce performance bottlenecks or unhandled errors, especially with large datasets.

@mvpoyatt mvpoyatt changed the title stashing progress Storing more fee vault info and linking to send packets Aug 17, 2024
@mvpoyatt mvpoyatt merged commit ffde8b0 into main Aug 19, 2024
3 checks passed
This was referenced Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants