Skip to content

Conversation

@lpahlavi
Copy link
Contributor

@lpahlavi lpahlavi commented Oct 24, 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 force-pushed the lpahlavi/add-cycles-cost-endpoints branch from 1248a02 to b4be97a Compare October 24, 2025 12:29
@lpahlavi lpahlavi force-pushed the lpahlavi/add-cycles-cost-endpoints branch from b4be97a to a101ab5 Compare October 24, 2025 12:50
@lpahlavi lpahlavi force-pushed the lpahlavi/add-cycles-cost-endpoints branch 4 times, most recently from d9e44f4 to 1deb585 Compare October 24, 2025 14:13
@lpahlavi lpahlavi force-pushed the lpahlavi/add-cycles-cost-endpoints branch from 1deb585 to d7a8a66 Compare October 24, 2025 15:49
@lpahlavi lpahlavi requested a review from gregorydemay October 24, 2025 17:51
@lpahlavi lpahlavi marked this pull request as ready for review October 24, 2025 17:51
@lpahlavi lpahlavi requested a review from a team as a code owner October 24, 2025 17:51
src/memory.rs Outdated
// requests and responses in logs.
*counter = counter.wrapping_add(1);
Id::from(current_request_id)
Id::from(ConstantSizeId::from(current_request_id))
Copy link
Contributor Author

@lpahlavi lpahlavi Oct 29, 2025

Choose a reason for hiding this comment

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

@gregorydemay I realized that this is necessary so that the CyclesCost endpoints give the correct cost back. The reason is, that currently the requests get initialized with a ConstantSizeId::ZERO ID here (which is called here), but in the actual update endpoints, the IDs get changed from a ConstantSizeId to an Id::Number here.

Note that I opened another PR (#514) with the relevant changes, but didn't want to rebase this one as it was already in review. I would aim to merge that one first, and then merge those changes here. I did include some changes here already just so that the CI is green.

lpahlavi added a commit that referenced this pull request Oct 31, 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`).
Base automatically changed from lpahlavi/refactor-multi-rpc-requests to main October 31, 2025 14:24
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 @lpahlavi for this PR! some minor comments but otherwise LGTM!

@lpahlavi lpahlavi merged commit c08ec55 into main Nov 3, 2025
11 checks passed
@lpahlavi lpahlavi deleted the lpahlavi/add-cycles-cost-endpoints branch November 3, 2025 10:23
@github-actions github-actions bot mentioned this pull request Oct 21, 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