# Every Reliable Channel message carries a ~18.75 KB bloom filter

## TL;DR
With the defaults in liblogosdelivery, every message sent over an SDS Reliable Channel carries the sender's whole bloom filter of messages it has seen. That's about 18.75 KB per message, whether the payload is 200 B or 200 KB, and whether the channel has seen 3 messages or 10,000. For apps that send many small messages, more than 90% of what goes on the wire is the filter.

Apps can't change this: `SdsHandler.new` doesn't pass the bloom parameters through, so nim-sds uses its defaults.

## Where it comes from (source refs)
- **nim-sds `sds/types/rolling_bloom_filter.nim`:** `DefaultBloomFilterCapacity = 10000` and `DefaultBloomFilterErrorRate = 0.001`.
- **nim-sds `sds/bloom.nim` `initializeBloomFilter`:**
  - `bitsPerElem = ceil(-ln(0.001)/ln(2)^2) = 15`, so `mBits = 10000 × 15 = 150,000` bits, which is **18,750 bytes**.
  - The bit array is allocated in full up front, so the size doesn't depend on how many messages the channel has actually seen.
- **nim-sds `sds/protobuf.nim` `serializeBloomFilter`:** writes the full `intArray` (field 1) plus capacity, error rate, k and m. It doesn't compress, and it doesn't treat an empty or sparse filter specially.
- **nim-sds `sds/sds.nim` `wrapOutgoingMessage`:** calls `serializeBloomFilter(channel.bloomFilter.filter)` on **every** outgoing message and puts the result in `SdsMessage.bloomFilter` (field 6). Each retransmission (`resendInterval`, `maxResendAttempts`) sends it again.
- **logos-delivery `logos_delivery/channels/scalable_data_sync/scalable_data_sync.nim` `SdsHandler.new`:**
  - It builds `ReliabilityConfig.init(maxCausalHistory, resendInterval, maxResendAttempts)` and nothing else.
  - So `bloomFilterCapacity`, `bloomFilterErrorRate` and `maxMessageHistory` are always the defaults, and `SdsConfig` has no field for them.

Checked against nim-sds b12f5ee and logos-delivery master 9473a7e (2026-10-20).

## What we saw
We run Scala, a shared calendar on Loam/Logos Delivery: each change is a small sealed event, and peers catch up on missed events through an app-level reconciliation.
- Scala's frames are **760–1368 B** each.
- On a Reliable Channel, each was about **20 KB on the wire**.
- On 2026-10-19/20, a relay node on our VPS carried **≈356 GB in 24 h** of traffic on Scala's shard.
- The volume was multiplied by a handful of test nodes. Their app-level catch-up rounds ran every 30 s and never converged, because those nodes were also on delivery_module 0.4.0, whose SDS stash drops messages (issue #169).
- Even so, the base cost per message was the filter: the same traffic over plain relay would have been about **15–25× smaller**.
- We moved Scala off Reliable Channels to plain relay, where it now repairs gaps with its own catch-up. Frames went from ~20 KB to 760–1368 B. Desktop↔desktop and desktop→phone sync work fine.

## Why it matters beyond us
- **Bandwidth:** phones, metered links and the relay mesh. Every relay node forwards the full 18.75 KB per message.
- **RLN:** a proof only limits the message count, not the size. Each rate-limited message is still about 19 KB.
- **Store:** store nodes keep the filter in every archived message.
- **Small channels pay the most:** a channel with 50 messages ever still ships a filter sized for 10,000.
- **SDS-R and retransmissions** repeat the cost.

## Possible fixes (roughly cheapest first)
1. **Expose `bloomFilterCapacity` / `bloomFilterErrorRate` (and `maxMessageHistory`) in `SdsConfig`** and pass them to `ReliabilityConfig.init`. Apps with small channels could then choose, for example, 500 @ 0.01 (about 600 B).
2. **Don't attach the filter to every message.**
   - Attach it every Nth message, on a timer, or only to sync or repair messages.
   - Between those, rely on causal history (`maxCausalHistory`, which is already sent).
3. **Compress or encode it sparsely.** A mostly empty fixed-size bit array compresses very well. Alternatively, send a run-length encoding or a fixed-size top-N of recent IDs while the channel is young.
4. **Size it to the channel:** start small and grow it (a scalable bloom filter), so cost tracks the messages the channel has actually seen.

Our ask: at least (1), so apps can pick a size that fits their channel. We'd be happy to test any change against Scala and Qaku.
