Skip to content

feat: multi-chain Soroban state synchronizer using CRDTs (#49)#92

Merged
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/crdt-state-sync
Jun 26, 2026
Merged

feat: multi-chain Soroban state synchronizer using CRDTs (#49)#92
elizabetheonoja-art merged 1 commit into
Utility-Protocol:mainfrom
real-venus:feat/crdt-state-sync

Conversation

@real-venus

Copy link
Copy Markdown
Contributor

Multi-Chain Soroban Contract State Synchronizer Using CRDTs (#49)

Closes #49

What's included

File Responsibility
src/types/crdt.ts LamportTimestamp, LWWRegister, ORSet, VectorClock, the CrdtEvent discriminated union, resource diffs, and bounds (chain priority mainnet > testnet > futurenet, 12-ledger / ~60 s reconcile timeout).
src/utils/lamportClock.ts LamportClock (tick / observe / tickAfter) and compareTimestamp — a total order by counter with chain-priority tie-breaking.
src/utils/crdtMerge.ts Pure engine: LWW register merge, tag-based OR-set with tombstones (remove carries the observed tags, so merges are order-independent), orSetValues, and a batched mergeEvents producing per-resource diffs + vector clocks + chain-seen counters.
src/workers/crdtMerge.worker.ts Accumulates the merged state off the main thread and posts diffs back.
src/store/slices/crdtSlice.ts Applies diffs immutably, tracks per-resource vector clocks + per-chain lastSeen, and a staleness watcher that flags a chain for a full snapshot re-fetch past the reconcile timeout.
src/hooks/useContractState.ts Stamps each ingested event with the originating chain's Lamport clock, batches to the worker (inline-merge fallback), runs the staleness watch, and auto-cleans on unmount.
tests/unit/* Clock ordering, CRDT convergence under arbitrary interleavings (LWW tie-breaks, OR-set add-wins, commutativity), incremental folding, and the store/staleness watcher.

…tocol#49)

Merges concurrent updates from multiple Soroban chains (testnet/futurenet/
mainnet) deterministically so the local store always converges without manual
reconciliation.

- types/crdt.ts: LamportTimestamp, LWWRegister, ORSet, VectorClock, the CrdtEvent
  discriminated union, resource diffs, and bounds (chain priority mainnet >
  testnet > futurenet, 12-ledger/~60s reconcile timeout)
- utils/lamportClock.ts: LamportClock (tick/observe/tickAfter) + compareTimestamp
  total order with chain-priority tie-breaking
- utils/crdtMerge.ts: pure engine — LWW register merge, tag-based OR-set with
  tombstones (remove carries observed tags so merges are order-independent),
  orSetValues, and a batched mergeEvents producing per-resource diffs + vector
  clocks + chain-seen counters
- workers/crdtMerge.worker.ts: accumulates merged state off-thread and posts diffs
- store/slices/crdtSlice.ts: applies diffs immutably, tracks per-resource vector
  clocks + per-chain lastSeen, and a staleness watcher flagging chains for a full
  snapshot re-fetch past the reconcile timeout
- hooks/useContractState.ts: stamps each ingested event with the originating
  chain's Lamport clock, batches to the worker (inline-merge fallback), runs the
  staleness watch, auto-cleans on unmount
- tests for the clock ordering, CRDT convergence under arbitrary interleavings
  (LWW tie-breaks, OR-set add-wins, commutativity), and the store/staleness
@elizabetheonoja-art elizabetheonoja-art merged commit 9ae7d98 into Utility-Protocol:main Jun 26, 2026
4 checks passed
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.

Multi-Chain Soroban Contract State Synchronizer Using Conflict-Free Replicated Data Types

2 participants