zksync_node_db_pruner

ZKsync database pruner

1 unstable release

0.1.0 Jul 13, 2024

45 downloads per month
Used in 2 crates (via zksync_node_framework)

MIT/Apache

1.5MB
31K SLoC

zksync_node_db_pruner

Database pruner is a component that regularly removes the oldest l1 batches from the database together with corresponding L2 blocks, events, etc.

There are two types of objects that are not fully cleaned:

  • Transactions only have BYTEA fields cleaned as some components rely on transactions existence.
  • Storage logs: only storage logs that have been overwritten are removed

Pruning workflow

(See node docs for a high-level pruning overview)

There are two phases of pruning an L1 batch, soft pruning and hard pruning. Every batch that would have its records removed if first soft-pruned. Soft-pruned batches cannot safely be used. One minute (this is configurable) after soft pruning, hard pruning is performed, where hard means physically removing data from the database.

The reasoning behind this split is to allow node components such as the API server to become aware of planned data pruning, and restrict access to the pruned data in advance. This ensures that data does not unexpectedly (from the component perspective) disappear from Postgres in a middle of an operation (like serving a Web3 request). At least in some case, like in VM-related Web3 methods, we cannot rely on database transactions for this purpose.

Dependencies

~85MB
~1.5M SLoC