fix: cooperative close uses actual spent amount instead of voucher ceiling#191
Open
fix: cooperative close uses actual spent amount instead of voucher ceiling#191
Conversation
…iling On cooperative close, the server required the close voucher's cumulativeAmount to be >= highest_voucher_amount (the pre-authorized reservation). This meant clients were charged the full reservation even when actual usage was much lower (e.g., $4 for a SELECT 1 query). This ports the fix from mppx (wevm/mppx#196) and wallet (tempoxyz/wallet#349): 1. The minimum close amount is now max(channel.spent, on_chain.settled) instead of highest_voucher_amount, allowing clients to close at actual usage cost. 2. The store update only overwrites highest_voucher_amount when the close amount is actually higher, preserving the original voucher for settlement if the close is at a lower (actual spent) amount. Amp-Thread-ID: https://ampcode.com/threads/T-019d5503-2e85-70ff-81ed-b5093c920fd5 Co-authored-by: Amp <amp@ampcode.com>
Contributor
|
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
On cooperative close, the server required the close voucher's
cumulativeAmountto be>= highest_voucher_amount(the pre-authorized reservation). This meant clients were charged the full reservation even when actual usage was much lower.Reproduced with Dune MPP: A
SELECT 1query (88ms execution, 4 bytes result) was charged the full $4.00 reservation instead of actual compute cost.Root Cause
handle_close()validated:And unconditionally overwrote the voucher:
Fix
Ports the fix from
mppx(wevm/mppx#196) andwallet(tempoxyz/wallet#349):Minimum close amount is now
max(channel.spent, on_chain.settled)instead ofhighest_voucher_amount, allowing clients to close at actual usage cost.Store update only overwrites
highest_voucher_amountwhen the close amount is actually higher, preserving the original voucher for settlement.Testing
All 240 existing tests pass. The behavioral change only affects cooperative close when the client sends a voucher below the highest pre-authorized amount but above actual spend — previously rejected, now accepted.