Skip to content

Commit

Permalink
Async LRU cache for Ethereum block data (paritytech#540)
Browse files Browse the repository at this point in the history
* async block data cache

* fmt

* fmt (mix of tabs and spaces?)

* fmt (remove type annotation to stay inline)
  • Loading branch information
nanocryk authored Jan 11, 2022
1 parent 467db6e commit a630bd4
Show file tree
Hide file tree
Showing 7 changed files with 1,031 additions and 776 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions client/rpc-core/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ pub trait EthApi {

/// Returns block with given hash.
#[rpc(name = "eth_getBlockByHash")]
fn block_by_hash(&self, _: H256, _: bool) -> Result<Option<RichBlock>>;
fn block_by_hash(&self, _: H256, _: bool) -> BoxFuture<Result<Option<RichBlock>>>;

/// Returns block with given number.
#[rpc(name = "eth_getBlockByNumber")]
fn block_by_number(&self, _: BlockNumber, _: bool) -> Result<Option<RichBlock>>;
fn block_by_number(&self, _: BlockNumber, _: bool) -> BoxFuture<Result<Option<RichBlock>>>;

/// Returns the number of transactions sent from given address at given time (block number).
#[rpc(name = "eth_getTransactionCount")]
Expand Down Expand Up @@ -125,28 +125,31 @@ pub trait EthApi {

/// Estimate gas needed for execution of given contract.
#[rpc(name = "eth_estimateGas")]
fn estimate_gas(&self, _: CallRequest, _: Option<BlockNumber>) -> Result<U256>;
fn estimate_gas(&self, _: CallRequest, _: Option<BlockNumber>) -> BoxFuture<Result<U256>>;

/// Get transaction by its hash.
#[rpc(name = "eth_getTransactionByHash")]
fn transaction_by_hash(&self, _: H256) -> Result<Option<Transaction>>;
fn transaction_by_hash(&self, _: H256) -> BoxFuture<Result<Option<Transaction>>>;

/// Returns transaction at given block hash and index.
#[rpc(name = "eth_getTransactionByBlockHashAndIndex")]
fn transaction_by_block_hash_and_index(&self, _: H256, _: Index)
-> Result<Option<Transaction>>;
fn transaction_by_block_hash_and_index(
&self,
_: H256,
_: Index,
) -> BoxFuture<Result<Option<Transaction>>>;

/// Returns transaction by given block number and index.
#[rpc(name = "eth_getTransactionByBlockNumberAndIndex")]
fn transaction_by_block_number_and_index(
&self,
_: BlockNumber,
_: Index,
) -> Result<Option<Transaction>>;
) -> BoxFuture<Result<Option<Transaction>>>;

/// Returns transaction receipt by transaction hash.
#[rpc(name = "eth_getTransactionReceipt")]
fn transaction_receipt(&self, _: H256) -> Result<Option<Receipt>>;
fn transaction_receipt(&self, _: H256) -> BoxFuture<Result<Option<Receipt>>>;

/// Returns an uncles at given block and index.
#[rpc(name = "eth_getUncleByBlockHashAndIndex")]
Expand All @@ -162,7 +165,7 @@ pub trait EthApi {

/// Returns logs matching given filter object.
#[rpc(name = "eth_getLogs")]
fn logs(&self, _: Filter) -> Result<Vec<Log>>;
fn logs(&self, _: Filter) -> BoxFuture<Result<Vec<Log>>>;

/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
#[rpc(name = "eth_getWork")]
Expand Down Expand Up @@ -203,11 +206,11 @@ pub trait EthFilterApi {

/// Returns filter changes since last poll.
#[rpc(name = "eth_getFilterChanges")]
fn filter_changes(&self, _: Index) -> Result<FilterChanges>;
fn filter_changes(&self, _: Index) -> BoxFuture<Result<FilterChanges>>;

/// Returns all logs matching given filter (in a range 'from' - 'to').
#[rpc(name = "eth_getFilterLogs")]
fn filter_logs(&self, _: Index) -> Result<Vec<Log>>;
fn filter_logs(&self, _: Index) -> BoxFuture<Result<Vec<Log>>>;

/// Uninstalls filter.
#[rpc(name = "eth_uninstallFilter")]
Expand Down
1 change: 1 addition & 0 deletions client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ libsecp256k1 = "0.3"
rand = "0.7"
lru = "0.6.6"
parking_lot = "0.11.1"
tokio = { version = "1.14", features = [ "sync" ] }

[features]
rpc_binary_search_estimate = []
Loading

0 comments on commit a630bd4

Please sign in to comment.