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

feat(torii-indexer): relation between txns and contracts #3055

Merged
merged 8 commits into from
Feb 22, 2025

Conversation

Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Feb 20, 2025

Summary by CodeRabbit

  • New Features
    • Transactions now include associated contract address details, providing enhanced data completeness.
    • The system’s transaction recording and storage have been updated to capture contract address information for improved transaction history.
    • A new table for transaction contracts has been created to optimize storage and retrieval of contract address associations.
    • The transaction processing methods have been enhanced to accept and utilize contract addresses effectively.
    • A new parameter for block numbers has been added to improve transaction tracking.

Copy link

coderabbitai bot commented Feb 20, 2025

Ohayo, sensei!

Walkthrough

The changes introduce a new parameter, contract_addresses, into multiple transaction processing methods within the Torii indexer. This update affects the Engine methods, the TransactionProcessor trait and its implementations, as well as the SQL layer for storing transactions. Additionally, the database schema is updated via a migration to include a new table for associating transactions with contract addresses.

Changes

File(s) Change Summary
crates/torii/indexer/src/engine.rs Updated process_transaction_with_events, process_transaction_with_receipt, and process_transaction method signatures to accept a new contract_addresses: &HashSet<Felt> parameter, enhancing contract handling in transaction processing.
crates/torii/indexer/src/processors/mod.rs Modified the TransactionProcessor trait’s process method signature to include contract_addresses: &HashSet<Felt> after the transaction_hash parameter.
crates/torii/indexer/src/processors/store_transaction.rs Updated the StoreTransactionProcessor implementation by adding contract_addresses: &HashSet<Felt> to the process method signature and propagating it into the call to db.store_transaction.
crates/torii/sqlite/src/lib.rs Altered the store_transaction method of the Sql struct to include the new contract_addresses parameter, enabling the storage of multiple contract addresses linked to a transaction.
crates/torii/migrations/20250220094437_transactions_contract.sql Created a new transaction_contract table with transaction_hash and contract_address columns, enforcing a unique constraint and establishing foreign key relationships to the transactions and contracts tables. Two indexes were also created for performance optimization.

Sequence Diagram(s)

sequenceDiagram
    participant E as Engine
    participant TP as TransactionProcessor
    participant DB as Database

    E->>TP: process_transaction(..., contract_addresses)
    TP->>DB: store_transaction(..., contract_addresses)
    DB-->>TP: Acknowledge storage
    TP-->>E: Return processing result
Loading

Possibly related PRs

Suggested labels

contributor

Suggested reviewers

  • glihm
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (1)
crates/torii/migrations/20250220094437_transactions_contract.sql (1)

1-1: Ohayo sensei, solid migration addition!
The SQL statement correctly adds a new contract_address column to the transactions table. Everything looks good! As a follow-up, consider if an index on this column might be beneficial in the future if queries frequently filter by contract address.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f244197 and d22d5eb.

