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(import-scripts): split ans104 and ans102 bundles #258

Merged
merged 2 commits into from
Jan 6, 2025

Conversation

karlprieb
Copy link
Collaborator

No description provided.

@karlprieb karlprieb requested a review from djwhitt January 6, 2025 17:12
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error @permaweb/aoconnect@0.0.57: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22"
error Found incompatible module.

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the import data scripts, focusing on restructuring the handling of data directories and types. The changes involve updating .gitignore to reflect new directory paths, modifying count-fetched-ids.ts, fetch-data-gql.ts, and import-data.ts to replace references to "bundles" with "ans104" and "ans102". The scripts now support more specific data processing for different types of data items, including enhanced tag-based categorization and improved data item tracking.

Changes

File Change Summary
.gitignore - Removed: /scripts/import-data/bundles
- Added: /scripts/import-data/ans102
- Added: /scripts/import-data/ans104
- Added: /scripts/import-data/data-items-per-block*
scripts/import-data/count-fetched-ids.ts - Replaced BUNDLES_DIR with ANS104_DIR and ANS102_DIR
- Updated command-line argument handling
- Modified file reading and output messages
scripts/import-data/fetch-data-gql.ts - Added tags field to GraphQL query
- Updated getRootTxId to return bundleType
- Introduced writeDataItemsPerBlockCount function
- Categorized transactions into ans102 and ans104
scripts/import-data/import-data.ts - Replaced BUNDLES_DIR with ANS104_DIR
- Updated ImportType to include ans104 and all
- Modified command-line argument and import logic

Sequence Diagram

