fix(session): keep server_spent monotonic on upsert#461
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b07d3f99d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| server_spent = CASE | ||
| WHEN LENGTH(channels.server_spent) > LENGTH(excluded.server_spent) THEN channels.server_spent | ||
| WHEN LENGTH(channels.server_spent) < LENGTH(excluded.server_spent) THEN excluded.server_spent | ||
| WHEN channels.server_spent >= excluded.server_spent THEN channels.server_spent | ||
| ELSE excluded.server_spent | ||
| END", |
There was a problem hiding this comment.
Preserve lower reconciled server spend
When a later receipt reconciles a reservation down (for example an earlier receipt reported spent=150 but the final successful receipt reports spent=120 with a higher/equal accepted cumulative), persist_session loads the existing record and calls set_server_spent(120) because server spend is explicitly latest-value, not monotonic. This conflict handler then keeps the old larger value, so ChannelRecord::close_amount() will overcharge during cooperative close instead of using the server’s latest actual spend.
Useful? React with 👍 / 👎.
Summary
server_spentvalue when saving an existing channelserver_spentwith the monotonic upsert behavior already used by deposit and cumulative amount fieldsCloses #413.
Verification
RUSTC="$(rustup which --toolchain stable rustc)" rustup run stable cargo test -p tempo-common stale_save_does_not_regress_server_spentRUSTC="$(rustup which --toolchain stable rustc)" rustup run stable cargo test -p tempo-common payment::session::store::storagePATH="$HOME/.cargo/bin:$PATH" make checkreached the finaltyposstep after passing nightly fmt, full workspace clippy, full workspace tests, and rustdoc; it stopped because the localtyposbinary is not installed.