stakwork / sphinx-relay

Node.js wrapper for communication between sphinx client and lightning node.
MIT License
248 stars 71 forks source link

Local Connection Issues #154

Open tehelsper opened 3 years ago

tehelsper commented 3 years ago

Can we get some guidance on how to connect locally? I've been working on adding to myNode, but connections repeatedly fail even though the port is open and sphinx-relay is connecting to lnd according to the log. Also, I get responses from http://:53001.

I'm not concerned about public access now. Just local network.

I randomly had a single set of config work one time. When changing back to that config and rebooting, the connection failed and now won't reconnect. What looks incorrect with this config?

"production": {
      "senza_url": "https://staging.senza.us/api/v2/",
      "macaroon_location": "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
      "tls_location": "/home/bitcoin/.lnd/tls.cert",
      "lnd_log_location": "/home/bitcoin/.lnd/logs/bitcoin/mainnet/lnd.log",
      "lncli_location": "/home/bitcoin/go/bin",
      "node_ip": "192.168.86.100",
      "lnd_ip": "192.168.86.100",
      "node_http_protocol": "http",
      "node_http_port": "53001",
      "lnd_port": "10009",
      "hub_api_url": "https://hub.sphinx.chat/api/v1",
      "hub_url": "https://hub.sphinx.chat/ping",
      "hub_invite_url": "https://hub.sphinx.chat/invites",
      "hub_check_invite_url": "https://hub.sphinx.chat/check_invite",
      "media_host": "memes.sphinx.chat",
      "tribes_host": "tribes.sphinx.chat",
      "public_url": "192.168.86.100:53001",
      "connection_string_path": "connection_string.txt",
      "ssl": {
        "enabled": false,
        "save": true,
        "port": "80"
      }
    }

Also, after the fist successful connection, I no longer seem to get the QR code display although I get the connection string.

tehelsper commented 3 years ago

Actually, I think this is definitely related to multiple connection attempts between Sphinx and Relay using the same device. I was able to replicate on a new device on the first try using localhost for node_ip and lnd_ip and a valid public_url (local IP) with port.

However, if I remove the account in Sphinx and try to add a new connection to the same device with a new connection_string, it always fails. The working connection does remain the the Keychain. Is it possible the clear that so I could delete connections and easily remake them for testing?

pitoi commented 3 years ago

Gonzalo may be able to help more, but the QR code displayed by relay is a one time use code to connect a fresh lightning/relay node to the app. Once you have the app connected, go to the main menu > Profile. Then scroll to 'export keys' and save that string. Paste that into the welcome screen on any other device and all devices will sync to that node. Hopefully that helps. We should remove the QR code once the node is in use.

tehelsper commented 3 years ago

That seems confusing from a user perspective. I would expect to be able to copy that connection string to any device and have it connect to the relay. If I have problems how do I reset everything to get back to the initial state?

Especially since a new connection string is generated on each restart of the service. I would expect them to continue working as long as they keep getting generated.

tehelsper commented 3 years ago

Also, what happens if the IP address of the device changes? That sometimes happens and would require generating a new connection_string and re-pair, correct? How does that process work?

gonzaloaune commented 3 years ago

@tehelsper the connection string is a one off "signup" method, the connection string is a base64 encoded string with the original address + port + one time password. We can't reuse that string otherwise if someone has that same code, they will be able to connect to your node.

Once the code is sent to your Relay, you get a secret key that the app will use from now on to connect to your Relay.

What happens if the IP changes? Same that happens if you have a server on the cloud via the IP only and the IP changes, you would need to remap the DNS config, so I would advise that instead of IP's, if you can use a DNS name or a Tor configuration since those will always remain pointing to your machine.

Answering your original questions:

What I would change from this file is:

"production": {
      "senza_url": "https://staging.senza.us/api/v2/",
      "macaroon_location": "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
      "tls_location": "/home/bitcoin/.lnd/tls.cert",
      "lnd_log_location": "/home/bitcoin/.lnd/logs/bitcoin/mainnet/lnd.log",
      "lncli_location": "/home/bitcoin/go/bin",
      "node_ip": "192.168.86.100",
      "lnd_ip": "192.168.86.100",
      "node_http_protocol": "http",
      "node_http_port": "53001",
      "lnd_port": "10009",
      "hub_api_url": "https://hub.sphinx.chat/api/v1",
      "hub_url": "https://hub.sphinx.chat/ping",
      "hub_invite_url": "https://hub.sphinx.chat/invites",
      "hub_check_invite_url": "https://hub.sphinx.chat/check_invite",
      "media_host": "memes.sphinx.chat",
      "tribes_host": "tribes.sphinx.chat",
      "public_url": "192.168.86.100:53001",
      "connection_string_path": "connection_string.txt",
      "ssl": {
        "enabled": false,
        "save": true,
        "port": "80"
      }
    }

