-
Notifications
You must be signed in to change notification settings - Fork 39
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(sdk): return state transition execution error #2454
base: v2.0-dev
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request enhances error handling across multiple components. In the JavaScript modules, error metadata handling is refined by extracting consensus error data directly using the Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Handler as waitForStateTransitionResultHandler
participant ErrorFn as createStateTransitionDeliverError
Client->>Handler: Initiate state transition request
Handler->>ErrorFn: Process gRPC error (txDeliverResult)
ErrorFn->>ErrorFn: Check for 'dash-serialized-consensus-error-bin' in metadata
ErrorFn->>Client: Return StateTransitionBroadcastError with error data
sequenceDiagram
participant B as BroadcastStateTransition
participant SDK as Rust SDK
participant GRPC as gRPC Response
B->>SDK: Invoke wait_for_response
SDK->>SDK: Match grpc_response version (e.g., V0)
SDK->>SDK: If error exists, convert response to StateTransitionBroadcastError
SDK->>B: Return structured error
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (7)
🔇 Additional comments (2)
✨ Finishing Touches
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: 0
🧹 Nitpick comments (5)
packages/rs-sdk/src/platform/transition/broadcast.rs (1)
88-109
: Ensure future response versions remain compatible
Matching ongrpc_response.version
is a good approach to catch newly introduced versions at compile-time. However, consider using a_ => None
arm if you prefer a safe fallback for unrecognized versions in production. Otherwise, this strict match is fine for forcing explicitly handled future versions.packages/js-dash-sdk/src/SDK/Client/Platform/broadcastStateTransition.ts (1)
92-94
: Consider verifying or defaultingerror.data
Assigningerror.data
togrpcError.metadata
is straightforward. However, iferror.data
can be null or undefined, consider null-checking or providing a default to avoid potential runtime errors.packages/dapi/lib/grpcServer/handlers/platform/waitForStateTransitionResultHandlerFactory.js (1)
52-56
: Use a shared constant for the metadata key
Defining'dash-serialized-consensus-error-bin'
as a constant in a central module can help avoid typos and maintain consistency across the codebase.packages/rs-sdk/src/error.rs (2)
87-97
: Consider using an enum for the error code field.Instead of using a raw
u32
for the error code, consider creating an enum to represent the possible error codes. This would provide better type safety and self-documentation.Example implementation:
#[derive(Debug, Clone, Copy)] pub enum StateTransitionBroadcastErrorCode { InvalidFormat = 1, ValidationFailed = 2, // Add other specific error codes } pub struct StateTransitionBroadcastError { pub code: StateTransitionBroadcastErrorCode, pub message: String, pub cause: Option<ConsensusError>, }
99-122
: Use more idiomatic Rust for the length check.The length check can be written more idiomatically using
!is_empty()
.- let cause = if value.data.len() > 0 { + let cause = if !value.data.is_empty() {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
packages/dapi/lib/grpcServer/handlers/platform/waitForStateTransitionResultHandlerFactory.js
(1 hunks)packages/js-dash-sdk/src/SDK/Client/Platform/broadcastStateTransition.ts
(1 hunks)packages/rs-sdk/src/error.rs
(2 hunks)packages/rs-sdk/src/platform/transition/broadcast.rs
(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/dapi/lib/grpcServer/handlers/platform/waitForStateTransitionResultHandlerFactory.js (1)
Learnt from: shumkov
PR: dashpay/platform#2270
File: packages/dapi/lib/grpcServer/handlers/platform/broadcastStateTransitionHandlerFactory.js:90-96
Timestamp: 2024-11-12T14:56:12.334Z
Learning: In `broadcastStateTransitionHandlerFactory.js`, error handling when querying transaction status is handled in the API script.
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: Rust packages (dash-sdk) / Tests
- GitHub Check: Rust packages (dash-sdk) / Linting
- GitHub Check: Rust packages (dash-sdk) / Check each feature
- GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
- GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
- GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
- GitHub Check: Build JS packages / Build JS
🔇 Additional comments (3)
packages/rs-sdk/src/platform/transition/broadcast.rs (2)
3-3
: No issues with the new import statement
This import aligns with the new error handling logic and appears consistent with the changes in this file.
7-10
: Imports for handling gRPC response versions
These new imports cleanly separate versioned response handling (wait_for_state_transition_result_response_v0
), improving maintainability and clarity by providing version-specific logic.packages/rs-sdk/src/error.rs (1)
2-2
: LGTM! Well-structured error handling implementation.The new error variant and its transparent error propagation align well with Rust's error handling best practices.
Also applies to: 81-85
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.
LGTM after tests are fixed. Works in DET.
Issue being fixed or feature implemented
The
wait_for_response
method didn't handle wait for state transition response with execution error. It led to the "metadata is missing" instead of actual state transition execution error.What was done?
How Has This Been Tested?
With existing tests and DET
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
Bug Fixes