refactor: TransactionCompat -> RpcConvert

This commit is contained in:
sprites0
2025-07-03 04:10:18 +00:00
parent 12d7d5a8b4
commit 7ed1290152
3 changed files with 37 additions and 76 deletions

View File

@ -1,21 +1,15 @@
use super::{HlEthApi, HlNodeCore}; use super::{HlEthApi, HlNodeCore};
use crate::evm::transaction::HlTxEnv; use crate::evm::transaction::HlTxEnv;
use alloy_consensus::TxType;
use alloy_primitives::{TxKind, U256};
use alloy_rpc_types::TransactionRequest; use alloy_rpc_types::TransactionRequest;
use alloy_signer::Either; use reth::rpc::server_types::eth::EthApiError;
use reth::rpc::server_types::eth::{revm_utils::CallFees, EthApiError, RpcInvalidTransactionError}; use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmFactory, TxEnvFor};
use reth_evm::{block::BlockExecutorFactory, ConfigureEvm, EvmEnv, EvmFactory, SpecFor};
use reth_primitives::NodePrimitives; use reth_primitives::NodePrimitives;
use reth_provider::{ProviderHeader, ProviderTx}; use reth_provider::{ProviderError, ProviderHeader, ProviderTx};
use reth_rpc_eth_api::{ use reth_rpc_eth_api::{
helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking}, helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking},
FromEthApiError, FromEvmError, FullEthApiTypes, IntoEthApiError, FromEvmError, FullEthApiTypes, RpcConvert, RpcTypes,
};
use revm::{
context::{Block as _, TxEnv},
Database,
}; };
use revm::context::TxEnv;
impl<N> EthCall for HlEthApi<N> impl<N> EthCall for HlEthApi<N>
where where
@ -44,7 +38,11 @@ where
EvmFactory: EvmFactory<Tx = HlTxEnv<TxEnv>>, EvmFactory: EvmFactory<Tx = HlTxEnv<TxEnv>>,
>, >,
>, >,
Error: FromEvmError<Self::Evm>, RpcConvert: RpcConvert<TxEnv = TxEnvFor<Self::Evm>, Network = Self::NetworkTypes>,
NetworkTypes: RpcTypes<TransactionRequest: From<TransactionRequest>>,
Error: FromEvmError<Self::Evm>
+ From<<Self::RpcConvert as RpcConvert>::Error>
+ From<ProviderError>,
> + SpawnBlocking, > + SpawnBlocking,
Self::Error: From<EthApiError>, Self::Error: From<EthApiError>,
N: HlNodeCore, N: HlNodeCore,

View File

