Repository navigation
fix(client): disable viem transport retries (retryCount=0) to avoid d… - #110
Conversation
…uplicate requests
WalkthroughThe client transport initialization in src/client/client.ts now passes explicit retry options to Viem’s custom transport, setting retryCount: 0 and retryDelay: 0. This disables automatic retries on transport calls. No other logic or public/exported signatures were changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as App
participant Client as Client (Viem)
participant Transport as Custom Transport
participant RPC as RPC Provider
App->>Client: createClient(config)
Client->>Transport: custom(getCustomTransportConfig(config), {retryCount:0, retryDelay:0})
note right of Transport: Retries disabled
App->>Client: request()
Client->>Transport: send()
Transport->>RPC: HTTP/JSON-RPC call
alt RPC error
RPC-->>Transport: error response
note right of Transport: No automatic retry
Transport-->>Client: propagate error
Client-->>App: error
else RPC success
RPC-->>Transport: result
Transport-->>Client: result
Client-->>App: result
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
src/client/client.ts (3)
86-90: Endpoint override not respected by transport (uses config.chain instead of effective chain).
fetchreads fromconfig.chain.rpcUrls..., but you mutatechainConfig(and may setendpoint) separately. Ifconfig.chainis undefined or not the same object, the transport will ignore the override or throw “Chain is not set.”Apply this minimal fix so the transport sees the effective chain:
const chainConfig = config.chain || localnet; if (config.endpoint) { chainConfig.rpcUrls.default.http = [config.endpoint]; } - const customTransport = custom(getCustomTransportConfig(config), {retryCount: 0, retryDelay: 0}); + const effectiveConfig = { ...config, chain: chainConfig }; + const customTransport = custom(getCustomTransportConfig(effectiveConfig), { retryCount: 0, retryDelay: 0 });Also applies to: 56-58
35-51: Provider routing triggers when no account AND no provider → throws instead of falling back to RPC.
isAddressis true whenaccountis undefined, so alleth_*methods trywindow.ethereumand throw if absent. Gate on provider existence and tighten the address check.-const isAddress = typeof config.account !== "object"; +const isAddress = typeof config.account === "string"; +const provider = + config.provider || + (typeof window !== "undefined" ? (window as any).ethereum : undefined); -if (method.startsWith("eth_") && isAddress) { +if (provider && method.startsWith("eth_") && isAddress) { - const provider = config.provider || window.ethereum; - if (!provider) { - throw new Error('No wallet provider available'); - } return await provider.request({method, params}); } else {
56-80: Add a request timeout and check response.ok (hang risk; unclear failures).Without a timeout, calls may hang indefinitely; also
response.okisn’t checked. Mirror viem’shttpdefault timeout (~10s) and surface HTTP errors. (viem.sh)- try { - const response = await fetch(config.chain.rpcUrls.default.http[0], { + try { + const ac = new AbortController(); + const timer = setTimeout(() => ac.abort(new Error("RPC request timeout")), 10_000); + const response = await fetch(config.chain.rpcUrls.default.http[0], { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ jsonrpc: "2.0", id: Date.now(), method, params, }), - }); + signal: ac.signal, + }); + clearTimeout(timer); - const data = await response.json(); + if (!response.ok) { + throw new Error(`HTTP ${response.status} ${response.statusText}`); + } + const data = await response.json();
🧹 Nitpick comments (2)
src/client/client.ts (2)
63-67: Use a stable JSON-RPC id (minor).
Date.now()can collide under high concurrency. Use a monotonic counter.- id: Date.now(), + id: ++jsonRpcId, // define `let jsonRpcId = 0;` once above
124-127: Background init now has zero retries—confirm desired UX.With retries disabled, a transient failure during
initializeConsensusSmartContract()will fail once and log. Consider a one-time delayed retry or user-level surface if initialization is required.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/client/client.ts(1 hunks)
🔇 Additional comments (1)
src/client/client.ts (1)
92-92: Disables viem retries correctly.Passing
{ retryCount: 0, retryDelay: 0 }tocustom(...)is the supported way to turn off transport-level retries. Looks good. (viem.sh)
Keep what Phase 2 needs and follow the existing chain-preset pattern: - testnetBradbury: Phase 2 addresses, refreshed ConsensusMain/ConsensusData ABIs and the new RPC/explorer URLs. ABIs keep the file's existing key order and narrow-ABI style; Appeals.canAppeal gains its decision-id argument. - createClient: an endpoint override copies the chain instead of mutating the shared preset. - check:chains: Bradbury reads a pinned copy of genlayer-consensus deployments/bradbury-phase-2.json and the explorer-verified ABIs through a CHAINS entry, instead of name checks in the loop. Removed: - genesisHash/addressManager chain fields and the identity check in the transport. It added ~15 RPC calls on first use and before every broadcast, and failed every CLI custom network based on testnet-bradbury. The SDK already resolves AddressManager on chain from ConsensusMain. - the 429 retry loop in the transport. Unrelated to Phase 2 and it partly reverses #110; it belongs in its own PR if wanted. - check:bradbury script, its node:test checks (not run anywhere) and the README section that described the removed behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Bradbury Phase 2 public RPC answers HTTP 429 once a burst passes about five concurrent calls, so getEpochInfo and getValidatorInfo failed on most runs. Retry reads up to three times, honouring Retry-After. Writes are never retried, so a transaction cannot be broadcast twice (#110). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix: target Bradbury Phase 2 and verify RPC network identity * fix: retry throttled RPC reads without repeating broadcasts * fix: resolve deployment contracts through AddressManager * fix: reduce Bradbury Phase 2 change to the chain preset Keep what Phase 2 needs and follow the existing chain-preset pattern: - testnetBradbury: Phase 2 addresses, refreshed ConsensusMain/ConsensusData ABIs and the new RPC/explorer URLs. ABIs keep the file's existing key order and narrow-ABI style; Appeals.canAppeal gains its decision-id argument. - createClient: an endpoint override copies the chain instead of mutating the shared preset. - check:chains: Bradbury reads a pinned copy of genlayer-consensus deployments/bradbury-phase-2.json and the explorer-verified ABIs through a CHAINS entry, instead of name checks in the loop. Removed: - genesisHash/addressManager chain fields and the identity check in the transport. It added ~15 RPC calls on first use and before every broadcast, and failed every CLI custom network based on testnet-bradbury. The SDK already resolves AddressManager on chain from ConsensusMain. - the 429 retry loop in the transport. Unrelated to Phase 2 and it partly reverses #110; it belongs in its own PR if wanted. - check:bradbury script, its node:test checks (not run anywhere) and the README section that described the removed behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(client): retry rate-limited RPC reads The Bradbury Phase 2 public RPC answers HTTP 429 once a burst passes about five concurrent calls, so getEpochInfo and getValidatorInfo failed on most runs. Retry reads up to three times, honouring Retry-After. Writes are never retried, so a transaction cannot be broadcast twice (#110). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Darien Hernandez <dohernandez@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What
retryCount: 0andretryDelay: 0increateClient.Why
Testing done
readContracton a failing method and observed a single request and single error.Decisions made
Checks
Reviewing tips
src/client/client.ts, particularly thecustom(getCustomTransportConfig(config), { retryCount: 0, retryDelay: 0 })change.User facing release notes
Summary by CodeRabbit