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]: LND uses deprecated 'getinfo' Bitcoin Core API; cannot connect to node #7256

Closed
optout21 opened this issue Dec 15, 2022 · 10 comments
Closed
Labels
bug Unintended code behaviour needs triage

Comments

@optout21
Copy link

optout21 commented Dec 15, 2022

Background

I have experienced issues connecting LND to Bitcoin Core, and while debugging I found that LND invokes the long-deprecated 'getinfo' API on Bitcoin Core RPC. I am not sure that this is the reason for the disconnection, but seems so, and it seems incorrect.
The bigger-context question is how is it possible to connect LND to a remote BTC node over HTTPS.

Your environment

  • version of lnd: v0.15.4-beta
  • which operating system (uname -a on *Nix) Linux ip-10-242-51-151 5.15.0-1026-aws #30~20.04.2-Ubuntu SMP Fri Nov 25 14:53:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • version of bitcoind: recent Bitcoin Core, exact version not known
  • LND, tag v0.15.4-beta, compiled from sources, on Ubuntu, debug, https://github.com/lightningnetwork/lnd/releases/tag/v0.15.4-beta
  • A remote Bitcoin core full node, accessible through https. Since I have not found a way to directly use a remote https node, I created an nginx proxy, that takes connections on localhost:8332 and forwards them to the remote node.
  • Empty ~/.lnd/mainnet folder

Steps to reproduce

  • I run LND using:
    ~/lnd/lnd-debug --bitcoin.active --bitcoin.mainnet --bitcoin.node=bitcoind --bitcoind.rpchost=localhost --bitcoind.rpcuser=X --bitcoind.rpcpass=Y --bitcoind.zmqpubrawblock=tcp://localhost:8332 --bitcoind.zmqpubrawtx=tcp://localhost:8333
  • LND daemon starts, until wallet creation/unlock
[INF] LTND: Waiting for wallet encryption password. Use `lncli create` to create a wallet, `lncli unlock` to unlock an existing wallet, or `lncli changepassword` to change the password of an existing wallet and unlock it.
  • In first run I have created a new wallet, using ~/lnd/lncli-debug create (new wallet, default options). (In subsequent runs, used only unlock.) lnd successfully unlocked!
  • Logs from LND:
2022-12-15 12:26:48.563 [INF] LNWL: Opened wallet
2022-12-15 12:26:48.687 [INF] CHRE: Primary chain is set to: bitcoin
2022-12-15 12:26:50.144 [ERR] LTND: unable to create partial chain control: unable to determine if bitcoind is pruned: unable to detect btcd version: status code: 403, response: ""
2022-12-15 12:26:50.144 [ERR] LTND: Shutting down because error in main method: error creating wallet config: unable to create partial chain control: unable to determine if bitcoind is pruned: unable to detect btcd version: status code: 403, response: ""
2022-12-15 12:26:50.145 [INF] LTND: Shutdown complete
  • Logs from nginx (access and postdata)
127.0.0.1 - X [15/Dec/2022:12:26:49 +0000] "POST / HTTP/1.1" 200 98 "-" "Go-http-client/1.1"
127.0.0.1 - X [15/Dec/2022:12:26:49 +0000] "POST / HTTP/1.1" 200 443 "-" "Go-http-client/1.1"
127.0.0.1 - X [15/Dec/2022:12:26:50 +0000] "POST / HTTP/1.1" 403 0 "-" "Go-http-client/1.1"
[15/Dec/2022:12:26:49 +0000] "POST / HTTP/1.1" 200 98 "-" "Go-http-client/1.1" [{\x22jsonrpc\x22:\x221.0\x22,\x22method\x22:\x22getblockhash\x22,\x22params\x22:[0],\x22id\x22:1}]
[15/Dec/2022:12:26:49 +0000] "POST / HTTP/1.1" 200 443 "-" "Go-http-client/1.1" [{\x22jsonrpc\x22:\x221.0\x22,\x22method\x22:\x22getblockchaininfo\x22,\x22params\x22:[],\x22id\x22:2}]
[15/Dec/2022:12:26:50 +0000] "POST / HTTP/1.1" 403 0 "-" "Go-http-client/1.1" [{\x22jsonrpc\x22:\x221.0\x22,\x22method\x22:\x22getinfo\x22,\x22params\x22:[],\x22id\x22:3}]

