Epoch-Boundary Snapshotting for Scheduled Releases
Overview
The Program Escrow contract supports scheduled automated releases for recipients over time. Historically, trigger_program_releases evaluated the live RELEASE_HISTORY and schedule registry at call time.
If a schedule was edited (e.g. by a program administrator) between when an off-chain caller decides to trigger releases and when the transaction lands on-chain, the payout could execute against a different recipient set than intended.
To resolve this, the contract introduces an epoch-boundary snapshot mechanism that freezes the currently-due schedule entries into an immutable batch reference prior to execution.
Lifecycle
- Create Snapshot: An authorized caller invokes
create_epoch_snapshotorcreate_epoch_snapshot_by. The contract evaluates the live registry, identifies all due schedules (now >= release_timestamp), and clones them into anEpochSnapshotstored under a uniqueepoch_id. - Execute Trigger: The caller invokes
trigger_program_releases(ortrigger_program_releases_by), passing theepoch_id. - Frozen Execution: The contract executes the token transfers using the
recipientandamountfrom the frozen snapshot instead of the live registry. - State Updates: After execution, the global
RELEASE_HISTORYand liveSCHEDULESregistry are updated. The corresponding schedule in the live registry is marked asreleased = true.
Security Assumptions
- Immutability: Once a snapshot is created, its recipient set and amounts are immutable. Even if an admin edits the schedule in the live registry, any trigger using the
epoch_idwill execute with the frozen values. - Single Execution: A schedule that is marked
released = truein the live registry will not be executed again, even if it is part of another snapshot. - Fallback: If
trigger_program_releasesis called withepoch_id = None, the contract falls back to evaluating the live registry at call time.
Relationship to RELEASE_HISTORY
The RELEASE_HISTORY and PROGRAM_DATA.payout_history are appended with the actual executed recipient and amount from the frozen snapshot (if provided), ensuring audit logs accurately reflect the destination of funds.