-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add coinbase rpc to getLogsRetryRanges (#1065)
* add coinbase rpc to getLogsRetryRanges * chore: changeset
- Loading branch information
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ponder/utils": patch | ||
--- | ||
|
||
Added retry range detection for coinbase rpcs. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { LimitExceededRpcError, numberToHex } from "viem"; | ||
import { expect, test } from "vitest"; | ||
import { getLogsRetryHelper } from "../getLogsRetryHelper.js"; | ||
import { type Params, getRequest } from "./utils.js"; | ||
|
||
const request = getRequest(process.env.RPC_URL_COINBASE_8453!); | ||
const fromBlock = 10_000_000n; | ||
const maxBlockRange = 999n; | ||
|
||
test("coinbase success", async () => { | ||
const logs = await request({ | ||
method: "eth_getLogs", | ||
params: [ | ||
{ | ||
address: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22", | ||
fromBlock: numberToHex(fromBlock), | ||
toBlock: numberToHex(fromBlock + maxBlockRange), | ||
}, | ||
], | ||
}); | ||
|
||
expect(logs).toHaveLength(77); | ||
}); | ||
|
||
test( | ||
"coinbase block range", | ||
async () => { | ||
const params: Params = [ | ||
{ | ||
address: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22", | ||
fromBlock: numberToHex(fromBlock), | ||
toBlock: numberToHex(fromBlock + maxBlockRange + 1n), | ||
}, | ||
]; | ||
|
||
const error = await request({ | ||
method: "eth_getLogs", | ||
params, | ||
}).catch((error) => error); | ||
|
||
expect(error).toBeInstanceOf(LimitExceededRpcError); | ||
expect(JSON.stringify(error)).includes( | ||
"please limit the query to at most 1000 blocks", | ||
); | ||
|
||
const retry = getLogsRetryHelper({ | ||
params, | ||
error, | ||
}); | ||
|
||
expect(retry).toStrictEqual({ | ||
shouldRetry: true, | ||
ranges: [ | ||
{ | ||
fromBlock: numberToHex(fromBlock), | ||
toBlock: numberToHex(fromBlock + maxBlockRange), | ||
}, | ||
{ | ||
fromBlock: numberToHex(fromBlock + maxBlockRange + 1n), | ||
toBlock: numberToHex(fromBlock + maxBlockRange + 1n), | ||
}, | ||
], | ||
}); | ||
}, | ||
{ timeout: 15_000 }, | ||
); |
This file contains 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