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

Core Lightning: CLNRest backend #2228

Merged
merged 17 commits into from
Jul 9, 2024

Conversation

niteshbalusu11
Copy link
Contributor

Description

Relates to issue: #1637

Depracates c-lightning-rest and adds a new backend using core-lightning team maintained CLN Rest.
Important Note: Minimum core-lightning version to use this is v24.02 due to breaking changes from cln team.
This PR should cover all features which the old backend was covering.
I have not tested this on iOS coz I wasn't able to get xcode to build zeus.

This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Configuration change
  • Locales update
  • Quality assurance
  • Other

Checklist

  • I’ve run yarn run tsc and made sure my code compiles correctly
  • I’ve run yarn run lint and made sure my code didn’t contain any problematic patterns
  • I’ve run yarn run prettier and made sure my code is formatted correctly
  • I’ve run yarn run test and made sure all of the tests pass

Testing

If you modified or added a utility file, did you add new unit tests?

  • No, I’m a fool
  • Yes
  • N/A

I have tested this PR on the following platforms (please specify OS version and phone model/VM):

  • Android
  • iOS

@kaloudis kaloudis changed the title New-cln-rest-api Core Lightning: CLNRest backend Jun 9, 2024
@kaloudis kaloudis added Core Lightning Issues specific to Core Lightning c-lightning-REST CLNRest labels Jun 9, 2024
@kaloudis kaloudis added this to the v0.9.0 milestone Jun 9, 2024
stores/SettingsStore.ts Outdated Show resolved Hide resolved
@niteshbalusu11
Copy link
Contributor Author

Fixed and rebased

Copy link

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

Ok looks like that you arrive before me, I left some comments because in this way I can build on top of you