📒 Files selected for processing (5)
  • crates/torii/indexer/src/engine.rs (3 hunks)
  • crates/torii/indexer/src/processors/mod.rs (1 hunks)
  • crates/torii/indexer/src/processors/store_transaction.rs (1 hunks)
  • crates/torii/migrations/20250220094437_transactions_contract.sql (1 hunks)
  • crates/torii/sqlite/src/lib.rs (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: ci
crates/torii/sqlite/src/lib.rs

[error] 557-557: Rust formatting check failed. Please run 'rustfmt' to format the code.

crates/torii/indexer/src/engine.rs

[error] 721-721: Rust formatting check failed. Please run 'rustfmt' to format the code.

🔇 Additional comments (4)
crates/torii/indexer/src/processors/store_transaction.rs (1)

21-25: Ohayo! The changes look good, sensei!

The addition of the contract_address parameter and its usage in the store_transaction call are implemented correctly.

crates/torii/indexer/src/processors/mod.rs (1)

102-102: Ohayo! The trait modification looks good, sensei!

The addition of the contract_address parameter to the TransactionProcessor trait's process method is implemented correctly.

crates/torii/indexer/src/engine.rs (1)

756-768: The parameter addition looks good, sensei!

The addition of the contract_address parameter to the process_transaction method and its usage in the processor call are implemented correctly.

crates/torii/sqlite/src/lib.rs (1)

518-574: The database changes look good, sensei!

The addition of the contract_address parameter to the store_transaction method and its inclusion in the SQL insert statement are implemented correctly.

🧰 Tools
🪛 GitHub Actions: ci

[error] 557-557: Rust formatting check failed. Please run 'rustfmt' to format the code.

@Larkooo Larkooo marked this pull request as draft February 20, 2025 10:37
@Larkooo Larkooo marked this pull request as ready for review February 20, 2025 13:59
@Larkooo Larkooo changed the title feat(torii-indexer): relation between txns and contract feat(torii-indexer): relation between txns and contracts Feb 20, 2025
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 9.52381% with 19 lines in your changes missing coverage. Please review.

Project coverage is 57.64%. Comparing base (f244197) to head (3b8031d).

Files with missing lines Patch % Lines
crates/torii/sqlite/src/lib.rs 0.00% 14 Missing ⚠️
crates/torii/indexer/src/engine.rs 33.33% 4 Missing ⚠️
.../torii/indexer/src/processors/store_transaction.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3055      +/-   ##
==========================================
- Coverage   57.65%   57.64%   -0.01%     
==========================================
  Files         439      439              
  Lines       59437    59448      +11     
==========================================
+ Hits        34267    34270       +3     
- Misses      25170    25178       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Nitpick comments (1)
crates/torii/sqlite/src/lib.rs (1)

576-583: Consider adding an index for better query performance, sensei!

The new many-to-many relationship table transaction_contract would benefit from an index to optimize queries that look up transactions by contract address or vice versa.

Add this index creation statement:

+self.executor.send(QueryMessage::other(
+    "CREATE INDEX IF NOT EXISTS idx_transaction_contract_lookup ON transaction_contract \
+     (contract_address, transaction_hash)".to_string(),
+    vec![],
+))?;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f8c815 and 68b8673.

📒 Files selected for processing (1)
  • crates/torii/sqlite/src/lib.rs (4 hunks)
🔇 Additional comments (1)
crates/torii/sqlite/src/lib.rs (1)

518-518: Ohayo! The parameter addition looks good, sensei!

The use of &HashSet<Felt> is an efficient choice for storing unique contract addresses.

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

🧹 Nitpick comments (1)
crates/torii/sqlite/src/lib.rs (1)

575-582: Consider adding an index for better query performance.

While the implementation correctly handles multiple contract addresses, adding an index on the transaction_contract table would improve query performance when looking up transactions by contract address.

Add the following index after the loop:

+        self.executor.send(QueryMessage::other(
+            "CREATE INDEX IF NOT EXISTS idx_transaction_contract_address ON transaction_contract \
+             (contract_address)",
+            vec![],
+        ))?;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68b8673 and 3b8031d.

📒 Files selected for processing (3)
  • crates/torii/indexer/src/processors/store_transaction.rs (2 hunks)
  • crates/torii/migrations/20250220094437_transactions_contract.sql (1 hunks)
  • crates/torii/sqlite/src/lib.rs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/torii/indexer/src/processors/store_transaction.rs
  • crates/torii/migrations/20250220094437_transactions_contract.sql
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: clippy
🔇 Additional comments (3)
crates/torii/sqlite/src/lib.rs (3)

1-1: LGTM, sensei!

The HashSet import is correctly added alongside other collection imports.


514-520: Ohayo! The method signature changes look good!

The parameter changes align with the requirements, using appropriate types for block numbers and contract addresses.


556-573: Nice work on the transaction storage, sensei!

The SQL statement is properly formatted and the transaction hash cloning is necessary for the subsequent contract relationship storage.

@Larkooo Larkooo enabled auto-merge (squash) February 21, 2025 09:02
Comment on lines +562 to +563
transaction_hash.clone(),
transaction_hash.clone(),
Copy link
Collaborator

@glihm glihm Feb 21, 2025

Choose a reason for hiding this comment

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

We still need the two of them? Or one should be enough?

@Larkooo Larkooo merged commit 0ad2796 into dojoengine:main Feb 22, 2025
13 of 15 checks passed
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.

2 participants