As seen, first getblockhash API is invoked, then getblockchaininfo, and then getinfo. The last call returns 403 error code, because this API does not exist.
BTC RPC reference: https://developer.bitcoin.org/reference/rpc/

Expected behaviour

Connect to the node, start up.

Actual behaviour

LND shuts down.

My questions

  • Why does LDN invoke a non-exisitng getinfo BTC API?
  • Is the error from getinfo the reason of shutdown?
  • How is it possible to connect LND to a remote Bitcoin Core node, running in a different location, accessible through an HTTPS link?

Note that after a short search I have not able to find an instance of invoking 'getinfo' in the LND codebase.

Update: Extra info: C-Lightning configured with the same remote-bitcoind-over-nginx-proxy instance worked fine.

@optout21 optout21 added bug Unintended code behaviour needs triage labels Dec 15, 2022
@ekimber
Copy link

ekimber commented Dec 23, 2022

If you are searching for rpc calls etc. bear in mind that LND depends on code in the btcsuite libraries so you may find them in there.

I would recommend connecting to a remote bitcoind node over wireguard. This works just fine. It's the JSON-RPC interface that you need, not the REST interface which is very limited

@ErikEk
Copy link
Contributor

ErikEk commented Dec 26, 2022

I think it is trying to request getinfo from a btcd client.

@optout21
Copy link
Author

It's the JSON-RPC interface that you need, not the REST interface which is very limited

I did use the JSON-RPC interface, it's visible in the logs (though content is a bit mangled):

[{\x22jsonrpc\x22:\x221.0\x22,\x22method\x22:\x22getinfo\x22,\x22params\x22:[],\x22id\x22:3}]

Thanks for the hint regarding wireguard, I may give a try, though the effect is probably very similar to my nginx proxy setup.

@optout21
Copy link
Author

I think it is trying to request getinfo from a btcd client.

I have no idea, but in that case why is it trying a btcd client, when btcd is not configured at all?

@optout21
Copy link
Author

An extra tidbit info: I managed to connect C-Lightning to the same remote-bitcoind-over-nginx-proxy setup since then, and it worked fine. This just shows to me that the problem is not with the remote node setup, but with LND setup.

@yyforyongyu
Copy link
Member

version of bitcoind: recent Bitcoin Core, exact version not known

Could you check the exact bitcoind version?

Why does LDN invoke a non-exisitng getinfo BTC API?

It uses this method to decide whether it's from btcd or bitcoind, see this method from btcd for details.

Is the error from getinfo the reason of shutdown?

I think so. My guess is the returned error from bitcoind has been changed lately, causing the above check in btcd to fail. So what's your bitcoind version?

@guggero
Copy link
Collaborator

guggero commented Jan 3, 2023

Could this be an authentication issue? Because the very last part of the error shows: status code: 403, response: "" which means "forbidden".

@songsjun
Copy link

songsjun commented Mar 3, 2023

Same issue, if I connect to a remote bitcoind RPC, I met the same issue. But I can get the right response via CURL, ip, port, user/passwd all is right.
I telnet the remote ports , 8332 and 8334, all is well.

If I connect to my local bitcoind RPC, 127.0.0.1, it works. if I used the eth0 interface(etc, 192.168.0.2), it doesn't work.
I can't find any reason.

@guggero
Copy link
Collaborator

guggero commented Mar 3, 2023

The problem isn't that lnd is calling the getinfo call. That's expected to fail on newer bitcoind nodes and is therefore used for determining the version of the backend connected.
The problem is that nginx seems to re-write the error that's returned by bitcoind. It should be an RPC error: https://github.com/btcsuite/btcd/blob/master/rpcclient/infrastructure.go#L1632

So I think you need to configure nginx to not change the HTTP status code and not rewrite the error's content.

@optout21
Copy link
Author

optout21 commented Mar 3, 2023

That's a plausible explanation, thanks.
I'm no longer blocked by this, and don't have the resources to validate it.
But I accept this plausible explanation, which means there is nothing wrong with LND behavior, so closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unintended code behaviour needs triage
Projects
None yet
Development

No branches or pull requests

6 participants