Skip to main content

peer_declares_its_own_limits

Function peer_declares_its_own_limits 

Source
pub async fn peer_declares_its_own_limits<F: SyncFixture>(
    open: impl AsyncFn() -> F,
) -> Result<RuleOutcome, Violation>
Expand description

SY-18: a peer declares the limits it imposes, synchronously, and the declaration is true: an event it admits lands, so a runner that read it learns of an event that cannot land before pushing, not at ingest.

The rule plays that runner. It reads [SyncPeer::limits] before it pushes anything, and then:

  1. reads it again, because a declaration that changes between two reads cannot be relied on before a push;
  2. holds max_event_bytes to VT-21’s floor, MIN_SUPPORTED_EVENT_DATA_LEN. Every peer the suite is mounted on passes this line, which is where the floor is compared across the peer set;
  3. runs the Turnstile experiment: a 340,000-byte seat map, already committed at its origin. If the declaration admits it, it is pushed and must land. If not, the runner parks it without a round trip, which is the prevention, and nothing is pushed;
  4. pushes two events at the declaration’s own boundary and at the contract’s envelope floors at once: max_event_bytes of opaque bytes (capped by max_batch_bytes), carried once in data and once in metadata, because the declaration bounds the two together; a type of MAX_EVENT_TYPE_LEN bytes; and MIN_SUPPORTED_TAGS_PER_EVENT tags of MAX_TAG_LEN bytes each. The declaration must admit each, and each must land, acknowledged as appended. A limit on the envelope or on metadata that the peer imposes without declaring it is a limit discovered at ingest;
  5. pulls the whole log back: every event that landed is held, byte for byte, which rejects a peer that accepts and truncates.

The asynchronous form of the declaration, which SY-18 also rejects, cannot be written: limits is not async on the port, so the compiler is that check and no mutant is needed for it.

A peer that declares more than MAX_PROVOKED_BATCH_BYTES has its boundary tested at that ceiling rather than at its declaration, because the event is allocated whole (H-13). The rule still runs.

§Rejects

tests/wrong_limits.rs carries eight mistakes over the KV-capped reference peer, one for each check above:

  • declarations rewritten over unchanged behaviour: no value cap, which admits the seat map that ingest then parks; the raw 131,072-byte value cap, as if a value held the payload alone, which admits a boundary event ingest refuses; a byte below VT-21’s floor; a declaration that changes between two reads; and max_batch_events of zero, which admits no event at all;
  • behaviour changed under an honest declaration: a cap of 1,024 bytes on metadata, Workers KV’s, that the declaration does not state; data truncated on a large push and acknowledged as appended; and a large event stored whole and acknowledged as skipped.

§Does not reject

A runner that ignores limits(). That is the runner’s defect, and #244 owns it; a peer can only make its declaration true. Nor limits that go stale between the read and the push: PeerLimits::admits is advisory, and what keeps that survivable is the Park and Split classes SY-36 checks.

Nor a lie about max_batch_bytes or max_batch_events alone. This rule holds the limits a peer imposes on an event, and reads the batch limits only to size the boundary event. A batch at them that is refused is peer_takes_a_batch_at_its_declared_limits’s to judge, and a batch over them is SY-36’s Split, not a fact that can never land.

§Errors

A Violation of SY-18 if the declaration changes between two reads, declares below VT-21’s floor, or admits no event at its own boundary; or if an event the declaration admits is refused, acknowledged as anything but one appended, or not handed back whole. The floor breach cites VT-21 in its message.