Skip to content

Commit 576e301

Browse files
committed
✨ Cleaner free rpc benchmarking
1 parent d5661ba commit 576e301

File tree

10 files changed

+426
-238
lines changed

10 files changed

+426
-238
lines changed

.changeset/light-books-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@konfeature/erpc-config-generator": patch
3+
---
4+
5+
More options for the free rpc benchmark during config, via the `freeRpcBenchmarkConfig` function

example/simple.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { http, createClient, toHex } from "viem";
2+
import { getBlock } from "viem/actions";
13
import {
24
arbitrum,
35
arbitrumSepolia,
@@ -6,6 +8,7 @@ import {
68
polygon,
79
polygonAmoy,
810
} from "viem/chains";
11+
import * as allChains from "viem/chains";
912
import {
1013
buildAlchemyUpstream,
1114
buildEnvioUpstream,
@@ -73,4 +76,37 @@ export default buildErpcConfig({
7376
}),
7477
],
7578
},
79+
// Properties for the rating of free rpc
80+
// Here we will perform the rpc benchmark on the eth_getLogs method, with from block being close to the latest block
81+
freeRpcBenchmarkConfig: async (chainId) => {
82+
// Get the latest block for the given chain id
83+
const chain = Object.values(allChains).find((c) => c.id === chainId);
84+
if (!chain) {
85+
throw new Error(`Chain ${chainId} not found`);
86+
}
87+
const latestBlock = await getBlock(
88+
// Create a dummy client
89+
createClient({ chain, transport: http() }),
90+
// Fetch the latest block
91+
{ blockTag: "latest" }
92+
);
93+
94+
return {
95+
debug: true,
96+
maxRpcLatencyInMs: 1000, // optional
97+
maxRpcCount: 10, // optional
98+
tracking: "yes", // optional (tracking params extracted to the chainlist params)
99+
benchmark: {
100+
retryCount: 1,
101+
retryDelayInMs: 1000,
102+
rpcTimeoutInMs: 5000,
103+
runs: 1,
104+
runsIntervalInMs: 200,
105+
request: {
106+
method: "eth_getLogs",
107+
params: [{ fromBlock: toHex(latestBlock.number) }],
108+
},
109+
},
110+
};
111+
},
76112
});

0 commit comments

Comments
 (0)