Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pending block with latest block in all RPC functions #75

Merged
merged 1 commit into from
Dec 2, 2024
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
95 changes: 95 additions & 0 deletions crates/rpc/rpc-eth-api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ where
number: BlockNumberOrTag,
full: bool,
) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
trace!(target: "rpc::eth", ?number, ?full, "Serving eth_getBlockByNumber");
Ok(EthBlocks::rpc_block(self, number.into(), full).await?)
}
Expand All @@ -440,6 +445,11 @@ where
&self,
number: BlockNumberOrTag,
) -> RpcResult<Option<U256>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
trace!(target: "rpc::eth", ?number, "Serving eth_getBlockTransactionCountByNumber");
Ok(EthBlocks::block_transaction_count(self, number.into()).await?.map(U256::from))
}
Expand All @@ -455,6 +465,11 @@ where
&self,
number: BlockNumberOrTag,
) -> RpcResult<Option<U256>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
trace!(target: "rpc::eth", ?number, "Serving eth_getUncleCountByBlockNumber");
Ok(EthBlocks::ommers(self, number.into())?.map(|ommers| U256::from(ommers.len())))
}
Expand All @@ -464,6 +479,11 @@ where
&self,
block_id: BlockId,
) -> RpcResult<Option<Vec<RpcReceipt<T::NetworkTypes>>>> {
#[cfg(feature = "telos")]
let block_id = match block_id {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block_id,
};
trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockReceipts");
Ok(EthBlocks::block_receipts(self, block_id).await?)
}
Expand All @@ -484,6 +504,11 @@ where
number: BlockNumberOrTag,
index: Index,
) -> RpcResult<Option<RpcBlock<T::NetworkTypes>>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex");
Ok(EthBlocks::ommer_by_block_and_index(self, number.into(), index).await?)
}
Expand Down Expand Up @@ -533,6 +558,11 @@ where
number: BlockNumberOrTag,
index: Index,
) -> RpcResult<Option<Bytes>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex");
Ok(EthTransactions::raw_transaction_by_block_and_tx_index(
self,
Expand All @@ -548,6 +578,11 @@ where
number: BlockNumberOrTag,
index: Index,
) -> RpcResult<Option<RpcTransaction<T::NetworkTypes>>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex");
Ok(EthTransactions::transaction_by_block_and_tx_index(self, number.into(), index.into())
.await?)
Expand Down Expand Up @@ -575,6 +610,11 @@ where

/// Handler for: `eth_getBalance`
async fn balance(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<U256> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getBalance");
Ok(EthState::balance(self, address, block_number).await?)
}
Expand All @@ -586,6 +626,11 @@ where
index: JsonStorageKey,
block_number: Option<BlockId>,
) -> RpcResult<B256> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getStorageAt");
Ok(EthState::storage_at(self, address, index, block_number).await?)
}
Expand All @@ -596,18 +641,33 @@ where
address: Address,
block_number: Option<BlockId>,
) -> RpcResult<U256> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getTransactionCount");
Ok(EthState::transaction_count(self, address, block_number).await?)
}

/// Handler for: `eth_getCode`
async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<Bytes> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getCode");
Ok(EthState::get_code(self, address, block_number).await?)
}

