-
Notifications
You must be signed in to change notification settings - Fork 265
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
feat(provider): LRUCache Layer #954
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some questions
crates/provider/src/layers/cache.rs
Outdated
) -> TransportResult<Option<Block>> { | ||
let hash = RequestType::new("eth_getBlockByNumber", (number, hydrate)); | ||
|
||
cache_get_or_fetch!(self, hash, self.inner.get_block_by_number(number, hydrate)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is problematic because of reorgs, we'd need to track chain height somehow, but out of scope for this pr imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
almost there
few more suggestions
@mattsse addressed the suggestions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last suggestions
let req = RequestType::new("eth_getBlockReceipts", (block,)); | ||
|
||
let redirect = | ||
!matches!(block, BlockId::Hash(_) | BlockId::Number(BlockNumberOrTag::Number(_))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the number case is also slightly problematic, but we can worry about this separately
async fn get_logs(&self, filter: &Filter) -> TransportResult<Vec<Log>> { | ||
let req = RequestType::new("eth_getLogs", filter.clone()); | ||
|
||
let params_hash = req.params_hash().ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also a bit nuanced because the blockrange variants allows the server to chose the range for example if upper bound is missing
* in-memory cache implementation * load and dump cache from fs * use RwLock * doc nits * feat: CacheConfig, load/save at specific paths * RequestType enum * params hash * clone and arc `CacheProvider` * add: get_block_by_hash * todos * refactor: port to transport layer * rm provider cache layer * use parking_lot::RwLock + tracing nits * cleanup nits * nit * move cache instance to layer * Revert "refactor: port to transport layer" This reverts commit bb05544. * use provider cache * use macro * cached get_proof * nit * nit * use parking_lot * make params hash independent of client * fix * cache_rpc_call_with_block! * fix: request type * redirect reqs with block tags to rpc * nits * get_accounts * chain_id * cfg gate wasm * rm get_accounts and get_chain_id * rm related tests * tests: run_with_temp_dir * feat: SharedCache * make CacheProvider generic over Network * add more methods * fmt * docs * docs * nit * fix * clippy * mv SharedCache * use schnellru * feat: get_derialized * nits
Motivation
Ref: #770
Solution
key
is the hash of the request and its params.Overrides the following RPC methods
get_block_by_number
get_block_by_hash
get_block_receipts
get_proof
get_storage_at
get_code_at
get_transaction_count
get_logs
get_transaction_by_hash
get_raw_transaction_by_hash
get_transaction_receipt
PR Checklist