I think that would be enough to get you started, otherwise let me know and we can review. To make a fresh install of Relay's DB, if you don't care about the data, you can remove the file in /home/bitcoin/.lnd/sphinx.db (I think that would be the location in your case) and restart relay, it will recreate the sphinx.db file and output a new QRCode.

Remember if you use a private IP, you will only be able to get access to it in your private network.

tehelsper commented 3 years ago

Thanks, I seemed to get it working just by setting the public_url properly.

Perfect, make sure to tell your router to assign a fixed IP address to your Relay server

Why require this? I REALLY don't want to force this on all myNode users. I would bet the vast majority use DHCP - they will set it up and get frustrated when their IP changes.

I think a model like lndconnect where the necessary data is encoded into a connection string would be better. Even if it required a password or something that was randomly generated to verify the connection, at least a user doesn't get stuck if they move, change networks, have power outages, etc...

godSaysHODL commented 3 years ago

Gonzalo may be able to help more, but the QR code displayed by relay is a one time use code to connect a fresh lightning/relay node to the app. Once you have the app connected, go to the main menu > Profile. Then scroll to 'export keys' and save that string. Paste that into the welcome screen on any other device and all devices will sync to that node. Hopefully that helps. We should remove the QR code once the node is in use.

whelp this stinks. I was having problems in the app after connecting, deleted and tried to re-pair and now it won't work at all... So because it's a one time sign up i'm screwed?

gonzaloaune commented 3 years ago

@godSaysHODL do you have a dedicated node with us or do you have your own? If you have your own, do you use Umbrel or myNode or custom?

godSaysHODL commented 3 years ago

@godSaysHODL do you have a dedicated node with us or do you have your own? If you have your own, do you use Umbrel or myNode or custom?

I use myNode

tehelsper commented 3 years ago

Yeah, I'm in the same state. I was testing upgrading to the latest relay and things are really screwed up now. How do I reset and start over? I tried removing the DB but I get the same connection string and don't see QR codes anymore.

I also have been checking the new UI I found at /static/, which seems nice, but doesn't work. I have an open channel but none of the boxes are checked, the hinted commands use placeholder values, no connection string is shown, and no QR code is displayed.

If I check the logs or connection_string.txt file, I get the same string over and over, but nothing will connect anymore.

Edit: Nevermind, after deleting the db and connection_string.txt file and restarting, I was able to reconnect. I still don't understand though - the connection string stayed the same, but re-importing the same value eventually worked.

Edit 2: Turns out I was also on an old MacOS app from like 3 months ago. UI makes much more sense now. Is tor the recommended way to connect now? Run a hidden service and use that as the public url? That would solve the local IP / DNS issues. Do all clients support tor?

gonzaloaune commented 3 years ago

@godSaysHODL you need to delete the sphinx.db file as @tehelsper did and restart Relay. We did yesterday some upgrades to our Android app which should solve the problems with signup so check if you can run the latest and let me know how it goes.

@tehelsper great you got it working! Tor is another way of connecting but not necessary. All clients support Tor although the iOS and Mac have a better implementation. If you use Android you need to have Orbot installed.

godSaysHODL commented 3 years ago

Where is the spinx dB in myNode, I'm not too familiar with searching through terminal

tehelsper commented 3 years ago

@godSaysHODL There will be a button to reset the data in the next myNode release.

@gonzaloaune Also, I know I've said this before, but I wish config settings for network were still separate from the one-time signup. Now that some people are using public_url=, I would like to give people the option to use tor, but now they are stuck using Sphinx only on their local network unless they reset their entire database.

gonzaloaune commented 3 years ago

@Evanfeenstra what do you think about having config settings for network separate as @tehelsper mentions?

RhinoAK commented 3 years ago

Gonzalo may be able to help more, but the QR code displayed by relay is a one time use code to connect a fresh lightning/relay node to the app. Once you have the app connected, go to the main menu > Profile. Then scroll to 'export keys' and save that string. Paste that into the welcome screen on any other device and all devices will sync to that node. Hopefully that helps. We should remove the QR code once the node is in use.

Is that sync to the Relay or sync to the device(mobile or desktop) client?