Skip to content

fix: import from 2.1 #688

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

Merged
merged 1 commit into from
Feb 17, 2025
Merged

fix: import from 2.1 #688

merged 1 commit into from
Feb 17, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Feb 17, 2025

No description provided.

@gfyrag gfyrag requested a review from a team as a code owner February 17, 2025 14:12
Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

The pull request converts identifier fields (ID) from direct integers to pointer types across multiple modules. The update adds new WithID methods for both Log and Transaction types and revises code and tests to correctly dereference these pointers. Documentation headers have been simplified by removing links. Changes span the API layer, controllers, storage, and test suites, ensuring consistent handling of nullable ID values and updating data validations and logging to reflect the pointer semantics.

Changes

File(s) Change Summary
internal/README.md Updated documentation: removed links from headers, changed ID fields from int to *int for Log and Transaction, and added WithID methods.
internal/log.go, internal/transaction.go Core model changes: updated ID fields from int to *int, added WithID methods, and adjusted related functions (e.g., ComputeHash, ChainLog) to dereference ID pointers.
internal/api/bulking/bulker.go, internal/api/v1/controllers_transactions.go, internal/api/v1/controllers_transactions_create_test.go, internal/api/v2/controllers_bulk_test.go, internal/api/v2/controllers_transactions_read_test.go API layer updates: modified return values and struct field types (e.g., TxID and ID from int to *int), and updated tests to use pointer values via pointer.For(0).
internal/controller/ledger/*.go Controller updates: altered log and transaction processing to dereference pointer ID fields in logging, error messages, and method calls (including test modifications for InsertLog).
internal/storage/ledger/*.go Storage layer enhancements: replaced ID == 0 checks with ID == nil, updated transaction commit/insert operations and pagination support to handle pointer types, and refined test assertions accordingly.
internal/transaction_test.go, pkg/testserver/helpers.go, test/e2e/api_ledgers_import_test.go Test and helper updates: revised transaction creation to use WithID, wrapped integer IDs with pointer.For(), and added a new end-to-end import test scenario for ledger data.

Sequence Diagram(s)

sequenceDiagram
    participant Tester as Test Suite
    participant Import as Import Endpoint
    participant Ledger as Ledger Engine
    participant DB as Database

    Tester->>Import: Send import request with ledger and JSON logs
    Import->>Ledger: Process import request (parse logs, set pointer-based IDs)
    Ledger->>DB: Insert logs and transactions with dereferenced IDs
    DB-->>Ledger: Confirm insertion
    Ledger-->>Import: Return import success
    Import-->>Tester: Respond with imported ledger data
Loading

Possibly related PRs

Suggested labels

build-images

Suggested reviewers

  • flemzord
  • Dav-14

Poem

Oh, how I hop with glee,
IDs now dance pointer-free!
With new WithID tricks in play,
Logs and transactions lead the way. 🐰
In docs and tests, the changes shine bright,
A clever code-hop into the light!
Hop on, dear coder, into the night!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c32cdf8 and 7b49031.

⛔ Files ignored due to path filters (4)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • tools/generator/go.mod is excluded by !**/*.mod
  • tools/generator/go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (23)
  • internal/README.md (44 hunks)
  • internal/api/bulking/bulker.go (4 hunks)
  • internal/api/v1/controllers_transactions.go (1 hunks)
  • internal/api/v1/controllers_transactions_create_test.go (3 hunks)
  • internal/api/v2/controllers_bulk_test.go (12 hunks)
  • internal/api/v2/controllers_transactions_read_test.go (1 hunks)
  • internal/controller/ledger/controller_default.go (4 hunks)
  • internal/controller/ledger/controller_default_test.go (4 hunks)
  • internal/controller/ledger/log_process.go (1 hunks)
  • internal/controller/ledger/log_process_test.go (2 hunks)
  • internal/doc.go (1 hunks)
  • internal/log.go (7 hunks)
  • internal/storage/ledger/logs.go (1 hunks)
  • internal/storage/ledger/logs_test.go (5 hunks)
  • internal/storage/ledger/moves_test.go (5 hunks)
  • internal/storage/ledger/paginator_column.go (1 hunks)
  • internal/storage/ledger/resource.go (1 hunks)
  • internal/storage/ledger/transactions.go (4 hunks)
  • internal/storage/ledger/transactions_test.go (11 hunks)
  • internal/transaction.go (2 hunks)
  • internal/transaction_test.go (6 hunks)
  • pkg/testserver/helpers.go (2 hunks)
  • test/e2e/api_ledgers_import_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • internal/doc.go