backends/CLNRest.ts Outdated Show resolved Hide resolved
backends/CLNRest.ts Outdated Show resolved Hide resolved
backends/CLNRest.ts Outdated Show resolved Hide resolved
@@ -1347,6 +1357,75 @@ export default class NodeConfiguration extends React.Component<
)}
</>
)}
{implementation === 'cln-rest' && (

Choose a reason for hiding this comment

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

why not use the same of c-lightning-REST? at the end of the day the UI is the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because cln-rest uses runes and the old one uses a macaroon. We can just delete the old when Zeus wants to depracate it completely. Right now both are supported.

Choose a reason for hiding this comment

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

Because cln-rest uses runes and the old one uses a macaroon.

are the same things a the concept level, you can just replace the string with implementation === 'cln-rest' ? "rune" : "macaroon" no?

Copy link
Contributor Author

@niteshbalusu11 niteshbalusu11 Jun 10, 2024

Choose a reason for hiding this comment

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

I just find them cleaner to be separate because old c-lightning-rest is sharing with LND anyway. Whatever Evan wants.

@sha-265
Copy link
Contributor

sha-265 commented Jun 10, 2024

you are too fast 😵‍💫

anyway, this is probably a good opportunity to fix getTransactions() that uses wrong api method (listfunds which return the wallet utxos, and not transactions history), as i did in my version:
https://github.com/sha-265/zeus/blob/c40d9c1ba20c504f5e3355cf33d9e8b4409fca09/backends/CLNRest.ts#L33

@niteshbalusu11
Copy link
Contributor Author

anyway, this is probably a good opportunity to fix getTransactions() that uses wrong api method (listfunds which return the wallet utxos, and not transactions history), as i did in my version: https://github.com/sha-265/zeus/blob/c40d9c1ba20c504f5e3355cf33d9e8b4409fca09/backends/CLNRest.ts#L33

Thank you for catching that. I think your code is missing tag == channel_open and tag == channel_close which idk if cln also records has deposit and withdrawal. also it records chain_fee separately.
Have to look into that.

@newtonick
Copy link
Contributor

newtonick commented Jun 11, 2024

I get this error when trying send onchain in signet via CLNRest (via this PR)

"unknown parameter: address, this may be caused by
a failure to autodetect key=value-style parameters.
Please try using the -k flag and explicit key=value
pairs of parameters."

image
image
image

I checked to make sure I had not issue with withdraw on my node via CLI.

image

backends/CLNRest.ts Outdated Show resolved Hide resolved
backends/CLNRest.ts Outdated Show resolved Hide resolved
@sha-265
Copy link
Contributor

sha-265 commented Jun 11, 2024

anyway, this is probably a good opportunity to fix getTransactions() that uses wrong api method (listfunds which return the wallet utxos, and not transactions history), as i did in my version: https://github.com/sha-265/zeus/blob/c40d9c1ba20c504f5e3355cf33d9e8b4409fca09/backends/CLNRest.ts#L33

Thank you for catching that. I think your code is missing tag == channel_open and tag == channel_close which idk if cln also records has deposit and withdrawal. also it records chain_fee separately. Have to look into that.

i don't see this tags (at least under wallet account), but there is a journal_entry tag that should be filtered out maybe.

@niteshbalusu11
Copy link
Contributor Author

i don't see this tags (at least under wallet account), but there is a journal_entry tag that should be filtered out maybe.

Yeah, that's the problem, it doesn't put it under wallet. Have to figure out where it does. In the examples in the docs, it puts it under some long string account. Have to see what that is.

@sha-265
Copy link
Contributor

sha-265 commented Jun 11, 2024

i don't see this tags (at least under wallet account), but there is a journal_entry tag that should be filtered out maybe.

Yeah, that's the problem, it doesn't put it under wallet. Have to figure out where it does. In the examples in the docs, it puts it under some long string account. Have to see what that is.

it's channel id according to the cln documentation:

account (string): The account name. If the account is a channel, the channel_id.

i'm not sure these events are relevant if you want only the on-chain transactions.

@niteshbalusu11
Copy link
Contributor Author

but i think in terms of performance query without account parameter, would be much more heavy as it returns all the non on-chain events

I agree. CLNs APIs don't seem to allow pagination as well which is annoying. Maybe someone can test with their mainnet node which is old and see how it performs.
They should ideally have a simple RPC for chain txs but I'm not gonna rant about their RPC build choices here.

@sha-265
Copy link
Contributor

sha-265 commented Jun 11, 2024

but i think in terms of performance query without account parameter, would be much more heavy as it returns all the non on-chain events

I agree. CLNs APIs don't seem to allow pagination as well which is annoying. Maybe someone can test with their mainnet node which is old and see how it performs. They should ideally have a simple RPC for chain txs but I'm not gonna rant about their RPC build choices here.

yep, not the best api i've come across 🤷‍♂️

another mitigation could be somehow to make only one query for getTransactions() and getInvoices() instead of two separated calls for the same data. creating getEvents() method and use it for all of them, or something

EDIT: and getPayments(), so 3 different calls

i would do that myself, but it won't get me the bounty probably haha 🥲

@newtonick
Copy link
Contributor

From what testing I have been able to do, I believe activity view needs some love. It might be helpful to start with what transactions should be included in this view. I'm not sure if this is documented somewhere (like a previous zeus GitHub issue/PR/etc). What I expect to be listed in the activity view is:

  • lightning Invoices (paid, unpaid, expired)
  • lightning payment (successful payments only) w/ fees
  • onchain withdraw/payment (in mempool and onchain) w/ fees
  • onchain receives (in mempool and onchain)

I don't expect to see channel open / close transactions but I also don't mind if they are in this view if it's communicated that they are part of an open/close channel transaction.

Right now I see multiple rows in the activity view for a single on chain payments. I have a hard time dissecting what information bkpr-listaccountevents is returning. Sorry this comment is not more helpful. I just wanted to provide feedback on what I have tested so far with this PR. Thank you for this work.

@niteshbalusu11
Copy link
Contributor Author

niteshbalusu11 commented Jun 13, 2024

What I expect to be listed in the activity view is:

lightning Invoices (paid, unpaid, expired)
lightning payment (successful payments only) >w/ fees
onchain withdraw/payment (in mempool and >onchain) w/ fees
onchain receives (in mempool and onchain)

This sounds good to me except expired and unpaid invoices, that could be a bit too much specially expired.
I will leave it to @kaloudis once he tests and gives feedback on what he thinks.

@newtonick
Copy link
Contributor

Here is an example of 40,000 sat onchain spend (https://mutinynet.com/tx/99a918361919956cc76801b6014e233d834466dbb25b4f031825e1eb60b972e8) that shows 3 rows in the activity view for a single spend transaction. The 40,000 sat row appears first as soon as I complete the spend (while the tx is in the mempool). This shows as a credit but is actually a debit. Then once the transaction is confirmed into 1+ blocks, 2 more rows appear. A debit of the utxo I used to make the spend and then a credit of the change back to my wallet.

image

@niteshbalusu11
Copy link
Contributor Author

Here is an example of 40,000 sat onchain spend (https://mutinynet.com/tx/99a918361919956cc76801b6014e233d834466dbb25b4f031825e1eb60b972e8) that shows 3 rows in the activity view for a single spend transaction. The 40,000 sat row appears first as soon as I complete the spend (while the tx is in the mempool). This shows as a credit but is actually a debit. Then once the transaction is confirmed into 1+ blocks, 2 more rows appear. A debit of the utxo I used to make the spend and then a credit of the change back to my wallet.

image

Ok, yeah this needs to be fixed. Only the spend should show up, not the utxos spent and change received.

@sha-265
Copy link
Contributor

sha-265 commented Jun 13, 2024

I don't expect to see channel open / close transactions

i agree, and it's also solve the potential performance issue, as you can request only wallet account events, and not all the events for all the accounts in this node, as i did in my code.

@niteshbalusu11
Copy link
Contributor Author

niteshbalusu11 commented Jun 14, 2024

ok @newtonick can you test now? I think it should be fixed. Note that if a channel closes, you will see an onchain payment because you're getting your money back.

@sha-265 unfortunately i think we can't get around the performance issue without compromising accuracy of the info because CLN displays change outputs as deposits and its really difficult to figure out if its a real deposit or a change output from like channel opens without checking channel opens from events. I asked in the CLN group if there is an easy way to check if an address is ours in CLN so that we can easily filter out change, let's see.

@sha-265
Copy link
Contributor

sha-265 commented Jun 14, 2024

i don't understand how tons of irrelevant events solving this, but at least you should get the same data only once and not three different times.

@niteshbalusu11
Copy link
Contributor Author

i don't understand how tons of irrelevant events solving this, but at least you should get the same data only once and not three different times.

I don't understand what you mean? I am getting only once.

@sha-265
Copy link
Contributor

sha-265 commented Jun 14, 2024

look here:

await this.paymentsStore.getPayments();
if (BackendUtils.supportsOnchainSends())
await this.transactionsStore.getTransactions();
await this.invoicesStore.getInvoices();

i think if you are using bkpr-listaccountevents this three calls are overlapping.

@niteshbalusu11
Copy link
Contributor Author

look here:

await this.paymentsStore.getPayments();
if (BackendUtils.supportsOnchainSends())
await this.transactionsStore.getTransactions();
await this.invoicesStore.getInvoices();

i think if you are using bkpr-listaccountevents this three calls are overlapping.

Ah, that's old code. I never touched that. Will look into it.

@niteshbalusu11
Copy link
Contributor Author

@Sjors
Copy link

Sjors commented Jun 26, 2024

I finally got the clnrest plugin to work (Python environments are a pain...). Happy to test all this when there's a testflight build.

backends/CLightningREST.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@kaloudis kaloudis left a comment

Choose a reason for hiding this comment

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

tACK

All things looking good. Congrats, @niteshbalusu11 you will be receiving the bounty.

We are expecting you to help address any issues that may arise during alpha and beta testing - not expecting anything major as we've already done some extensive testing

@kaloudis kaloudis merged commit c1e948a into ZeusLN:master Jul 9, 2024
3 checks passed
@Sjors
Copy link

Sjors commented Jul 15, 2024

Just tested the https://github.com/ZeusLN/zeus/releases/tag/v0.9.0-beta1 release on iOs. It manages to connect!

I can seen my utxos on the coins screen. I can see my channels.

I can create an invoice to receive. The screen doesn't update when the invoice is paid, but afaik it didn't do that with c-lightning-rest either.

The Activity tab still crashes as it did with c-lightning-rest.

The combination of the above two things means I can't see if a payment to me succeeded.

I can pay a regular bolt11 invoice.

@niteshbalusu11
Copy link
Contributor Author

The Activity tab still crashes as it did with c-lightning-rest.

@Sjors is your node really old with a lot of data?

@Sjors
Copy link

Sjors commented Jul 15, 2024

@niteshbalusu11 the node is very old, but it does run the latest v24.05. It has 10K+ transactions, mostly keysends from podcasting 2.0 listeners.

I guess it's tripping over missing field in older transactions?

@niteshbalusu11
Copy link
Contributor Author

I guess it's tripping over missing field in older transactions?

It could also be that the response from the 10k+ txns could be very large because the RPC call right now has no way limit the records returned. Working on figuring that part out.

@niteshbalusu11
Copy link
Contributor Author

This might fix some issues.

#2290

@sha-265
Copy link
Contributor

sha-265 commented Sep 1, 2024

Important Note: Minimum core-lightning version to use this is v24.02 due to breaking changes from cln team.

I don't know how, but it's working for me with older version

@Sjors
Copy link

Sjors commented Sep 2, 2024

The screen doesn't update when the invoice is paid, but afaik it didn't do that with c-lightning-rest either.

More recently this usually does work.

The Activity tab still crashes as it did with c-lightning-rest.

This is fixed since.

@niteshbalusu11 niteshbalusu11 deleted the new-cln-rest-api branch September 2, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-lightning-REST CLNRest Core Lightning Issues specific to Core Lightning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants