Skip to content

Conversation

@lpahlavi
Copy link
Contributor

@lpahlavi lpahlavi commented Oct 24, 2025

This PR refactors the way requests are created in the EVM RPC canister to make the way for #509 where CyclesCost endpoints are added to estimate the cycles cost of requests.

The refactoring introduces a new MultiRpcResult struct which represents the HTTP outcalls required to answer a request. MultiRpcResult currently only has a public send_and_reduce method, however #509 adds a cycles_cost method. This will allow re-using the request creation logic (e.g. computing the estimated response size) between the actual request endpoints (e.g. eth_getLogs) and the cycles cost endpoints (e.g. eth_getLogsCyclesCost).

pub type MultiCallResults<T> = MultiResults<RpcService, T, RpcError>;
pub type ReducedResult<T> = canhttp::multi::ReducedResult<RpcService, T, RpcError>;

fn process_result<T>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method was moved from candid_rpc/mod.rs (unchanged).

@lpahlavi lpahlavi force-pushed the lpahlavi/refactor-multi-rpc-requests branch from afe5e68 to a65dec5 Compare October 24, 2025 09:13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were moved to rpc_client/tests.rs (unchanged).

@lpahlavi lpahlavi force-pushed the lpahlavi/refactor-multi-rpc-requests branch from a65dec5 to eddd95a Compare October 24, 2025 09:36
@lpahlavi lpahlavi changed the title feat: add endpoints to calculate request costs refactor: prepare to add RequestCost endpoints Oct 24, 2025
@lpahlavi lpahlavi force-pushed the lpahlavi/refactor-multi-rpc-requests branch from eddd95a to 24b69e2 Compare October 24, 2025 11:41
@lpahlavi lpahlavi requested a review from gregorydemay October 24, 2025 13:00
@lpahlavi lpahlavi marked this pull request as ready for review October 24, 2025 13:00
@lpahlavi lpahlavi requested a review from a team as a code owner October 24, 2025 13:00
Copy link
Contributor

@gregorydemay gregorydemay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this refactoring @lpahlavi ! Some minor questions about lifetimes

@lpahlavi lpahlavi requested a review from gregorydemay October 31, 2025 12:41
@lpahlavi lpahlavi merged commit fd431be into main Oct 31, 2025
11 checks passed
@lpahlavi lpahlavi deleted the lpahlavi/refactor-multi-rpc-requests branch October 31, 2025 14:24
lpahlavi added a commit that referenced this pull request Nov 3, 2025
Building on the refactoring from #508, this PR adds query endpoints for
all `eth_*` endpoints on the EVM RPC canister that allow estimating the
number of cycles required for a request. This improves on the existing
`requestCost` endpoint in 2 significant ways:
* The new query endpoints (e.g. `eth_getLogsCyclesCost`) have the same
signature as their update counterparts (e.g. `eth_getLogs`) instead of
requiring the user to construct the raw JSON payload themselves.
* The new query endpoints can be used to compute the cycles cost of
requests with multiple RPC providers (e.g. with the default providers).

As a result, the existing `requestCost` endpoint is left for backwards
compatibility but is now deprecated.

In addition, the `EvmRpcClient` now has a `request_cost()` method that
allows computing the estimated cost of a request with the new query
endpoints.
@lpahlavi lpahlavi mentioned this pull request Nov 3, 2025
lpahlavi added a commit that referenced this pull request Nov 3, 2025
## 🤖 New release

* `evm_rpc_client`: 0.1.0 -> 0.2.0 (✓ API compatible changes)
* `evm_rpc`: 2.6.0 -> 2.7.0 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `evm_rpc_client`

<blockquote>

## [0.2.0] - 2025-11-03

### Added

- Add `.request_cost()` method to `RequestBuilder` to compute the cycles
cost of a request via the new `CyclesCost`
query endpoints
([#509](#509))
- Add the option to configure a retry strategy in the EVM RPC client to
e.g., try a request with increasingly many
cycles if it fails to to insufficient cycles
([#512](#512))

[0.2.0]:
evm_rpc_client-v0.1.0...evm_rpc_client-v0.2.0
</blockquote>

## `evm_rpc`

<blockquote>

## [2.7.0] - 2025-11-03

### Added

- For each `eth_*` endpoint, add a new corresponding `eth_*CyclesCost`
query endpoint with the same Candid arguments, that allows computing the
cycles cost of calling the corresponding `eth_*` update endpoint
([#508](#508),
[#509](#509))

### Changed

- Use constant-size request IDs in JSON-RPC requests to allow for
consistent request cycles costs
([#514](#514))

[2.7.0]:
v2.6.0...v2.7.0
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Louis Pahlavi <[email protected]>
@github-actions github-actions bot mentioned this pull request Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants