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: waitForAcceptance now chek on finality status #479

Merged
merged 2 commits into from
Mar 1, 2025

Conversation

ptisserand
Copy link
Collaborator

@ptisserand ptisserand commented Feb 28, 2025

Close #441

Summary by CodeRabbit

  • Refactor
    • Streamlined transaction status management to improve overall reliability.
    • Enhanced error handling by ensuring comprehensive checks during transaction processing.
    • Introduced a new class and enums for better transaction status representation.

Copy link

docs-page bot commented Feb 28, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/focustree/starknet.dart~479

Documentation is deployed and generated using docs.page.

Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Walkthrough

The update refactors transaction status handling by introducing a new class _Status that encapsulates both execution and finality statuses, replacing the previous string-based approach. Functions such as waitForState, waitForTransaction, and waitForAcceptance now delegate status verification to new private methods (_waitForTransactionStatus, _waitForExecutionStatus, and _waitForFinalityStatus). The receipt parsing and error handling logic have been updated to work with the _Status object, ensuring a more structured and unified process for managing transaction statuses.

Changes

File Changes Summary
packages/starknet/…/util.dart - Added new _Status class for transaction execution and finality statuses.
- Updated method signatures for waitForState, waitForTransaction, and waitForAcceptance to use new private methods.
- Introduced _waitForTransactionStatus, _waitForExecutionStatus, and _waitForFinalityStatus to streamline status checking and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant WT as waitForTransaction
    participant WES as _waitForExecutionStatus
    participant WTS as _waitForTransactionStatus
    participant S as _Status
    C->>WT: Call waitForTransaction(...)
    WT->>WES: Invoke _waitForExecutionStatus(...)
    WES->>WTS: Delegate execution status check
    WTS->>S: Update status from receipt
    S-->>WTS: Return updated execution status
    WTS-->>WES: Pass execution result
    WES-->>WT: Return result
    WT-->>C: Return execution status
Loading
sequenceDiagram
    participant C as Client
    participant WA as waitForAcceptance
    participant WFS as _waitForFinalityStatus
    participant WTS as _waitForTransactionStatus
    participant S as _Status
    C->>WA: Call waitForAcceptance(...)
    WA->>WFS: Invoke _waitForFinalityStatus(...)
    WFS->>WTS: Delegate finality status check
    WTS->>S: Update status from receipt
    S-->>WTS: Return updated finality status
    WTS-->>WFS: Pass finality result
    WFS-->>WA: Return result
    WA-->>C: Return finality status
Loading

Possibly related PRs

Poem

In a burrow deep within our code,
I, the rabbit, hop down the status road.
_Status now guards each state with grace,
Guiding transactions through every phase.
Bugs scatter as I bound with glee—
Clean code is the joy of a bunny like me! 🐰


📜 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 6b987fe and e229f8e.

