Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a standalone gas estimate type #12250

Open
mattsse opened this issue Nov 1, 2024 · 0 comments
Open

Introduce a standalone gas estimate type #12250

mattsse opened this issue Nov 1, 2024 · 0 comments
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request S-needs-triage This issue needs to be labelled

Comments

@mattsse
Copy link
Collaborator

mattsse commented Nov 1, 2024

Describe the feature

with

pub trait RpcNodeCore: Clone + Send + Sync {

we now have a way to plugin additional logic into the rpc stack:

for example:

pub trait EthApiSpec:
RpcNodeCore<

we can use this as the entrypoint to abstract away more evm specific logic, for example gas estimation:

/// Estimate gas needed for execution of the `request` at the [`BlockId`].
fn estimate_gas_at(
&self,
request: TransactionRequest,
at: BlockId,
state_override: Option<StateOverride>,
) -> impl Future<Output = Result<U256, Self::Error>> + Send {
Call::estimate_gas_at(self, request, at, state_override)
}

which has a very simple interface

but perhaps it would be simpler if we introduce a new trait and type like EthApiCore {type Estimator;} so that it can plugged into the rpc stack by implementing

so we can do trait Call: EthApiCore< Estimator: impl trait GasEstimator> or similar.

this can then be plugged into the rpc type like

impl<N> RpcNodeCore for OpEthApi<N>

this means we need to convert this into a standalone type first:

/// Estimate gas needed for execution of the `request` at the [`BlockId`].
fn estimate_gas_at(
&self,
request: TransactionRequest,
at: BlockId,
state_override: Option<StateOverride>,
) -> impl Future<Output = Result<U256, Self::Error>> + Send
where
Self: LoadPendingBlock,
{
async move {
let (cfg, block_env, at) = self.evm_env_at(at).await?;
self.spawn_blocking_io(move |this| {
let state = this.state_at_block_id(at)?;
this.estimate_gas_with(cfg, block_env, request, state, state_override)
})
.await
}
}

Additional context

No response

@mattsse mattsse added C-enhancement New feature or request S-needs-triage This issue needs to be labelled A-rpc Related to the RPC implementation labels Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request S-needs-triage This issue needs to be labelled
Projects
Status: Todo
Development

No branches or pull requests

1 participant