Skip to content

Commit d941cc4

Browse files
authored
Merge pull request #86 from TheBlueMatt/main
Update to 0.0.105.0
2 parents e4e7f2f + f7e1608 commit d941cc4

File tree

422 files changed

+149133
-83346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+149133
-83346
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
cd ..
3939
git clone https://github.com/lightningdevkit/ldk-c-bindings
4040
cd ldk-c-bindings
41-
git checkout 0.0.104
41+
git checkout 0.0.105
4242
- name: Rebuild C bindings without STD
4343
run: |
4444
cd ldk-c-bindings
@@ -122,7 +122,7 @@ jobs:
122122
cd ..
123123
git clone https://github.com/lightningdevkit/ldk-c-bindings
124124
cd ldk-c-bindings
125-
git checkout 0.0.104
125+
git checkout 0.0.105
126126
- name: Rebuild C bindings, and check the sample app builds + links
127127
run: |
128128
cd ldk-c-bindings
@@ -172,7 +172,7 @@ jobs:
172172
cd ..
173173
git clone https://github.com/lightningdevkit/ldk-c-bindings
174174
cd ldk-c-bindings
175-
git checkout 0.0.104
175+
git checkout 0.0.105
176176
- name: Rebuild C bindings, and check the sample app builds + links
177177
run: |
178178
cd ldk-c-bindings
@@ -275,7 +275,7 @@ jobs:
275275
cd ..
276276
git clone https://github.com/lightningdevkit/ldk-c-bindings
277277
cd ldk-c-bindings
278-
git checkout 0.0.104
278+
git checkout 0.0.105
279279
- name: Checkout Android AAR binaries and artifacts
280280
run: |
281281
# Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
@@ -330,14 +330,14 @@ jobs:
330330
run: rustup target install aarch64-apple-darwin
331331
- name: Fetch upstream LLVM/clang snapshot
332332
run: |
333-
wget -O clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz
334-
if [ "$(shasum -a 256 clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "d051234eca1db1f5e4bc08c64937c879c7098900f7a0370f3ceb7544816a8b09" ]; then
333+
wget -O clang+llvm-13.0.1-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/clang+llvm-13.0.1-x86_64-apple-darwin.tar.xz
334+
if [ "$(shasum -a 256 clang+llvm-13.0.1-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "dec02d17698514d0fc7ace8869c38937851c542b02adf102c4e898f027145a4d" ]; then
335335
echo "Bad hash"
336336
exit 1
337337
fi
338338
- name: Unpack upstream LLVM+clang and use it by default
339339
run: |
340-
tar xvvf clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz
340+
tar xvvf clang+llvm-13.0.1-x86_64-apple-darwin.tar.xz
341341
- name: Checkout source code
342342
uses: actions/checkout@v2
343343
with:
@@ -355,11 +355,11 @@ jobs:
355355
cd ..
356356
git clone https://github.com/lightningdevkit/ldk-c-bindings
357357
cd ldk-c-bindings
358-
git checkout 0.0.104
358+
git checkout 0.0.105
359359
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
360360
run: |
361361
cd ldk-c-bindings
362-
export PATH=`pwd`/clang+llvm-13.0.0-x86_64-apple-darwin/bin:$PATH
362+
export PATH=`pwd`/clang+llvm-13.0.1-x86_64-apple-darwin/bin:$PATH
363363
CC=clang ./genbindings.sh ../rust-lightning true
364364
cd ..
365365
- name: Fetch OpenJDK 16
@@ -389,7 +389,7 @@ jobs:
389389
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
390390
export JAVA_HOME=`pwd`/jdk-16.0.1.jdk/Contents/Home
391391
export PATH=$JAVA_HOME/bin:$PATH
392-
export PATH=`pwd`/clang+llvm-13.0.0-x86_64-apple-darwin/bin:$PATH
392+
export PATH=`pwd`/clang+llvm-13.0.1-x86_64-apple-darwin/bin:$PATH
393393
./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
394394
if [ "${{ matrix.platform }}" = "macos-11" ]; then
395395
export CC="clang --target=aarch64-apple-darwin"

gen_type_mapping.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
291291
else:
292292
from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".clone_ptr()", "")
293293
elif ty_info.passed_as_ptr:
294-
opaque_arg_conv = opaque_arg_conv + "\n// Warning: we need a move here but no clone is available for " + ty_info.rust_obj
294+
opaque_arg_conv = opaque_arg_conv + "\n// WARNING: we need a move here but no clone is available for " + ty_info.rust_obj
295295
# TODO: Once we support features cloning (which just isn't in C yet), we can make this a compile error instead!
296296
from_hu_conv = (from_hu_conv[0], from_hu_conv[1] + ";\n" +
297297
"// Due to rust's strict-ownership memory model, in some cases we need to \"move\"\n" +
@@ -311,7 +311,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
311311
if not holds_ref and ty_info.is_ptr and (ty_info.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns: # is_ptr, not holds_ref implies passing a pointed-to value to java, which needs copied
312312
opaque_ret_conv_suf += indent + ty_info.var_name + "_var = " + ty_info.rust_obj.replace("LDK", "") + "_clone(" + ty_info.var_name + ");\n"
313313
elif not holds_ref and ty_info.is_ptr:
314-
opaque_ret_conv_suf += indent + "// Warning: we may need a move here but no clone is available for " + ty_info.rust_obj + "\n"
314+
opaque_ret_conv_suf += indent + "// WARNING: we may need a move here but no clone is available for " + ty_info.rust_obj + "\n"
315315

316316
opaque_ret_conv_suf += indent + "CHECK((((uintptr_t)" + ty_info.var_name + "_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.\n"
317317
opaque_ret_conv_suf += indent + "CHECK((((uintptr_t)&" + ty_info.var_name + "_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.\n"
@@ -367,7 +367,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
367367
if (ty_info.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns:
368368
ret_conv = (ret_conv[0] + ty_info.rust_obj.replace("LDK", "") + "_clone(&", ");")
369369
else:
370-
ret_conv = (ret_conv[0], ";\n// Warning: We likely need to clone here, but no clone is available, so we just do it for Java instances")
370+
ret_conv = (ret_conv[0], ";\n// WARNING: We likely need to clone here, but no clone is available, so we just do it for Java instances")
371371
ret_conv = (ret_conv[0], ret_conv[1] + "" + self.consts.trait_struct_inc_refcnt(ty_info).replace(ty_info.var_name + "_conv", "(*" + ty_info.var_name + "_ret)"))
372372
if not is_free:
373373
needs_full_clone = not is_free and (not ty_info.is_ptr and not holds_ref or ty_info.requires_clone == True) and ty_info.requires_clone != False
@@ -384,7 +384,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
384384
else:
385385
base_conv = base_conv + self.consts.trait_struct_inc_refcnt(ty_info)
386386
if needs_full_clone:
387-
base_conv = base_conv + "// Warning: we may need a move here but no clone is available for " + ty_info.rust_obj + "\n"
387+
base_conv = base_conv + "// WARNING: we may need a move here but no clone is available for " + ty_info.rust_obj + "\n"
388388
else:
389389
base_conv = base_conv + "\n" + "FREE((void*)" + ty_info.var_name + ");"
390390
if from_hu_conv is None:
@@ -410,7 +410,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
410410
from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".clone_ptr()", "")
411411
base_conv += "\n" + "FREE((void*)" + ty_info.var_name + ");"
412412
elif needs_full_clone:
413-
base_conv = base_conv + "\n// Warning: we may need a move here but no clone is available for " + ty_info.rust_obj
413+
base_conv = base_conv + "\n// WARNING: we may need a move here but no clone is available for " + ty_info.rust_obj
414414
if not needs_full_clone and ty_info.rust_obj != "LDKu8slice" and (not holds_ref or is_free):
415415
# Don't bother free'ing slices passed in - Rust doesn't auto-free the
416416
# underlying unlike Vecs, and it gives Java more freedom.
@@ -465,7 +465,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
465465
# If we're trying to return a ref, we have to clone.
466466
if (ty_info.rust_obj.replace("LDK", "") + "_clone") not in self.clone_fns:
467467
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_conv = &", "")
468-
ret_conv = (ret_conv[0], ";\n// Warning: we really need to clone here, but no clone is available for " + ty_info.rust_obj)
468+
ret_conv = (ret_conv[0], ";\n// WARNING: we really need to clone here, but no clone is available for " + ty_info.rust_obj)
469469
ret_conv_name += " | 1"
470470
else:
471471
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_conv = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_conv = ", ";")
@@ -506,7 +506,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
506506
elif ty_info.is_ptr:
507507
assert(not is_free)
508508
if ty_info.rust_obj in self.complex_enums:
509-
ret_conv = ("uintptr_t ret_" + ty_info.var_name + " = (uintptr_t)", " | 1; // Warning: We should clone here!")
509+
ret_conv = ("uintptr_t ret_" + ty_info.var_name + " = (uintptr_t)", " | 1; // WARNING: We should clone here!")
510510
from_hu_sfx = self.consts.add_ref("this", ty_info.var_name)
511511
if ty_info.rust_obj.replace("LDK", "") + "_clone" in self.clone_fns:
512512
ret_conv_pfx = ty_info.rust_obj + " *ret_" + ty_info.var_name + " = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + " ret conversion\");\n"

genbindings.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,17 @@ def java_c_types(fn_arg, ret_arr_len):
124124
rust_obj = None
125125
arr_access = None
126126
java_hu_ty = None
127-
if fn_arg.startswith("LDKThirtyTwoBytes"):
127+
if fn_arg.startswith("LDKPaymentPreimage") or fn_arg.startswith("LDKPaymentSecret") or fn_arg.startswith("LDKPaymentHash"):
128+
if fn_arg.startswith("LDKPaymentPreimage"):
129+
fn_arg = "uint8_t (*" + fn_arg[19:] + ")[32]"
130+
elif fn_arg.startswith("LDKPaymentSecret"):
131+
fn_arg = "uint8_t (*" + fn_arg[17:] + ")[32]"
132+
elif fn_arg.startswith("LDKPaymentHash"):
133+
fn_arg = "uint8_t (*" + fn_arg[15:] + ")[32]"
134+
assert var_is_arr_regex.match(fn_arg[8:])
135+
rust_obj = "LDKThirtyTwoBytes"
136+
arr_access = "data"
137+
elif fn_arg.startswith("LDKThirtyTwoBytes"):
128138
fn_arg = "uint8_t (*" + fn_arg[18:] + ")[32]"
129139
assert var_is_arr_regex.match(fn_arg[8:])
130140
rust_obj = "LDKThirtyTwoBytes"
@@ -481,7 +491,7 @@ def map_fn_with_ref_option(line, re_match, ret_arr_len, c_call_string, doc_comme
481491
takes_self_ptr = True
482492
elif arg_ty.var_name in params_nullable:
483493
argument_conversion_info = type_mapping_generator.map_type_with_info(arg_ty, False, None, is_free, True, True)
484-
if argument_conversion_info.arg_conv is not None and "Warning" in argument_conversion_info.arg_conv:
494+
if argument_conversion_info.arg_conv is not None and "WARNING" in argument_conversion_info.arg_conv:
485495
arg_ty_info = java_c_types(argument, None)
486496
print("WARNING: Remapping argument " + arg_ty_info.var_name + " of function " + method_name + " to a reference")
487497
print(" The argument appears to require a move, or not clonable, and is nullable.")
@@ -496,11 +506,11 @@ def map_fn_with_ref_option(line, re_match, ret_arr_len, c_call_string, doc_comme
496506
arg_ty_info.requires_clone = False
497507
argument_conversion_info = type_mapping_generator.map_type_with_info(arg_ty_info, False, None, is_free, True, True)
498508
assert argument_conversion_info.nullable
499-
assert argument_conversion_info.arg_conv is not None and "Warning" not in argument_conversion_info.arg_conv
509+
assert argument_conversion_info.arg_conv is not None and "WARNING" not in argument_conversion_info.arg_conv
500510
else:
501511
argument_conversion_info = type_mapping_generator.map_type_with_info(arg_ty, False, None, is_free, True, False)
502512

503-
if argument_conversion_info.arg_conv is not None and "Warning" in argument_conversion_info.arg_conv:
513+
if argument_conversion_info.arg_conv is not None and "WARNING" in argument_conversion_info.arg_conv:
504514
if argument_conversion_info.rust_obj in constructor_fns:
505515
assert not is_free
506516
for explode_arg in constructor_fns[argument_conversion_info.rust_obj].split(','):
@@ -904,7 +914,7 @@ def map_tuple(struct_name, field_lines):
904914
write_c("\tmemcpy(ret.data, orig->data, sizeof(" + ty_info.c_ty + ") * ret.datalen);\n")
905915
write_c("\treturn ret;\n}\n")
906916
elif (ty_info.rust_obj.replace("LDK", "") + "_clone") in clone_fns:
907-
ty_name = "CVec_" + ty_info.rust_obj.replace("LDK", "") + "Z";
917+
ty_name = struct_name.replace("LDK", "")
908918
clone_fns.add(ty_name + "_clone")
909919
write_c("static inline " + struct_name + " " + ty_name + "_clone(const " + struct_name + " *orig) {\n")
910920
write_c("\t" + struct_name + " ret = { .data = MALLOC(sizeof(" + ty_info.rust_obj + ") * orig->datalen, \"" + struct_name + " clone bytes\"), .datalen = orig->datalen };\n")

java_strings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty):
630630
return arr_name + " != null ? Arrays.stream(" + arr_name + ").mapToLong(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null"
631631
elif elem_ty.java_ty == "long":
632632
return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null"
633+
elif elem_ty.java_hu_ty == "UInt5":
634+
return arr_name + " != null ? InternalUtils.convUInt5Array(" + arr_name + ") : null"
633635
else:
634636
return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray(" + arr_ty.java_ty + "::new) : null"
635637

@@ -880,7 +882,8 @@ def native_c_map_trait(self, struct_name, field_vars, flattened_field_vars, fiel
880882
else:
881883
java_trait_constr = java_trait_constr + arg_info.arg_name
882884

883-
java_trait_constr = java_trait_constr + ");\n"
885+
java_trait_constr += ");\n"
886+
java_trait_constr += "\t\t\t\tReference.reachabilityFence(arg);\n"
884887
if fn_line.ret_ty_info.java_ty != "void":
885888
if fn_line.ret_ty_info.from_hu_conv is not None:
886889
java_trait_constr = java_trait_constr + "\t\t\t\t" + fn_line.ret_ty_info.java_ty + " result = " + fn_line.ret_ty_info.from_hu_conv[0] + ";\n"

src/main/java/org/ldk/batteries/ChannelManagerConstructor.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import javax.annotation.Nullable;
44
import org.ldk.enums.Network;
5+
import org.ldk.enums.Recipient;
56
import org.ldk.structs.*;
6-
import org.ldk.util.TwoTuple;
77

88
import java.io.IOException;
99
import java.util.HashSet;
@@ -104,16 +104,20 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
104104
this.logger = logger;
105105
byte[] random_data = keys_interface.get_secure_random_bytes();
106106
this.net_graph = net_graph;
107+
Result_SecretKeyNoneZ node_secret = keys_interface.get_node_secret(Recipient.LDKRecipient_Node);
108+
assert node_secret.is_ok();
107109
if (net_graph != null) {
108110
//TODO: We really need to expose the Access here to let users prevent DoS issues
109111
this.graph_msg_handler = NetGraphMsgHandler.of(net_graph, Option_AccessZ.none(), logger);
110112
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
111113
graph_msg_handler.as_RoutingMessageHandler(),
112-
keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
114+
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
115+
random_data, logger, no_custom_messages.as_CustomMessageHandler());
113116
} else {
114117
this.graph_msg_handler = null;
115118
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
116-
keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
119+
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
120+
random_data, logger, no_custom_messages.as_CustomMessageHandler());
117121
}
118122
NioPeerHandler nio_peer_handler = null;
119123
try {
@@ -146,16 +150,20 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
146150
this.logger = logger;
147151
byte[] random_data = keys_interface.get_secure_random_bytes();
148152
this.net_graph = net_graph;
153+
Result_SecretKeyNoneZ node_secret = keys_interface.get_node_secret(Recipient.LDKRecipient_Node);
154+
assert node_secret.is_ok();
149155
if (net_graph != null) {
150156
//TODO: We really need to expose the Access here to let users prevent DoS issues
151157
this.graph_msg_handler = NetGraphMsgHandler.of(net_graph, Option_AccessZ.none(), logger);
152158
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
153159
graph_msg_handler.as_RoutingMessageHandler(),
154-
keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
160+
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
161+
random_data, logger, no_custom_messages.as_CustomMessageHandler());
155162
} else {
156163
this.graph_msg_handler = null;
157164
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
158-
keys_interface.get_node_secret(), random_data, logger, no_custom_messages.as_CustomMessageHandler());
165+
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
166+
random_data, logger, no_custom_messages.as_CustomMessageHandler());
159167
}
160168
NioPeerHandler nio_peer_handler = null;
161169
try {

src/main/java/org/ldk/enums/CreationError.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ public enum CreationError {
1313
*/
1414
LDKCreationError_RouteTooLong,
1515
/**
16-
* The unix timestamp of the supplied date is <0 or can't be represented as `SystemTime`
16+
* The Unix timestamp of the supplied date is less than zero or greater than 35-bits
1717
*/
1818
LDKCreationError_TimestampOutOfBounds,
19-
/**
20-
* The supplied expiry time could cause an overflow if added to a `PositiveTimestamp`
21-
*/
22-
LDKCreationError_ExpiryTimeOutOfBounds,
2319
/**
2420
* The supplied millisatoshi amount was greater than the total bitcoin supply.
2521
*/
2622
LDKCreationError_InvalidAmount,
23+
/**
24+
* Route hints were required for this invoice and were missing. Applies to
25+
* [phantom invoices].
26+
*
27+
* [phantom invoices]: crate::utils::create_phantom_invoice
28+
*/
29+
LDKCreationError_MissingRouteHints,
2730
; static native void init();
2831
static { init(); }
2932
}

0 commit comments

Comments
 (0)