Skip to content

feat: optional zstd compression for event payloads at ingest#173

Draft
imp0stor wants to merge 3 commits intohoytech:masterfrom
imp0stor:feat/event-payload-zstd-ingest
Draft

feat: optional zstd compression for event payloads at ingest#173
imp0stor wants to merge 3 commits intohoytech:masterfrom
imp0stor:feat/event-payload-zstd-ingest

Conversation

@imp0stor
Copy link

@imp0stor imp0stor commented Feb 28, 2026

Summary

This PR adds an optional ingest-time event-payload compression path that keeps default behavior unchanged.

  • Adds a new EventPayload marker byte 0x02 for zstd-compressed payloads without dictionary metadata.
  • Keeps existing payload formats fully supported:
    • 0x00 uncompressed payload
    • 0x01 zstd + dictionary id
  • Adds decode support for 0x02 in decodeEventPayload(...).
  • Adds optional writer-side compression in writeEvents(...) gated by env var:
    • STRFRY_EVENT_PAYLOAD_ZSTD_LEVEL=1..22
    • unset or 0 => current behavior (no ingest compression)
  • Adds format note in golpe.yaml and operator note in strfry.conf.

Why

For installations prioritizing storage and bandwidth efficiency, immutable signed event JSON is a strong candidate for compress-once semantics. This provides a low-risk, opt-in path while preserving current defaults.

Compatibility

  • NIP-01 websocket behavior unchanged.
  • Existing DB payload records (0x00, 0x01) remain readable.
  • New 0x02 records decode transparently for reads.

Notes

I could not run a full local build here because this environment is missing strfry's golpe build include (golpe/rules.mk). The change is intentionally scoped to payload encode/decode logic to simplify review and testing.

Strange Signal added 3 commits February 28, 2026 18:29
When enabled, strfry keeps ALL versions of replaceable events (kinds 0, 3,
10000-19999, 30000-39999) instead of deleting old versions when newer ones
arrive.

This is useful for:
- Audit trails
- Historical analysis
- Compliance requirements

Enable with env var: STRFRY_RETAIN_REPLACED_EVENTS=true
The previous implementation could cause index corruption by storing
older incoming events. This fix:

1. When NEWER event arrives: keep old event in storage (audit) but
   still update replace index to point to new event. NIP-01 queries
   return only latest; old events queryable by ID.

2. When OLDER event arrives: reject it (even in audit mode) to prevent
   index corruption. Use external JSONL audit log to capture these.

This preserves NIP-01 compliance while enabling audit trail for
events that were superseded by newer versions.
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