Skip to content

feat(node,store): optionally store new blocks as zstd - #6851

Draft
MoonBoi9001 wants to merge 5 commits into
mb9/read-compressed-blocksfrom
mb9/compress-new-blocks
Draft

MoonBoi9001 wants to merge 5 commits into
mb9/read-compressed-blocksfrom
mb9/compress-new-blocks

Conversation

@MoonBoi9001

@MoonBoi9001 MoonBoi9001 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

TL;DR

Adds a block_compression setting, for all chains or a single chain, that stores new blocks in the block cache as zstd. It is off by default and leaves existing blocks alone; #6853 converts existing blocks.

Motivation

#6850 has the measurements: zstd at level 1 stores blocks in 48% to 60% less space than pglz across 8 chains and makes 19-block lookups 13% to 23% faster. With those readers in place, this is the switch that starts writing compressed blocks.

Summary

  • block_compression = "zstd:<level>" under [chains] or on one chain; "none", the default, keeps today's behaviour.
  • Blocks are compressed before a database connection is taken.
  • The data_zstd column is added the first time a chain writes a compressed block rather than by a migration, since adding it needs a brief exclusive lock on a large, busy table. graph-node waits at most 2 seconds for that lock; if it can't get it, it stores blocks uncompressed and tries again after 1 minute, doubling the wait up to 1 hour. Several nodes trying at once is harmless thanks to add column if not exists.
  • Chains that never turn compression on never get the column.
  • The database user must own the chain's blocks table.

Warning

Upgrade every node before turning the setting on, since older versions fetch a compressed block from the chain's provider each time they need it.

@MoonBoi9001
MoonBoi9001 added this pull request to stack #6852 December 1, 2026 10:15
@MoonBoi9001 MoonBoi9001 changed the title feat(store): optionally store new blocks as zstd feat(node,store): optionally store new blocks 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
@MoonBoi9001
MoonBoi9001 force-pushed the mb9/compress-new-blocks branch from aa7c42e to fcf2265 Compare December 1, 2026 17:24
@MoonBoi9001
MoonBoi9001 marked this pull request as draft December 1, 2026 17:48
The block store took each chain's network, shard and cache size as a tuple that callers
unpacked by position; a named struct makes each field explicit and leaves room for more.
Blocks were turned into what gets stored while holding a database connection. Do that before
taking one, so that slower steps such as compression can be added there.
A chain can be set up to compress new blocks with zstd, off by default. Add the column for
them when the first block is compressed, and store blocks uncompressed until that works.
Shared storage ignores the setting.
Nothing could turn on zstd compression for the blocks that get cached. Add block_compression
to the configuration, for all chains or for a single chain.
What we know about a blocks table's column for compressed blocks, and when we last looked for
it or tried to add it, sat behind 3 separate locks. It is now 1 enum behind 1 lock, and writers
get a named answer about whether they can compress instead of an Option<bool>.
@MoonBoi9001
MoonBoi9001 force-pushed the mb9/compress-new-blocks branch from fcf2265 to 13c9197 Compare December 2, 2026 17:20

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