mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Compare commits
5 Commits
491e902904
...
b37ba15765
| Author | SHA1 | Date | |
|---|---|---|---|
| b37ba15765 | |||
| 3080665702 | |||
| 4896e4f0ea | |||
| 458f506ad2 | |||
| 1c7136bfab |
@ -12,6 +12,7 @@ use reth_hl::{
|
||||
chainspec::{parser::HlChainSpecParser, HlChainSpec},
|
||||
node::{
|
||||
cli::{Cli, HlNodeArgs},
|
||||
rpc::precompile::{HlBlockPrecompileApiServer, HlBlockPrecompileExt},
|
||||
storage::tables::Tables,
|
||||
HlNode,
|
||||
},
|
||||
@ -72,6 +73,10 @@ fn main() -> eyre::Result<()> {
|
||||
info!("eth_getProof is disabled by default");
|
||||
}
|
||||
|
||||
ctx.modules.merge_configured(
|
||||
HlBlockPrecompileExt::new(ctx.registry.eth_api().clone()).into_rpc(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.apply(|builder| {
|
||||
|
||||
@ -61,7 +61,7 @@ where
|
||||
DB: Database<Error = ProviderError> + fmt::Debug,
|
||||
{
|
||||
let block_number = evm_env.block_env().number;
|
||||
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
|
||||
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
|
||||
|
||||
let mut evm = self.evm_config().evm_with_env(db, evm_env);
|
||||
apply_precompiles(&mut evm, &hl_extras);
|
||||
@ -82,7 +82,7 @@ where
|
||||
I: InspectorFor<Self::Evm, DB>,
|
||||
{
|
||||
let block_number = evm_env.block_env().number;
|
||||
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
|
||||
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
|
||||
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(db, evm_env, inspector);
|
||||
apply_precompiles(&mut evm, &hl_extras);
|
||||
@ -103,7 +103,7 @@ where
|
||||
I: IntoIterator<Item = Recovered<&'a ProviderTx<Self::Provider>>>,
|
||||
{
|
||||
let block_number = evm_env.block_env().number;
|
||||
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
|
||||
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
|
||||
|
||||
let mut evm = self.evm_config().evm_with_env(db, evm_env);
|
||||
apply_precompiles(&mut evm, &hl_extras);
|
||||
|
||||
@ -98,7 +98,7 @@ where
|
||||
tx_env.set_gas_limit(tx_env.gas_limit().min(highest_gas_limit));
|
||||
|
||||
let block_number = evm_env.block_env().number;
|
||||
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
|
||||
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
|
||||
|
||||
let mut evm = self.evm_config().evm_with_env(&mut db, evm_env);
|
||||
apply_precompiles(&mut evm, &hl_extras);
|
||||
|
||||
@ -3,6 +3,7 @@ use crate::{
|
||||
node::{evm::apply_precompiles, types::HlExtras},
|
||||
HlBlock, HlPrimitives,
|
||||
};
|
||||
use alloy_eips::BlockId;
|
||||
use alloy_evm::Evm;
|
||||
use alloy_network::Ethereum;
|
||||
use alloy_primitives::U256;
|
||||
@ -26,7 +27,9 @@ use reth::{
|
||||
};
|
||||
use reth_evm::{ConfigureEvm, Database, EvmEnvFor, HaltReasonFor, InspectorFor, TxEnvFor};
|
||||
use reth_primitives::NodePrimitives;
|
||||
use reth_provider::{BlockReader, ChainSpecProvider, ProviderError, ProviderHeader, ProviderTx};
|
||||
use reth_provider::{
|
||||
BlockReaderIdExt, ChainSpecProvider, ProviderError, ProviderHeader, ProviderTx,
|
||||
};
|
||||
use reth_rpc::RpcTypes;
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{
|
||||
@ -43,6 +46,7 @@ mod block;
|
||||
mod call;
|
||||
pub mod engine_api;
|
||||
mod estimate;
|
||||
pub mod precompile;
|
||||
mod transaction;
|
||||
|
||||
pub trait HlRpcNodeCore: RpcNodeCore<Primitives: NodePrimitives<Block = HlBlock>> {}
|
||||
@ -232,7 +236,7 @@ where
|
||||
I: InspectorFor<Self::Evm, DB>,
|
||||
{
|
||||
let block_number = evm_env.block_env().number;
|
||||
let hl_extras = self.get_hl_extras(block_number.try_into().unwrap())?;
|
||||
let hl_extras = self.get_hl_extras(block_number.to::<u64>().into())?;
|
||||
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(db, evm_env, inspector);
|
||||
apply_precompiles(&mut evm, &hl_extras);
|
||||
@ -245,10 +249,10 @@ where
|
||||
N: HlRpcNodeCore,
|
||||
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
|
||||
{
|
||||
fn get_hl_extras(&self, block_number: u64) -> Result<HlExtras, ProviderError> {
|
||||
fn get_hl_extras(&self, block: BlockId) -> Result<HlExtras, ProviderError> {
|
||||
Ok(self
|
||||
.provider()
|
||||
.block_by_number(block_number)?
|
||||
.block_by_id(block)?
|
||||
.map(|block| HlExtras {
|
||||
read_precompile_calls: block.body.read_precompile_calls.clone(),
|
||||
highest_precompile_address: block.body.highest_precompile_address,
|
||||
|
||||
44
src/node/rpc/precompile.rs
Normal file
44
src/node/rpc/precompile.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use alloy_eips::BlockId;
|
||||
use jsonrpsee::proc_macros::rpc;
|
||||
use jsonrpsee_core::{async_trait, RpcResult};
|
||||
use reth_rpc_convert::RpcConvert;
|
||||
use reth_rpc_eth_types::EthApiError;
|
||||
use tracing::trace;
|
||||
|
||||
use crate::node::{
|
||||
rpc::{HlEthApi, HlRpcNodeCore},
|
||||
types::HlExtras,
|
||||
};
|
||||
|
||||
/// A custom RPC trait for fetching block precompile data.
|
||||
#[rpc(server, namespace = "eth")]
|
||||
#[async_trait]
|
||||
pub trait HlBlockPrecompileApi {
|
||||
/// Fetches precompile data for a given block.
|
||||
#[method(name = "blockPrecompileData")]
|
||||
async fn block_precompile_data(&self, block: BlockId) -> RpcResult<HlExtras>;
|
||||
}
|
||||
|
||||
pub struct HlBlockPrecompileExt<N: HlRpcNodeCore, Rpc: RpcConvert> {
|
||||
eth_api: HlEthApi<N, Rpc>,
|
||||
}
|
||||
|
||||
impl<N: HlRpcNodeCore, Rpc: RpcConvert> HlBlockPrecompileExt<N, Rpc> {
|
||||
/// Creates a new instance of the [`HlBlockPrecompileExt`].
|
||||
pub fn new(eth_api: HlEthApi<N, Rpc>) -> Self {
|
||||
Self { eth_api }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<N, Rpc> HlBlockPrecompileApiServer for HlBlockPrecompileExt<N, Rpc>
|
||||
where
|
||||
N: HlRpcNodeCore,
|
||||
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
|
||||
{
|
||||
async fn block_precompile_data(&self, block: BlockId) -> RpcResult<HlExtras> {
|
||||
trace!(target: "rpc::eth", ?block, "Serving eth_blockPrecompileData");
|
||||
let hl_extras = self.eth_api.get_hl_extras(block).map_err(EthApiError::from)?;
|
||||
Ok(hl_extras)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user