Causal Delivery Check
Causal Delivery Check
You are writing the gate that decides whether an incoming message can be delivered now or must stay buffered.
Given receiver vector clock local, message vector clock msg, and sender index s, return whether the message is causally deliverable.
Deliverability conditions:
msg[s] == local[s] + 1(exact next message from sender)- For all
i != s,msg[i] <= local[i](all dependencies already seen)
Function signature
func IsCausallyDeliverable(local []int, msg []int, sender int) bool
Example
local = [2,0,1]
msg = [2,1,1]
sender = 1
output = true
Implementation blueprint (near-solution)
- Check sender rule first:
- if
msg[sender] != local[sender] + 1, returnfalse.
- if
- Scan all indices except sender:
- if any
msg[i] > local[i], returnfalse.
- if any
- Otherwise return
true.
Reference pseudocode:
if msg[s] != local[s] + 1: return false
for i in [0..n-1], i != s:
if msg[i] > local[i]: return false
return true
Why this is correct
- Sender equality enforces no gaps or duplicates in sender stream.
- Non-sender
<=enforces all causal prerequisites are already delivered.
Constraints
len(local) == len(msg)1 <= len(local) <= 1000000 <= sender < len(local)0 <= local[i], msg[i]
Common mistakes
- Using
>=for sender comparison. - Applying same rule to sender and non-sender components.
- Mutating
localin this check-only function.
Run tests to see results
No issues detected