🚧 Files skipped from review as they are similar to previous changes (22)
  • internal/controller/ledger/log_process.go
  • internal/storage/ledger/resource.go
  • internal/api/v2/controllers_transactions_read_test.go
  • internal/api/bulking/bulker.go
  • internal/controller/ledger/log_process_test.go
  • pkg/testserver/helpers.go
  • internal/storage/ledger/moves_test.go
  • test/e2e/api_ledgers_import_test.go
  • internal/log.go
  • internal/api/v1/controllers_transactions_create_test.go
  • internal/transaction.go
  • internal/controller/ledger/controller_default.go
  • internal/transaction_test.go
  • internal/storage/ledger/transactions_test.go
  • internal/storage/ledger/paginator_column.go
  • internal/api/v1/controllers_transactions.go
  • internal/storage/ledger/logs_test.go
  • internal/api/v2/controllers_bulk_test.go
  • internal/storage/ledger/logs.go
  • internal/storage/ledger/transactions.go
  • internal/controller/ledger/controller_default_test.go
  • internal/README.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests

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

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 82.50000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 81.55%. Comparing base (a5b1d09) to head (7b49031).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/log.go 76.92% 3 Missing ⚠️
internal/controller/ledger/controller_default.go 71.42% 2 Missing ⚠️
internal/storage/ledger/paginator_column.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #688      +/-   ##
==========================================
- Coverage   81.61%   81.55%   -0.07%     
==========================================
  Files         131      131              
  Lines        7071     7085      +14     
==========================================
+ Hits         5771     5778       +7     
- Misses        996     1004       +8     
+ Partials      304      303       -1     

☔ 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 (9)
internal/api/v1/controllers_transactions.go (1)

20-21: LGTM! Consider adding documentation for pointer fields.

The changes correctly update the ID fields to pointer types. Consider adding documentation to explain why these fields are pointers and the significance of the json:"-" tag on the ID field.

 type Ret struct {
 	Aux

 	Reverted                  bool                     `json:"reverted"`
 	PreCommitVolumes          ledger.PostCommitVolumes `json:"preCommitVolumes,omitempty"`
 	PreCommitEffectiveVolumes ledger.PostCommitVolumes `json:"preCommitEffectiveVolumes,omitempty"`
+	// TxID is a pointer to allow for null values in the JSON response
 	TxID                      *int                     `json:"txid"`
+	// ID is excluded from JSON serialization as it's used internally
 	ID                        *int                     `json:"-"`
 }
test/e2e/api_ledgers_import_test.go (2)

56-60: Verify test data integrity.

The test data contains transactions with sequential IDs starting from 0, which might not reflect real-world scenarios where IDs could have gaps or start from different values. Consider adding test cases with non-sequential IDs to ensure robust handling of imported data.


68-105: Enhance test coverage for edge cases.

While the test verifies basic import functionality, consider adding test cases for:

  1. Invalid JSON format
  2. Missing required fields
  3. Inconsistent hash values
  4. Out-of-order transactions
internal/controller/ledger/controller_default.go (1)

208-208: Add nil checks before dereferencing IDs.

The code dereferences pointer IDs without checking for nil values. While these IDs are likely to be non-nil in the current implementation, adding nil checks would make the code more robust against future changes.

Apply this pattern for safer dereferencing:

-return fmt.Errorf("importing log %d: %w", *log.ID, err)
+if log.ID == nil {
+    return fmt.Errorf("importing log with nil ID: %w", err)
+}
+return fmt.Errorf("importing log %d: %w", *log.ID, err)

Also applies to: 220-220, 224-224, 233-233, 276-276, 283-283

internal/storage/ledger/transactions_test.go (1)

561-562: Add error handling test cases for nil IDs.

While the current test cases cover the happy path, consider adding test cases that verify proper error handling when transaction IDs are nil.

Also applies to: 573-574, 712-713

internal/README.md (4)

478-479: Updated Log ID Field to Pointer Type

The ID field in the Log struct has been updated to use a pointer (*int) instead of a direct integer. Please verify that this change is consistently handled in serialization/deserialization and that the logic correctly checks for nil IDs where necessary.


520-524: Addition of Log.WithID Method

The new WithID method for the Log type allows setting an ID value and returning an updated copy. Ensure that its behavior is well documented—specifically, that the method converts the provided integer into a pointer and that consumers are aware that it returns a new instance rather than mutating the receiver.


847-848: Updated Transaction ID Field to Pointer Type

The ID field in the Transaction struct has been modified to be of type *int. Confirm that this change does not impact any logic that assumes the ID is always non-nil and that nullability is correctly handled in business rules and JSON marshaling.


