mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-08 03:01:12 -04:00
changed block_with_senders() to recovered_block() (#14894)
This commit is contained in:
committed by
GitHub
parent
771cd3ce58
commit
493011ed0c
@@ -130,7 +130,7 @@ impl<N: NodePrimitives> Chain<N> {
|
||||
}
|
||||
|
||||
/// Returns the block with matching hash.
|
||||
pub fn block_with_senders(&self, block_hash: BlockHash) -> Option<&RecoveredBlock<N::Block>> {
|
||||
pub fn recovered_block(&self, block_hash: BlockHash) -> Option<&RecoveredBlock<N::Block>> {
|
||||
self.blocks.iter().find_map(|(_num, block)| (block.hash() == block_hash).then_some(block))
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ where
|
||||
// Fetch the block with senders for execution.
|
||||
let block_with_senders = self
|
||||
.provider
|
||||
.block_with_senders(block_number.into(), TransactionVariant::WithHash)?
|
||||
.recovered_block(block_number.into(), TransactionVariant::WithHash)?
|
||||
.ok_or_else(|| ProviderError::HeaderNotFound(block_number.into()))?;
|
||||
|
||||
// Configure the executor to use the previous block's state.
|
||||
|
||||
@@ -94,7 +94,7 @@ where
|
||||
let block_id = latest.hash().into();
|
||||
let block = self
|
||||
.provider()
|
||||
.block_with_senders(block_id, Default::default())
|
||||
.recovered_block(block_id, Default::default())
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.ok_or(EthApiError::HeaderNotFound(block_id.into()))?;
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ pub trait EthBlocks: LoadBlock {
|
||||
Self: FullEthApiTypes,
|
||||
{
|
||||
async move {
|
||||
let Some(block) = self.block_with_senders(block_id).await? else { return Ok(None) };
|
||||
let Some(block) = self.recovered_block(block_id).await? else { return Ok(None) };
|
||||
|
||||
let block = from_block((*block).clone(), full.into(), self.tx_resp_builder())?;
|
||||
Ok(Some(block))
|
||||
@@ -205,7 +205,7 @@ pub trait EthBlocks: LoadBlock {
|
||||
pub trait LoadBlock: LoadPendingBlock + SpawnBlocking + RpcNodeCoreExt {
|
||||
/// Returns the block object for the given block id.
|
||||
#[expect(clippy::type_complexity)]
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
) -> impl Future<
|
||||
|
||||
@@ -94,7 +94,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
|
||||
let total_gas_limit = self.call_gas_limit();
|
||||
|
||||
let base_block =
|
||||
self.block_with_senders(block).await?.ok_or(EthApiError::HeaderNotFound(block))?;
|
||||
self.recovered_block(block).await?.ok_or(EthApiError::HeaderNotFound(block))?;
|
||||
let mut parent = base_block.sealed_header().clone();
|
||||
|
||||
let this = self.clone();
|
||||
@@ -262,7 +262,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
|
||||
|
||||
let ((evm_env, _), block) = futures::try_join!(
|
||||
self.evm_env_at(target_block),
|
||||
self.block_with_senders(target_block)
|
||||
self.recovered_block(target_block)
|
||||
)?;
|
||||
|
||||
let block = block.ok_or(EthApiError::HeaderNotFound(target_block))?;
|
||||
|
||||
@@ -299,7 +299,7 @@ pub trait LoadFee: LoadBlock {
|
||||
None => {
|
||||
// fetch pending base fee
|
||||
let base_fee = self
|
||||
.block_with_senders(BlockNumberOrTag::Pending.into())
|
||||
.recovered_block(BlockNumberOrTag::Pending.into())
|
||||
.await?
|
||||
.ok_or(EthApiError::HeaderNotFound(BlockNumberOrTag::Pending.into()))?
|
||||
.base_fee_per_gas()
|
||||
@@ -335,7 +335,7 @@ pub trait LoadFee: LoadBlock {
|
||||
///
|
||||
/// See also: <https://github.com/ethereum/pm/issues/328#issuecomment-853234014>
|
||||
fn gas_price(&self) -> impl Future<Output = Result<U256, Self::Error>> + Send {
|
||||
let header = self.block_with_senders(BlockNumberOrTag::Latest.into());
|
||||
let header = self.recovered_block(BlockNumberOrTag::Latest.into());
|
||||
let suggested_tip = self.suggested_priority_fee();
|
||||
async move {
|
||||
let (header, suggested_tip) = futures::try_join!(header, suggested_tip)?;
|
||||
@@ -347,7 +347,7 @@ pub trait LoadFee: LoadBlock {
|
||||
/// Returns a suggestion for a base fee for blob transactions.
|
||||
fn blob_base_fee(&self) -> impl Future<Output = Result<U256, Self::Error>> + Send {
|
||||
async move {
|
||||
self.block_with_senders(BlockNumberOrTag::Latest.into())
|
||||
self.recovered_block(BlockNumberOrTag::Latest.into())
|
||||
.await?
|
||||
.and_then(|h| {
|
||||
h.maybe_next_block_blob_fee(
|
||||
|
||||
@@ -300,7 +300,7 @@ pub trait Trace:
|
||||
if block.is_some() {
|
||||
return Ok(block)
|
||||
}
|
||||
self.block_with_senders(block_id).await
|
||||
self.recovered_block(block_id).await
|
||||
};
|
||||
|
||||
let ((evm_env, _), block) = futures::try_join!(self.evm_env_at(block_id), block)?;
|
||||
|
||||
@@ -206,7 +206,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
|
||||
Self: LoadBlock,
|
||||
{
|
||||
async move {
|
||||
if let Some(block) = self.block_with_senders(block_id).await? {
|
||||
if let Some(block) = self.recovered_block(block_id).await? {
|
||||
let block_hash = block.hash();
|
||||
let block_number = block.number();
|
||||
let base_fee_per_gas = block.base_fee_per_gas();
|
||||
@@ -278,7 +278,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
|
||||
.await?;
|
||||
|
||||
let block_id = num.into();
|
||||
self.block_with_senders(block_id)
|
||||
self.recovered_block(block_id)
|
||||
.await?
|
||||
.and_then(|block| {
|
||||
let block_hash = block.hash();
|
||||
@@ -317,7 +317,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
|
||||
Self: LoadBlock,
|
||||
{
|
||||
async move {
|
||||
if let Some(block) = self.block_with_senders(block_id).await? {
|
||||
if let Some(block) = self.recovered_block(block_id).await? {
|
||||
if let Some(tx) = block.body().transactions().get(index) {
|
||||
return Ok(Some(tx.encoded_2718().into()))
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ where
|
||||
|
||||
let ((evm_env, _), block) = futures::try_join!(
|
||||
self.eth_api().evm_env_at(block_hash.into()),
|
||||
self.eth_api().block_with_senders(block_hash.into()),
|
||||
self.eth_api().recovered_block(block_hash.into()),
|
||||
)?;
|
||||
|
||||
let block = block.ok_or(EthApiError::HeaderNotFound(block_id))?;
|
||||
@@ -496,7 +496,7 @@ where
|
||||
let target_block = block_number.unwrap_or_default();
|
||||
let ((mut evm_env, _), block) = futures::try_join!(
|
||||
self.eth_api().evm_env_at(target_block),
|
||||
self.eth_api().block_with_senders(target_block),
|
||||
self.eth_api().recovered_block(target_block),
|
||||
)?;
|
||||
|
||||
let opts = opts.unwrap_or_default();
|
||||
@@ -600,7 +600,7 @@ where
|
||||
let this = self.clone();
|
||||
let block = this
|
||||
.eth_api()
|
||||
.block_with_senders(hash.into())
|
||||
.recovered_block(hash.into())
|
||||
.await?
|
||||
.ok_or(EthApiError::HeaderNotFound(hash.into()))?;
|
||||
|
||||
@@ -618,7 +618,7 @@ where
|
||||
let this = self.clone();
|
||||
let block = this
|
||||
.eth_api()
|
||||
.block_with_senders(block_id.into())
|
||||
.recovered_block(block_id.into())
|
||||
.await?
|
||||
.ok_or(EthApiError::HeaderNotFound(block_id.into()))?;
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ where
|
||||
|
||||
let block_id = parent_block.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));
|
||||
let (mut evm_env, current_block_id) = self.eth_api().evm_env_at(block_id).await?;
|
||||
let current_block = self.eth_api().block_with_senders(current_block_id).await?;
|
||||
let current_block = self.eth_api().recovered_block(current_block_id).await?;
|
||||
let current_block = current_block.ok_or(EthApiError::HeaderNotFound(block_id))?;
|
||||
|
||||
let eth_api = self.inner.eth_api.clone();
|
||||
|
||||
@@ -374,7 +374,7 @@ where
|
||||
},
|
||||
);
|
||||
|
||||
let block = self.eth_api().block_with_senders(block_id);
|
||||
let block = self.eth_api().recovered_block(block_id);
|
||||
let (maybe_traces, maybe_block) = futures::try_join!(traces, block)?;
|
||||
|
||||
let mut maybe_traces =
|
||||
@@ -472,9 +472,7 @@ where
|
||||
|
||||
let Some(transactions) = res else { return Ok(None) };
|
||||
|
||||
let Some(block) = self.eth_api().block_with_senders(block_id).await? else {
|
||||
return Ok(None)
|
||||
};
|
||||
let Some(block) = self.eth_api().recovered_block(block_id).await? else { return Ok(None) };
|
||||
|
||||
Ok(Some(BlockOpcodeGas {
|
||||
block_hash: block.hash(),
|
||||
|
||||
@@ -328,7 +328,7 @@ where
|
||||
|
||||
// we need the block's transactions but we don't need the transaction hashes
|
||||
let block = provider
|
||||
.block_with_senders(block_number.into(), TransactionVariant::NoHash)?
|
||||
.recovered_block(block_number.into(), TransactionVariant::NoHash)?
|
||||
.ok_or_else(|| ProviderError::HeaderNotFound(block_number.into()))?;
|
||||
|
||||
fetch_block_duration += fetch_block_start.elapsed();
|
||||
|
||||
@@ -316,12 +316,12 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider<N> {
|
||||
/// hashes, since they would need to be calculated on the spot, and we want fast querying.**
|
||||
///
|
||||
/// Returns `None` if block is not found.
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
self.consistent_provider()?.block_with_senders(id, transaction_kind)
|
||||
self.consistent_provider()?.recovered_block(id, transaction_kind)
|
||||
}
|
||||
|
||||
fn sealed_block_with_senders(
|
||||
@@ -2546,7 +2546,7 @@ mod tests {
|
||||
),
|
||||
(
|
||||
TWO,
|
||||
block_with_senders,
|
||||
recovered_block,
|
||||
|block: &SealedBlock, _: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
(BlockHashOrNumber::Number(block.number), TransactionVariant::WithHash),
|
||||
block.clone().try_recover().ok()
|
||||
@@ -2555,7 +2555,7 @@ mod tests {
|
||||
),
|
||||
(
|
||||
TWO,
|
||||
block_with_senders,
|
||||
recovered_block,
|
||||
|block: &SealedBlock, _: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
|
||||
(BlockHashOrNumber::Hash(block.hash()), TransactionVariant::WithHash),
|
||||
block.clone().try_recover().ok()
|
||||
|
||||
@@ -844,14 +844,14 @@ impl<N: ProviderNodeTypes> BlockReader for ConsistentProvider<N> {
|
||||
/// hashes, since they would need to be calculated on the spot, and we want fast querying.**
|
||||
///
|
||||
/// Returns `None` if block is not found.
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
self.get_in_memory_or_storage_by_block(
|
||||
id,
|
||||
|db_provider| db_provider.block_with_senders(id, transaction_kind),
|
||||
|db_provider| db_provider.recovered_block(id, transaction_kind),
|
||||
|block_state| Ok(Some(block_state.block().recovered_block().clone())),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -379,12 +379,12 @@ impl<N: ProviderNodeTypes> BlockReader for ProviderFactory<N> {
|
||||
self.provider()?.pending_block_and_receipts()
|
||||
}
|
||||
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
self.provider()?.block_with_senders(id, transaction_kind)
|
||||
self.provider()?.recovered_block(id, transaction_kind)
|
||||
}
|
||||
|
||||
fn sealed_block_with_senders(
|
||||
|
||||
@@ -550,7 +550,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, N> {
|
||||
)
|
||||
}
|
||||
|
||||
fn block_with_senders<H, HF, B, BF>(
|
||||
fn recovered_block<H, HF, B, BF>(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
_transaction_kind: TransactionVariant,
|
||||
@@ -1217,12 +1217,12 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> BlockReader for DatabaseProvid
|
||||
/// If the header for this block is not found, this returns `None`.
|
||||
/// If the header is found, but the transactions either do not exist, or are not indexed, this
|
||||
/// will return None.
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
self.block_with_senders(
|
||||
self.recovered_block(
|
||||
id,
|
||||
transaction_kind,
|
||||
|block_number| self.header_by_number(block_number),
|
||||
@@ -1243,7 +1243,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> BlockReader for DatabaseProvid
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
self.block_with_senders(
|
||||
self.recovered_block(
|
||||
id,
|
||||
transaction_kind,
|
||||
|block_number| self.sealed_header(block_number),
|
||||
|
||||
@@ -1655,7 +1655,7 @@ impl<N: FullNodePrimitives<SignedTx: Value, Receipt: Value, BlockHeader: Value>>
|
||||
Err(ProviderError::UnsupportedProvider)
|
||||
}
|
||||
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
_id: BlockHashOrNumber,
|
||||
_transaction_kind: TransactionVariant,
|
||||
|
||||
@@ -595,7 +595,7 @@ impl<T: SignedTransaction, ChainSpec: EthChainSpec> BlockReader for MockEthProvi
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
_id: BlockHashOrNumber,
|
||||
_transaction_kind: TransactionVariant,
|
||||
|
||||
@@ -117,7 +117,7 @@ pub trait BlockReader:
|
||||
/// Returns the block's transactions in the requested variant.
|
||||
///
|
||||
/// Returns `None` if block is not found.
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
@@ -184,12 +184,12 @@ impl<T: BlockReader> BlockReader for Arc<T> {
|
||||
fn block_by_number(&self, num: u64) -> ProviderResult<Option<Self::Block>> {
|
||||
T::block_by_number(self, num)
|
||||
}
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
T::block_with_senders(self, id, transaction_kind)
|
||||
T::recovered_block(self, id, transaction_kind)
|
||||
}
|
||||
fn sealed_block_with_senders(
|
||||
&self,
|
||||
@@ -245,12 +245,12 @@ impl<T: BlockReader> BlockReader for &T {
|
||||
fn block_by_number(&self, num: u64) -> ProviderResult<Option<Self::Block>> {
|
||||
T::block_by_number(self, num)
|
||||
}
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
id: BlockHashOrNumber,
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
T::block_with_senders(self, id, transaction_kind)
|
||||
T::recovered_block(self, id, transaction_kind)
|
||||
}
|
||||
fn sealed_block_with_senders(
|
||||
&self,
|
||||
@@ -342,13 +342,10 @@ pub trait BlockReaderIdExt: BlockReader + ReceiptProviderIdExt {
|
||||
transaction_kind: TransactionVariant,
|
||||
) -> ProviderResult<Option<RecoveredBlock<Self::Block>>> {
|
||||
match id {
|
||||
BlockId::Hash(hash) => {
|
||||
self.block_with_senders(hash.block_hash.into(), transaction_kind)
|
||||
}
|
||||
BlockId::Number(num) => self.convert_block_number(num)?.map_or_else(
|
||||
|| Ok(None),
|
||||
|num| self.block_with_senders(num.into(), transaction_kind),
|
||||
),
|
||||
BlockId::Hash(hash) => self.recovered_block(hash.block_hash.into(), transaction_kind),
|
||||
BlockId::Number(num) => self
|
||||
.convert_block_number(num)?
|
||||
.map_or_else(|| Ok(None), |num| self.recovered_block(num.into(), transaction_kind)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ impl<C: Send + Sync, N: NodePrimitives> BlockReader for NoopProvider<C, N> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn block_with_senders(
|
||||
fn recovered_block(
|
||||
&self,
|
||||
_id: BlockHashOrNumber,
|
||||
_transaction_kind: TransactionVariant,
|
||||
|
||||
Reference in New Issue
Block a user