lightningj-org/lightningj

Exception: Could not initialize class org.lightningj.lnd.util.JsonGenUtils

Closed this issue · 9 comments

First of all thanks for making lightningj! It seems like a great way to use the lnd api without a lot of setup, and I'd love to get it working on my system. No problems initializing the SynchronousLndAPI, but I'm hitting an exception using calling any functions on it like channelBalance or listPeers. I'd appreciate any help debugging this- thanks!

Your environment

  • lightningj 0.4.1-Beta
  • Java
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
  • OSX
  • I'm consuming the library from Clojure, but I don't think it's a Clojure issue.

Steps to reproduce

Here's my Clojure code:

(ns lntest.core
  (:import [org.lightningj.lnd.wrapper SynchronousLndAPI]
           [org.lightningj.lnd.util JsonGenUtils]
           [java.io File]))

;; works fine
(def -api (SynchronousLndAPI. "localhost" 10009
                              (File. "/tmp/lnd/tls.cert")
                              (File. "/tmp/lnd/admin.macaroon")))

;; exception here
(.channelBalance -api)

It's similar to the synchronous api example:

SynchronousLndAPI synchronousLndAPI = new SynchronousLndAPI("localhost",10001,
new File("/Library/Application Support/Lnd/tls.cert"),
new File(System.getProperty("user.home")+ "/Library/Application Support/Lnd/admin.macaroon"));
System.out.println(synchronousLndAPI.channelBalance().toJsonAsString(true));

Expected behavior

No errors

Actual behavior

Exception: Could not initialize class org.lightningj.lnd.util.JsonGenUtils

Full error:

#error {
 :cause "Could not initialize class org.lightningj.lnd.util.JsonGenUtils"
 :via
 [{:type java.lang.NoClassDefFoundError
   :message "Could not initialize class org.lightningj.lnd.util.JsonGenUtils"
   :at [org.lightningj.lnd.wrapper.Message toJson "Message.java" 75]}]
 :trace
 [[org.lightningj.lnd.wrapper.Message toJson "Message.java" 75]
  [org.lightningj.lnd.wrapper.Message toJsonAsString "Message.java" 88]
  [org.lightningj.lnd.wrapper.Message toString "Message.java" 119]
  [org.lightningj.lnd.wrapper.API processRequest "API.java" 138]
  [org.lightningj.lnd.wrapper.SynchronousLndAPI channelBalance "SynchronousLndAPI.java" 312]
  [org.lightningj.lnd.wrapper.SynchronousLndAPI channelBalance "SynchronousLndAPI.java" 292]
  [sun.reflect.NativeMethodAccessorImpl invoke0 "NativeMethodAccessorImpl.java" -2]
  [sun.reflect.NativeMethodAccessorImpl invoke "NativeMethodAccessorImpl.java" 62]
  [sun.reflect.DelegatingMethodAccessorImpl invoke "DelegatingMethodAccessorImpl.java" 43]
  [java.lang.reflect.Method invoke "Method.java" 497]
  [clojure.lang.Reflector invokeMatchingMethod "Reflector.java" 93]
  [clojure.lang.Reflector invokeNoArgInstanceMember "Reflector.java" 313]
  [lntest.core$eval4859 invokeStatic "form-init5219208140711651485.clj" 1]
  [lntest.core$eval4859 invoke "form-init5219208140711651485.clj" 1]
  [clojure.lang.Compiler eval "Compiler.java" 7062]
  [clojure.lang.Compiler eval "Compiler.java" 7025]
  [clojure.core$eval invokeStatic "core.clj" 3206]
  [clojure.core$eval invoke "core.clj" 3202]
  [clojure.main$repl$read_eval_print__8572$fn__8575 invoke "main.clj" 243]
  [clojure.main$repl$read_eval_print__8572 invoke "main.clj" 243]
  [clojure.main$repl$fn__8581 invoke "main.clj" 261]
  [clojure.main$repl invokeStatic "main.clj" 261]
  [clojure.main$repl doInvoke "main.clj" 177]
  [clojure.lang.RestFn invoke "RestFn.java" 1523]
  [clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__820 invoke "interruptible_eval.clj" 87]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.AFn applyTo "AFn.java" 144]
  [clojure.core$apply invokeStatic "core.clj" 657]
  [clojure.core$with_bindings_STAR_ invokeStatic "core.clj" 1965]
  [clojure.core$with_bindings_STAR_ doInvoke "core.clj" 1965]
  [clojure.lang.RestFn invoke "RestFn.java" 425]
  [clojure.tools.nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 85]
  [clojure.tools.nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55]
  [clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__865$fn__868 invoke "interruptible_eval.clj" 222]
  [clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__860 invoke "interruptible_eval.clj" 190]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
  [java.lang.Thread run "Thread.java" 745]]}