/// Handler for: `eth_getHeaderByNumber`
async fn header_by_number(&self, block_number: BlockNumberOrTag) -> RpcResult<Option<Header>> {
#[cfg(feature = "telos")]
let block_number: BlockNumberOrTag = match block_number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => block_number,
};
trace!(target: "rpc::eth", ?block_number, "Serving eth_getHeaderByNumber");
Ok(EthBlocks::rpc_block_header(self, block_number.into()).await?)
}
Expand All @@ -624,6 +684,11 @@ where
payload: SimulatePayload,
block_number: Option<BlockId>,
) -> RpcResult<Vec<SimulatedBlock<RpcBlock<T::NetworkTypes>>>> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?block_number, "Serving eth_simulateV1");
Ok(EthCall::simulate_v1(self, payload, block_number).await?)
}
Expand All @@ -636,6 +701,11 @@ where
state_overrides: Option<StateOverride>,
block_overrides: Option<Box<BlockOverrides>>,
) -> RpcResult<Bytes> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?request, ?block_number, ?state_overrides, ?block_overrides, "Serving eth_call");
Ok(EthCall::call(
self,
Expand Down Expand Up @@ -663,6 +733,11 @@ where
request: TransactionRequest,
block_number: Option<BlockId>,
) -> RpcResult<AccessListResult> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_createAccessList");
Ok(EthCall::create_access_list_at(self, request, block_number).await?)
}
Expand All @@ -674,6 +749,11 @@ where
block_number: Option<BlockId>,
state_override: Option<StateOverride>,
) -> RpcResult<U256> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_estimateGas");
Ok(EthCall::estimate_gas_at(
self,
Expand All @@ -696,6 +776,11 @@ where
address: Address,
block: BlockId,
) -> RpcResult<Option<alloy_rpc_types::Account>> {
#[cfg(feature = "telos")]
let block = match block {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block,
};
trace!(target: "rpc::eth", "Serving eth_getAccount");
Ok(EthState::get_account(self, address, block).await?)
}
Expand Down Expand Up @@ -727,6 +812,11 @@ where
newest_block: BlockNumberOrTag,
reward_percentiles: Option<Vec<f64>>,
) -> RpcResult<FeeHistory> {
#[cfg(feature = "telos")]
let newest_block = match newest_block {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => newest_block,
};
trace!(target: "rpc::eth", ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory");
Ok(EthFees::fee_history(self, block_count.to(), newest_block, reward_percentiles).await?)
}
Expand Down Expand Up @@ -797,6 +887,11 @@ where
keys: Vec<JsonStorageKey>,
block_number: Option<BlockId>,
) -> RpcResult<EIP1186AccountProofResponse> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
trace!(target: "rpc::eth", ?address, ?keys, ?block_number, "Serving eth_getProof");
Ok(EthState::get_proof(self, address, keys, block_number)?.await?)
}
Expand Down
35 changes: 35 additions & 0 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,11 @@ where
{
/// Handler for `debug_getRawHeader`
async fn raw_header(&self, block_id: BlockId) -> RpcResult<Bytes> {
#[cfg(feature = "telos")]
let block_id = match block_id {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block_id,
};
let header = match block_id {
BlockId::Hash(hash) => self.inner.provider.header(&hash.into()).to_rpc_result()?,
BlockId::Number(number_or_tag) => {
Expand All @@ -902,6 +907,11 @@ where

/// Handler for `debug_getRawBlock`
async fn raw_block(&self, block_id: BlockId) -> RpcResult<Bytes> {
#[cfg(feature = "telos")]
let block_id = match block_id {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block_id,
};
let block = self
.inner
.provider
Expand All @@ -925,6 +935,11 @@ where
/// Handler for `debug_getRawTransactions`
/// Returns the bytes of the transaction for the given hash.
async fn raw_transactions(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>> {
#[cfg(feature = "telos")]
let block_id = match block_id {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block_id,
};
let block = self
.inner
.provider
Expand All @@ -936,6 +951,11 @@ where

/// Handler for `debug_getRawReceipts`
async fn raw_receipts(&self, block_id: BlockId) -> RpcResult<Vec<Bytes>> {
#[cfg(feature = "telos")]
let block_id = match block_id {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block_id,
};
Ok(self
.inner
.provider
Expand Down Expand Up @@ -991,6 +1011,11 @@ where
block: BlockNumberOrTag,
opts: Option<GethDebugTracingOptions>,
) -> RpcResult<Vec<TraceResult>> {
#[cfg(feature = "telos")]
let block = match block {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => block,
};
let _permit = self.acquire_trace_permit().await;
Self::debug_trace_block(self, block.into(), opts.unwrap_or_default())
.await
Expand All @@ -1015,6 +1040,11 @@ where
block: BlockNumberOrTag,
include_preimages: bool,
) -> RpcResult<ExecutionWitness> {
#[cfg(feature = "telos")]
let block = match block {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => block,
};
let _permit = self.acquire_trace_permit().await;
Self::debug_execution_witness(self, block, include_preimages).await.map_err(Into::into)
}
Expand All @@ -1026,6 +1056,11 @@ where
block_id: Option<BlockId>,
opts: Option<GethDebugTracingCallOptions>,
) -> RpcResult<GethTrace> {
#[cfg(feature = "telos")]
let block_id = match block_id {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_id,
};
let _permit = self.acquire_trace_permit().await;
Self::debug_trace_call(self, request, block_id, opts.unwrap_or_default())
.await
Expand Down
20 changes: 20 additions & 0 deletions crates/rpc/rpc/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ where
state_overrides: Option<StateOverride>,
block_overrides: Option<Box<BlockOverrides>>,
) -> Result<Bytes> {
#[cfg(feature = "telos")]
let block_id = match block_id {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_id,
};
self.eth
.call(request, block_id, state_overrides, block_overrides)
.instrument(engine_span!())
Expand All @@ -81,6 +86,11 @@ where

/// Handler for: `eth_getCode`
async fn get_code(&self, address: Address, block_id: Option<BlockId>) -> Result<Bytes> {
#[cfg(feature = "telos")]
let block_id = match block_id {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_id,
};
self.eth.get_code(address, block_id).instrument(engine_span!()).await
}

Expand All @@ -99,6 +109,11 @@ where
number: BlockNumberOrTag,
full: bool,
) -> Result<Option<RpcBlock<Eth::NetworkTypes>>> {
#[cfg(feature = "telos")]
let number = match number {
BlockNumberOrTag::Pending => BlockNumberOrTag::Latest,
_ => number,
};
self.eth.block_by_number(number, full).instrument(engine_span!()).await
}

Expand All @@ -119,6 +134,11 @@ where
keys: Vec<JsonStorageKey>,
block_number: Option<BlockId>,
) -> Result<EIP1186AccountProofResponse> {
#[cfg(feature = "telos")]
let block_number = match block_number {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_number,
};
self.eth.get_proof(address, keys, block_number).instrument(engine_span!()).await
}
}
5 changes: 5 additions & 0 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ where

/// Handler for `ots_hasCode`
async fn has_code(&self, address: Address, block_id: Option<BlockId>) -> RpcResult<bool> {
#[cfg(feature = "telos")]
let block_id = match block_id {
Some(BlockId::Number(BlockNumberOrTag::Pending)) => Some(BlockId::Number(BlockNumberOrTag::Latest)),
_ => block_id,
};
EthApiServer::get_code(&self.eth, address, block_id).await.map(|code| !code.is_empty())
}

Expand Down
7 changes: 7 additions & 0 deletions crates/rpc/rpc/src/reth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_errors::RethResult;
use reth_primitives::BlockId;
#[cfg(feature = "telos")]
use reth_primitives::BlockNumberOrTag;
use reth_provider::{BlockReaderIdExt, ChangeSetReader, StateProviderFactory};
use reth_rpc_api::RethApiServer;
use reth_rpc_eth_types::{EthApiError, EthResult};
Expand Down Expand Up @@ -95,6 +97,11 @@ where
&self,
block_id: BlockId,
) -> RpcResult<HashMap<Address, U256>> {
#[cfg(feature = "telos")]
let block_id = match block_id {
BlockId::Number(BlockNumberOrTag::Pending) => BlockId::Number(BlockNumberOrTag::Latest),
_ => block_id,
};
Ok(Self::balance_changes_in_block(self, block_id).await?)
}
}
Expand Down
Loading
Loading