Skip to content

fix: use per-destination tx sequence counters - #15

Merged
LeoLTM merged 1 commit into
mainfrom
fix/per-peer-tx-sequence
Oct 24, 2026
Merged

LeoLTM merged 1 commit into
mainfrom
fix/per-peer-tx-sequence

Conversation

@LeoLTM

@LeoLTM LeoLTM commented Oct 24, 2026

Copy link
Copy Markdown
Member

Problem

A device that talks to several peers used one shared outgoing sequence counter, but receivers validate the counter per source address (§7.2). Traffic to peer A advances the counter peer B sees. Once more than SeqCounterAcceptWindow (15) messages go elsewhere, B drops the next message as Stale and the sender's request times out (E_TIMEOUT). Stale doesn't update last_seen, so B keeps dropping until the counter happens to wrap back into the window, which makes the failure look flaky.

Seen on the kart: OTA triggers from the headunit to zc_lights and zc_motor failed with returnCode=6. Those are the two ECUs the headunit regularly sends commands to. zc_buttons and zc_battery worked because the headunit had never messaged them before, so the OTA request counted as FirstSeen.

Fix

  • E2EProtection::next_sequence(dest) keeps one counter per destination, bounded by MaxTrackedPeers. Destinations beyond the table share the old counter as a fallback.
  • All four unicast send paths in Runtime pass their destination: fire-and-forget, notify, response and request. SD messages keep their separate counter.
  • Spec §7.2 and the README now say "per destination" instead of "per device".

Wire format is unchanged. Only the sender needs the update, so peers still on v0.2.3 accept the new counters.

Tests

  • New RuntimeTest.MultiPeerSender_TrafficToOtherPeer_DoesNotStaleRequest: a consumer sends 20 messages to provider A, then a request to provider B. It fails before the fix (B drops the request as stale) and passes after.
  • New E2E unit tests: counters are independent per destination, and destinations beyond a full table share the fallback counter.
  • All 287 tests pass. The zc_motor ESP32 firmware and the sero-node native binding both build against this branch.

A device talking to several peers shared one outgoing counter, while
receivers validate per source address. Traffic to one peer advanced the
counter seen by another, so after more than SeqCounterAcceptWindow
messages elsewhere the next request was dropped as Stale and the sender
timed out (E_TIMEOUT). Since Stale does not update last_seen, the peer
stayed stuck until the counter wrapped back into the window.

Keep one counter per destination (bounded by MaxTrackedPeers, with the
old shared counter as fallback). Wire format is unchanged and receivers
need no update.
@LeoLTM
LeoLTM merged commit 6bb2744 into main Oct 24, 2026
6 checks passed
@LeoLTM
LeoLTM deleted the fix/per-peer-tx-sequence branch October 24, 2026 00:19
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