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(rpc): Fix http batch request to handle single item requests #3694

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

masonmcbride
Copy link
Contributor

@masonmcbride masonmcbride commented Feb 6, 2025

This pull request fixes the bug described in #3676. Using http, if a batch of requests only has one item, the request marshalls it as a single request and would create an error because the response logic is expecting a batch of responses. This pr changes how the client side unmarshalls the response by first trying to unmarshall it as a batch and returning it if successful. If it fails, it then tries to unmarshall as a response and returns that if successful. If both fail, it returns a Unmarshall error, as expected.

Omarsy's pr #3678 also fixed this issue from the server side inside the handlers.go file. I kept it as is but reverted earlier changes I made to it. The only file that changes in this pr is the client.go file.

I added a test that specifically verifies client side http batch request functionality, and this code is also covered by previous tests TestRPCClient_E2E_Endpoints from github.com/gnolang/gno/tm2/pkg/bft/rpc/client and TestClient_SendRequest from github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/client/http

@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Feb 6, 2025
@Gno2D2 Gno2D2 requested a review from a team February 6, 2025 09:39
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Feb 6, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Feb 6, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: masonmcbride/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@masonmcbride masonmcbride changed the title Update http batch request to handle singletons fix(rpc): Update http batch request to handle singletons Feb 6, 2025
@notJoon
Copy link
Member

notJoon commented Feb 6, 2025

duplicated with #3678

@n2p5
Copy link
Contributor

n2p5 commented Feb 6, 2025

It looks like we've resolved this issue with the RPC server patch #3678 , but I still think it is worthwhile thinking about how we could make the client more forgiving as well. I'll pass long feedback line in a review.

Copy link
Contributor

@n2p5 n2p5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice first pass, please see my comments in line for a few changes.

tm2/pkg/bft/rpc/lib/client/http/client.go Outdated Show resolved Hide resolved
tm2/pkg/bft/rpc/lib/client/http/client.go Outdated Show resolved Hide resolved
@n2p5
Copy link
Contributor

n2p5 commented Feb 6, 2025

@notJoon I still think this is worth patching so that Batching responses for the client will work, even on older test nets. This follows the robustness principle (Postel's Law). If we can coax a slightly malformed response into a correct one, then it is better for the end-user experience. But, with the server patch, all testnets moving forward should be fine with the server side-only change.

@Gno2D2 Gno2D2 requested a review from a team February 6, 2025 18:30
@Gno2D2 Gno2D2 removed the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Feb 6, 2025
@masonmcbride
Copy link
Contributor Author

masonmcbride commented Feb 7, 2025

I updated both the server side (Omar's solution) and the client side (mine) functions associated with batch requests so that they have the same functionality but are more readable. On the server side, it tries to unmarshall into a slice of Responses and if it can't it tried to unmarshall into a single Response but both cases perform the same process which is abstracted out as processRequest. On the client side, sendRequestCommon has R ResponseType which is a *types.RPCResponse | types.RPCResponses so it uses a switch case on the return type and exhausts the cases for a clear program flow.

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tm2/pkg/bft/rpc/lib/client/http/client.go 82.35% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@n2p5 n2p5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this PR simple and let's remove the server handler changes, since it has been addressed in another PR and any refactoring we might want to do can come in a separate PR.

Also - since we are modifying the client.go, let's make sure that the functions your code touches have proper test coverage that address the expected behavior that this change is making.

Please add the tests and update your PR description as well.

@Gno2D2 Gno2D2 requested a review from a team February 7, 2025 20:14
@masonmcbride masonmcbride changed the title fix(rpc): Update http batch request to handle singletons fix(rpc): Fix http batch request to handle single item requests Feb 9, 2025
@zivkovicmilos zivkovicmilos self-requested a review February 9, 2025 08:08
@zivkovicmilos
Copy link
Member

@masonmcbride

Thank you for opening up the PR 🙏

Gimme a bit of time to get to this and review, it look promising 🫡

@masonmcbride masonmcbride requested a review from n2p5 February 10, 2025 22:49
Copy link
Contributor

@n2p5 n2p5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the initiative on this. I'm going to wait for feedback from @zivkovicmilos or someone else from the core team to weigh in on this, but thanks for addressing my feedback and for adding test coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: Triage
Development

Successfully merging this pull request may close these issues.

5 participants