Skip to content

Commit

Permalink
Merge pull request #2 from TheBlueMatt/main
Browse files Browse the repository at this point in the history
Expose Features
  • Loading branch information
arik-so authored Mar 6, 2021
2 parents b52dde8 + 0941c5e commit 246459d
Show file tree
Hide file tree
Showing 294 changed files with 34,185 additions and 18,729 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Building

A release build of the Java bindings library for Linux is available in git. Thus, the bindings should work as long as the `LD_LIBRARY_PATH` includes the top-level directory of this repository.

To build the bindings locally, the bindings require some additional work which is still making its way upstream, for now it should be built against the [rust-lightning 2020-10-java-bindings-base branch on git.bitcoin.ninja](https://git.bitcoin.ninja/?p=rust-lightning;a=shortlog;h=refs/heads/2020-10-java-bindings-base). Check that branch out locally and run the `genbindings.sh` script in it to build the required binaries. Thereafter, in this repo, run the `genbindings.sh` script with the first argument pointing to the rust-lightning directory, the second the relevant JNI CFLAGS, the third argument set to `true` or `false` to indicate whether building in debug mode, and the third set to true or false to indicate if the bindings should be built with workarounds required for Android. JNI CFLAGS on debian are likely "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/". When running a program linking against the library in debug mode, LD_PRELOAD should likely include the relevant `libclang_rt.asan-platform.so` path.
To build the bindings locally, the bindings require some additional work which is still making its way upstream, for now it should be built against the [rust-lightning 2021-03-java-bindings-base branch on git.bitcoin.ninja](https://git.bitcoin.ninja/?p=rust-lightning;a=shortlog;h=refs/heads/2021-03-java-bindings-base). Check that branch out locally and run the `genbindings.sh` script in it to build the required binaries. Thereafter, in this repo, run the `genbindings.sh` script with the first argument pointing to the rust-lightning directory, the second the relevant JNI CFLAGS, the third argument set to `true` or `false` to indicate whether building in debug mode, and the third set to true or false to indicate if the bindings should be built with workarounds required for Android. JNI CFLAGS on debian are likely "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/". When running a program linking against the library in debug mode, LD_PRELOAD should likely include the relevant `libclang_rt.asan-platform.so` path.

Status
======
Expand Down
12 changes: 6 additions & 6 deletions gen_type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
else:
arr_name = "ret"
arr_len = ret_arr_len
if arr_name == "arg":
arr_name = "ret"
if ty_info.c_ty == "int8_tArray":
(set_pfx, set_sfx) = self.consts.set_native_arr_contents(arr_name + "_arr", arr_len, ty_info)
ret_conv = ("int8_tArray " + arr_name + "_arr = " + self.consts.create_native_arr_call(arr_len, ty_info) + ";\n" + set_pfx, "")
Expand Down Expand Up @@ -70,7 +72,9 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
else:
assert not arr_len.isdigit() # fixed length arrays not implemented
assert ty_info.java_ty[len(ty_info.java_ty) - 2:] == "[]"
conv_name = "arr_conv_" + str(len(ty_info.java_hu_ty))
if arr_name == "":
arr_name = "ret"
conv_name = arr_name + "_conv_" + str(len(ty_info.java_hu_ty))
idxc = chr(ord('a') + (len(ty_info.java_hu_ty) % 26))
ty_info.subty.var_name = conv_name
#XXX: We'd really prefer to only ever set to False, avoiding lots of clone, but need smarter free logic
Expand All @@ -84,8 +88,6 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
# ChannelMonitors inside of vecs.
ty_info.subty.requires_clone = False
subty = self.map_type_with_info(ty_info.subty, False, None, is_free, holds_ref)
if arr_name == "":
arr_name = "arg"
arg_conv = ty_info.rust_obj + " " + arr_name + "_constr;\n"
arg_conv = arg_conv + arr_name + "_constr." + arr_len + " = " + self.consts.get_native_arr_len_call[0] + arr_name + self.consts.get_native_arr_len_call[1] + ";\n"
arg_conv = arg_conv + "if (" + arr_name + "_constr." + arr_len + " > 0)\n"
Expand Down Expand Up @@ -120,8 +122,6 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
if ty_info.is_ptr:
arg_conv_cleanup = "FREE(" + arr_name + "_constr." + ty_info.arr_access + ");"

if arr_name == "arg":
arr_name = "ret"
ret_conv = (ty_info.rust_obj + " " + arr_name + "_var = ", "")
if subty.ret_conv is None:
ret_conv = ("DUMMY", "DUMMY")
Expand Down Expand Up @@ -165,7 +165,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
elif subty.java_ty == "long":
from_hu_conv = ("Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray()", "/* TODO 2 " + subty.java_hu_ty + " */")
else:
from_hu_conv = ("(" + ty_info.java_ty + ")Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray()", "/* TODO 2 " + subty.java_hu_ty + " */")
from_hu_conv = ("Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray(" + ty_info.java_ty + "::new)", "/* TODO 2 " + subty.java_hu_ty + " */")

return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = arg_conv_cleanup,
Expand Down
4 changes: 2 additions & 2 deletions java_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class CommonBase {
size_t alloc_count = 0;
size_t alloc_size = 0;
for (allocation* a = allocation_ll; a != NULL; a = a->next) {
fprintf(stderr, "%s %p remains:\\n", a->struct_name, a->ptr);
fprintf(stderr, "%s %p (%lu bytes) remains:\\n", a->struct_name, a->ptr, a->alloc_len);
backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
fprintf(stderr, "\\n\\n");
alloc_count++;
Expand Down Expand Up @@ -651,7 +651,7 @@ def native_c_map_trait(self, struct_name, field_vars, field_fns):

out_c = out_c + "\tjobject obj = (*env)->NewLocalRef(env, j_calls->o);\n\tCHECK(obj != NULL);\n"
if fn_line.ret_ty_info.c_ty.endswith("Array"):
out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " arg = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
elif not fn_line.ret_ty_info.passed_as_ptr:
out_c = out_c + "\treturn (*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
else:
Expand Down
Binary file modified liblightningjni.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public ChannelManagerConstructor(LDKNetwork network, UserConfig config, byte[] c
channel_monitors = new TwoTuple[0];
channel_manager_latest_block_hash = null;
this.chain_watch = chain_watch;
// Note that current_blockchain_tip_hash will be required in a future version but is currently unused.
channel_manager = ChannelManager.constructor_new(network, fee_estimator, chain_watch, tx_broadcaster, logger, keys_interface, config, current_blockchain_tip_height);
channel_manager = ChannelManager.constructor_new(fee_estimator, chain_watch, tx_broadcaster, logger, keys_interface, config, network, current_blockchain_tip_hash, current_blockchain_tip_height);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ldk/enums/LDKNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum LDKNetwork {
LDKNetwork_Bitcoin,
LDKNetwork_Testnet,
LDKNetwork_Regtest,
LDKNetwork_Signet,
; static native void init();
static { init(); }
}
2 changes: 1 addition & 1 deletion src/main/java/org/ldk/enums/LDKSecp256k1Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public enum LDKSecp256k1Error {
LDKSecp256k1Error_InvalidSecretKey,
LDKSecp256k1Error_InvalidRecoveryId,
LDKSecp256k1Error_InvalidTweak,
LDKSecp256k1Error_TweakCheckFailed,
LDKSecp256k1Error_NotEnoughMemory,
LDKSecp256k1Error_CallbackPanicked,
; static native void init();
static { init(); }
}
Loading

0 comments on commit 246459d

Please sign in to comment.