Skip to content

Commit b3c00ed

Browse files
authored
fix: convert headers in newHeads (#20036)
1 parent 7922edf commit b3c00ed

File tree

15 files changed

+76
-93
lines changed

15 files changed

+76
-93
lines changed

crates/optimism/rpc/src/eth/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ where
194194
type NetworkTypes = Rpc::Network;
195195
type RpcConvert = Rpc;
196196

197-
fn tx_resp_builder(&self) -> &Self::RpcConvert {
198-
self.inner.eth_api.tx_resp_builder()
197+
fn converter(&self) -> &Self::RpcConvert {
198+
self.inner.eth_api.converter()
199199
}
200200
}
201201

crates/optimism/rpc/src/eth/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ where
108108
if let Some(flashblock) = flashblock.flatten() {
109109
// if flashblocks are supported, attempt to find id from the pending block
110110
if let Some(receipt) = flashblock
111-
.find_and_convert_transaction_receipt(hash, this.tx_resp_builder())
111+
.find_and_convert_transaction_receipt(hash, this.converter())
112112
{
113113
return receipt;
114114
}
@@ -164,7 +164,7 @@ where
164164
// if flashblocks are supported, attempt to find id from the pending block
165165
if let Ok(Some(pending_block)) = this.pending_flashblock().await &&
166166
let Some(Ok(receipt)) = pending_block
167-
.find_and_convert_transaction_receipt(hash, this.tx_resp_builder())
167+
.find_and_convert_transaction_receipt(hash, this.converter())
168168
{
169169
return Ok(Some(receipt));
170170
}

crates/primitives-traits/src/block/recovered.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ mod rpc_compat {
668668
{
669669
/// Converts the block into an RPC [`Block`] with the given [`BlockTransactionsKind`].
670670
///
671-
/// The `tx_resp_builder` closure transforms each transaction into the desired response
671+
/// The `converter` closure transforms each transaction into the desired response
672672
/// type.
673673
///
674674
/// `header_builder` transforms the block header into RPC representation. It takes the
@@ -677,7 +677,7 @@ mod rpc_compat {
677677
pub fn into_rpc_block<T, RpcH, F, E>(
678678
self,
679679
kind: BlockTransactionsKind,
680-
tx_resp_builder: F,
680+
converter: F,
681681
header_builder: impl FnOnce(SealedHeader<B::Header>, usize) -> Result<RpcH, E>,
682682
) -> Result<Block<T, RpcH>, E>
683683
where
@@ -688,9 +688,7 @@ mod rpc_compat {
688688
{
689689
match kind {
690690
BlockTransactionsKind::Hashes => self.into_rpc_block_with_tx_hashes(header_builder),
691-
BlockTransactionsKind::Full => {
692-
self.into_rpc_block_full(tx_resp_builder, header_builder)
693-
}
691+
BlockTransactionsKind::Full => self.into_rpc_block_full(converter, header_builder),
694692
}
695693
}
696694

@@ -699,7 +697,7 @@ mod rpc_compat {
699697
/// For transaction hashes, only necessary parts are cloned for efficiency.
700698
/// For full transactions, the entire block is cloned.
701699
///
702-
/// The `tx_resp_builder` closure transforms each transaction into the desired response
700+
/// The `converter` closure transforms each transaction into the desired response
703701
/// type.
704702
///
705703
/// `header_builder` transforms the block header into RPC representation. It takes the
@@ -708,7 +706,7 @@ mod rpc_compat {
708706
pub fn clone_into_rpc_block<T, RpcH, F, E>(
709707
&self,
710708
kind: BlockTransactionsKind,
711-
tx_resp_builder: F,
709+
converter: F,
712710
header_builder: impl FnOnce(SealedHeader<B::Header>, usize) -> Result<RpcH, E>,
713711
) -> Result<Block<T, RpcH>, E>
714712
where
@@ -720,7 +718,7 @@ mod rpc_compat {
720718
match kind {
721719
BlockTransactionsKind::Hashes => self.to_rpc_block_with_tx_hashes(header_builder),
722720
BlockTransactionsKind::Full => {
723-
self.clone().into_rpc_block_full(tx_resp_builder, header_builder)
721+
self.clone().into_rpc_block_full(converter, header_builder)
724722
}
725723
}
726724
}
@@ -769,10 +767,10 @@ mod rpc_compat {
769767
/// Converts the block into an RPC [`Block`] with full transaction objects.
770768
///
771769
/// Returns [`BlockTransactions::Full`] with complete transaction data.
772-
/// The `tx_resp_builder` closure transforms each transaction with its metadata.
770+
/// The `converter` closure transforms each transaction with its metadata.
773771
pub fn into_rpc_block_full<T, RpcHeader, F, E>(
774772
self,
775-
tx_resp_builder: F,
773+
converter: F,
776774
header_builder: impl FnOnce(SealedHeader<B::Header>, usize) -> Result<RpcHeader, E>,
777775
) -> Result<Block<T, RpcHeader>, E>
778776
where
@@ -803,7 +801,7 @@ mod rpc_compat {
803801
index: Some(idx as u64),
804802
};
805803

806-
tx_resp_builder(Recovered::new_unchecked(tx, sender), tx_info)
804+
converter(Recovered::new_unchecked(tx, sender), tx_info)
807805
})
808806
.collect::<Result<Vec<_>, E>>()?;
809807

crates/rpc/rpc-builder/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ where
968968
RethRpcModule::Web3 => Web3Api::new(self.network.clone()).into_rpc().into(),
969969
RethRpcModule::Txpool => TxPoolApi::new(
970970
self.eth.api.pool().clone(),
971-
dyn_clone::clone(self.eth.api.tx_resp_builder()),
971+
dyn_clone::clone(self.eth.api.converter()),
972972
)
973973
.into_rpc()
974974
.into(),

crates/rpc/rpc-eth-api/src/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ where
550550
trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash");
551551
Ok(EthTransactions::transaction_by_hash(self, hash)
552552
.await?
553-
.map(|tx| tx.into_transaction(self.tx_resp_builder()))
553+
.map(|tx| tx.into_transaction(self.converter()))
554554
.transpose()
555555
.map_err(T::Error::from)?)
556556
}

crates/rpc/rpc-eth-api/src/helpers/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pub trait EthBlocks: LoadBlock<RpcConvert: RpcConvert<Primitives = Self::Primiti
5959

6060
let block = block.clone_into_rpc_block(
6161
full.into(),
62-
|tx, tx_info| self.tx_resp_builder().fill(tx, tx_info),
63-
|header, size| self.tx_resp_builder().convert_header(header, size),
62+
|tx, tx_info| self.converter().fill(tx, tx_info),
63+
|header, size| self.converter().convert_header(header, size),
6464
)?;
6565
Ok(Some(block))
6666
}
@@ -155,7 +155,7 @@ pub trait EthBlocks: LoadBlock<RpcConvert: RpcConvert<Primitives = Self::Primiti
155155
.collect::<Vec<_>>();
156156

157157
return Ok(self
158-
.tx_resp_builder()
158+
.converter()
159159
.convert_receipts_with_block(inputs, block.sealed_block())
160160
.map(Some)?)
161161
}
@@ -256,7 +256,7 @@ pub trait EthBlocks: LoadBlock<RpcConvert: RpcConvert<Primitives = Self::Primiti
256256
alloy_consensus::Block::<alloy_consensus::TxEnvelope, _>::uncle(header);
257257
let size = block.length();
258258
let header = self
259-
.tx_resp_builder()
259+
.converter()
260260
.convert_header(SealedHeader::new_unhashed(block.header), size)?;
261261
Ok(Block {
262262
uncles: vec![],

crates/rpc/rpc-eth-api/src/helpers/call.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
172172
calls,
173173
default_gas_limit,
174174
chain_id,
175-
this.tx_resp_builder(),
175+
this.converter(),
176176
)?
177177
} else {
178178
let evm = this.evm_config().evm_with_env(&mut db, evm_env);
@@ -182,7 +182,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
182182
calls,
183183
default_gas_limit,
184184
chain_id,
185-
this.tx_resp_builder(),
185+
this.converter(),
186186
)?
187187
};
188188

@@ -192,7 +192,7 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA
192192
result.block,
193193
results,
194194
return_full_transactions.into(),
195-
this.tx_resp_builder(),
195+
this.converter(),
196196
)?;
197197

198198
blocks.push(block);
@@ -711,7 +711,7 @@ pub trait Call:
711711
request.as_mut().set_nonce(nonce);
712712
}
713713

714-
Ok(self.tx_resp_builder().tx_env(request, evm_env)?)
714+
Ok(self.converter().tx_env(request, evm_env)?)
715715
}
716716

