Skip to content

feat(node,store): read cached blocks stored as zstd - #6850

Draft
MoonBoi9001 wants to merge 5 commits into
masterfrom
mb9/read-compressed-blocks
Draft

MoonBoi9001 wants to merge 5 commits into
masterfrom
mb9/read-compressed-blocks

Conversation

@MoonBoi9001

@MoonBoi9001 MoonBoi9001 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

TL;DR

Lets graph-node read cached blocks stored as zstd-compressed JSON in a new data_zstd column, receipts included. Nothing writes such blocks yet: this lands first so every node can read compressed blocks before any node writes them (#6851).

Motivation

The block cache is the largest table on many indexers. Postgres can only compress it with pglz or lz4, since TOAST has no zstd option (support has been proposed but is not committed). In a sample of 1,000 random blocks per chain from that cache, zstd at level 1 stored blocks in 48% to 60% less space than pglz, while lz4 saved only 4% to 15%.

Smaller blocks are also faster to read. Lookups of 19 blocks took 13% to 23% less time than with pglz: a Base lookup reads 168 pages instead of 289, and Postgres spends 0.8 ms of CPU on it instead of 13.9 ms, since graph-node now does the uncompressing. All figures were measured with Postgres 14 and the data in memory.

Summary

  • Read a block from data_zstd when data holds only a placeholder, {"timestamp": ..., "__zstd": true}, which keeps timestamp queries working and looks like a block without data to older versions.
  • Read the receipts of a compressed block from the same column.
  • Uncompress after returning the connection to the pool: a 19-block lookup now holds a connection for 1.25 ms instead of 7.66 ms on Base, and 1.20 ms instead of 9.05 ms on mainnet.
  • Delete a block whose compressed data can't be read, together with every other block at its number, so it is fetched again instead of on every read, and a block from a fork can't be left as the only one at that number.
  • graphman chain check-blocks reports and deletes damaged compressed blocks.
  • Refuse to uncompress a block that claims to be over 512 MiB, so damaged data can't exhaust memory.

@MoonBoi9001
MoonBoi9001 added this pull request to stack #6852 December 1, 2026 10:15
@MoonBoi9001 MoonBoi9001 changed the title feat(store): read cached blocks stored as zstd feat(node,store): read cached blocks stored as zstd Dec 1, 2026
@MoonBoi9001
MoonBoi9001 marked this pull request as ready for review December 1, 2026 10:43
@MoonBoi9001
MoonBoi9001 marked this pull request as draft December 1, 2026 10:57
@MoonBoi9001
MoonBoi9001 marked this pull request as ready for review December 1, 2026 16:56
The block cache can hold a block as zstd-compressed JSON in a new column, with a small
placeholder where the JSON used to be. Uncompress such blocks, and treat those that can't be
uncompressed as not cached. Nothing writes compressed blocks yet.
The check-blocks command stops with an error for a cached block that it can't read. Delete a
block whose compressed data is damaged instead, so that it gets fetched again.
The query for the receipts of a block only looks at uncompressed JSON. Get them from the
compressed data if the block is compressed, reading nothing but the receipts. Chains without
the column for compressed blocks take no extra query.
@MoonBoi9001
MoonBoi9001 force-pushed the mb9/read-compressed-blocks branch from 388a08f to 016207d Compare December 1, 2026 17:24
@MoonBoi9001
MoonBoi9001 marked this pull request as draft December 1, 2026 17:48
Lookups of compressed blocks uncompressed them while holding a pooled database connection,
so other queries waited on that CPU work. The block storage now returns the rows as stored,
and the chain store uncompresses them after giving the connection back.
A block whose compressed data can't be read was never replaced, since a block fetched again
never overwrites a stored one, so every read logged an error and went back to RPC. Reads now
delete every block with that number, so a block from a fork can't be left as the only one.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant