bnb-chain / opbnb

MIT License
403 stars 163 forks source link

feat(op-node): add l1 cache size config #225

Closed welkin22 closed 2 months ago

welkin22 commented 3 months ago

Description

This PR includes two changes:

  1. Added a configuration item: l1.rpc-max-cache-size, with a default value of 1000. Its value must be greater than or equal to 1. It is recommended that the configured value be greater than or equal to the maximum height difference between the L1 blocks corresponding to the unsafe block height and the safe block height.
  2. When the l1 receipts cache is full, log a message to remind the user.

Rationale

In https://github.com/bnb-chain/opbnb/pull/104, I made modifications to the receipt cache of the L1 client, significantly improving the cache hit rate. However, there are some issues when the safe block height lags far behind the unsafe block height. Firstly, the L1 receipt cache data corresponding to the safe block height is only deleted from the cache after the safe block height is processed. If the safe block height lags too far behind the unsafe block height, the L1 receipt cache becomes full. This prevents the new unsafe block height from accessing the cache, triggering the optimization logic in https://github.com/bnb-chain/opbnb/pull/87, where the unsafe block height continues to produce blocks based on the same L1 block height instead of moving to the next L1 block height. Additionally, the maximum value of our cache is hardcoded in the code. If the transaction volume of the chain is too low and the batcher submission frequency is very low, it is easy for the safe block height to lag behind the unsafe block height. We need to allow users to configure the maximum value of the cache to ensure it is greater than or equal to the maximum height difference between the L1 blocks corresponding to the unsafe block height and the safe block height.

Example

none

Changes

Notable changes: