Skip to content

fix: send room deltas instead of full state to Freenet API#201

Open
netsirius wants to merge 2 commits intomainfrom
fix/send-room-delta-only
Open

fix: send room deltas instead of full state to Freenet API#201
netsirius wants to merge 2 commits intomainfrom
fix/send-room-delta-only

Conversation

@netsirius
Copy link
Collaborator

Summary

  • Room sync now computes a delta from the last synced baseline and sends UpdateData::Delta instead of serializing the entire ChatRoomStateV1 on every change
  • Falls back to UpdateData::State (full state) only on first sync when no baseline exists
  • Skips the network send when delta computation returns None, updating last_synced_state to prevent re-queuing
  • Extracted pure compute_update_data() function with 4 unit tests

Closes #17

What changed

ui/src/components/app/sync_info.rs

  • needs_to_send_update() now returns (ChatRoomStateV1, Option<ChatRoomStateV1>) per room — the current state paired with the last synced baseline

ui/src/components/app/freenet_api/room_synchronizer.rs

  • New compute_update_data(state, baseline, params) -> Option<UpdateData> — pure function that computes a delta via ComposableState::summarize() + ComposableState::delta(), or falls back to full state when no baseline exists
  • process_rooms() calls compute_update_data() and sends the result
  • When delta is None, updates last_synced_state so the room isn't re-queued

Why this is safe

  • The room contract already handles UpdateData::Delta in update_state() — deserializes ChatRoomStateV1Delta and calls apply_delta()
  • All sub-components are CRDT-like: idempotent, deduplicated by ID, deterministically ordered
  • The #[composable] macro enforces field application order (config -> bans -> members -> member_info -> secrets -> messages)
  • Freenet nodes compute per-subscriber deltas via get_state_delta() + summaries — this change only affects the client-to-node path
  • ensure_members_for_message_authors() in the contract injects missing member entries into deltas, preventing rejection of messages from pruned members

Tests

4 unit tests on compute_update_data():

  • no_baseline_returns_full_state — first sync sends UpdateData::State
  • identical_states_returns_none — no changes produces None
  • changed_state_returns_delta — new message produces UpdateData::Delta
  • delta_is_smaller_than_full_state — delta bytes < full state bytes

@netsirius netsirius requested a review from iduartgomez March 27, 2026 15:07
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.

Only send room delta to Freenet API not entire state

2 participants