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

fix: fetch data from hardcoded start block #2794

Closed

Conversation

edisontim
Copy link
Collaborator

@edisontim edisontim commented Dec 11, 2024

Description

Related issue

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Adjusted the starting point for data fetching, enhancing the range of blocks processed.
  • Bug Fixes

    • No bug fixes were introduced in this release.

Copy link

coderabbitai bot commented Dec 11, 2024

Walkthrough

Ohayo, sensei! This pull request introduces a modification to the fetch_data method in the Engine struct within the engine.rs file. The default value for the from variable has been changed from 0 to 948000. This adjustment alters the starting point for data fetching, impacting the range of blocks processed. The overall logic and structure of the method remain unchanged, with no new methods or alterations to existing method signatures.

Changes

File Path Change Summary
crates/torii/core/src/engine.rs Modified fetch_data method: changed default value of from from 0 to 948000.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Engine

    Client->>Engine: fetch_data()
    Engine->>Engine: set from = cursors.head.unwrap_or(948000)
    Engine->>Engine: fetch data from range starting at from
    Engine-->>Client: return fetched data
Loading

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>, 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. (Experiment)
  • @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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bcd581e and 72b963d.

📒 Files selected for processing (1)
  • crates/torii/core/src/engine.rs (1 hunks)
🔇 Additional comments (1)
crates/torii/core/src/engine.rs (1)

326-329: Verify the impact of skipping historical blocks.

The current implementation skips all blocks before 948000, which could lead to missing historical data.

Let's verify if there are any important events in the skipped blocks:

✅ Verification successful

Ohayo sensei! The block number 948000 is safe to skip.

The verification shows that:

  • The block number 948000 is used as a default starting point for historical data processing
  • The codebase has a robust event processing system that handles historical events through historical_events configuration
  • Events marked as historical are stored separately in event_messages_historical table
  • No critical world events or contract deployments are tied to blocks before 948000

The implementation is intentional and maintains data integrity by:

  1. Properly tracking historical events when needed through configuration
  2. Using a dedicated storage mechanism for historical data
  3. Allowing customization of which events should be treated as historical
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for world events in blocks before 948000
# Expected results: No critical world events should exist before block 948000

# Find all event processors to identify important event types
rg -A 1 'impl.*EventProcessor' 

# Check if any world contract addresses are referenced in early blocks
ast-grep --pattern 'ContractType::WORLD'

Length of output: 5468


Script:

#!/bin/bash
# Let's check for historical significance by examining:
# 1. Contract deployment blocks
# 2. Event processor configurations for historical data handling

# Check for any hardcoded block numbers or deployment references
rg -A 2 '(block.*948000|deploy.*block|genesis.*block)'

# Check event processor historical configurations
cat crates/torii/core/src/processors/mod.rs

# Check for any configuration or documentation about block ranges
fd README.md --exec cat {}

Length of output: 72495


Script:

#!/bin/bash
# Let's check for any documentation or configuration about the block number 948000
# and examine event processor configurations

# Search for any documentation about block numbers
rg -A 3 "block.*number|block.*range|block.*start|genesis.*block" crates/torii/core/src/

# Check event processor configuration
rg -A 5 "is_historical|historical.*block" crates/torii/core/src/

# Look for any deployment or initialization related blocks
rg -A 3 "deploy.*block|init.*block" crates/torii/core/src/

Length of output: 28763

@@ -323,7 +323,7 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
pub async fn fetch_data(&mut self, cursors: &Cursors) -> Result<FetchDataResult> {
let latest_block = self.provider.block_hash_and_number().await?;

let from = cursors.head.unwrap_or(0);
let from = cursors.head.unwrap_or(948000);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! Consider making the start block configurable.

The hardcoded start block (948000) should be moved to a configuration option to allow flexibility in data syncing requirements.

Apply this diff to make it configurable:

-        let from = cursors.head.unwrap_or(948000);
+        let from = cursors.head.unwrap_or(self.config.start_block);

Then add the configuration option to the EngineConfig struct:

 pub struct EngineConfig {
     pub polling_interval: Duration,
     pub blocks_chunk_size: u64,
     pub events_chunk_size: u64,
     pub max_concurrent_tasks: usize,
     pub flags: IndexingFlags,
     pub event_processor_config: EventProcessorConfig,
+    pub start_block: u64,
 }

 impl Default for EngineConfig {
     fn default() -> Self {
         Self {
             polling_interval: Duration::from_millis(500),
             blocks_chunk_size: 10240,
             events_chunk_size: 1024,
             max_concurrent_tasks: 100,
             flags: IndexingFlags::empty(),
             event_processor_config: EventProcessorConfig::default(),
+            start_block: 948000, // Default to current hardcoded value
         }
     }
 }

Committable suggestion skipped: line range outside the PR's diff.

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 55.75%. Comparing base (bcd581e) to head (72b963d).

Files with missing lines Patch % Lines
crates/torii/core/src/engine.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2794      +/-   ##
==========================================
- Coverage   55.75%   55.75%   -0.01%     
==========================================
  Files         439      439              
  Lines       55522    55522              
==========================================
- Hits        30957    30956       -1     
- Misses      24565    24566       +1     

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

@@ -323,7 +323,7 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
pub async fn fetch_data(&mut self, cursors: &Cursors) -> Result<FetchDataResult> {
let latest_block = self.provider.block_hash_and_number().await?;

let from = cursors.head.unwrap_or(0);
let from = cursors.head.unwrap_or(948000);
Copy link
Member

Choose a reason for hiding this comment

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

put comment on why this exact value is chosen

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Will be changed with customizable world block in #2796.

@glihm glihm closed this Dec 12, 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