Skip to content

Updates to use the original ZSTD compression via C Wrapper#236

Merged
mateeullahmalik merged 1 commit intomasterfrom
ZSTDWrapper
Nov 24, 2025
Merged

Updates to use the original ZSTD compression via C Wrapper#236
mateeullahmalik merged 1 commit intomasterfrom
ZSTDWrapper

Conversation

@mateeullahmalik
Copy link
Collaborator

@mateeullahmalik mateeullahmalik commented Nov 21, 2025

Summary

Updates ZSTD compression implementation to use DataDog/zstd
(C wrapper) instead of klauspost/zstd (pure Go) to ensure
consistent RQID generation between SDK-JS and backend
services.

Problem

SDK-JS uses the official ZSTD C library for compression,
while the Lumera backend (chain keeper and supernode) was
using klauspost/zstd (pure Go implementation). These two
libraries produce different compressed bytes for the
same input, resulting in:

  • Different BLAKE3 hashes
  • Different RQIDs (content-addressed identifiers)
  • Files uploaded via SDK-JS cannot be retrieved by backend
  • Backend generates incorrect RQIDs that don't match client
    expectations

Solution

Switched to DataDog/zstd (CGO wrapper around official C
library) with compression level 3 in three critical
locations:

  1. lumera/x/action/v1/keeper/crypto.go - Chain-level
    RQID verification
  2. supernode/pkg/cascadekit/ids.go - Supernode RQID
    generation
  3. supernode/pkg/utils/utils.go - Utility compression
    functions

This ensures:

  • ✅ Consistent compression across SDK-JS and backend
  • ✅ Matching RQIDs between client and server
  • ✅ Proper file retrieval and verification

Testing

  • Tested on local devnet (lumera-devnet-1)
  • Verified RQID consistency between upload and download
  • Confirmed no "sql: no rows in result set" errors
  • Validated compression/decompression round-trip

Related Issues

Fixes SDK-JS file upload/download compatibility issues.

@roomote-v0
Copy link

roomote-v0 bot commented Nov 24, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. The changes look correct for aligning ZSTD compression with SDK-JS. I've flagged a minor refactoring opportunity to reduce duplication.

  • Refactor ZstdCompress to reuse Compress

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the pure Go zstd implementation (klauspost/compress/zstd) with DataDog's C wrapper (DataDog/zstd) to ensure byte-for-byte compression compatibility with SDK-JS, which is critical for consistent RQID (content-addressed identifier) generation across client and backend services.

Key Changes:

  • Switched all zstd compression calls to use DataDog/zstd library with compression level 3
  • Simplified compression/decompression functions by removing concurrency configuration (handled internally by C library)
  • Updated tests to use the new compression API

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/utils/utils.go Replaced klauspost/compress/zstd with DataDog/zstd for Compress, Decompress, ZstdCompress, ZstdDecompress, and HighCompress functions; removed io and runtime imports no longer needed
pkg/cascadekit/ids.go Updated generateIDFiles and generateIDs to use DataDog/zstd.CompressLevel with level 3 for RQID generation; removed encoder reuse pattern
pkg/cascadekit/cascadekit_test.go Updated test compression calls to use zstd.CompressLevel(nil, data, 3) API
go.mod Moved DataDog/zstd from indirect to direct dependency; moved klauspost/compress to indirect (still required by other dependencies)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 292 to 298
func ZstdCompress(data []byte) ([]byte, error) {
encoder, err := zstd.NewWriter(nil)
compressed, err := zstd.CompressLevel(nil, data, 3)
if err != nil {
return nil, fmt.Errorf("failed to create zstd encoder: %v", err)
return nil, fmt.Errorf("failed to compress with zstd: %v", err)
}
defer encoder.Close()

return encoder.EncodeAll(data, nil), nil
return compressed, nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZstdCompress is functionally equivalent to Compress with level=3. Consider reusing Compress to reduce duplication and centralize logic.

func ZstdCompress(data []byte) ([]byte, error) {
  return Compress(data, 3)
}

Fix it with Roo Code or mention @roomote and request a fix.

@mateeullahmalik mateeullahmalik merged commit 39f7708 into master Nov 24, 2025
12 of 13 checks passed
@mateeullahmalik mateeullahmalik deleted the ZSTDWrapper branch December 15, 2025 08:02
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.

3 participants