Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 8 additions & 14 deletions crates/optimism/rpc/src/eth/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use std::sync::Arc;

use crate::{OpEthApi, OpEthApiError};
use alloy_eips::BlockNumberOrTag;
use reth_primitives_traits::RecoveredBlock;
use reth_rpc_eth_api::{
helpers::{pending_block::PendingEnvBuilder, LoadPendingBlock},
FromEvmError, RpcConvert, RpcNodeCore,
};
use reth_rpc_eth_types::{builder::config::PendingBlockKind, EthApiError, PendingBlock};
use reth_storage_api::{
BlockReader, BlockReaderIdExt, ProviderBlock, ProviderReceipt, ReceiptProvider,
use reth_rpc_eth_types::{
builder::config::PendingBlockKind, pending_block::PendingBlockAndReceipts, EthApiError,
PendingBlock,
};
use reth_storage_api::{BlockReader, BlockReaderIdExt, ReceiptProvider};

impl<N, Rpc> LoadPendingBlock for OpEthApi<N, Rpc>
where
Expand All @@ -38,15 +38,9 @@ where
/// Returns the locally built pending block
async fn local_pending_block(
&self,
) -> Result<
Option<(
Arc<RecoveredBlock<ProviderBlock<Self::Provider>>>,
Arc<Vec<ProviderReceipt<Self::Provider>>>,
)>,
Self::Error,
> {
Comment on lines -42 to -47
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so much better

if let Ok(Some(block)) = self.pending_flashblock() {
return Ok(Some(block));
) -> Result<Option<PendingBlockAndReceipts<Self::Primitives>>, Self::Error> {
if let Ok(Some(pending)) = self.pending_flashblock() {
return Ok(Some(pending));
}

// See: <https://github.com/ethereum-optimism/op-geth/blob/f2e69450c6eec9c35d56af91389a1c47737206ca/miner/worker.go#L367-L375>
Expand All @@ -65,6 +59,6 @@ where
.receipts_by_block(block_id)?
.ok_or(EthApiError::ReceiptsNotFound(block_id.into()))?;

Ok(Some((Arc::new(block), Arc::new(receipts))))
Ok(Some(PendingBlockAndReceipts { block: Arc::new(block), receipts: Arc::new(receipts) }))
}
}
6 changes: 3 additions & 3 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ pub trait EthBlocks:
}

// If no pending block from provider, build the pending block locally.
if let Some((block, receipts)) = self.local_pending_block().await? {
return Ok(Some((block, receipts)));
if let Some(pending) = self.local_pending_block().await? {
return Ok(Some((pending.block, pending.receipts)));
}
}

Expand Down Expand Up @@ -296,7 +296,7 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking + RpcNodeCoreExt {

// If no pending block from provider, try to get local pending block
return match self.local_pending_block().await? {
Some((block, _)) => Ok(Some(block)),
Some(pending) => Ok(Some(pending.block)),
None => Ok(None),
};
}
Expand Down
4 changes: 3 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ pub trait LoadPendingBlock:
let pending = self.pending_block_env_and_cfg()?;

Ok(match pending.origin {
PendingBlockEnvOrigin::ActualPending(block, receipts) => Some((block, receipts)),
PendingBlockEnvOrigin::ActualPending(block, receipts) => {
Some(PendingBlockAndReceipts { block, receipts })
}
PendingBlockEnvOrigin::DerivedFromLatest(..) => {
self.pool_pending_block().await?.map(PendingBlock::into_block_and_receipts)
}
Expand Down
18 changes: 15 additions & 3 deletions crates/rpc/rpc-eth-types/src/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ pub type PendingBlockReceipts<N> = Arc<Vec<<N as NodePrimitives>::Receipt>>;

/// A type alias for a pair of an [`Arc`] wrapped [`RecoveredBlock`] and a vector of
/// [`NodePrimitives::Receipt`].
Comment on lines 85 to 86
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like this comment needs to be updated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Not blocking)

pub type PendingBlockAndReceipts<N> = (PendingRecoveredBlock<N>, PendingBlockReceipts<N>);
#[derive(Debug)]
pub struct PendingBlockAndReceipts<N: NodePrimitives> {
/// The pending recovered block.
pub block: PendingRecoveredBlock<N>,
/// The receipts for the pending block.
pub receipts: PendingBlockReceipts<N>,
}

/// Locally built pending block for `pending` tag.
#[derive(Debug, Clone, Constructor)]
Expand Down Expand Up @@ -118,13 +124,19 @@ impl<N: NodePrimitives> PendingBlock<N> {
/// Converts this [`PendingBlock`] into a pair of [`RecoveredBlock`] and a vector of
/// [`NodePrimitives::Receipt`]s, taking self.
pub fn into_block_and_receipts(self) -> PendingBlockAndReceipts<N> {
(self.executed_block.recovered_block, self.receipts)
PendingBlockAndReceipts {
block: self.executed_block.recovered_block,
receipts: self.receipts,
}
}

/// Returns a pair of [`RecoveredBlock`] and a vector of [`NodePrimitives::Receipt`]s by
/// cloning from borrowed self.
pub fn to_block_and_receipts(&self) -> PendingBlockAndReceipts<N> {
(self.executed_block.recovered_block.clone(), self.receipts.clone())
PendingBlockAndReceipts {
block: self.executed_block.recovered_block.clone(),
receipts: self.receipts.clone(),
}
}

/// Returns a hash of the parent block for this `executed_block`.
Expand Down