931-935: Addition of Transaction.WithID Method

The new WithID method for the Transaction type provides a clean way to set the ID on a transaction. Please ensure that this method wraps the provided ID in a pointer properly and that its copy semantics align with other methods on this type. Adding clarifying documentation or examples in the README might be helpful for future users.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5b1d09 and c32cdf8.

⛔ Files ignored due to path filters (4)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • tools/generator/go.mod is excluded by !**/*.mod
  • tools/generator/go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (22)
  • internal/README.md (100 hunks)
  • internal/api/bulking/bulker.go (4 hunks)
  • internal/api/v1/controllers_transactions.go (1 hunks)
  • internal/api/v1/controllers_transactions_create_test.go (3 hunks)
  • internal/api/v2/controllers_bulk_test.go (12 hunks)
  • internal/api/v2/controllers_transactions_read_test.go (1 hunks)
  • internal/controller/ledger/controller_default.go (4 hunks)
  • internal/controller/ledger/controller_default_test.go (4 hunks)
  • internal/controller/ledger/log_process.go (1 hunks)
  • internal/controller/ledger/log_process_test.go (2 hunks)
  • internal/log.go (7 hunks)
  • internal/storage/ledger/logs.go (1 hunks)
  • internal/storage/ledger/logs_test.go (5 hunks)
  • internal/storage/ledger/moves_test.go (5 hunks)
  • internal/storage/ledger/paginator_column.go (1 hunks)
  • internal/storage/ledger/resource.go (1 hunks)
  • internal/storage/ledger/transactions.go (4 hunks)
  • internal/storage/ledger/transactions_test.go (11 hunks)
  • internal/transaction.go (2 hunks)
  • internal/transaction_test.go (6 hunks)
  • pkg/testserver/helpers.go (2 hunks)
  • test/e2e/api_ledgers_import_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • internal/storage/ledger/resource.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Tests
🔇 Additional comments (26)
internal/api/v2/controllers_transactions_read_test.go (1)

30-30: Verify the test logic using transaction ID.

The test should use the transaction's ID (tx.ID) instead of a hardcoded value 0 to ensure the correct transaction is being queried. This would better validate the transaction retrieval logic.

-		Builder: query.Match("id", 0),
+		Builder: query.Match("id", tx.ID),
internal/controller/ledger/log_process_test.go (1)

72-75: LGTM! Proper handling of ID as pointer type.

The changes correctly implement the pointer-based ID handling using pointer.For(0) to set the log ID.

pkg/testserver/helpers.go (1)

39-39: LGTM! Proper conversion of SDK transaction ID to pointer type.

The change correctly converts the SDK transaction ID to a pointer type using pointer.For(int(tx.ID.Int64())).

internal/storage/ledger/logs.go (1)

90-92: LGTM! The ID check has been correctly updated.

The condition has been updated to check for nil instead of 0, which aligns with the transition to pointer types for IDs.

internal/controller/ledger/log_process.go (1)

80-80: LGTM! The ID is correctly dereferenced in the debug log.

The log statement now properly dereferences the ID pointer to display the actual value.

internal/transaction_test.go (1)

81-81: LGTM! Test cases have been consistently updated to use pointer IDs.

The changes correctly reflect the transition to pointer types for IDs:

  • Using WithID(0) for new transactions
  • Setting log.ID using pointer.For(0)

Also applies to: 90-90, 99-99, 152-153, 162-163

internal/storage/ledger/moves_test.go (1)

62-62:

❓ Verification inconclusive

Verify the hardcoded TransactionID values.

All moves (m1-m5) are now using a hardcoded TransactionID: 0 instead of referencing tx.ID. This could break the relationship between moves and their originating transactions. Please verify if this is intentional or if the moves should maintain their relationship with the transaction created at line 35.

Run the following script to check how TransactionID is used in moves across the codebase:

Also applies to: 79-79, 96-96, 113-113, 130-130


🏁 Script executed:

#!/bin/bash
# Description: Check how TransactionID is used in moves

# Search for TransactionID usage in move-related code
rg -A 5 'TransactionID.*Move'

# Search for test cases involving moves and transactions
rg -A 5 'TestMove.*Transaction'

Length of output: 65


Manual Verification Required: Confirm Transaction Relationship Handling

The automated search did not reveal any references connecting moves to dynamic transaction IDs (e.g., via tx.ID). This inconclusive output means we cannot confirm if using a hardcoded TransactionID: 0 in internal/storage/ledger/moves_test.go (at lines 62, 79, 96, 113, and 130) is intentional. Please manually verify whether the moves’ association with their originating transaction—created around line 35—should instead use the actual transaction ID.

internal/api/v1/controllers_transactions_create_test.go (2)

5-5: LGTM!

The import of the pointer package is necessary for handling pointer-based IDs.


224-224: LGTM!

The changes correctly update the test to use pointer-based IDs, maintaining consistency with the new ID handling approach.

Also applies to: 234-236

internal/storage/ledger/paginator_column.go (1)

226-229: LGTM!

The addition of pointer type handling for int64 and int is well-implemented and necessary for supporting the new pointer-based ID fields.

internal/storage/ledger/logs_test.go (3)

43-43: LGTM!

The test assertions are correctly updated to dereference the pointer-based IDs before comparison.

Also applies to: 61-61


133-135: LGTM!

The hash consistency test is properly updated to handle pointer-based IDs.


218-218: LGTM!

The pagination test assertions are correctly updated to dereference pointer-based IDs.

Also applies to: 226-226, 241-241

internal/transaction.go (2)

42-42: LGTM!

The conversion of the ID field to a pointer type is well-implemented and aligns with the broader effort to standardize ID handling.


66-69: LGTM!

The WithID method is a clean implementation for setting pointer-based IDs, following the builder pattern consistently used throughout the codebase.

internal/api/bulking/bulker.go (1)

144-144:

❓ Verification inconclusive

LGTM! Correctly dereferencing log IDs.

The changes correctly dereference the log IDs across all action handlers in the processElement method, aligning with the transition to pointer-based ID fields.

Run the following script to verify that all log ID dereferences are consistent:

Also applies to: 186-186, 203-203, 247-247


🏁 Script executed:

#!/bin/bash
# Description: Verify that all log ID dereferences are consistent.
# Test: Search for log.ID usage. Expect: All occurrences should be dereferenced.
rg -A 2 'log\.ID' | grep -v '\*log\.ID'

Length of output: 41


Manual verification required: Validate log ID dereferences across action handlers

The changes in internal/api/bulking/bulker.go (lines 144, 186, 203, and 247) appear to correctly dereference the log.ID field (e.g., using *log.ID). However, the automated check using:

rg -A 2 'log\.ID' | grep -v '\*log\.ID'

did not produce output, which is inconclusive. Please ensure through manual verification that every instance of log.ID in the codebase is properly dereferenced.

internal/storage/ledger/transactions.go (3)

77-77: LGTM! Correctly dereferencing transaction IDs in moves.

The changes correctly dereference the transaction IDs when setting the TransactionID field in the moves.

Also applies to: 89-89


121-123: LGTM! Correctly handling nil transaction IDs.

The condition now correctly checks for nil transaction IDs before generating a new ID.


142-143: LGTM! Correctly dereferencing transaction ID in trace attributes.

The change correctly dereferences the transaction ID when setting trace attributes.

internal/log.go (4)

94-94: LGTM! Correctly updated ID field type.

The ID field is correctly changed to a pointer type, allowing for nullable IDs.


107-109: LGTM! Correctly setting ID in ChainLog.

The changes correctly use pointer.For to set the ID in the ChainLog method.


162-167: LGTM! Correctly handling nil IDs in ComputeHash.

The changes correctly handle nil IDs when computing the hash.


176-179: LGTM! Added WithID method.

The new WithID method provides a clean way to set the ID field.

internal/controller/ledger/controller_default_test.go (1)

61-64: LGTM! Correctly setting log IDs in test mocks.

The changes correctly set log IDs using pointer.For in all test mocks, ensuring consistency with the pointer-based ID fields.

Also applies to: 110-114, 153-157, 194-198

internal/api/v2/controllers_bulk_test.go (1)

72-74: LGTM! Consistent use of pointer.For() for ID fields.

The changes correctly implement pointer-based ID handling, ensuring consistency across the codebase.

Also applies to: 125-127, 155-157

internal/storage/ledger/transactions_test.go (1)

240-241: LGTM! Correct assertions for pointer-based IDs.

The test assertions correctly handle the pointer-based IDs by dereferencing them before comparison.

Also applies to: 262-263, 288-289

@gfyrag gfyrag force-pushed the fix/import-from-2.1 branch from c32cdf8 to 7b49031 Compare February 17, 2025 14:51
@gfyrag gfyrag added this pull request to the merge queue Feb 17, 2025
Merged via the queue into main with commit db39a0f Feb 17, 2025
9 of 10 checks passed
@gfyrag gfyrag deleted the fix/import-from-2.1 branch February 17, 2025 15:10
@gfyrag gfyrag mentioned this pull request Mar 14, 2025
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