Hi

Thank you for your feedback. I will look into this later tonight after work and see what could be the problem and try to fix it.

Thanks! Really appreciate it. Let me know if you need any help reproducing it.

Hi again,

I have created a test project in java using gradle, se attached project (there is only two relevant ApiTest, build.gradle) and it seem to work as expected.

test_for_issue_1.zip

I use java version "1.8.0_121" and run it from Intellij. Are you sure it cannot be anything with clojure? (I have no experience with clojure unfortunately).

Thanks for your test project, that gets me a bit further. I think if I can get your test project working, I can work out the translation to Clojure.

I'm getting a different error now connecting to my lnd service running in a container. I'm using the correct admin.macaroon and tls.cert, and the service is running with the RPC port published (10009):

$ docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
65890c47d795        btcd                         "./start-btcd.sh"        6 minutes ago       Up 6 minutes        8333-8334/tcp, 18333-18334/tcp, 18555-18556/tcp, 28901-28902/tcp   btcd
3bbbaa61380e        lnd                          "./start-lnd.sh"         6 minutes ago       Up 6 minutes        0.0.0.0:9735->9735/tcp, 0.0.0.0:10009->10009/tcp                   alice

However, it seems the server keeps closing the request from your test client.

$ ./gradlew run
:compileJava
:processResources UP-TO-DATE
:classes
:run
Exception in thread "main" org.lightningj.lnd.wrapper.ServerSideException: UNKNOWN
        at org.lightningj.lnd.wrapper.StatusExceptionWrapper.wrap(StatusExceptionWrapper.java:74)
        at org.lightningj.lnd.wrapper.SynchronousLndAPI.channelBalance(SynchronousLndAPI.java:314)
        at org.lightningj.lnd.wrapper.SynchronousLndAPI.channelBalance(SynchronousLndAPI.java:292)
        at test.ApiTest.main(ApiTest.java:17)
Caused by: io.grpc.StatusRuntimeException: UNKNOWN
        at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:210)
        at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:191)
        at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:124)
        at org.lightningj.lnd.proto.LightningGrpc$LightningBlockingStub.channelBalance(LightningGrpc.java:1975)
        at org.lightningj.lnd.wrapper.SynchronousLndAPI.channelBalance(SynchronousLndAPI.java:310)
        ... 2 more
Caused by: java.nio.channels.ClosedChannelException
        at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source)
:run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.381 secs

Is there any other configuration I must do in order to connect to a lnd instance from my client?

Here's the source btw, I made a few tweaks:

package test;

import org.lightningj.lnd.wrapper.SynchronousLndAPI;

import java.io.File;

/**
 * Created by philip on 2018-04-25.
 */
public class ApiTest {

    public static void main(String[] args) throws Exception{
        SynchronousLndAPI synchronousLndAPI = new SynchronousLndAPI("localhost",10009,
                new File("/tmp/lnd/tls.cert"),
                new File("/tmp/lnd/admin.macaroon"));

        System.out.println(synchronousLndAPI.channelBalance().toJsonAsString(true));

    }
}

Really strange problem. I have done some testing by using wrong tls.cert and wrong macaroon but that didn't given me the same error, but more descriptive ones.

I run my LND at a separate server with portforward over ssh and it works every time.

Can you try to use lncli and check if it is possible that way to see the channelbalance? Maybe it is something with docker.

Also could it be something with the local firewall? I'm just guessing now. I have tried to block the traffic and I get another more descriptive error message for that test also. Would be interesting to hear if you get lncli working but not the API. Then there is something strange with the underlying Netty or GRPC libraries.

I ended up trying the setup without using containers and got it working. So the problem definitely isn't with lightningj.

One tip for anyone trying this from Clojure, is I had to manually include the 'javax.json-api' library [javax.json/javax.json-api "1.1.2"], whereas the java test project did not have to. Not sure why that is.

Thanks for your patience helping me out!

Glad you got it working! I would be interesting to see the end result of your project once it is finished and public.