refactor: single source of truth for SYNC_BATCH_LIMIT (closes #207)#369
Conversation
|
single source of truth please, the best way you see fit |
Single source of truth for the sync-batch cap, replacing the two mirror constants that had drifted apart only in name (storage's `SYNC_BATCH_LIMIT` vs the client listener's `MAX_SYNC_BATCH_SIZE`, both literally `10_000`). Placement: `willow-common`. It's the workspace-wide leaf where the shared `WireMessage::SyncBatch` already lives, and is already a dep of `willow-client`. Adding it to `willow-storage` (which previously only depended on willow-state and willow-worker) is a one-line cost and keeps the cap colocated with the wire type it bounds. Tradeoffs considered: - workspace const in `Cargo.toml` env var: rejected — not a real Rust constant, requires `option_env!` parsing, and the cap is a protocol invariant, not a deploy knob. - new `willow-limits` crate: rejected — one constant doesn't justify a crate; willow-common is already the right home. - promoting to `ClientConfig`: rejected for now — both producer (storage) and consumer (client) need to agree at compile time; runtime tunability is a separate feature behind its own PR. Behaviour unchanged: same numeric value (10_000), same enforcement points. Removes the "keep these in sync" comment hazard.
|
Done. Picked
Behaviour unchanged. Tradeoffs in the PR body — short version: rejected Generated by Claude Code |
Hoists the sync-batch cap into
willow-common::SYNC_BATCH_LIMITand deletes the two mirror constants in storage and client. Behaviour unchanged (still10_000); the change is purely "single source of truth, ship".Placement
Constant lives in
crates/common/src/lib.rs.willow-commonis the workspace-wide leaf that already ownsWireMessage::SyncBatch(the wire type the cap bounds) and is already a dep ofwillow-client. Adding it as a dep ofwillow-storageis a one-line cost; both crates now import the samepub constfrom the same place.What changed
crates/common/src/lib.rs— newpub const SYNC_BATCH_LIMIT: usize = 10_000;with a doc comment that names both call sites and explains why they MUST agree.crates/storage/src/store.rs— drop the associatedconst SYNC_BATCH_LIMITonStorageEventStore, drop the// TODO(#207)mirror-warning comment, switchSelf::SYNC_BATCH_LIMIT/StorageEventStore::SYNC_BATCH_LIMITto the imported free constant.crates/client/src/listeners.rs— drop the localconst MAX_SYNC_BATCH_SIZE, useSYNC_BATCH_LIMITfrom common (also unifies the name).crates/storage/Cargo.toml— addwillow-commondep.Tradeoffs considered
[env]var or build-script knob. Rejected — not a real Rust constant, requiresoption_env!parsing, and the cap is a protocol invariant (producer must not exceed validator), not a deploy knob.willow-limitscrate. Rejected — one constant doesn't justify a crate;willow-commonis already the right home.ClientConfig. Rejected for this PR — both producer (storage) and consumer (client) need to agree at compile time, so runtime tunability would require a coordinated wire-level negotiation. That's a separate feature; this PR closes the "drift hazard" bug today.Verification
cargo check -p willow-common -p willow-storage -p willow-client— clean.cargo clippy -p willow-common -p willow-storage -p willow-client --all-targets -- -D warnings— clean.cargo test -p willow-storage— 33/33 pass, includinghistory_caps_caller_limit_to_sync_batch_limitwhich directly exercises the cap.Closes #207.
Generated by Claude Code