bnb-chain / op-geth

GNU Lesser General Public License v3.0
58 stars 47 forks source link

Fix: clear difflayer cache when truncate not triggered #141

Closed krish-nr closed 2 months ago

krish-nr commented 2 months ago

Description

This PR aims to fix a potential memory leak issue in nodebuffer.

Rationale

In #121 we introduced a potential memory leak risk. When the block height difference between stateid and truncate tail in the differlayer exceeds the limit size (90,000), we attempt to trigger a truncate. However, to prevent repeated deletions, we added a condition. If the condition is not met, we do not perform the truncate and return directly, waiting until the next trigger. Before returning, we forgot to clear the difflayer cache, which causes the difflayer to be unrecoverable, resulting in a memory leak. The diagram shows the monitoring of this part of the memory (pathdb_difflayer_hashcache_size).

The metric shows the memory usage of difflayer before and after enabling this fix.

image

Example

N/A

Changes