DIM · Dagon Inference Marketplace

Channel lifecycle

A channel has two stored states, Open and Closing. Finalizing deletes the account, so "finalized" is the absence of the channel, not a third status. Three times govern it:

Symbol Field Meaning
T service_end_unix Service end, set at open; must be in the future. Gateways refuse new Holds from T on.
G grace_secs Grace for redemption after closing begins; 1 second to 30 days, and under a Mandate at most max_grace_secs.
D close_deadline_unix min(T, now) + G, set once by begin_close or close_on_revoked; 0 while Open.
stateDiagram-v2
    [*] --> Open: open_channel
    Open --> Open: redeem / top_up
    Open --> Closing: begin_close / close_on_revoked (D = min(T, now) + G)
    Closing --> Closing: redeem while now < D
    Closing --> [*]: finalize once now ≥ D (refund budget − redeemed, close account)

Transitions

From Instruction Who To Condition
— open_channel vault owner, or the Mandate's agent Open epoch is last_channel_epoch + 1; budget available; Mandate limits hold
Open top_up vault owner, or the Mandate's agent Open before T
Open redeem anyone, with the session key's proof Open settled_total ≤ budget
Open begin_close vault owner, Mandate agent, or seller_settler Closing sets D
Open close_on_revoked anyone Closing the Mandate or an ancestor is revoked or expired
Closing redeem anyone, with the session key's proof Closing now < D
Closing begin_close, close_on_revoked as above Closing no effect: D is never moved
Closing finalize anyone closed now ≥ D

What the times guarantee

  • The seller has a known window. With c the time closing begins, D = min(T, c) + G: the seller always has G from the earlier of c and T to redeem its latest voucher, and nothing can change G after opening. Sellers therefore redeem before T + G and watch for begin_close.
  • The buyer always gets the rest back. After D, anyone can finalize: budget − redeemed returns to the vault's free balance and any Mandate reservation is released.
  • Service ends at T, redemption does not. The program does not stop redemption at T; only D does. A channel past T stays Open, and redeemable, until someone begins closing it.
  • No replay after close. A finalized channel's address cannot be recreated, because epochs only increase by one per vault (A31). A later redeem or finalize at that address fails in Anchor's loader with AccountNotInitialized (3012).

Mandate lifecycle

stateDiagram-v2
    [*] --> Live: create_mandate
    Live --> Inactive: revoke_mandate / expiry passes
    Inactive --> [*]: close_mandate (no live channels, no reservation, no children)

A Mandate is inactive once it or any ancestor is revoked or expired: it can no longer open or top up channels, and its channels can be moved to Closing by anyone with close_on_revoked. Its open channels still redeem until their deadlines and still finalize normally.