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

chore(rpc): pending block helper trait #8640

Merged
merged 44 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cab888f
Make on_blocking_task method accessible in default trait method impls
emhane Jun 1, 2024
b902f35
Minimise thread interface eth api
emhane Jun 1, 2024
c35b40e
Update docs and symbol name
emhane Jun 1, 2024
8ccddd3
Add missing reth primitives to op feature
emhane Jun 1, 2024
257dc5d
Remove feature gate to fix broken test
emhane Jun 1, 2024
40194d6
Fix flaky test
emhane Jun 1, 2024
68e64b4
fixup! Fix flaky test
emhane Jun 1, 2024
30b63cc
fixup! Fix flaky test
emhane Jun 1, 2024
fcc64ea
Update lock file
emhane Jun 1, 2024
734ac99
Reinsert functions for spawning blocking threads into EthTransactions
emhane Jun 4, 2024
c000f43
Drive-by, update docs
emhane Jun 4, 2024
d1b91ad
Move spawn cpu heavy to trait
emhane Jun 4, 2024
eec99b8
Fix lint
emhane Jun 4, 2024
924024f
Revert impl for spawning blocking io
emhane Jun 4, 2024
ea6cbd3
Make impl of spawn blocking default trait methods
emhane Jun 4, 2024
ecb6771
Update docs
emhane Jun 5, 2024
fe494dc
Revert unrelated changes
emhane Jun 5, 2024
ba6f403
Merge branch 'main' into emhane/blocking-read
emhane Jun 5, 2024
55d2649
Merge branch 'matt/scaffold-ethapi' into emhane/blocking-read
emhane Jun 5, 2024
139f97f
Merge branch 'matt/scaffold-ethapi' into emhane/blocking-read
emhane Jun 5, 2024
8b8ed16
Fix lint
emhane Jun 5, 2024
f3ed6bd
Add super traits to spawn blocking
emhane Jun 5, 2024
16334cd
Move impl of methods using evm config to default trait methods
emhane Jun 5, 2024
20d2489
Move EthApi state access methods into trait
emhane Jun 5, 2024
4a40032
Move EthTransaction impls to default trait methods
emhane Jun 5, 2024
f2df915
Move state rpc methods into new trait default impl
emhane Jun 5, 2024
ca19811
fixup! Move state rpc methods into new trait default impl
emhane Jun 5, 2024
8ee373c
Move EthTransactions impl to default trait methods
emhane Jun 6, 2024
6dfac1a
Add trait for pending block
emhane Jun 6, 2024
90f67b6
Merge branch 'matt/scaffold-ethapi' into emhane/ethapi-txns
emhane Jun 6, 2024
0db764e
Merge branch 'matt/scaffold-ethapi' into emhane/ethapi-txns
emhane Jun 6, 2024
2340e87
Merge branch 'emhane/ethapi-txns' into emhane/ethapi-pending-block
emhane Jun 6, 2024
3c0b7ab
Fix lint
emhane Jun 6, 2024
6634723
Merge branch 'emhane/ethapi-txns' into emhane/ethapi-pending-block
emhane Jun 6, 2024
e93cb32
Nitpick
emhane Jun 8, 2024
b1a3160
Return impl types without ref
emhane Jun 8, 2024
9ec16f0
Move RawTransactionForwarder into traits mod
emhane Jun 8, 2024
34eac96
Merge branch 'matt/scaffold-ethapi' into emhane/ethapi-txns
emhane Jun 8, 2024
13edf49
Fix merge conflicts
emhane Jun 8, 2024
42f7d74
Merge branch 'emhane/ethapi-txns' of github.com:paradigmxyz/reth into…
emhane Jun 8, 2024
a355c26
Merge branch 'emhane/ethapi-txns' into emhane/ethapi-pending-block
emhane Jun 8, 2024
4b81978
Fix lint
emhane Jun 8, 2024
4efb2e8
Merge branch 'matt/scaffold-ethapi' into emhane/ethapi-pending-block
emhane Jun 8, 2024
008f939
Fix lint
emhane Jun 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ tracing.workspace = true
tracing-futures = "0.2"
schnellru.workspace = true
futures.workspace = true
derive_more.workspace = true
derive_more = { workspace = true, default-features = false, features = ["deref", "deref_mut", "constructor"] }
dyn-clone.workspace = true

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
eth::{
api::{traits::SpawnBlocking, EthTransactions},
api::{EthTransactions, LoadState, SpawnBlocking},
error::{EthApiError, EthResult},
revm_utils::{prepare_call_env, EvmOverrides},
},
Expand Down Expand Up @@ -65,7 +65,7 @@ impl<Provider, Eth> DebugApi<Provider, Eth> {
impl<Provider, Eth> DebugApi<Provider, Eth>
where
Provider: BlockReaderIdExt + HeaderProvider + ChainSpecProvider + 'static,
Eth: EthTransactions + 'static,
Eth: EthTransactions + LoadState + SpawnBlocking + 'static,
{
/// Acquires a permit to execute a tracing call.
async fn acquire_trace_permit(&self) -> Result<OwnedSemaphorePermit, AcquireError> {
Expand Down Expand Up @@ -614,7 +614,7 @@ where
impl<Provider, Eth> DebugApiServer for DebugApi<Provider, Eth>
where
Provider: BlockReaderIdExt + HeaderProvider + ChainSpecProvider + 'static,
Eth: EthApiSpec + SpawnBlocking + 'static,
Eth: EthApiSpec + SpawnBlocking + LoadState + 'static,
{
/// Handler for `debug_getRawHeader`
async fn raw_header(&self, block_id: BlockId) -> RpcResult<Bytes> {
Expand Down
22 changes: 18 additions & 4 deletions crates/rpc/rpc/src/eth/api/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use reth_transaction_pool::TransactionPool;

use crate::eth::api::EthBlocks;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Copy link
Member Author

Choose a reason for hiding this comment

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

use super::traits::LoadPendingBlock;

impl<Provider, Pool, Network, EvmConfig> EthBlocks for EthApi<Provider, Pool, Network, EvmConfig>
where
Provider: BlockReaderIdExt + BlockReader + ReceiptProvider,
Expand Down Expand Up @@ -94,7 +96,10 @@ where
pub(crate) async fn block(
&self,
block_id: impl Into<BlockId>,
) -> EthResult<Option<reth_primitives::SealedBlock>> {
) -> EthResult<Option<reth_primitives::SealedBlock>>
where
Self: LoadPendingBlock,
{
self.block_with_senders(block_id)
.await
.map(|maybe_block| maybe_block.map(|block| block.block))
Expand All @@ -104,7 +109,10 @@ where
pub(crate) async fn block_with_senders(
&self,
block_id: impl Into<BlockId>,
) -> EthResult<Option<reth_primitives::SealedBlockWithSenders>> {
) -> EthResult<Option<reth_primitives::SealedBlockWithSenders>>
where
Self: LoadPendingBlock,
{
let block_id = block_id.into();

if block_id.is_pending() {
Expand Down Expand Up @@ -133,7 +141,10 @@ where
&self,
block_id: impl Into<BlockId>,
full: bool,
) -> EthResult<Option<RichBlock>> {
) -> EthResult<Option<RichBlock>>
where
Self: LoadPendingBlock,
{
let block = match self.block_with_senders(block_id).await? {
Some(block) => block,
None => return Ok(None),
Expand All @@ -151,7 +162,10 @@ where
pub(crate) async fn rpc_block_header(
&self,
block_id: impl Into<BlockId>,
) -> EthResult<Option<Header>> {
) -> EthResult<Option<Header>>
where
Self: LoadPendingBlock,
{
let header = self.rpc_block(block_id, false).await?.map(|block| block.inner.header);
Ok(header)
}
Expand Down
16 changes: 10 additions & 6 deletions crates/rpc/rpc/src/eth/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
eth::{
api::{EthTransactions, SpawnBlocking},
api::{EthTransactions, LoadPendingBlock, LoadState, SpawnBlocking},
error::{ensure_success, EthApiError, EthResult, RevertError, RpcInvalidTransactionError},
revm_utils::{
apply_state_overrides, build_call_evm_env, caller_gas_allowance,
Expand All @@ -25,11 +25,11 @@ use reth_rpc_types::{
};
use reth_transaction_pool::TransactionPool;
use revm::{
db::{CacheDB, DatabaseRef},
db::CacheDB,
primitives::{
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, HaltReason, TransactTo,
},
DatabaseCommit,
DatabaseCommit, DatabaseRef,
};
use revm_inspectors::access_list::AccessListInspector;
use tracing::trace;
Expand All @@ -43,6 +43,7 @@ const ESTIMATE_GAS_ERROR_RATIO: f64 = 0.015;

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Self: LoadState,
Pool: TransactionPool + Clone + 'static,
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Expand All @@ -59,7 +60,7 @@ where
let (cfg, block_env, at) = self.evm_env_at(at).await?;

self.spawn_blocking_io(move |this| {
let state = this.state_at(at)?;
let state = this.state_at_block_id(at)?;
this.estimate_gas_with(cfg, block_env, request, state, state_override)
})
.await
Expand All @@ -85,7 +86,10 @@ where
bundle: Bundle,
state_context: Option<StateContext>,
mut state_override: Option<StateOverride>,
) -> EthResult<Vec<EthCallResponse>> {
) -> EthResult<Vec<EthCallResponse>>
where
Self: LoadPendingBlock,
{
let Bundle { transactions, block_override } = bundle;
if transactions.is_empty() {
return Err(EthApiError::InvalidParams(String::from("transactions are empty.")))
Expand Down Expand Up @@ -394,7 +398,7 @@ where
at: BlockId,
mut request: TransactionRequest,
) -> EthResult<AccessListWithGasUsed> {
let state = self.state_at(at)?;
let state = self.state_at_block_id(at)?;

let mut env = build_call_evm_env(cfg, block, request.clone())?;

Expand Down
3 changes: 3 additions & 0 deletions crates/rpc/rpc/src/eth/api/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ use reth_rpc_types::FeeHistory;
use reth_transaction_pool::TransactionPool;
use tracing::debug;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Copy link
Member Author

Choose a reason for hiding this comment

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

use super::traits::LoadPendingBlock;

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Self: LoadPendingBlock,
Pool: TransactionPool + Clone + 'static,
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Expand Down
Loading
Loading