BeeKEM manages concurrency by assuming causal delivery of operations. When operations are not causally ordered (concurrent), BeeKEM uses specific merge strategies to ensure all peers converge to the same tree structure.
Merging Concurrent Path Changes (Updates)
When applying a path change from another member that was created concurrently:
- Validate the path: A path is valid only if the originating member is at the same leaf index and the path length matches. If the tree structure changed (e.g., a concurrent add reshuffled leaves), the path is invalid.
- Invalid Path Handling: If invalid, only update the leaf's public key by merging it with the existing one. The rest of the path is blanked.
- Valid Path Handling:
- At the leaf: Merge the new public key with the existing one. If the existing key was in the "removed keys" list, it is substituted. Otherwise, both are kept as conflict keys.
- At inner nodes: Merge the new secret store's versions into the existing one. Remove versions whose public keys are in the "removed keys" list and append new versions. If the node was blank, insert the new store.
- Root State: If the root has a single version, record the new encrypter. If the root has multiple conflicting versions, clear the encrypter. A tree with conflicts has no valid root key until a fresh update is performed.
Merging Concurrent Membership Changes (Adds/Removes)
If a batch of concurrent operations includes an add or remove:
- Apply all operations in the batch.
- Cleanup Step:
- Re-blank removed members' paths: Ensures that concurrent updates from other members didn't accidentally write data back onto a path belonging to a removed member.
- Sort and re-add concurrent leaves: If multiple members added leaves concurrently, they might target the same position. Pull these leaves out, sort them deterministically by identity, and re-insert them in order to ensure structural convergence.
Causal Ordering and Epochs
Operations form a Directed Acyclic Graph (DAG) where each operation records its causal predecessors. When concurrency exists (multiple heads), BeeKEM:
- Topologically sorts operations.
- Groups them into epochs (sets of mutually concurrent operations).
- Applies epochs in causal order.
- If concurrency is too complex to merge incrementally (e.g., after a membership change), the entire tree is replayed from scratch by re-applying all topologically sorted operations in epoch order.