fix: ensure only one from_block field is set in subscribeToTransactionsWithProofs
Issue being fixed or feature implemented
This PR resolves a bug in dapi-client where providing fromBlockHash to subscribeToTransactionsWithProofs() would still result in a gRPC error due to unintended Protobuf serialization of fromBlockHeight = 0.
What was done?
- Updated validation logic to only throw if
fromBlockHeightwas explicitly passed and is zero. - Ensured that
fromBlockHeightis only used whenfromBlockHashis not present. - No functional change to other fields or logic.
How Has This Been Tested?
CI
Breaking Changes
N/A
Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e tests
- [ ] I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
- [ ] I have made corresponding changes to the documentation if needed
For repository code-owners and collaborators only
- [ ] I have assigned this pull request to a milestone
Summary by CodeRabbit
- Bug Fixes
- Improved the transaction subscription process by refining how optional parameters are handled. This update enhances reliability by preventing errors when certain identifiers are absent, ensuring that the subscription service functions more predictably.
Walkthrough
The update refines the subscribeToTransactionsWithProofs function within the client library. It adjusts the conditional logic for handling the options object by ensuring that the check for a zero value on fromBlockHeight only occurs when the option is explicitly provided. Additionally, the request construction now gives precedence to fromBlockHash—if present—before considering fromBlockHeight. These modifications enhance the robustness of the parameter handling and error management within the function without altering the exported API.
Changes
| File(s) Changed | Summary of Changes |
|---|---|
packages/js-dapi-client/.../subscribeToTransactionsWithProofsFactory.js |
Updated the conditionals in subscribeToTransactionsWithProofs: now checks for fromBlockHeight only if explicitly provided and prioritizes fromBlockHash over fromBlockHeight. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant Function as subscribeToTransactionsWithProofs
participant RequestBuilder as Request
Caller->>Function: Call subscribeToTransactionsWithProofs(options)
Function->>Function: Check if options.fromBlockHash exists?
alt fromBlockHash exists
Function->>RequestBuilder: Set request.fromBlockHash
else
Function->>Function: Check if options.fromBlockHeight is explicitly provided
alt fromBlockHeight provided
Function->>RequestBuilder: Set request.fromBlockHeight
end
end
Function->>Caller: Return TransactionsWithProofsRequest
Poem
I'm a bunny in a code-filled glen,
Hoping through conditions now and then.
If a hash is there, I choose it right,
Else height steps in with a delight.
Bugs flee when logic's sound and neat—
Hoppity happy, I make the code complete!
🐇✨
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai planto trigger planning for file edits and PR creation.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
@coderabbitai review
:white_check_mark: Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
I see now that there is a specific test case that does this (block height 0, but with a block hash). It doesn't really make sense to me that you would pass both parameters in the same call, but maybe there is a reason? :thinking:
EDIT: actually the fact that core.proto defines those params using a oneof would seem to indicate they should never be both passed. Not sure what the best fix is, but I'm pretty sure there's an issue here.
Based on some testing with gRPCurl, fromBlockHash is the one that actually determines the response if both values are provided. This matches what is described in protobuf oneOf docs:
Note that if multiple values are set, the last set value as determined by the order in the proto will overwrite all previous ones.