Skip to content

Add rpc/client2.go implementing a second-generation Solana JSON RPC c…#437

Open
928799934 wants to merge 3 commits into
solana-foundation:mainfrom
928799934:main
Open

Add rpc/client2.go implementing a second-generation Solana JSON RPC c…#437
928799934 wants to merge 3 commits into
solana-foundation:mainfrom
928799934:main

Conversation

@928799934
Copy link
Copy Markdown

…lient.

Supports configuring custom HTTP clients, request headers, and rate limiters via options, with automatic rate limit checks before each request.

…lient.

Supports configuring custom HTTP clients, request headers, and rate limiters via options,
with automatic rate limit checks before each request.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 22, 2026

Greptile Summary

This PR adds rpc/client2.go, a new second-generation Solana JSON RPC client (Client2) that wraps the existing jsonrpc.RPCClient with support for configurable HTTP clients, custom headers, and rate limiting via golang.org/x/time/rate.

  • New2 constructs a Client2 using an option-function pattern, applying each option to an RPCClientOpts struct before building the underlying JSON-RPC client.
  • Client2 delegates CallForInto, CallWithCallback, and CallBatch to the inner client, inserting a rate.Limiter.Wait call before each request when a limiter is configured.
  • The function signature New2(rpcEndpoint string, fns OptionFuncs) is non-variadic while the docstring shows variadic-style call examples — none of the documented examples will compile as written.

Confidence Score: 3/5

The new client introduces a public API whose documented usage examples will not compile, which would immediately break any caller who follows the docs.

The New2 function takes a concrete OptionFuncs slice as its second parameter, but all three docstring examples call it with either zero option arguments or with individual func(*RPCClientOpts) values — none of which match the required type. Every new caller will hit a compile error before they can use the client at all.

rpc/client2.go — the New2 signature and its docstring examples are inconsistent and need to be reconciled before the API is usable.

Important Files Changed

Filename Overview
rpc/client2.go New second-generation RPC client with rate limiting and option-function configuration; has a non-variadic signature mismatch with its own documented examples (none compile), plus previously flagged issues with double-pointer in rate-limited CallForInto and dead OptionFuncs type.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Client2
    participant rate.Limiter
    participant jsonrpc.RPCClient

    Caller->>Client2: CallForInto / CallWithCallback / CallBatch
    alt limiter is nil
        Client2->>jsonrpc.RPCClient: forward call directly
        jsonrpc.RPCClient-->>Client2: result
    else limiter is set
        Client2->>rate.Limiter: Wait(ctx)
        rate.Limiter-->>Client2: nil or ctx error
        alt ctx cancelled / deadline exceeded
            Client2-->>Caller: error
        else token acquired
            Client2->>jsonrpc.RPCClient: forward call
            jsonrpc.RPCClient-->>Client2: result
        end
    end
    Client2-->>Caller: result / error
Loading

Reviews (3): Last reviewed commit: "change CustomHeaders -> CustomHeader" | Re-trigger Greptile

Comment thread rpc/client2.go Outdated
Comment thread rpc/client2.go
Comment thread rpc/client2.go
Comment thread rpc/client2.go Outdated
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