fiatjaf / sparko

c-lightning RPC over HTTP with fine-grained permissions, SSE and spark-wallet support
38 stars 12 forks source link

c-lightning v0.11.0: strconv.ParseUint: parsing \"s10\": invalid syntax #18

Closed Sjors closed 2 years ago

Sjors commented 2 years ago

See: https://github.com/btcpayserver/btcpayserver/issues/3720#issuecomment-1121397212

Running c-lightning v0.11.0.1 on Ubuntu 22.04

$ lightning-cli invoicewithdescriptionhash 1000 no-hash 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
{
   "code": 500,
   "message": "error making invoice on lightningd: strconv.ParseUint: parsing \"s10\": invalid syntax",
   "data": null
}
Sjors commented 2 years ago

It's surprisingly hard to install c-lightning v0.10 (pip3 install mrkd mistune==0.8.4 helps).

But I verified the plugin does work with the older version:

{
   "bolt11": "lntb10n1p38jh0upp...hxgp3pg82d",
   "description_hash": "f0ce4a761f04c7bef42fc323cca4850f317c62421e69654fea4d605e70c339b2",
   "expires_at": 1652725884,
   "payment_hash": "33778288c87c8aeaf3aad4065cd536eda1ce306d078fbaa0aaf22c20009f5998",
   "preimage": "86455d538845e8b7b774a113429d55e99f104a1214cc1b24e00919d29dab0809"
}
fiatjaf commented 2 years ago

I can't reproduce this. I'm running v0.11.0.1-13-gf90ee0e latest master and it works for me.

fiatjaf commented 2 years ago

Yeah, tried with both the released binaries and compiling from source right now and it works in both.

Moreover, nowhere in my code there are any calls to strconv.ParseUint(). I imagine this error must be coming from zpay32, the invoice parser from the LND codebase which is not consistently versioned so maybe you got a different version than I did? But unlikely.

Can you try generating an invoice with amount set to 123456 to see if the error message changes?

Sjors commented 2 years ago

With that amount the error is parsing \"s1234560\": invalid syntax"

I cross-compiled the plugin on a macOS Intel machine. The lightning node run on Ubuntu. I'll see if I can get the compilation to work on Ubuntu instead, just need install Go...

Sjors commented 2 years ago

I tried building the plugin on Ubuntu, but I get the same result: works fine with c-lightning v0.10 and fails with v0.11.0.1 (compiled from source at the tag).

Fresh installation of Go 1.18.1 linux/amd64 on Ubuntu 22.04.

I'm not sure how to find the version of zpay32. On macOS I have a separate installation of Lnd, but not on Ubuntu, so whichever version it picked would have been only based on this repo.

Sjors commented 2 years ago

For good measure I compiled master @ https://github.com/ElementsProject/lightning/commit/f90ee0ecfd5c029955b0eac6378e52d3b8a77a88 as well. Same error.

Sjors commented 2 years ago

Even the downloaded binary throws the error: https://github.com/fiatjaf/sparko/releases/tag/invoicewithdescriptionhash-v1.2

Sjors commented 2 years ago

I tried something else, which also didn't work :-(

Inside sparko/invoicewithdescriptionhash/cmd I did:

go get -u github.com/lightningnetwork/lnd/zpay32
rm -r dist && make

I'm also not seeing anything in cat ../../go.sum | grep zpay32

fiatjaf commented 2 years ago

With that amount the error is parsing \"s1234560\": invalid syntax"

I would say that indicates something weird in the bolt11 parsing. As 1000 will show up as 10 on the encoded invoice while 123456 will show up as 123456.

But from that prefix s I think the problem could be that lightningd is using different encodings for the "chain" part of the invoice between the two versions. You're doing all this on testnet? Not mainnet or regtest?

What does it look like when you generate a normal invoice with the invoice command on lightningd v0.11.0?

Sjors commented 2 years ago

I also tried building with go build (see #19) which doesn't change the error.

I'm using Signet.

Generating a regular invoice works fine:

{
   "payment_hash": "e9c1f8a3a4325d831d62dbf83f372c4b00d42bc1edc1ac6b5d92a205dbaf205c",
   "expires_at": 1652796393,
   "bolt11": "lntbs10n1p385utfsp5mqzf6tl0g7xd...qxzp572",
   "payment_secret": "d8049d2fef478cd85b883989c4031811be226711d2b27e4549386f1ccc18ed22"
}

And with 123456:

{
   "payment_hash": "fe0c18dc6a8d638f3e424324c87ba35e9facf59a338854e3b019dcf2adbaff2c",
   "expires_at": 1652796469,
   "bolt11": "lntbs1234560p1p385ud4sp5rm...pf34czp",
   "payment_secret": "1eddc51b2dacf12afe3c971d9678693334cda5bbb966b037aaed1a7b59339b57"
}

(so that's where the prefix s and trailing 0 come in?

Sjors commented 2 years ago

zpay32 does seem to be aware of signet, but only since https://github.com/lightningnetwork/lnd/pull/5025 (v0.13.0-beta), whereas this repo seems to depend on v0.10.1-beta of LND.