lightningj-org/lightningj

Error: trying to initialize a wallet. org.lightningj.lnd.wrapper.CommunicationException: UNAVAILABLE

Closed this issue · 24 comments

Subject of the issue

I am using your library and I am finding some problems that can not be solved. I have disabled the firewall, in case that could be the problem. Can you help me please?

Your environment

  • version of lightningj 0.5.0-Beta
  • version and vendor of JDK 1.8
  • your operationg systems. Ubuntu 18.04.1 LTS
Estado HTTP 500 – Internal Server Error

Tipo Informe de Excepción

mensaje org.lightningj.lnd.wrapper.CommunicationException: UNAVAILABLE

descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.

excepción

javax.servlet.ServletException: org.lightningj.lnd.wrapper.CommunicationException: UNAVAILABLE
	com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
causa raíz

org.lightningj.lnd.wrapper.CommunicationException: UNAVAILABLE
	org.lightningj.lnd.wrapper.StatusExceptionWrapper.wrap(StatusExceptionWrapper.java:72)
	org.lightningj.lnd.wrapper.SynchronousWalletUnlockerAPI.genSeed(SynchronousWalletUnlockerAPI.java:110)
	org.lightningj.lnd.wrapper.SynchronousWalletUnlockerAPI.genSeed(SynchronousWalletUnlockerAPI.java:88)
	com.jorgefernandez.tft.blocklotto.service.BlockLotto.initWallet(BlockLotto.java:32)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
	com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
	com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
	com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
	com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
	com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
causa raíz

io.grpc.StatusRuntimeException: UNAVAILABLE
	io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:210)
	io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:191)
	io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:124)
	org.lightningj.lnd.proto.WalletUnlockerGrpc$WalletUnlockerBlockingStub.genSeed(WalletUnlockerGrpc.java:336)
	org.lightningj.lnd.wrapper.SynchronousWalletUnlockerAPI.genSeed(SynchronousWalletUnlockerAPI.java:106)
	org.lightningj.lnd.wrapper.SynchronousWalletUnlockerAPI.genSeed(SynchronousWalletUnlockerAPI.java:88)
	com.jorgefernandez.tft.blocklotto.service.BlockLotto.initWallet(BlockLotto.java:32)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
	com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
	com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
	com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
	com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
	com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
	com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
causa raíz

io.netty.channel.AbstractChannel$AnnotatedConnectException: Conexión rehusada: localhost/127.0.0.1:10001
	sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:323)
	io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
	io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:633)
	io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
	io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
	io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
	io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	java.lang.Thread.run(Thread.java:748)
causa raíz

java.net.ConnectException: Conexión rehusada
	sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:323)
	io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
	io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:633)
	io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
	io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
	io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
	io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	java.lang.Thread.run(Thread.java:748)
nota La traza completa de la causa de este error se encuentra en los archivos de diario del servidor.

Apache Tomcat/9.0.12

Hi kovutech

My best guess is that it is some communication problems between the tomcat server and LND. Can you tell me a bit more about the environment? Is it two docker images or just a plain ubuntu? If it would be an SSL issue I think there is another error. Are you able to connect to LND using lncli from the same machine?

Can we double check that your LND GRPC is listening on port 10001?

This is the command that I use to create the first node.
lnd --rpclisten=localhost:10001 --listen=localhost:10011 --restlisten=localhost:8001 --no-macaroons

And this is my lnd.conf file.

[Application Options]
datadir=data
logdir=log
debuglevel=info
debughtlc=true

[Bitcoin]
bitcoin.simnet=1
bitcoin.active=1
bitcoin.node=btcd

[btcd]
btcd.rpcuser=kek
btcd.rpcpass=kek

[Application Options]
; Path to TLS certificate for lnd's RPC and REST services.
 tlscertpath=~/.lnd/tls.cert

; Path to TLS private key for lnd's RPC and REST services.
 tlskeypath=~/.lnd/tls.key

Really strange, are you sure you are not running SELinux or something that might block the communication between processes? You can check with 'getenforce'.

If not I have to create a similar setup and try myself later this evening.

When I run 'getenforce' I get 'Disabled'. I don't know if I have other program that is blocking the communication between process.

I will try with a similar setup and come back to you tomorrow morning.

Do you have any basic example to init a wallet in Async and Sync mode to test if the enviromment is ok?

Hmm, I'm started thinking that maybe GRPC isn't started until wallet is unlocked/initialized.

Could you try just once to initialize using lncli and make sure the wallet is unlocket and synced and then create an invoice or something using the provided examples. If that works we can skip looking at communication problems and into how to initialize using the API.

Hi!, I can initialize the wallet running lncli.
When run this example code https://github.com/lightningj-org/lightningj/blob/master/src/examples/lnd/AsynchronousLndAPIExample.java , I get this information in output window.

Sending WalletBalance request...
Received WalletBalance response: 
{
    "total_balance": 0,
    "confirmed_balance": 0,
    "unconfirmed_balance": 0
}
WalletBalance call closed.
Subscribing to invoices call...
Press Ctrl-C to stop listening for invoices

The error occurs when I try to initialize a second node. I manage the ports to create lnd nodes always with new free port but the conecction is refused.

In this line

List<String> words = walletUnlockerAPI.genSeed(null, null).getCipherSeedMnemonic();

The error

19-Oct-2018 00:28:22.751 GRAVE [http-nio-8080-exec-4] com.sun.jersey.spi.container.ContainerResponse.mapMappableContainerException The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
 org.lightningj.lnd.wrapper.CommunicationException: UNAVAILABLE
	at org.lightningj.lnd.wrapper.StatusExceptionWrapper.wrap(StatusExceptionWrapper.java:72)
	at org.lightningj.lnd.wrapper.SynchronousWalletUnlockerAPI.genSeed(SynchronousWalletUnlockerAPI.java:110)
	at org.lightningj.lnd.wrapper.SynchronousWalletUnlockerAPI.genSeed(SynchronousWalletUnlockerAPI.java:88)

I have looked into the LND Source code and how lncli performs those calls. It seems that they perform calls using domain socket as a backup if the GRPC tcp port isn't ready for connection. I guess the WalletAPI have to have similar support in order to get this working.

This seems like a bit of effort to get working so I will not be able to provide a fix for this in at least a couple of days I'm afraid.

Hi again, I have looked a bit further and tested with following setup:

lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=neutrino --neutrino.connect=faucet.lightning.community --rpclisten=localhost:10001 --listen=localhost:10011 -- --no-macaroons

Then I had the same issue as you when connecting to "localhost" (due to attempt to connect to IPV6 interface on localhost) but when connecting to "127.0.0.1" :

SynchronousWalletUnlockerAPI syncWalletLndAPI = new SynchronousWalletUnlockerAPI("127.0.0.1",10001,
new File(System.getProperty("user.home") + "/Library/Application Support/Lnd/tls.cert"),
null);

Then i get further and when running:
syncWalletLndAPI.initWallet(null,null,null,null)
I get io.grpc.StatusRuntimeException: UNKNOWN: password must have at least 8 characters
So it seems I get response from server. (I haven't yet figure out what parameter to specify, if you know please share valid parameters).

Hi herrvendil,

First you need to get 24 words to create the necessary seed for the creation of the wallet.

List<String> words = null;
        try {
            words = walletUnlockerAPI.genSeed(null, null).getCipherSeedMnemonic();
        } catch (StatusException e) {
            e.printStackTrace();
        } catch (ValidationException e) {
            e.printStackTrace();
        }

When you get the 24 words you can call initWallet

        try {
            walletUnlockerAPI.initWallet(wallet.getPass().getBytes(), words, null, null);
        } catch (StatusException e) {
            e.printStackTrace();
        } catch (ValidationException e) {
            e.printStackTrace();
        }

wallet.getPass() has "passpass" for example.

Now when I run this code:

    List<String> words = syncWalletLndAPI.genSeed(null,null).getCipherSeedMnemonic();
    System.out.println(syncWalletLndAPI.initWallet("foobar123".getBytes(),words,null,null));

The call is successful and LND starts up and begin to synchronize. I don't need any unix socket, existing API works.

So maybe your LND node is binding itself to the wrong interface.

The error happens when I try to create a second node.
The first node runs without any problems.

I have now tried to start two lnd i parallell:
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=neutrino --neutrino.connect=faucet.lightning.community --rpclisten=localhost:10001 --listen=localhost:10011 -- --no-macaroons
and
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=neutrino --neutrino.connect=faucet.lightning.community --rpclisten=localhost:20001 --listen=localhost:20011 --no-macaroons --datadir=node2 --restlisten localhost:20012

And both are waiting to get unlocked, I then run:

    // To create a synchronousAPI there are three constructors available
    // One simple with host,port and certificate to trust, last file is the file path to the macaroon, use null if no macaroons are used.
    SynchronousWalletUnlockerAPI syncWalletLndAPI1 = new SynchronousWalletUnlockerAPI("127.0.0.1",10001,
            new File(System.getProperty("user.home") + "/Library/Application Support/Lnd/tls.cert"),
            null);
    SynchronousWalletUnlockerAPI syncWalletLndAPI2 = new SynchronousWalletUnlockerAPI("127.0.0.1",20001,
            new File(System.getProperty("user.home") + "/Library/Application Support/Lnd/tls.cert"),
            null);

    List<String> words = syncWalletLndAPI1.genSeed(null,null).getCipherSeedMnemonic();
    System.out.println(syncWalletLndAPI1.initWallet("foobar123".getBytes(),words,null,null));
    List<String> words2 = syncWalletLndAPI2.genSeed(null,null).getCipherSeedMnemonic();
    System.out.println(syncWalletLndAPI2.initWallet("foobar123".getBytes(),words2,null,null));

// System.out.println(syncWalletLndAPI1.unlockWallet("foobar123".getBytes(),null));
// System.out.println(syncWalletLndAPI2.unlockWallet("foobar123".getBytes(),null));

    // To close the api use the method
    syncWalletLndAPI1.close();
    syncWalletLndAPI2.close();

And both succeds to be activated so I'm afraid I cannot reproduce your problem.

Hello! I don't have any problems when I execute the code that you sent, but when I try to initialize a second wallet after initializing the first one, the error appears. I am creating an API REST to call the commands and use JSON to send and receive the parameters. I'm looking for related problems on the web, but I do not get any relevant information.

Maybe the problem is LND related? That the second node isn't started correctly due to other conflicting ports, other than the GRPC one? I had problems starting the second node when not adding the --restlisten localhost:20012 option since both started listening on the same by default.

I use always --restlisten localhost: when I configure the node.
Now I am trying to initialize wallets in asynchronous mode. The error comes when I want to generate the seed (24 words).

Errors:
The first time I call the wallet initialization

	at org.lightningj.lnd.wrapper.StatusExceptionWrapper.wrap(StatusExceptionWrapper.java:72)
	at org.lightningj.lnd.wrapper.StreamObserverWrapper.onError(StreamObserverWrapper.java:110)
	at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:385)
	at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
	at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:339)
	at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:443)
	at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63)
	at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:525)
	at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:446)
	at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:557)
	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:107)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE: Channel shutdown invoked
	at io.grpc.Status.asRuntimeException(Status.java:526)
	... 13 more

The next attempts

org.lightningj.lnd.wrapper.CommunicationException: UNAVAILABLE
	at org.lightningj.lnd.wrapper.StatusExceptionWrapper.wrap(StatusExceptionWrapper.java:72)
	at org.lightningj.lnd.wrapper.StreamObserverWrapper.onError(StreamObserverWrapper.java:110)
	at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:385)
	at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
	at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:339)
	at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:443)
	at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63)
	at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:525)
	at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:446)
	at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:557)
	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:107)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE
	at io.grpc.Status.asRuntimeException(Status.java:526)
	... 13 more
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Conexión rehusada: /127.0.0.1:10002
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:323)
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:633)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	... 1 more
Caused by: java.net.ConnectException: Conexión rehusada
	... 11 more

Does the error also occur during synchronous mode, or does it work then? I haven't tested asynchronous during wallet operations.

Syncronous: It works on the first try, but fails on the next ones.
Asyncronous: If fails generating the seed in the first attempt, reused connection in next ones.

Did you find any resolution to this issue?

Closing this issue.