-
Notifications
You must be signed in to change notification settings - Fork 68
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
Conversation
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
error @permaweb/aoconnect@0.0.57: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22" 📝 WalkthroughWalkthroughThe pull request introduces modifications to the import data scripts, focusing on restructuring the handling of data directories and types. The changes involve updating Changes
Sequence DiagramsequenceDiagram
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
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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.
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 forbundleType
.
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, only1.0.0
and2.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
📒 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 ofwriteDataItemsPerBlockCount
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
: IntroducedANS104_DIR
replaces the outdated bundles directory.
Aligns with the updated approach for version-specific bundle types.
37-37
: Renaming import type to includeans104
andall
.
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
: ExpandedimportType
condition to handleans104
andall
.
Keeps logic consistent with newly introduced directory and type.
114-114
: Function signature updated fortype: 'transactions' | 'ans104'
.
Declaring the imported data category explicitly is clearer.
124-125
: Importing ans104 fromANS104_DIR
.
Queueing bundles atendpoint = .../queue-bundle
fits the new naming.
Line range hint
167-211
: Switch statement updated to handletransaction
,ans104
, orall
.
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
: Addingdata-items-per-block*
to ignore list.
Prevents large CSV exports from cluttering the repo.
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); |
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.
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.
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); |
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.
@karlprieb Looks like I can't commit this change for some reason, but it appears to be a legit issue.
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.
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!
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 enhancementThe addition of the
tags
field to the GraphQL query is necessary for determining bundle types.
187-187
: LGTM: Bundle type determination logicThe 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 implementationThe implementation correctly tracks data items per block using a counter map.
370-412
: LGTM: Data items count trackingThe implementation correctly:
- Creates timestamped CSV files
- Includes per-block counts and total count
- Handles directory creation and error cases
474-519
: LGTM: Updated progress loggingThe progress logging now correctly tracks and displays counts for both ANS-102 and ANS-104 bundles.
330-330
: Verify bundle type assumptionThe 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:
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); | ||
} | ||
} |
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.
Fix the incorrect bundle type caching logic
The caching implementation has potential issues:
- Line 306-308: The cached value is not properly destructured
- 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.
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); | |
} | |
} |
No description provided.