-
Notifications
You must be signed in to change notification settings - Fork 3
Fix timestamp parsing in block header #156
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
Conversation
WalkthroughAdds Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Block as AlgorandBlock (source)
participant Util as algorandBlockToHeader()
participant Header as Header object
rect #e6f7ff
Block->>Util: pass block (timestamp in seconds)
note right of Util: compute timestamp_ms = timestamp * 1000\ncreate Date(timestamp_ms)
Util->>Header: return header { timestamp: Date(...), ... }
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)packages/node/src/algorand/utils.algorand.spec.ts (1)
🔇 Additional comments (3)
Comment |
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: 0
🧹 Nitpick comments (2)
packages/node/src/algorand/utils.algorand.ts (1)
16-23: LGTM! Timestamp conversion fix is correct.The multiplication by 1000 correctly converts Algorand's Unix timestamp (seconds) to milliseconds for the JavaScript Date constructor. However, consider making the comment more descriptive for maintainability.
Apply this diff to improve the comment:
- timestamp: new Date(block.timestamp * 1000), // Add MS + timestamp: new Date(block.timestamp * 1000), // Convert from seconds to millisecondspackages/node/src/algorand/utils.algorand.spec.ts (1)
98-102: LGTM! Test correctly validates the timestamp conversion fix.The test validates that the timestamp conversion from seconds to milliseconds produces the expected Date value. The test implementation is correct and will catch any regression in the timestamp conversion logic.
Consider moving this test to a separate describe block for "Block Header Conversion" since it's testing the
algorandBlockToHeaderfunction rather than transaction filtering. This would improve test organization:describe('Block Header Conversion', () => { let app: INestApplication; let api: AlgorandApiService; let block: AlgorandBlock; beforeAll(async () => { [app, api] = await prepareApiService(); block = await api.api.getBlockByHeight(30478896); }); afterAll(async () => { await app?.close(); }); it('can correctly get a block timestamp date', () => { const header = algorandBlockToHeader(block); expect(header.timestamp).toEqual(new Date('2023-07-13T10:44:35.000Z')); }); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/node/src/algorand/utils.algorand.spec.ts(2 hunks)packages/node/src/algorand/utils.algorand.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/node/src/algorand/utils.algorand.spec.ts (1)
packages/node/src/algorand/utils.algorand.ts (1)
algorandBlockToHeader(16-23)
🔇 Additional comments (2)
packages/node/src/algorand/utils.algorand.spec.ts (1)
8-8: LGTM!The import addition is necessary for the new test case and correctly formatted.
packages/node/src/algorand/utils.algorand.ts (1)
85-98: I need to check the actual codebase to verify the timestamp format handling. Let me search for the AlgorandBlock type and how timestamps are processed.Based on my verification, I've found evidence supporting the reviewer's concern:
Algorand's block timestamp is in seconds since epoch, while SubQuery's timestamp field is stored as a unix timestamp in milliseconds.
The review comment correctly identifies a timestamp format inconsistency in the code:
- Line 21 (
algorandBlockToHeader) converts the timestamp to milliseconds- Line 92 (
filterBlockTimestamp) receivesblock.timestampdirectly in secondsThis appears to be a legitimate issue that needs verification against the actual
filterBlockTimestampimplementation to confirm the expected format.Confirm that
filterBlockTimestampexpects milliseconds format and fix line 92 accordingly.If
filterBlockTimestampfrom@subql/node-coreexpects milliseconds (consistent with SubQuery's timestamp storage), then line 92 should convert the timestamp to milliseconds before passing it to the function, similar to whatalgorandBlockToHeaderdoes at line 21.
938fa36 to
ed345cb
Compare
Coverage reportCaution Test run failed
Test suite run failedFailed tests: 3/19. Failed suites: 2/4.Report generated by 🧪jest coverage report action from ed345cb |
Description
Algorand block timestamps do not include MS so when converting to a date it would produce an incorrect time. This has now been fiexed by adding MS.
Type of change
Please delete options that are not relevant.
Checklist
Summary by CodeRabbit
Bug Fixes
Tests