sequenceDiagram
    participant CLI as Command Line Interface
    participant FetchScript as fetch-data-gql.ts
    participant ImportScript as import-data.ts
    
    CLI->>FetchScript: Execute with parameters
    FetchScript->>FetchScript: Fetch transactions
    FetchScript->>FetchScript: Categorize by bundle type
    FetchScript->>FetchScript: Write data items per block
    
    CLI->>ImportScript: Execute with import type
    ImportScript->>ImportScript: Determine import directory
    ImportScript->>ImportScript: Process data items
    ImportScript-->>CLI: Complete import
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. (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.

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
Contributor

@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

🧹 Nitpick comments (4)
scripts/import-data/fetch-data-gql.ts (2)

187-187: Consider using an enum or string literal type for bundleType.
Defining a limited set of allowed bundle types may reduce potential errors and provide clearer intent.


220-232: Handle unexpected or future bundle version tags gracefully.
Currently, only 1.0.0 and 2.0.0 versions are considered. If additional versions are introduced, they may need handling in a fallback branch.

scripts/import-data/count-fetched-ids.ts (2)

42-49: Command-line arg for --ans104Dir introduced.
This is consistent with the new approach, but ensure usage docs are updated for external users.


50-54: Command-line arg for --ans102Dir introduced.
Mirrors the ans104 approach. Confirm README or usage docs are updated accordingly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 349638f and b49d22b.

📒 Files selected for processing (4)
  • .gitignore (1 hunks)
  • scripts/import-data/count-fetched-ids.ts (4 hunks)
  • scripts/import-data/fetch-data-gql.ts (6 hunks)
  • scripts/import-data/import-data.ts (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (macos-latest)
🔇 Additional comments (24)
scripts/import-data/fetch-data-gql.ts (11)

176-179: Looks good on GraphQL fields for tags.
No issues spotted with these added lines.


269-273: Data structures are well-organized.
Using Maps and Sets for categorizing transactions is straightforward and clear.


297-304: Incrementing data per block looks good.
Implementation is correct for counting data items per block.


338-338: Return structure is consistent.
No issues found with the returned object.


370-413: CSV export for data items per block is well-done.
Implementation is straightforward, correctly creates the output CSV, and appends a total row.


474-484: Introduced counters and data retrieval for ans104/ans102 appear correct.
The approach to retrieving and counting separate transaction types is aligned with the new structure.


491-493: Writing ans104 transactions to file looks fine.
No issues found.


494-496: Writing ans102 transactions to file looks fine.
No issues found.


505-507: Good use of writeDataItemsPerBlockCount in main loop.
Ensures each range's processed data is promptly written.


510-511: Incrementing ans104/ans102 counters.
Logic is correct for summing transaction counts.


518-518: Logged output for newly introduced bundle counts.
The log statement is consistent with the new approach for ans-104 and ans-102.

scripts/import-data/count-fetched-ids.ts (4)

27-28: New directory variables established for ans104 and ans102.
This creates a more explicit and maintainable directory structure.


101-106: Fetching ans104 files from the correct folder.
Implementation is appropriate for the new directory naming.


131-145: Ans104 counting logic.
Reading files, extracting block heights, and counting is aligned with the new directory structure.


147-159: Ans102 counting logic similarly implemented.
Structure mirrors ans104 and ensures consistent file handling.

scripts/import-data/import-data.ts (7)

35-35: Introduced ANS104_DIR replaces the outdated bundles directory.
Aligns with the updated approach for version-specific bundle types.


37-37: Renaming import type to include ans104 and all.
This better reflects the new data categories in the system.


82-86: Command-line arg for --ans104Dir introduced.
Implementation is consistent. Make sure any relevant docs are updated.


94-95: Expanded importType condition to handle ans104 and all.
Keeps logic consistent with newly introduced directory and type.


114-114: Function signature updated for type: 'transactions' | 'ans104'.
Declaring the imported data category explicitly is clearer.


124-125: Importing ans104 from ANS104_DIR.
Queueing bundles at endpoint = .../queue-bundle fits the new naming.


Line range hint 167-211: Switch statement updated to handle transaction, ans104, or all.
Reading from the correct directories is logically correct.

.gitignore (2)

17-18: Ignoring new ans102 and ans104 directories.
Helps keep versioned content separate and untracked.


22-22: Adding data-items-per-block* to ignore list.
Prevents large CSV exports from cluttering the repo.

Comment on lines 306 to 330
const cachedRootTxId = rootTxIdCache.get(bundleId);
const rootTxIdForBundle =
cachedRootTxId ?? (await getRootTxId(bundleId));

if (rootTxId === undefined) {
if (rootTxIdForBundle === undefined) {
txsMissingRootTx.add(bundleId);
} else {
rootTxIdsForBundles.set(bundleId, rootTxId);
bundles.get(blockHeight)?.add(rootTxId);
const { rootTxId, bundleType } = rootTxIdForBundle;
if (rootTxId !== null) {
rootTxIdCache.set(bundleId, { rootTxId, bundleType });
if (bundleType === 'ans102') {
if (!ans102.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans102.get(blockHeight)?.add(rootTxId);
} else if (bundleType === 'ans104') {
if (!ans104.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans104.get(blockHeight)?.add(rootTxId);
}
}
}
} else {
bundles.get(blockHeight)?.add(bundleId);
ans104.get(blockHeight)?.add(bundleId);
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 6, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the incorrect ans104.set call for ans102 path.
When bundleType is 'ans102', the code incorrectly calls ans104.set(blockHeight, new Set()) on line 318. This likely causes items meant for ans102 to be placed in ans104 instead.

Please apply this fix:

 if (bundleType === 'ans102') {
   if (!ans102.has(blockHeight)) {
-    ans104.set(blockHeight, new Set());
+    ans102.set(blockHeight, new Set());
   }
   ans102.get(blockHeight)?.add(rootTxId);
 } else if (bundleType === 'ans104') {
📝 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
const cachedRootTxId = rootTxIdCache.get(bundleId);
const rootTxIdForBundle =
cachedRootTxId ?? (await getRootTxId(bundleId));
if (rootTxId === undefined) {
if (rootTxIdForBundle === undefined) {
txsMissingRootTx.add(bundleId);
} else {
rootTxIdsForBundles.set(bundleId, rootTxId);
bundles.get(blockHeight)?.add(rootTxId);
const { rootTxId, bundleType } = rootTxIdForBundle;
if (rootTxId !== null) {
rootTxIdCache.set(bundleId, { rootTxId, bundleType });
if (bundleType === 'ans102') {
if (!ans102.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans102.get(blockHeight)?.add(rootTxId);
} else if (bundleType === 'ans104') {
if (!ans104.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans104.get(blockHeight)?.add(rootTxId);
}
}
}
} else {
bundles.get(blockHeight)?.add(bundleId);
ans104.get(blockHeight)?.add(bundleId);
const cachedRootTxId = rootTxIdCache.get(bundleId);
const rootTxIdForBundle =
cachedRootTxId ?? (await getRootTxId(bundleId));
if (rootTxIdForBundle === undefined) {
txsMissingRootTx.add(bundleId);
} else {
const { rootTxId, bundleType } = rootTxIdForBundle;
if (rootTxId !== null) {
rootTxIdCache.set(bundleId, { rootTxId, bundleType });
if (bundleType === 'ans102') {
if (!ans102.has(blockHeight)) {
ans102.set(blockHeight, new Set());
}
ans102.get(blockHeight)?.add(rootTxId);
} else if (bundleType === 'ans104') {
if (!ans104.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans104.get(blockHeight)?.add(rootTxId);
}
}
}
} else {
ans104.get(blockHeight)?.add(bundleId);

Copy link
Collaborator

Choose a reason for hiding this comment

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

@karlprieb Looks like I can't commit this change for some reason, but it appears to be a legit issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.87%. Comparing base (19f1cb0) to head (4fcabf4).
Report is 23 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #258   +/-   ##
========================================
  Coverage    70.87%   70.87%           
========================================
  Files           35       35           
  Lines         8967     8967           
  Branches       523      523           
========================================
  Hits          6355     6355           
  Misses        2610     2610           
  Partials         2        2           

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

Copy link
Contributor

@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 UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b49d22b and 4fcabf4.

📒 Files selected for processing (1)
  • scripts/import-data/fetch-data-gql.ts (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (ubuntu-latest)
🔇 Additional comments (6)
scripts/import-data/fetch-data-gql.ts (6)

176-179: LGTM: GraphQL query enhancement

The addition of the tags field to the GraphQL query is necessary for determining bundle types.


187-187: LGTM: Bundle type determination logic

The implementation correctly identifies bundle types based on the Bundle-Version tag value:

  • '1.0.0' → ans102
  • '2.0.0' → ans104

Also applies to: 220-232


297-303: LGTM: Data items tracking implementation

The implementation correctly tracks data items per block using a counter map.


370-412: LGTM: Data items count tracking

The implementation correctly:

  • Creates timestamped CSV files
  • Includes per-block counts and total count
  • Handles directory creation and error cases

474-519: LGTM: Updated progress logging

The progress logging now correctly tracks and displays counts for both ANS-102 and ANS-104 bundles.


330-330: Verify bundle type assumption

The code assumes all unchecked bundles are ANS-104 when BUNDLES_FETCH_ROOT_TX is false. This might lead to incorrect categorization.

Run this script to verify if there are any ANS-102 bundles that might be miscategorized:

Comment on lines +306 to +327
const cachedRootTxId = rootTxIdCache.get(bundleId);
const rootTxIdForBundle =
cachedRootTxId ?? (await getRootTxId(bundleId));

if (rootTxId === undefined) {
if (rootTxIdForBundle === undefined) {
txsMissingRootTx.add(bundleId);
} else {
rootTxIdsForBundles.set(bundleId, rootTxId);
bundles.get(blockHeight)?.add(rootTxId);
const { rootTxId, bundleType } = rootTxIdForBundle;
if (rootTxId !== null) {
rootTxIdCache.set(bundleId, { rootTxId, bundleType });
if (bundleType === 'ans102') {
if (!ans102.has(blockHeight)) {
ans102.set(blockHeight, new Set());
}
ans102.get(blockHeight)?.add(rootTxId);
} else if (bundleType === 'ans104') {
if (!ans104.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans104.get(blockHeight)?.add(rootTxId);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the incorrect bundle type caching logic

The caching implementation has potential issues:

  1. Line 306-308: The cached value is not properly destructured
  2. Line 313: Destructuring is done after the undefined check

Apply this diff to fix the caching logic:

-          const cachedRootTxId = rootTxIdCache.get(bundleId);
-          const rootTxIdForBundle =
-            cachedRootTxId ?? (await getRootTxId(bundleId));
+          const cached = rootTxIdCache.get(bundleId);
+          const rootTxIdForBundle = cached ?? await getRootTxId(bundleId);

           if (rootTxIdForBundle === undefined) {
             txsMissingRootTx.add(bundleId);
           } else {
📝 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
const cachedRootTxId = rootTxIdCache.get(bundleId);
const rootTxIdForBundle =
cachedRootTxId ?? (await getRootTxId(bundleId));
if (rootTxId === undefined) {
if (rootTxIdForBundle === undefined) {
txsMissingRootTx.add(bundleId);
} else {
rootTxIdsForBundles.set(bundleId, rootTxId);
bundles.get(blockHeight)?.add(rootTxId);
const { rootTxId, bundleType } = rootTxIdForBundle;
if (rootTxId !== null) {
rootTxIdCache.set(bundleId, { rootTxId, bundleType });
if (bundleType === 'ans102') {
if (!ans102.has(blockHeight)) {
ans102.set(blockHeight, new Set());
}
ans102.get(blockHeight)?.add(rootTxId);
} else if (bundleType === 'ans104') {
if (!ans104.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans104.get(blockHeight)?.add(rootTxId);
}
}
const cached = rootTxIdCache.get(bundleId);
const rootTxIdForBundle = cached ?? await getRootTxId(bundleId);
if (rootTxIdForBundle === undefined) {
txsMissingRootTx.add(bundleId);
} else {
const { rootTxId, bundleType } = rootTxIdForBundle;
if (rootTxId !== null) {
rootTxIdCache.set(bundleId, { rootTxId, bundleType });
if (bundleType === 'ans102') {
if (!ans102.has(blockHeight)) {
ans102.set(blockHeight, new Set());
}
ans102.get(blockHeight)?.add(rootTxId);
} else if (bundleType === 'ans104') {
if (!ans104.has(blockHeight)) {
ans104.set(blockHeight, new Set());
}
ans104.get(blockHeight)?.add(rootTxId);
}
}

@djwhitt djwhitt merged commit acdbe27 into develop Jan 6, 2025
5 of 6 checks passed
@djwhitt djwhitt deleted the PE-7360-ans102 branch January 6, 2025 18:49
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