Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea
*.iml

target/
pom.xml.tag
pom.xml.releaseBackup
Expand All @@ -9,3 +12,5 @@ buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

data/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ldk"]
path = ldk
url = https://github.com/lightningdevkit/ldk-garbagecollected.git
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We currently use v0.0.98.3 of LDK since all newer versions have a failing test:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.ldk.ManualMsgHandlingPeerTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running org.ldk.HumanObjectPeerTest
Running test with flags 0
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.021 sec <<< FAILURE!
org.ldk.HumanObjectPeerTest.test_message_handler()  Time elapsed: 0.02 sec  <<< FAILURE!
java.lang.ExceptionInInitializerError
	at org.ldk.structs.Logger.<init>(Logger.java:17)
	at org.ldk.structs.Logger.new_impl(Logger.java:35)
	at org.ldk.HumanObjectPeerTestInstance$Peer.<init>(HumanObjectPeerTest.java:208)
	at org.ldk.HumanObjectPeerTestInstance$Peer.<init>(HumanObjectPeerTest.java:297)
	at org.ldk.HumanObjectPeerTestInstance.do_test_message_handler(HumanObjectPeerTest.java:610)
	at org.ldk.HumanObjectPeerTest.do_test_run(HumanObjectPeerTest.java:879)
	at org.ldk.HumanObjectPeerTest.do_test(HumanObjectPeerTest.java:884)
	at org.ldk.HumanObjectPeerTest.test_message_handler(HumanObjectPeerTest.java:911)
Caused by: java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:208)
	at java.base/java.nio.file.Files.copy(Files.java:3112)
	at org.ldk.impl.bindings.<clinit>(bindings.java:32)
	... 26 more

Running org.ldk.PeerTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

Results :

Failed tests:   org.ldk.HumanObjectPeerTest.test_message_handler()

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

Choose a reason for hiding this comment

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

This implies that a matching liblightningjni native library was not found - how are you importing the LDK dependency and what platform are you running on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LDK is declared as a Maven module ldk:

<module>ldk</module>

The ldk-sample module then decalres it as a dependency:

<dependency>
<groupId>org.ldk</groupId>
<artifactId>ldk-java</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

Tests are run either through the parent module by LD_LIBRARY_PATH=$PWD/ldk ./mvnw verify or within the ldk module / directory directly by LD_LIBRARY_PATH=$PWD mvn verify. Both lead to the same test failure mentioned in the initial comment.

The platform is a Ubuntu 20.04.2 LTS with kernel 5.4.0-77-generic (x86_64) and Java 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64

Choose a reason for hiding this comment

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

Is it possible the files in resources are being stripped by your build process? Note that the resources files are not included in the git tree, only in the release binaries (though you can fetch them directly from https://git.bitcoin.ninja/ldk-java-bins if you want).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since LDK is now on maven central, this one is no longer a real blocker. But maybe I will try to find out more anyway.

117 changes: 117 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {

private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
2 changes: 2 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# ldk-sample-java
sample implementation of LDK for Java (https://github.com/lightningdevkit/ldk-garbagecollected)

## Status / Purpose

This repository contains a sample implementation of LDK as the result of following the steps described in [Building a Node with LDK in Java](https://lightningdevkit.org/docs/build_node).
Its main purpose is providing feedback to the LDK developers.
Therefore:
* code quality / maintainability is bad
* **do NOT use this implementation in production**
1 change: 1 addition & 0 deletions ldk
Submodule ldk added at a2e02c
38 changes: 38 additions & 0 deletions ldk-sample/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ldk-parent</artifactId>
<groupId>com.getlipa</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ldk-sample</artifactId>

<dependencies>
<dependency>
<groupId>org.ldk</groupId>
<artifactId>ldk-java</artifactId>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be much more convenient to have LDK on Maven Central (https://search.maven.org/). See also: https://central.sonatype.org/publish/publish-guide/

Moreover, we could assist with publishing to Maven Central / OSSRH as we have some experience in this.

Choose a reason for hiding this comment

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

We are now published on Central under org.lightningdevkit, artifact ldk-java!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, I will certainly try out building with ldk as a Maven dependency. I guess this would also solve the issue with the failing test, since all necessary binaries are included (besides that ldk tests are no longer executed when imported as a Maven dependency), right?

Choose a reason for hiding this comment

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

Yes, it should include the release binaries for Apple amd64/A-1 and Linux amd64. I can include other platforms as needed, though windows will be a pain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess Windows is pretty much always a pain 😜
I've just tried it on my ubuntu machine and it looks good - thanks 👍

Choose a reason for hiding this comment

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

If you need it I can work on a windows build, its probably less effort than OSX was :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We currently have no need for a Windows build, thanks :)

<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.15.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>

</project>
Loading