Skip to content

feat(payments): streaming per-tick payments with mid-stream cancellation#21

Open
fozagtx wants to merge 2 commits into
projnanda:mainfrom
fozagtx:hackathon/kaizen-streaming-payments
Open

feat(payments): streaming per-tick payments with mid-stream cancellation#21
fozagtx wants to merge 2 commits into
projnanda:mainfrom
fozagtx:hackathon/kaizen-streaming-payments

Conversation

@fozagtx

@fozagtx fozagtx commented Jun 11, 2026

Copy link
Copy Markdown

Problem

Problem #3: Streaming pay-per-second payments with mid-stream cancellation

What this does

Adds a StreamingPayments plugin at ("payments", "streaming") that extends prepaid credits with per-tick billing. Either party can cancel mid-stream; unused remainder is never spent. Backward-compatible with the existing Payments protocol.

Key APIs

Method Returns Notes
open_stream(to, rate_per_tick, max_total, ref) StreamHandle Drains first tick immediately
tick_stream(ref, current_tick) bool Per-round billing, enforces max & balance
close_stream(ref) Receipt Unused remainder never spent
verify_payment(ref) PaymentStatus STREAMING / CONFIRMED / FAILED
pay() / refund() Receipt / None Backward-compatible one-shot

Three adversarial validators

  1. Conservationsum(debited) == sum(credited) across the full trace
  2. No drain-after-close — no payment_debited events after stream_closed
  3. No over-bill on partition — no debits after payer/payee are network-partitioned

Files changed (7)

  • packages/nest-plugins-reference/nest_plugins_reference/payments/streaming.py — plugin (~340 lines)
  • packages/nest-plugins-reference/tests/test_streaming_payments.py — 18 tests (~300 lines)
  • packages/nest-core/nest_core/validators.py — 3 validators (~190 lines)
  • packages/nest-core/tests/test_validators.py — 7 validator tests
  • packages/nest-core/nest_core/plugins.py — registry entry
  • packages/nest-core/nest_core/types.pyPaymentStatus.STREAMING enum
  • scenarios/streaming_payments.yaml + streaming_payments_partition.yaml

CI

All green: uv sync · ruff check · ruff format · pyright · pytest (366 passed)

Verify

uv run pytest packages/nest-plugins-reference/tests/test_streaming_payments.py -v
uv run pytest packages/nest-core/tests/test_validators.py -v -k streaming

fozagtx added 2 commits June 11, 2026 13:35
- Implements StreamingPayments layer extending prepaid credits with per-tick billing
- Two attack validators:
  * conservation: verifies sum(debited) == sum(credited)
  * no_drain_after_close: prevents payment_debited after stream closure
- Test scenario: 5 buyers, 5 sellers, 100 rounds, seed 42
- Comprehensive test suite: 18 tests, all passing in 0.35 seconds
- Scenario type registered in validator registry

Key APIs:
- open_stream(to, rate_per_tick, max_total): Returns StreamHandle with immediate first-tick drain
- tick_stream(stream_ref): Per-round billing, enforces max_total and balance constraints
- close_stream(stream_ref): Finalizes payment, creates Receipt
- verify_payment(ref): Returns PaymentStatus.STREAMING or .CONFIRMED
- Backward compatible: pay() method supports one-shot payments

All CI checks passing: uv sync, ruff check, ruff format, pyright, pytest (359 passed)
…yments

- New validator: no_overbill_on_partition — catches debits after
  payer/payee partition (problem spec requirement projnanda#2)
- All 3 required validators now present: conservation,
  no-drain-after-close, no-overbill-on-partition
- Example:: blocks added to every public method (StreamHandle,
  balance, quote, open_stream, tick_stream, close_stream, pay,
  verify_payment, refund) per rubric docs_quality requirements
- Scenario YAMLs corrected to match ScenarioConfig schema
- New scenario: streaming_payments_partition.yaml with buyer/seller
  partition groups for partition-validator coverage
- 7 new validator unit tests (conservation pass/fail,
  drain-after-close pass/fail, partition pass/fail/ignore-unrelated)
- All CI green: uv sync, ruff, pyright, 366 tests passing
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.

1 participant