Skip to content

fix(session): keep server_spent monotonic on upsert#461

Open
EfeDurmaz16 wants to merge 1 commit into
tempoxyz:mainfrom
EfeDurmaz16:fix/server-spent-monotonic-upsert
Open

fix(session): keep server_spent monotonic on upsert#461
EfeDurmaz16 wants to merge 1 commit into
tempoxyz:mainfrom
EfeDurmaz16:fix/server-spent-monotonic-upsert

Conversation

@EfeDurmaz16
Copy link
Copy Markdown

Summary

  • preserve the larger server_spent value when saving an existing channel
  • align server_spent with the monotonic upsert behavior already used by deposit and cumulative amount fields
  • add a regression test for stale saves that would otherwise lower the cooperative close target

Closes #413.

Verification

  • RUSTC="$(rustup which --toolchain stable rustc)" rustup run stable cargo test -p tempo-common stale_save_does_not_regress_server_spent
  • RUSTC="$(rustup which --toolchain stable rustc)" rustup run stable cargo test -p tempo-common payment::session::store::storage
  • PATH="$HOME/.cargo/bin:$PATH" make check reached the final typos step after passing nightly fmt, full workspace clippy, full workspace tests, and rustdoc; it stopped because the local typos binary is not installed.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +298 to +303
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",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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.

bug: server_spent field lacks monotonic-max protection in channel upsert

1 participant