Skip to content

[PeerX Backlog # 83] Atomic batch settlement with delta snapshots (drop the "Layer-2" framing) #83

Description

@ameeribro4-sudo

Problem Statement
A user submitting N swaps in an atomic batch currently pays roughly
N× the per-swap cost because every swap re-runs KYC, fee math,
cache invalidation, and event emission. The "atomic" semantic requires
all-or-nothing rollback, which today is implemented by cloning the
entire Portfolio (see Issue #70).

(The historical title called this "Layer-2" — that framing implied
rollup / optimistic semantics that do not apply here. Retitled.)

Expected Outcome
Build on Issue #70's delta snapshot machinery so that pre-settlement
state can be cheaply rebuilt, and amortize the fixed costs of KYC,
rate limits, cache invalidation, and event emission across N swaps in
a single batch.

Acceptance Criteria

  • Established by measurement: run the existing execute_batch_atomic
    on a 100-swap fixture and capture baseline gas; the implementation
    target is "≤ baseline minus amortized fixed-cost overhead" — i.e.
    no worse than the current implementation, with N swaps paying one
    KYC check, one cache flush, and one batched event.
  • State is recoverable on partial failure via the delta list (Issue [PeerX Backlog # 70] Avoid cloning entire Portfolio for atomic batch #70).
  • No regressions in the 100% rollback-on-failure property test.

Files Affected

  • peerx-contracts/counter/src/lib.rs, batch.rs.

Dependency Issue #70.
Difficulty / Effort 🥑 / XL
Labels feature, performance, priority/medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26featurePeerX Backlog label feature (bulk-imported)performancePeerX Backlog label performance (bulk-imported)priority/mediumPeerX Backlog label priority/medium (bulk-imported)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions