-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): paginate world deploy logs (#3217)
- Loading branch information
Showing
14 changed files
with
150 additions
and
180 deletions.
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 @@ | ||
--- | ||
"@latticexyz/cli": patch | ||
--- | ||
|
||
When deploying to an existing world, the deployer now paginates with [`fetchLogs`](https://github.com/latticexyz/mud/blob/main/packages/block-logs-stream/src/fetchLogs.ts) to find the world deployment. |
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,7 @@ | ||
--- | ||
"@latticexyz/block-logs-stream": patch | ||
--- | ||
|
||
- For block range size errors, `fetchLogs` now reduces the max block range for subsequent requests in its loop. For block out of range or response size errors, only the current request's block range is reduced until the request succeeds, then it resets to the max block range. | ||
- Added `fetchBlockLogs` to find all matching logs of the given block range, grouped by block number, in a single async call. | ||
- Loosened the `publicClient` type and switched to tree shakable actions. |
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
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,26 @@ | ||
import { AbiEvent } from "viem"; | ||
import { GroupLogsByBlockNumberResult, groupLogsByBlockNumber } from "./groupLogsByBlockNumber"; | ||
import { FetchLogsOptions, FetchLogsResult, fetchLogs } from "./fetchLogs"; | ||
import { iteratorToArray } from "@latticexyz/common/utils"; | ||
|
||
/** | ||
* Fetches all logs from the blockchain for the given range, grouped by block number. | ||
* | ||
* @remarks | ||
* The function will fetch logs according to the given options. | ||
* If the function encounters rate limits, it will retry until `maxRetryCount` is reached. | ||
* If the function encounters a block range that is too large, it will half the block range and retry, until the block range can't be halved anymore. | ||
* | ||
* @param {FetchLogsOptions<AbiEvent[]>} options See `FetchLogsOptions`. | ||
* | ||
* @returns {GroupLogsByBlockNumberResult} See `GroupLogsByBlockNumberResult`. | ||
* | ||
* @throws Will throw an error if the block range can't be reduced any further. | ||
*/ | ||
export async function fetchBlockLogs<abiEvents extends readonly AbiEvent[]>( | ||
opts: FetchLogsOptions<abiEvents>, | ||
): Promise<GroupLogsByBlockNumberResult<FetchLogsResult<abiEvents>["logs"][number]>> { | ||
const fetchedLogs = await iteratorToArray(fetchLogs(opts)); | ||
const logs = fetchedLogs.flatMap(({ logs }) => logs); | ||
return groupLogsByBlockNumber(logs); | ||
} |
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
Oops, something went wrong.