Skip to content

Respect request drops properly in spawned execution tasks #20090

@mattsse

Description

@mattsse

Describe the feature

currently all rpc calls follow this pattern:

/// Executes the call request (`eth_call`) and returns the output
fn call(
&self,
request: RpcTxReq<<Self::RpcConvert as RpcConvert>::Network>,
block_number: Option<BlockId>,
overrides: EvmOverrides,
) -> impl Future<Output = Result<Bytes, Self::Error>> + Send {
async move {
let res =
self.transact_call_at(request, block_number.unwrap_or_default(), overrides).await?;
Self::Error::ensure_success(res.result)
}
}

let this = self.clone();
self.spawn_with_call_at(request, at, overrides, move |db, evm_env, tx_env| {
this.transact(db, evm_env, tx_env)
})

this gets called from the rpc request's context but the spawned task that performs the execution is fully detached and usually fully sync (evm execution)

we can use a tokio_util::sync::CancellationToken; and check during sync execution if this was cancelled and on the callsite use the drop_guard()

TODO

  • introduce a struct CallCtx {token: Cancellationtoken} that for now just wraps the token (we use a struct in case we need more things later)
  • Integrate in spawn fns: like
    fn spawn_with_call_at<F, R>(
    &self,
    request: RpcTxReq<<Self::RpcConvert as RpcConvert>::Network>,
    at: BlockId,
    overrides: EvmOverrides,
    f: F,
    ) -> impl Future<Output = Result<R, Self::Error>> + Send
  • Instantiate it and the drop guard on the callsite
    self.spawn_with_call_at(request, at, overrides, move |db, evm_env, tx_env| {
    this.transact(db, evm_env, tx_env)
    })

we can start with eth_call and then also integrate this in heaver tracing calls

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rpcRelated to the RPC implementationC-enhancementNew feature or requestinhouseOnly for reth team

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions