Skip to content

feat: add mayachain rpc endpoint#1273

Merged
kaladinlight merged 1 commit into
developfrom
mayachain-rpc-endpoint
Apr 21, 2026
Merged

feat: add mayachain rpc endpoint#1273
kaladinlight merged 1 commit into
developfrom
mayachain-rpc-endpoint

Conversation

@kaladinlight
Copy link
Copy Markdown
Member

@kaladinlight kaladinlight commented Apr 21, 2026

Summary by CodeRabbit

  • New Features

    • Added /rpc API endpoint supporting GET and POST requests for RPC proxy services.
  • Documentation

    • Updated API documentation with corrected naming and new /rpc endpoint specifications.

@kaladinlight kaladinlight requested a review from a team as a code owner April 21, 2026 17:20
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

The changes add an RPC proxy routing feature to the MayaChain API with a shared response handler for centralized proxy management. Existing LCD and Midgard handlers are refactored to use this helper. Documentation is updated with new RPC endpoints, and a Docker build dependency is pinned to a specific version for deterministic builds.

Changes

Cohort / File(s) Summary
RPC Proxy Implementation
go/coinstacks/mayachain/api/api.go
Added RPC handler method that forwards HTTP GET and POST requests to upstream RPC client. Introduced shared handleProxyResponse helper to centralize proxy response handling with upstream status code forwarding. Refactored existing LCD and Midgard handlers to delegate response processing to the new helper instead of manual unmarshalling.
API Documentation
go/coinstacks/mayachain/api/swagger.json
Updated /lcd endpoint summary text from "Mayanode" to "Mayachain". Added new /rpc path with GET and POST operations, including distinct operationId values (GetRPC and PostRPC).
Build Configuration
go/coinstacks/mayachain/build/Dockerfile.local
Pinned github.com/cespare/reflex dependency to explicit version v0.3.1 instead of @latest for deterministic Docker builds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A new RPC path hops into view,
Where requests get forwarded right on through,
With handlers refined and responses aligned,
The proxy now serves with helpers designed! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature being added: an RPC endpoint for Mayachain, which aligns with the core changes in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mayachain-rpc-endpoint

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (1)
go/coinstacks/mayachain/api/api.go (1)

394-407: Consider streaming the upstream body instead of unmarshal + re-marshal.

handleProxyResponse decodes the upstream JSON into any and then re-encodes it via api.HandleResponse. For a pass-through proxy this is wasteful, reorders JSON object keys, loses numeric precision for large integers (tendermint RPC returns heights, IDs, etc. as numbers that can exceed JS safe-int range; after round-tripping through any, large int64 values become float64), and only accepts application/json upstream responses. Writing the raw bytes through preserves fidelity and is cheaper.

♻️ Suggested refactor
 func (a *API) handleProxyResponse(w http.ResponseWriter, res *resty.Response) {
 	if res.StatusCode() != http.StatusOK {
 		api.HandleError(w, res.StatusCode(), string(res.Body()))
 		return
 	}
 
-	var result any
-	if err := json.Unmarshal(res.Body(), &result); err != nil {
-		api.HandleError(w, http.StatusInternalServerError, err.Error())
-		return
-	}
-
-	api.HandleResponse(w, http.StatusOK, result)
+	if ct := res.Header().Get("Content-Type"); ct != "" {
+		w.Header().Set("Content-Type", ct)
+	}
+	w.WriteHeader(http.StatusOK)
+	_, _ = w.Write(res.Body())
 }

Note: this would make the LCD/Midgard handlers also pass through raw upstream bytes, which is a behavior change worth a quick sanity-check against any clients relying on the previous re-encoded form.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go/coinstacks/mayachain/api/api.go` around lines 394 - 407, The
handleProxyResponse function currently unmarshals upstream JSON into a Go any
and then re-encodes via api.HandleResponse, which is inefficient and can change
numeric precision and key ordering; change handleProxyResponse to stream the raw
response body bytes and copy headers/status directly to the client instead of
json.Unmarshal/json.Marshal: read res.Body() (or io.Copy from
res.RawResponse.Body if available) and write those bytes to w while preserving
Content-Type and status code, and use api.HandleError only on non-200 responses
or read errors; update references in handleProxyResponse to stop using the
intermediate result variable and avoid api.HandleResponse re-encoding.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@go/coinstacks/mayachain/api/api.go`:
- Around line 344-359: The POST /rpc handler should explicitly forward the
incoming request's Content-Type (and other proxy-relevant headers) to the resty
request and avoid shadowing err: replace body, err := io.ReadAll(r.Body) with
body, readErr := io.ReadAll(r.Body) and handle readErr, and after setting the
body call req.SetHeader("Content-Type", r.Header.Get("Content-Type")) (and
optionally forward headers like "Content-Encoding", "Authorization", "Accept")
before calling req.Post(path) so the proxied request preserves header fidelity.

---

Nitpick comments:
In `@go/coinstacks/mayachain/api/api.go`:
- Around line 394-407: The handleProxyResponse function currently unmarshals
upstream JSON into a Go any and then re-encodes via api.HandleResponse, which is
inefficient and can change numeric precision and key ordering; change
handleProxyResponse to stream the raw response body bytes and copy
headers/status directly to the client instead of json.Unmarshal/json.Marshal:
read res.Body() (or io.Copy from res.RawResponse.Body if available) and write
those bytes to w while preserving Content-Type and status code, and use
api.HandleError only on non-200 responses or read errors; update references in
handleProxyResponse to stop using the intermediate result variable and avoid
api.HandleResponse re-encoding.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1596b06d-398c-437c-b616-3096b791f9ab

📥 Commits

Reviewing files that changed from the base of the PR and between fd48a7b and 2924b79.

📒 Files selected for processing (3)
  • go/coinstacks/mayachain/api/api.go
  • go/coinstacks/mayachain/api/swagger.json
  • go/coinstacks/mayachain/build/Dockerfile.local

Comment thread go/coinstacks/mayachain/api/api.go
@kaladinlight kaladinlight merged commit ec8be18 into develop Apr 21, 2026
3 checks passed
@kaladinlight kaladinlight deleted the mayachain-rpc-endpoint branch April 21, 2026 17:33
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.

1 participant