feat(payments): streaming per-tick payments with mid-stream cancellation#21
Open
fozagtx wants to merge 2 commits into
Open
feat(payments): streaming per-tick payments with mid-stream cancellation#21fozagtx wants to merge 2 commits into
fozagtx wants to merge 2 commits into
Conversation
- 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
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.
Problem
Problem #3: Streaming pay-per-second payments with mid-stream cancellation
What this does
Adds a
StreamingPaymentsplugin 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 existingPaymentsprotocol.Key APIs
open_stream(to, rate_per_tick, max_total, ref)StreamHandletick_stream(ref, current_tick)boolclose_stream(ref)Receiptverify_payment(ref)PaymentStatusSTREAMING/CONFIRMED/FAILEDpay()/refund()Receipt/NoneThree adversarial validators
sum(debited) == sum(credited)across the full tracepayment_debitedevents afterstream_closedFiles 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 testspackages/nest-core/nest_core/plugins.py— registry entrypackages/nest-core/nest_core/types.py—PaymentStatus.STREAMINGenumscenarios/streaming_payments.yaml+streaming_payments_partition.yamlCI
All green:
uv sync·ruff check·ruff format·pyright·pytest(366 passed)Verify