feat: add TIP-1034 tempo session#510
Open
brendanjryan wants to merge 6 commits into
Open
Conversation
commit: |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the new
tempo/sessionflow on the TIP-1034 precompile.The PR makes
tempo.sessiona precompile-backed session interface for HTTP, SSE, and WebSocket payments, while moving the previous channel implementation behind explicit legacy exports.What This PR Implements
tempo.sessionclient and server implementations backed by the TIP-1034TIP20EscrowChannelprecompiletempo.session.client,tempo.session.server, andtempo.session.precompilemodule boundariestempo/legacyand exposed throughsessionLegacyAPIsrequest.methodDetails.sessionSnapshotso clients can resume from server state without local persistenceEnd-to-End Flow
sequenceDiagram participant Client participant Manager as SessionManager participant Server participant Store as Channel store participant Chain as TIP-1034 precompile Client->>Manager: fetch/sse/ws paid resource Manager->>Server: request without credential Server->>Store: resolve reusable channel snapshot Server-->>Manager: 402 tempo.session challenge alt no reusable channel Manager->>Chain: open channel transaction Manager->>Server: retry with open credential + initial voucher else reusable snapshot available Manager->>Manager: hydrate runtime from server snapshot Manager->>Server: retry with voucher credential end Server->>Chain: verify/open/top-up/settle as needed Server->>Store: persist channel accounting Server-->>Manager: 200 + Payment-Receipt Manager->>Manager: reconcile receipt into state machine loop streaming or repeated requests Server-->>Manager: need-voucher event when headroom is low alt required cumulative exceeds deposit Manager->>Chain: top-up transaction Manager->>Server: post top-up credential end Manager->>Server: post/send voucher credential Server-->>Manager: receipt end Client->>Manager: close() Manager->>Server: close credential alt close challenge expired Server-->>Manager: fresh 402 tempo.session challenge Manager->>Server: retry close credential end Server->>Chain: close channel Server-->>Manager: close receiptServer Behavior
tempo.session()now creates a precompile-backed server method. It validates open, top-up, voucher, and close credentials against the canonical TIP-1034 channel descriptor, tracks accepted cumulative vouchers separately from spent units, and can settle channels on a configured schedule.The server attaches reusable session state to challenges when it can resolve a channel. The snapshot includes the channel descriptor, deposit, accepted cumulative amount, required cumulative amount, settled amount, spent amount, close state, and unit count. This lets clients hydrate from the server as the source of session state instead of requiring local persistence.
SSE and WebSocket transports use the same channel accounting model. Both can request additional voucher headroom, enforce local spend accounting, and drive top-up/voucher management posts without duplicating settlement logic.
Client Behavior
The client-side
sessionManager()owns a pure state-machine runtime for session lifecycle transitions. It opens channels, signs incremental vouchers, posts top-ups when the server asks for more deposit, reconciles receipts, and cooperatively closes the channel.HTTP, SSE, and WebSocket paths share the same credential state and voucher policy. The client keeps deposit, spent, and cumulative voucher authorization explicit so server snapshots can hydrate state without letting the server inflate the next signed voucher boundary.
close()now retries once when the close credential was signed against an expired challenge and the server returns a freshtempo/sessionchallenge.Public Interfaces and Controls
tempo.session.method()creates the precompile-backed client payment method forMppx.create()tempo.session()creates the auto-driving client session managertempo.session()on the server creates the precompile-backed server methodtempo.session.settle()andtempo.session.settleBatch()expose server settlement controlssessionManager.fetch(),sessionManager.sse(), andsessionManager.ws()power HTTP, SSE, and WebSocket flowssessionManager.topUp()andsessionManager.close()expose manual lifecycle controlsVITE_TEMPO_NETWORK=localnet|moderatoswitches the playground and tests between Docker localnet and Tempo ModeratoVITE_RPC_URLoverrides the selected network RPC URLAPI and Plumbing Changes
src/Constants.tssrc/tempo/session/client,src/tempo/session/server, andsrc/tempo/session/precompilesrc/tempo/legacyFetch.from()and transport helpers understand the session challenge/retry flow used for automatic voucher managementCompatibility
request.methodDetailsPublic Interfaces
Client
Default managed client. The server challenge supplies protocol details such as
chainId,escrowContract,operator, fee-payer support, suggested deposit, and reusable session snapshots.Managed client store for channel hints and restart recovery. The manager sends stored open channels as
Payment-Sessionon HTTP requests and WebSocket probes. Servers can read that hint inresolveChannelId()and return a snapshot; if no snapshot is returned, the client can use the stored descriptor/cumulative data as a fallback voucher context.Managed client options:
Low-level client method for
Mppx.create():Server
Default server method. The server owns session policy and advertises it in the challenge.
Server options:
Server lifecycle controls: