Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Nostr zaps: currently display as 0-amount payments instead of their actual amounts #2763

Open
chrisguida opened this issue Jan 22, 2025 · 22 comments
Labels
Bug Something isn't working CLNRest

Comments

@chrisguida
Copy link

Describe the bug

I've recently hooked up my CLN node to Nostr and I'm starting to send and receive zaps, which tend to be small payments <100sat.

In RTL, the amounts display correctly:

Image

However in Zeus, the amounts just say 0:

Image

Even when clicking on details, the amounts still all say 0:

Image

Reproduce

Follow steps above

ZEUS version

v0.9.4

Node interface

Core Lightning (CLNRest)

Network

Clearnet

Device

Android Pixel 8a

Device operating system

Android 15

Log output

@chrisguida chrisguida added the Bug Something isn't working label Jan 22, 2025
@kaloudis
Copy link
Contributor

Could this potentially be a bug with CLN? I see new payments sent to bolt11 invoices returning 0 for amount_msat and null for amount_sent_msat from our sql queries. Very peculiar.

@kaloudis
Copy link
Contributor

This is not true for all payments though. I have some from as recent as two days ago returning both values correctly.

Query in question fwiw https://github.com/ZeusLN/zeus/blob/master/backends/CLNRest.ts#L254

@chrisguida
Copy link
Author

Yes, and as I already mentioned, RTL displays everything just fine, so perhaps they are querying differently?

@chrisguida
Copy link
Author

Oh whoa, you're using the sql plugin. That thing may not be... entirely stable. I'll test the query

@kaloudis
Copy link
Contributor

I believe the getPays endpoint doesn't have all the info we need, so we use the SQL here.

It appears these payments in question all have status 'failed'

@kaloudis
Copy link
Contributor

ah, the sql route was done for perf purposes. see #2298

@chrisguida
Copy link
Author

chrisguida commented Jan 23, 2025

ok this is the result i get

cl sql -k query=" \
select \
  sp.payment_hash \
, sp.groupid \
, min(sp.status) as status \
, min(sp.destination) as destination \
, min(sp.created_at) as created_at \
, min(sp.description) as description \
, min(sp.bolt11) as bolt11 \
, min(sp.bolt12) as bolt12 \
, sum(case when sp.status = 'complete' then sp.amount_sent_msat else null end) as amount_sent_msat \
, sum(case when sp.status = 'complete' then sp.amount_msat else 0 end) as amount_msat \
, max(sp.payment_preimage) as preimage \
from sendpays sp group by sp.payment_hash, sp.groupid \
order by created_index desc \
limit 150"
{
   "rows": [
      [
         "<redacted payment hash>"",
         6860742985498932927,
         "complete",
         null,
         1737592160,
         null,
         "<redacted bolt11>",
         null,
         43114,
         null,
         "<redacted preimage>"
      ],
................

This displays as a 0 in Zeus, even though the amount_sent_msat is clearly 43114 msat. However, amount_msat is null, perhaps that's the issue?

@chrisguida chrisguida changed the title Nostr zaps: display as 0-amount payments instead of their actual amounts [bug] Nostr zaps: currently display as 0-amount payments instead of their actual amounts Jan 23, 2025
@newtonick
Copy link
Contributor

newtonick commented Jan 23, 2025

According to core lightning docs for sendpay it looks like amount_msat is an optionally returned value. The documentation does not spell out what specific circumstances would lead to the value being null. I'm not sure why this would happen.

Zeus appears to use amount_sent_msat and amount_msat to determine the fee/cost of sending the payment in models/Payment.ts.

It doesn't appear to me that this issue is specific to CLNRest. I believe models/Payment.ts has had both amount_sent_msat and amount_msat to calculate fee for a payment prior to PR #2228 to build in CLNRest support.

I'm not sure how to properly handle amount_sat being null.

But the simplest option seems like it would be to adjust the function getAmount in models/Payment.ts to pull the amount from amount_sent_msat if amount_msat is null.

@newtonick
Copy link
Contributor

I suck at writing JS, but I believe this would fix the issue.

@computed public get getAmount(): number | string {
        return this.amount_msat
            ? Number(this.amount_msat.toString().replace('msat', '')) / 1000
            : this.value_sat ||
                  this.value ||
                  Number(this.msatoshi_sent) / 1000 ||
                  0;
    }

could be modified to:

@computed public get getAmount(): number | string {
        return this.amount_msat
            ? Number(this.amount_msat.toString().replace('msat', '')) / 1000
            : this.value_sat ||
                  this.value ||
                  Number(this.msatoshi_sent) / 1000 ||
                  Number(this.amount_sent_msat) / 1000 ||
                  0;
    }

@chrisguida
Copy link
Author

chrisguida commented Jan 23, 2025

Perhaps @ShahanaFarooqui can comment on when/why CLN returns null for amount_msat, I assume this has to do with the nature of zaps being essentially tips, perhaps this is what happens when there's no amount on the invoice or something?

@ShahanaFarooqui
Copy link

I believe the amount_msat field in the sendpays table will only be non-null for partial payments (with a non-zero part ID) or self-payments. While amount_sent_msat represents the total amount paid (including fees), amount_msat reflects the amount associated with a specific part of a partial payment.

@chrisguida
Copy link
Author

It seems like Zeus is attempting to calculate the fees, does this mean that for some invoices the fees are impossible to calculate?

@kaloudis kaloudis linked a pull request Jan 23, 2025 that will close this issue
30 tasks
@ShahanaFarooqui
Copy link

Hi @chrisguida,

After spending 370 sats, I found out that amount_sats, amount_sent_msat, and destination are never null on my node! 😄

My CLN node is running on v24.08. It seems there might be an issue with your query results or possibly a bug.

Below is my node's response from the query you referenced in comment:

  • 1st row: Self-payment of 70 sats
  • 2nd row: Invoice payment of 100 sats (no MPP)
  • 3rd row: MPP with only one completed part for 150 sats
  • 4th row: "Any amount" invoice payment (no MPP)
{
   "rows": [
      [
         "<redacted payment hash>",
         1,
         "complete",
         "<redacted destination>",
         1737654645,
         null,
         "<redacted bolt11>",
         null,
         70000,
         70000,
         "<redacted preimage>"
      ],
      [
         "<redacted payment hash>",
         1,
         "complete",
         "<redacted destination>",
         1737653234,
         null,
         "<redacted bolt11>",
         null,
         101010,
         100000,
         "<redacted preimage>"
      ],
      [
         "<redacted payment hash>",
         1,
         "complete",
         "<redacted destination>",
         1737653109,
         null,
        "<redacted bolt11>",
         null,
         150091,
         150000,
         "<redacted preimage>"
      ],
      [
         "<redacted payment hash>",
         1,
         "complete",
         "<redacted destination>",
         1737652290,
         null,
        "<redacted bolt11>",
         null,
         121012,
         120000,
        "<redacted preimage>"
      ]
   ]
}

But at least Zeus's bug is resolved by updating the msatoshi_sent data point to amount_sent_msat, as all "msatoshi_" fields were deprecated following The great msat purge :)

@chrisguida
Copy link
Author

@ShahanaFarooqui hmm, very odd!

I guess this is a problem unique to the invoices Primal and Amethyst are generating for Nostr zaps?

here is a sample zap invoice from Amethyst, does anything jump out at you that would cause amount_msat to be null once this invoice is paid?

₿ cl decode lnbc25u1pne9ze4sp506vcyk5lpltly9v23vzg0a7n6ca5fwhls2anepzltfept809j6uqpp5a9fs4lvdvda4wk4c6qrndg84l3k7ya6vv7y2g58jje7ekdjz2yhshp5f0ahycfmsj4z54gvdf43trh8cdsmt0hdngnrf3sjmgtepnkhdn9qxqyjw5qcqpjrzjqvgd98tnc655mdyujl2vxz38k6hygu5k3s8qg027ejxka2q7473jyr2nx5qqfnqqqyqqqqlgqqqqn3qq2q9qxpqysgqcwqfpy5paq2xevlccsft79fp696dddfc9vn0444n7eyxaaf2gpqqsxvhumq8332c8kgamt2cy0jqhq4f68qk3285re6809lxxg3898cpccum7l
{
   "type": "bolt11 invoice",
   "currency": "bc",
   "created_at": 1737657141,
   "expiry": 604800,
   "payee": "03d337fbdceefe898eb4a79ab50c21286ed9fe2c7c3fd4a8653ea22ea1e5848a2f",
   "amount_msat": 2500000,
   "description_hash": "4bfb72613b84aa2a550c6a6b158ee7c361b5beed9a2634c612da1790ced76cca",
   "min_final_cltv_expiry": 18,
   "payment_secret": "7e99825a9f0fd7f2158a8b0487f7d3d63b44baff82bb3c845f5a72159de596b8",
   "features": "02024100",
   "routes": [
      [
         {
            "pubkey": "0310d29d73c6a94db49c97d4c30a27b6ae4472968c0e043d5ecc8d6ea81eafa322",
            "short_channel_id": "873269x1228x1",
            "fee_base_msat": 1000,
            "fee_proportional_millionths": 2500,
            "cltv_expiry_delta": 80
         }
      ]
   ],
   "payment_hash": "e9530afd8d637b575ab8d00736a0f5fc6de2774c6788a450f2967d9b3642512f",
   "signature": "3045022100c380909281e8146cb3f8c412bf1521d174d6b5382b26fad6b3f6486ef52a40400220081997e6c078c5583d91ddad5823e40b82a9d1c168a8f41e747797e63222729f",
   "valid": true
}

@ShahanaFarooqui
Copy link

ShahanaFarooqui commented Jan 23, 2025

@chrisguida, Nope, nothing seems out of ordinary.

I just tested a zap payment (created on Primal) and sendpay query is still responding with amount_msat and amount_sent_msat:

lightning-cli decode "lnbc210n1pne9xjcpp50k38c4erndm25drdz6hu9w7gv5p3z2ayaatf65l3l68gvndwqm4qhp5y8vup88etcv8t5acxpcp4slqwr6s6y5e3lpnnkevqucvwmdhcudqcqzpuxqr8pqsp5wuzj6k6l85yltrq2rfkjj9pzrnkwcuaetr05h9twg6jpyuy83p6s9qxpqysgqjekccmscp0kcnkx8gjeqda2s7n3ndzr0wuuf82f9uktmdmwssc2s4893eegq37trv28gcg3m5tmdfnk5wpc6lvvrjrueg8whzrrtymcq6xkq93"

{
   "type": "bolt11 invoice",
   "currency": "bc",
   "created_at": 1737661016,
   "expiry": 7200,
   "payee": "02fcc5bfc48e83f06c04483a2985e1c390cb0f35058baa875ad2053858b8e80dbd",
   "amount_msat": 21000,
   "description_hash": "21d9c09cf95e1875d3b830701ac3e070f50d12998fc339db2c0730c76db7c71a",
   "min_final_cltv_expiry": 60,
   "payment_secret": "77052d5b5f3d09f58c0a1a6d2914221cecec73b958df4b956e46a41270878875",
   "features": "02024100",
   "payment_hash": "7da27c57239b76aa346d16afc2bbc86503112ba4ef569d53f1fe8e864dae06ea",
   "signature": "3045022100966d8c6e180bed89d8c744b206f550f4e336886f773893a925e597b6edd0861502200a9cb1ce5008f963628e8c223ba2f6d4ced47071afb18390f9941dd710c6b26f",
   "valid": true
}

RTL received successful payment response as:

{
	"destination": "02fcc5bfc48e83f06c04483a2985e1c390cb0f35058baa875ad2053858b8e80dbd",
	"payment_hash": "7da27c57239b76aa346d16afc2bbc86503112ba4ef569d53f1fe8e864dae06ea",
	"created_at": 1737661071.161475,
	"parts": 1,
	"amount_msat": 21000,
	"amount_sent_msat": 21010,
	"payment_preimage": "<redacted preimage>",
	"status": "complete"
}

And the response from sendpays table query is:

[
	 "7da27c57239b76aa346d16afc2bbc86503112ba4ef569d53f1fe8e864dae06ea",
	 1,
	 "complete",
	 "02fcc5bfc48e83f06c04483a2985e1c390cb0f35058baa875ad2053858b8e80dbd",
	 1737661071,
	 null,
	 "lnbc210n1pne9xjcpp50k38c4erndm25drdz6hu9w7gv5p3z2ayaatf65l3l68gvndwqm4qhp5y8vup88etcv8t5acxpcp4slqwr6s6y5e3lpnnkevqucvwmdhcudqcqzpuxqr8pqsp5wuzj6k6l85yltrq2rfkjj9pzrnkwcuaetr05h9twg6jpyuy83p6s9qxpqysgqjekccmscp0kcnkx8gjeqda2s7n3ndzr0wuuf82f9uktmdmwssc2s4893eegq37trv28gcg3m5tmdfnk5wpc6lvvrjrueg8whzrrtymcq6xkq93",
	 null,
	 21010,
	 21000,
	 "<redacted preimage>"
]

Now you owe me 370 + 21 = 391 Sats 😄!!!

@chrisguida
Copy link
Author

chrisguida commented Jan 23, 2025

@ShahanaFarooqui very odd indeed! I wonder if this has to do with the fact that I'm using https://github.com/gudnuf/cln_nwc, though I'm not sure how that would make a difference, it's just forwarding the invoice to CLN to pay afaik... maybe this is an issue on CLN 24.11 and not 24.08? Should I upgrade to 24.11.1? Does the newer version have any changes related to this?

PS send me an invoice or a Nostr profile and I'll be sure to zap you back! :)

@chrisguida
Copy link
Author

Yeah, sure enough, listpays does not have a value for amount_msat on any of these. Very weird.

      {
         "bolt11": "lnbc5u1pne9rjgpp5nym6kyv45elpyc4cddvqtexz5jmmnhscmcnp3w2x6a9lp5lqa5jshp5xlqn6h9r3fe0ej87em5ywpeyxkfhwgqaxhf26d9jd3hyagwy0qtqcqzzsxqrrs0sp5jl2lv58gl0k59vu7h79dxdqqq5s56wkc47z44fwyncae9vec9f7q9qxpqysgq5satfulhk4dfasxf94hszkhzhqt0fvaj9x3az75h3puy5za776ekf8k8g7tg757nzpgyz0e2hyu6pm24vk5e87ss2m36pjgkd3m9c6qp5k6gcp",
         "payment_hash": "9937ab1195a67e1262b86b5805e4c2a4b7b9de18de2618b946d74bf0d3e0ed25",
         "status": "complete",
         "created_at": 1737657930,
         "completed_at": 1737657933,
         "preimage": "<redacted>",
         "amount_sent_msat": 501732,
         "created_index": 1528,
         "updated_index": 1528
      }

@chrisguida
Copy link
Author

I suppose clients could extract the amount_msat from the bolt11, but that seems suboptimal.

@ShahanaFarooqui
Copy link

I am not familiar with cln_nwc but can it be related to xpay?

@chrisguida
Copy link
Author

Ah yeah, it could! I should upgrade to 24.11.1 and see if that fixes it

@chrisguida
Copy link
Author

Ok so it looks like 24.11.1 actually does fix this!

      {
         "bolt11": "lnbc5u1pne9vkppp5nnsn9pfg58wf7fullakpqe2dsn65388547fzxy4h5j6cajjh8c0qhp5pgmq5gus2lw9twjwvtq54lr9ek67zn4jxz2ksyrsjval5gjgtd4qcqzzsxqrrs0sp55klhhzd4pclf5tm7d0r4jyafl6tkvghcuktw8rgj4z5a93z3g5ts9qxpqysgqvaxu35qmhl3vhu94hkv7uzkf4fhz0whz67dxtx3wuxay25cp2gyr4p483u6z8qksexccwvj455q3vmqpanppwpwc8tsce5gcwdfnqvcq8mjh5u",
         "destination": "03b428ba4b48b524f1fa929203ddc2f0971c2077c2b89bb5b22fd83ed82ac2f7e1",
         "payment_hash": "9ce1328528a1dc9f279fff6c10654d84f5489cf4af922312b7a4b58eca573e1e",
         "status": "complete",
         "created_at": 1737667266,
         "completed_at": 1737667269,
         "preimage": "<redacted>",
         "amount_msat": 500000,
         "amount_sent_msat": 501857,
         "created_index": 1529,
         "updated_index": 1529
      }

Zeus looking great too!

Image

So the moral of the story is, don't use xpay on 24.11, and Zeus haha

@chrisguida
Copy link
Author

Ah yeah, shoulda read item 2 on the release xD

https://github.com/ElementsProject/lightning/releases/tag/v24.11.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working CLNRest
Projects
None yet
Development

No branches or pull requests

4 participants