Support for batching individual RPC calls #3274
Unanswered
holic
asked this question in
Idea / Feature Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to add an option into MUD's logs fetching mechanism (used to sync data from chain) that turns an RPC request like
eth_getLogs
into[eth_getBlockByNumber, eth_getLogs]
to help with issues related to load balanced RPCs: https://indexsupply.com/shovel/docs/#unsynchronized-ethereum-nodesHowever, I am failing to find a good entry point into Viem to do this without creating a bunch of wrappers around Viem things (e.g. http transport or rpc client) or "prop drilling" options through the whole MUD stack.
For context, when using MUD's sync tooling, you provide a Viem client, which allows users to configure their transport in a way that suits them/their RPC best (http vs ws, fallbacks, retries, etc.).
Some ideas on the Viem side that could help with this (ordered by favorite to least favorite):
Extend
EIP1193RequestFn
or offer an alternative that supports batched calls likerequest([body, body])
. I realize the EIP-1193 spec doesn't account for this, so I'm not sure how best to model this on the Viem side. This could would likely require some refactoring of the batch scheduler and de-duping.Expose transport options or whether batching is enabled. If I can detect that batching is enabled, I could do the RPC calls in parallel like
Promise.all([eth_getBlockByNumber, eth_getLogs])
and expect the batch scheduler to put this into a single RPC call.Expose
url
inHttpRpcClient
so I can take this as a type of client for fetching logs and be able to throwRpcRequestError
using theurl
. Without this, I'd have to make my owncreateHttpRpcClient
wrapper that either exposesurl
or internally throws theRpcRequestError
with the providedurl
.HttpRpcClient
as a client type means we miss out on retry logic, fallback handling, etc. that transports give. So although this would be a small hole to poke, it probably isn't a great overall solution.Allow
onRequest
andonResponse
overrides insideEIP1193RequestFn
options. This means I could write a transport wrapper that taps into the RPC request/response lifecycle to transform specificeth_getLogs
requests into the desired[eth_getBlockByNumber, eth_getLogs]
.Beta Was this translation helpful? Give feedback.
All reactions