📒 Files selected for processing (1)
  • packages/starknet/lib/src/util.dart (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-integration
  • GitHub Check: analyze
  • GitHub Check: lint
🔇 Additional comments (9)
packages/starknet/lib/src/util.dart (9)

19-23: Well-designed status encapsulation.

This new _Status class effectively encapsulates both execution and finality statuses, providing a clear structure for transaction state management.


25-41: Good implementation of execution status enumeration.

The enum implementation with string values and a fromString method follows Dart best practices. This provides type safety and prevents errors from string typos.


43-61: Comprehensive finality status enumeration.

The finality status enum covers all necessary states and follows the same pattern as the execution status enum. Good consistent implementation.


63-146: Robust transaction status handling with improved error detection.

The updated implementation provides more structured status tracking by using the _Status class. The error detection now explicitly checks both execution and finality status, which makes the code more robust.


148-164: Clean abstraction for execution status checks.

This new helper function nicely encapsulates the logic for waiting on execution status, making the code more maintainable and reducing duplication.


166-182: Well-implemented finality status check abstraction.

This helper function mirrors the execution status check pattern and provides the core functionality needed to fulfill the PR objective of checking finality status.


198-206: Clean delegation to specialized helper function.

The refactored implementation maintains the same functionality while delegating to the more specialized helper function, which improves code maintainability.


222-229: Simplified implementation through proper abstraction.

The update removes duplicated logic by delegating to the specialized helper function, while maintaining the same behavior for waitForTransaction.


232-256: Key improvement: waitForAcceptance now properly checks finality status.

This change is the core of the PR - waitForAcceptance now correctly checks finality status (ACCEPTED_ON_L1 or ACCEPTED_ON_L2) rather than execution status, addressing the issue mentioned in the PR objectives.


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.
  • @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: 0

🧹 Nitpick comments (5)
packages/starknet/lib/src/util.dart (5)

20-24: Consider using an enum or sealed class for statuses.
Using plain strings increases the risk of typos and ambiguity. An enum (or similar) would help ensure type safety and clarity across the codebase.


26-31: Add documentation comments for _waitForTransactionStatus.
This method is pivotal in orchestrating transaction status checks. Including doc comments clarifying the purpose and parameters (especially checkStatus) will improve readability and maintainability.


45-58: Reduce repetition when assigning _status from receipt properties.
All non-pending receipts share the same assignment pattern. Consider refactoring into a helper function or single unified mapping to eliminate repeated lines and ease maintenance.


87-88: Check completeness of _errorStates and consider exponential backoff.

  • _errorStates currently only includes 'REVERTED'. If other error statuses (e.g., 'REJECTED') exist, consider adding them.
  • Using a constant interval is fine for now, but exponential backoff might improve performance and reduce network load.

Also applies to: 92-92, 96-96


161-161: Fix minor spelling in documentation.
“Succeeded” is spelled with a double “c”.

-/// Returns `true` when [transactionHash] execution status is in `{PENDING, SUCEEDED}`
+/// Returns `true` when [transactionHash] execution status is in `{PENDING, SUCCEEDED}`

Also applies to: 165-165

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4841e40 and 6b987fe.

📒 Files selected for processing (1)
  • packages/starknet/lib/src/util.dart (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: analyze
  • GitHub Check: lint
  • GitHub Check: test-integration
🔇 Additional comments (8)
packages/starknet/lib/src/util.dart (8)

37-37: Initialization defaults look fine.
Using _Status('UNKNOWN', 'UNKNOWN') as a fallback when transaction data is unavailable is reasonable.


77-77: Consistent fallback for TXN_HASH_NOT_FOUND.
Re-initializing _status to UNKNOWN aligns with the existing approach in line 37. No concerns here.


101-117: _waitForExecutionStatus is implemented cleanly.
The delegation to _waitForTransactionStatus with execution field checks is straightforward.


119-135: _waitForFinalityStatus correctly parallels _waitForExecutionStatus.
The approach provides a consistent pattern for finality checks.


137-159: waitForState wrapper logic is coherent.
The usage of _waitForExecutionStatus enforcing the specified states is clear and maintains simplicity.


175-175: Usage of ['PENDING', 'SUCCEEDED'] is correct.
Matches the documentation once spelling is addressed. No other issues found.

Also applies to: 178-178


187-187: Documentation updates for acceptance logic are well-defined.
They outline the finality-based acceptance and retry approach clearly.

Also applies to: 191-191


202-202: waitForFinalityStatus usage for acceptance checks is consistent.
Ensures the transaction is truly “accepted” by verifying it reaches ACCEPTED_ON_L1 or ACCEPTED_ON_L2.

Also applies to: 204-204

@ptisserand ptisserand merged commit f18adb7 into focustree:main Mar 1, 2025
10 checks passed
@ptisserand ptisserand deleted the fix/waitForAcceptance branch March 1, 2025 09:35
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.

waitForAcceptance bug
1 participant