feat(jsonrpc): eth-compatible JSON-RPC server bootstrap - #1654
Open
libotony wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Bootstrap of an Ethereum-compatible JSON-RPC 2.0 server for Thor.
This PR lands the server engine and wiring only — a minimal, self-contained JSON-RPC core plus two example namespaces to prove the full request path end to end. It is intentionally small; the complete Ethereum method set, websocket subscriptions, filters and write paths are out of scope and tracked as follow-ups.
What's in it
Reflection-based registry (
api/jsonrpc/server) — a from-scratch JSON-RPC 2.0 core, no dependency ongo-ethereum/rpc. It reflects over a service struct's exported methods and exposes each as<namespace>_<method>, following go-ethereum'srpc/service.gocontract:Method() error,Method(args...) Result,Method(args...) (Result, error),Method(ctx, args...) (Result, error).context.Contextis injected by the server and is not part of the JSON params.-32602if missing); omission is tail-only.HTTP transport (
server/http.go) —POST /rpc, single request and batch array, notification handling (noid→ no reply, per spec), batch-size cap.Error model (
server/json.go) — standard codes (-32700/-32600/-32601/-32602/-32603/-32000) plus aDataErrorinterface so business errors can attach structurederror.data. A panic inside a method is recovered at the call layer and returned as-32603instead of tearing down the connection.Package layout — three packages with a clear dependency direction:
api/jsonrpc/server— the transport-agnostic engine (stdlib only).api/jsonrpc/service— thor business namespaces (eth,net).api/jsonrpc— top-level composition +Mount.Example methods —
eth_chainId,eth_blockNumber,net_version. Enough to exercise reflection, dispatch, batching and error codes; not a complete namespace.Wiring — a new
--enable-rpcflag mounts the server under/rpcon the existing REST router, reusing thor's middleware chain. Off by default.Dependencies
Stacked on top of
eth-equivalence(the PR base). Should be reviewed/merged after it.Type of change
How Has This Been Tested?
Unit tests cover the reflection contract (signature acceptance/rejection, ctx injection, required vs optional args), dispatch and every error code, batch and notification handling, and the two example namespaces against a genesis-only
testchain.go test ./api/jsonrpc/...go build ./...golangci-lint run+modernizecleanTest Configuration:
Checklist: