Repository navigation
feat(node,store): read cached blocks stored as zstd - #6850
Draft
MoonBoi9001 wants to merge 5 commits into
Draft
MoonBoi9001 wants to merge 5 commits into
MoonBoi9001 wants to merge 5 commits into
Conversation
MoonBoi9001
marked this pull request as ready for review
December 1, 2026 10:43
MoonBoi9001
marked this pull request as draft
December 1, 2026 10:57
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
force-pushed
the
mb9/read-compressed-blocks
branch
from
December 1, 2026 17:24
388a08f to
016207d
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TL;DR
Lets graph-node read cached blocks stored as zstd-compressed JSON in a new
data_zstdcolumn, 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
data_zstdwhendataholds only a placeholder,{"timestamp": ..., "__zstd": true}, which keeps timestamp queries working and looks like a block without data to older versions.graphman chain check-blocksreports and deletes damaged compressed blocks.