717717
/// Prepares the [`reth_evm::EvmEnv`] for execution of calls.

crates/rpc/rpc-eth-api/src/helpers/receipt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub trait LoadReceipt:
3838
calculate_gas_used_and_next_log_index(meta.index, &all_receipts);
3939

4040
Ok(self
41-
.tx_resp_builder()
41+
.converter()
4242
.convert_receipts(vec![ConvertReceiptInput {
4343
tx: tx
4444
.try_into_recovered_unchecked()

crates/rpc/rpc-eth-api/src/helpers/transaction.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
290290
};
291291

292292
return Ok(Some(
293-
self.tx_resp_builder().fill(tx.clone().with_signer(*signer), tx_info)?,
293+
self.converter().fill(tx.clone().with_signer(*signer), tx_info)?,
294294
))
295295
}
296296
}
@@ -316,7 +316,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
316316
RpcNodeCore::pool(self).get_transaction_by_sender_and_nonce(sender, nonce)
317317
{
318318
let transaction = tx.transaction.clone_into_consensus();
319-
return Ok(Some(self.tx_resp_builder().fill_pending(transaction)?));
319+
return Ok(Some(self.converter().fill_pending(transaction)?));
320320
}
321321

322322
// Note: we can't optimize for contracts (account with code) and cannot shortcircuit if
@@ -364,9 +364,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
364364
base_fee: base_fee_per_gas,
365365
index: Some(index as u64),
366366
};
367-
Ok(self
368-
.tx_resp_builder()
369-
.fill(tx.clone().with_signer(*signer), tx_info)?)
367+
Ok(self.converter().fill(tx.clone().with_signer(*signer), tx_info)?)
370368
})
371369
})
372370
.ok_or(EthApiError::HeaderNotFound(block_id))?
@@ -509,7 +507,7 @@ pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
509507
}
510508
}
511509

512-
let tx = self.tx_resp_builder().build_simulate_v1_transaction(request)?;
510+
let tx = self.converter().build_simulate_v1_transaction(request)?;
513511

514512
let raw = tx.encoded_2718().into();
515513

crates/rpc/rpc-eth-api/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub trait EthApiTypes: Send + Sync + Clone {
3030
type RpcConvert: RpcConvert<Network = Self::NetworkTypes>;
3131

3232
/// Returns reference to transaction response builder.
33-
fn tx_resp_builder(&self) -> &Self::RpcConvert;
33+
fn converter(&self) -> &Self::RpcConvert;
3434
}
3535

3636
/// Adapter for network specific block type.

0 commit comments

Comments
 (0)