Skip to content

xpay: don't increase the payment counter for check - #9704

Open
coolstack-coder wants to merge 2 commits into
ElementsProject:masterfrom
coolstack-coder:xpay-check-counter
Open

coolstack-coder wants to merge 2 commits into
ElementsProject:masterfrom
coolstack-coder:xpay-check-counter

Conversation

@coolstack-coder

Copy link
Copy Markdown
Contributor

Fixes #9281.

check xpay builds a payment just like a real xpay call does, and new_payment() always took the next id with xpay->counter++. So every check used up a payment id. The ids name each payment's private askrene layer (xpay-N) and prefix its log lines, so the next real payment's numbering skipped ahead.

A check-only payment returns from preapprove_succeed() before age_layer(), so it never creates a layer and nothing keeps its id. This PR gives it the current counter value without incrementing, so the next real payment gets that id.

Commits:

  1. tests: adds test_xpay_check_keeps_counter as xfail(strict=True): two check xpay calls then a real xpay, expecting the payment to log as 0: and not 2:.
  2. plugin-xpay: the fix, which also removes the xfail marker.
  • Changelog-Fixed in the fix commit
  • Test added
  • Related issue linked

Comment thread tests/test_xpay.py
l1.rpc.xpay(inv)

# The first real payment is still payment 0, not payment 2.
l1.daemon.wait_for_log(r'plugin-cln-xpay: 0: ')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe match a line that only a real payment writes, for example:

l1.daemon.wait_for_log(r'plugin-cln-xpay: 0: .*Success: preimage=')

(look at attempt_info(. . . "Success: preimage=%s"), at xpay.c at line 1417)

Comment thread tests/test_xpay.py
l1.rpc.xpay(inv)


def test_xpay_check_keeps_counter(node_factory):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe also lets cover check xkeysend?

Comment thread plugins/xpay/xpay.c
payment->unique_id = xpay->counter++;
/* `check` never pays, so don't use up an id for it: the next real
* payment can have this one. */
if (command_check_only(cmd))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so a check payment and a real payment can now have the same id in the logs

xpay gives every payment a unique id taken from a plugin-wide counter.
The id names the payment's private askrene layer ("xpay-N") and
prefixes every log line for that payment. `check xpay` builds a payment
too, so each check moves the counter on even though nothing is paid.

Add a test that runs `check xpay` twice and then pays: the payment
should still be payment 0, but today it is payment 2.

Reported-by: Lagrang3 in ElementsProject#9281
new_payment() always took the next id with `xpay->counter++`, and all
three xpay entry points (bolt11, bolt12 and keysend) build the payment
before they look at command_check_only(). So `check xpay` used up an id
each time, and the next real payment's layer and log prefix skipped
numbers.

A check-only payment returns from preapprove_succeed() before
age_layer(), so it never creates its "xpay-N" layer and nothing else
holds on to the id. Give it the current counter value without bumping
it, so the next real payment gets that id.

Fixes: ElementsProject#9281
Changelog-Fixed: xpay: `check xpay` no longer increases the payment counter.
@sangbida
sangbida enabled auto-merge (rebase) November 23, 2026 06:51
@daywalker90

Copy link
Copy Markdown
Collaborator

test_xpay.py::test_xpay_simple is failing because of this fix. Please change the hardcoded ID's:

  • [tests/test_xpay.py:210] (xpay-15 → now xpay-7)
  • [tests/test_xpay.py:225] (xpay-17 → now xpay-8)

This branch has not been deployed

No deployments
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.

xpay check should not increase payment counter

3 participants