@ -20,7 +20,6 @@ use reth::{
}; };
use reth_evm::ConfigureEvm; use reth_evm::ConfigureEvm;
use reth_network::NetworkInfo; use reth_network::NetworkInfo;
use reth_optimism_rpc::eth::EthApiNodeBackend;
use reth_primitives::NodePrimitives; use reth_primitives::NodePrimitives;
use reth_provider::{ use reth_provider::{
BlockNumReader, BlockReader, BlockReaderIdExt, ProviderBlock, ProviderHeader, ProviderReceipt, BlockNumReader, BlockReader, BlockReaderIdExt, ProviderBlock, ProviderHeader, ProviderReceipt,
@ -31,11 +30,11 @@ use reth_rpc_eth_api::{
AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState, AddDevSigners, EthApiSpec, EthFees, EthSigner, EthState, LoadBlock, LoadFee, LoadState,
SpawnBlocking, Trace, SpawnBlocking, Trace,
}, },
EthApiTypes, FromEvmError, RpcNodeCore, RpcNodeCoreExt, EthApiTypes, FromEvmError, RpcConverter, RpcNodeCore, RpcNodeCoreExt,
}; };
use std::{fmt, sync::Arc}; use std::{fmt, sync::Arc};
use crate::HlPrimitives; use reth_optimism_rpc::eth::EthApiNodeBackend;
mod block; mod block;
mod call; mod call;
@ -57,6 +56,8 @@ pub(crate) struct HlEthApiInner<N: HlNodeCore> {
pub struct HlEthApi<N: HlNodeCore> { pub struct HlEthApi<N: HlNodeCore> {
/// Gateway to node's core components. /// Gateway to node's core components.
pub(crate) inner: Arc<HlEthApiInner<N>>, pub(crate) inner: Arc<HlEthApiInner<N>>,
/// Converter for RPC types.
tx_resp_builder: RpcConverter<Ethereum, N::Evm, EthApiError, ()>,
} }
impl<N: HlNodeCore> fmt::Debug for HlEthApi<N> { impl<N: HlNodeCore> fmt::Debug for HlEthApi<N> {
@ -69,13 +70,14 @@ impl<N> EthApiTypes for HlEthApi<N>
where where
Self: Send + Sync, Self: Send + Sync,
N: HlNodeCore, N: HlNodeCore,
N::Evm: std::fmt::Debug,
{ {
type Error = EthApiError; type Error = EthApiError;
type NetworkTypes = Ethereum; type NetworkTypes = Ethereum;
type TransactionCompat = Self; type RpcConvert = RpcConverter<Ethereum, N::Evm, EthApiError, ()>;
fn tx_resp_builder(&self) -> &Self::TransactionCompat { fn tx_resp_builder(&self) -> &Self::RpcConvert {
self &self.tx_resp_builder
} }
} }
@ -83,7 +85,7 @@ impl<N> RpcNodeCore for HlEthApi<N>
where where
N: HlNodeCore, N: HlNodeCore,
{ {
type Primitives = HlPrimitives; type Primitives = N::Primitives;
type Provider = N::Provider; type Provider = N::Provider;
type Pool = N::Pool; type Pool = N::Pool;
type Evm = <N as RpcNodeCore>::Evm; type Evm = <N as RpcNodeCore>::Evm;
@ -152,6 +154,7 @@ impl<N> SpawnBlocking for HlEthApi<N>
where where
Self: Send + Sync + Clone + 'static, Self: Send + Sync + Clone + 'static,
N: HlNodeCore, N: HlNodeCore,
N::Evm: std::fmt::Debug,
{ {
#[inline] #[inline]
fn io_task_spawner(&self) -> impl TaskSpawner { fn io_task_spawner(&self) -> impl TaskSpawner {
@ -189,11 +192,13 @@ where
} }
} }
impl<N> LoadState for HlEthApi<N> where impl<N> LoadState for HlEthApi<N>
where
N: HlNodeCore< N: HlNodeCore<
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>, Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
Pool: TransactionPool, Pool: TransactionPool,
> >,
N::Evm: std::fmt::Debug,
{ {
} }
@ -210,7 +215,11 @@ where
impl<N> EthFees for HlEthApi<N> impl<N> EthFees for HlEthApi<N>
where where
Self: LoadFee, Self: LoadFee<
Provider: ChainSpecProvider<
ChainSpec: EthChainSpec<Header = ProviderHeader<Self::Provider>>,
>,
>,
N: HlNodeCore, N: HlNodeCore,
{ {
} }
@ -268,6 +277,9 @@ where
.proof_permits(ctx.config.proof_permits) .proof_permits(ctx.config.proof_permits)
.build_inner(); .build_inner();
Ok(HlEthApi { inner: Arc::new(HlEthApiInner { eth_api }) }) Ok(HlEthApi {
inner: Arc::new(HlEthApiInner { eth_api }),
tx_resp_builder: Default::default(),
})
} }
} }

View File

@ -1,28 +1,14 @@
use super::HlNodeCore; use super::HlNodeCore;
use crate::{ use crate::node::rpc::HlEthApi;
node::{ use alloy_primitives::{Bytes, B256};
primitives::{tx_wrapper::convert_recovered, TransactionSigned},
rpc::HlEthApi,
},
HlPrimitives,
};
use alloy_network::{Ethereum, Network};
use alloy_primitives::{Bytes, Signature, B256};
use reth::{ use reth::{
builder::FullNodeComponents, rpc::server_types::eth::utils::recover_raw_transaction,
primitives::{Receipt, Recovered},
providers::ReceiptProvider,
rpc::{
eth::helpers::types::EthRpcConverter,
server_types::eth::{utils::recover_raw_transaction, EthApiError},
types::{TransactionInfo, TransactionRequest},
},
transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool}, transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool},
}; };
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider}; use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
use reth_rpc_eth_api::{ use reth_rpc_eth_api::{
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking}, helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt, TransactionCompat, FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt,
}; };
impl<N> LoadTransaction for HlEthApi<N> impl<N> LoadTransaction for HlEthApi<N>
@ -33,41 +19,6 @@ where
{ {
} }
impl<N> TransactionCompat for HlEthApi<N>
where
N: FullNodeComponents<Provider: ReceiptProvider<Receipt = Receipt>>,
{
type Primitives = HlPrimitives;
type Transaction = <Ethereum as Network>::TransactionResponse;
type Error = EthApiError;
fn fill(
&self,
tx: Recovered<TransactionSigned>,
tx_info: TransactionInfo,
) -> Result<Self::Transaction, Self::Error> {
let builder = EthRpcConverter::default();
builder.fill(convert_recovered(tx), tx_info)
}
fn build_simulate_v1_transaction(
&self,
request: TransactionRequest,
) -> Result<TransactionSigned, Self::Error> {
let Ok(tx) = request.build_typed_tx() else {
return Err(EthApiError::TransactionConversionError);
};
// Create an empty signature for the transaction.
let signature = Signature::new(Default::default(), Default::default(), false);
Ok(TransactionSigned(reth_primitives::TransactionSigned::new_unhashed(
tx.into(),
signature,
)))
}
}
impl<N> EthTransactions for HlEthApi<N> impl<N> EthTransactions for HlEthApi<N>
where where
Self: LoadTransaction<Provider: BlockReaderIdExt>, Self: LoadTransaction<Provider: BlockReaderIdExt>,