feat(op-node): pre-fetch block info and transaction #163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In #100 and #104, I modified the pre-fetch logic for receipts. Based on metrics, we found that the performance of the block info and transaction retrieval APIs is also poor when L1 load is high. We need to fetch this data in advance and put it into cache. As the InfoAndTxsByHash is called in the FetchReceipts interface, the pre-fetch logic for block info and transaction data has already been performed in the receipts. I just need to make some modifications to the existing unreasonable parts to make pre-fetch effective for block info and transactions.
Rationale
LRU cache is not applicable in all cases, so I added the bool parameter isReadOrderly to EthClient. When we request L1 from our EthClient, we request the data in order of block height, so isReadOrderly should be true. When we request L2 from our EthClient, we do not request in order of block height, so isReadOrderly should be false. When isReadOrderly is true, the LRU cache should not insert the most recently accessed block at the front of the queue, causing the data in the queue to not be sorted in order of block height(When the LRU cache is full, the queue sorted in block height order can help us eliminate old and no longer needed block heights). Therefore, I use Peek instead of Get method to avoid this situation.
Example
none
Changes
Notable changes:
isReadOrderly
to EthClient. WhenisReadOrderly
is true, I use Peek instead of Get method in LRU cache.