Skip to content

Commit 9aa1eeb

Browse files
authored
Merge pull request #94 from TheBlueMatt/main
2 parents ecf12eb + b4c915c commit 9aa1eeb

File tree

446 files changed

+14331
-6597
lines changed

Some content is hidden

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

446 files changed

+14331
-6597
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
fetch-depth: 0
2828
- name: Install cbindgen
29-
run: cargo install --force cbindgen
29+
run: cargo install --version 0.20.0 cbindgen
3030
- name: Checkout Rust-Lightning and LDK-C-Bindings git
3131
run: |
3232
git config --global user.email "[email protected]"
@@ -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.105
41+
git checkout 0.0.106
4242
- name: Rebuild C bindings without STD
4343
run: |
4444
cd ldk-c-bindings
@@ -110,7 +110,7 @@ jobs:
110110
with:
111111
fetch-depth: 0
112112
- name: Install cbindgen
113-
run: cargo install --force cbindgen
113+
run: cargo install --version 0.20.0 cbindgen
114114
- name: Checkout Rust-Lightning and LDK-C-Bindings git
115115
run: |
116116
git config --global user.email "[email protected]"
@@ -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.105
125+
git checkout 0.0.106
126126
- name: Rebuild C bindings, and check the sample app builds + links
127127
run: |
128128
cd ldk-c-bindings
@@ -160,7 +160,7 @@ jobs:
160160
with:
161161
fetch-depth: 0
162162
- name: Install cbindgen
163-
run: cargo install --force cbindgen
163+
run: cargo install --version 0.20.0 cbindgen
164164
- name: Checkout Rust-Lightning and LDK-C-Bindings git
165165
run: |
166166
git config --global user.email "[email protected]"
@@ -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.105
175+
git checkout 0.0.106
176176
- name: Rebuild C bindings, and check the sample app builds + links
177177
run: |
178178
cd ldk-c-bindings
@@ -192,6 +192,7 @@ jobs:
192192
cd ../..
193193
mkdir -p src/main/resources/
194194
cp "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/liblightningjni_MacOSX-"* src/main/resources/
195+
rm src/main/resources/liblightningjni_MacOSX-*-leaktracking.nativelib
195196
- name: Build Java Release Bindings
196197
run: |
197198
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
@@ -263,7 +264,7 @@ jobs:
263264
- name: Install cbindgen
264265
run: |
265266
. $HOME/.cargo/env
266-
cargo install --force cbindgen
267+
cargo install --version 0.20.0 cbindgen
267268
- name: Checkout Rust-Lightning and LDK-C-Bindings git
268269
run: |
269270
git config --global user.email "[email protected]"
@@ -275,7 +276,7 @@ jobs:
275276
cd ..
276277
git clone https://github.com/lightningdevkit/ldk-c-bindings
277278
cd ldk-c-bindings
278-
git checkout 0.0.105
279+
git checkout 0.0.106
279280
- name: Checkout Android AAR binaries and artifacts
280281
run: |
281282
# Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
@@ -330,20 +331,20 @@ jobs:
330331
run: rustup target install aarch64-apple-darwin
331332
- name: Fetch upstream LLVM/clang snapshot
332333
run: |
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
334+
wget -O clang+llvm-14.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-apple-darwin.tar.xz
335+
if [ "$(shasum -a 256 clang+llvm-14.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "cf5af0f32d78dcf4413ef6966abbfd5b1445fe80bba57f2ff8a08f77e672b9b3" ]; then
335336
echo "Bad hash"
336337
exit 1
337338
fi
338339
- name: Unpack upstream LLVM+clang and use it by default
339340
run: |
340-
tar xvvf clang+llvm-13.0.1-x86_64-apple-darwin.tar.xz
341+
tar xvvf clang+llvm-14.0.0-x86_64-apple-darwin.tar.xz
341342
- name: Checkout source code
342343
uses: actions/checkout@v2
343344
with:
344345
fetch-depth: 0
345346
- name: Install cbindgen
346-
run: cargo install --force cbindgen
347+
run: cargo install --version 0.20.0 cbindgen
347348
- name: Checkout Rust-Lightning and LDK-C-Bindings git
348349
run: |
349350
git config --global user.email "[email protected]"
@@ -355,11 +356,11 @@ jobs:
355356
cd ..
356357
git clone https://github.com/lightningdevkit/ldk-c-bindings
357358
cd ldk-c-bindings
358-
git checkout 0.0.105
359+
git checkout 0.0.106
359360
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
360361
run: |
361362
cd ldk-c-bindings
362-
export PATH=`pwd`/clang+llvm-13.0.1-x86_64-apple-darwin/bin:$PATH
363+
export PATH=`pwd`/clang+llvm-14.0.0-x86_64-apple-darwin/bin:$PATH
363364
CC=clang ./genbindings.sh ../rust-lightning true
364365
cd ..
365366
- name: Fetch OpenJDK 16
@@ -389,7 +390,7 @@ jobs:
389390
export LDK_GARBAGECOLLECTED_GIT_OVERRIDE="$(git describe --tag HEAD)"
390391
export JAVA_HOME=`pwd`/jdk-16.0.1.jdk/Contents/Home
391392
export PATH=$JAVA_HOME/bin:$PATH
392-
export PATH=`pwd`/clang+llvm-13.0.1-x86_64-apple-darwin/bin:$PATH
393+
export PATH=`pwd`/clang+llvm-14.0.0-x86_64-apple-darwin/bin:$PATH
393394
./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false
394395
if [ "${{ matrix.platform }}" = "macos-11" ]; then
395396
export CC="clang --target=aarch64-apple-darwin"
@@ -430,6 +431,18 @@ jobs:
430431
diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-x86_64.nativelib src/main/resources/liblightningjni_MacOSX-x86_64.nativelib || echo
431432
diff "ldk-java-bins/${LDK_GARBAGECOLLECTED_GIT_OVERRIDE}/"liblightningjni_MacOSX-aarch64.nativelib src/main/resources/liblightningjni_MacOSX-aarch64.nativelib || echo
432433
fi
434+
- name: Upload CI x86_64 build for analysis
435+
if: matrix.platform == 'macos-11'
436+
uses: actions/[email protected]
437+
with:
438+
name: liblightningjni_MacOSX-x86_64.nativelib.ci-build
439+
path: src/main/resources/liblightningjni_MacOSX-x86_64.nativelib
440+
- name: Upload CI aarch64 build for analysis
441+
if: matrix.platform == 'macos-11'
442+
uses: actions/[email protected]
443+
with:
444+
name: liblightningjni_MacOSX-aarch64.nativelib.ci-build
445+
path: src/main/resources/liblightningjni_MacOSX-aarch64.nativelib
433446
- name: Run Java Tests against release bins
434447
run: |
435448
if [ "${{ matrix.platform }}" != "macos-11" ]; then

gen_type_mapping.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,12 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
439439
if from_hu_conv is None:
440440
from_hu_conv = (self.consts.get_ptr(ty_info.var_name), "")
441441
from_hu_conv = (from_hu_conv[0], to_hu_conv_sfx)
442+
fully_qualified_ty = self.consts.fully_qualified_hu_ty_path(ty_info)
443+
to_hu_call = fully_qualified_ty + ".constr_from_ptr(" + ty_info.var_name + ")"
442444
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
443445
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
444446
ret_conv = ret_conv, ret_conv_name = ty_info.var_name + "_ref",
445-
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ")") + ";\n" + self.consts.add_ref(ty_info.var_name + "_hu_conv", "this") + ";",
447+
to_hu_conv = self.consts.var_decl_statement(fully_qualified_ty, ty_info.var_name + "_hu_conv", to_hu_call) + ";\n" + self.consts.add_ref(ty_info.var_name + "_hu_conv", "this") + ";",
446448
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)
447449
if ty_info.rust_obj in self.result_types:
448450
if holds_ref:
@@ -484,7 +486,15 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
484486
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";" + to_hu_conv_sfx,
485487
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)
486488

487-
# The manually-defined types - TxOut and u5
489+
# The manually-defined types - TxOut, u5, and Error
490+
if ty_info.rust_obj == "LDKError":
491+
assert from_hu_conv is None
492+
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
493+
arg_conv = "", arg_conv_name = "(LDKError){ ._dummy = 0 }", arg_conv_cleanup = None,
494+
ret_conv = ("/*", "*/"), ret_conv_name = "0",
495+
to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_conv", "new " + ty_info.java_hu_ty + "(" + ty_info.var_name + ")") + ";",
496+
to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("0", ""))
497+
488498
if ty_info.rust_obj == "LDKu5":
489499
assert from_hu_conv is None
490500
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,

genbindings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ def java_c_types(fn_arg, ret_arr_len):
320320
fn_arg = fn_arg[6:].strip()
321321
arr_access = "chars"
322322
arr_len = "len"
323+
elif fn_arg.startswith("LDKError ") or fn_arg == "LDKError":
324+
java_ty = consts.c_type_map['uint32_t'][0]
325+
java_hu_ty = "UnqualifiedError"
326+
rust_obj = "LDKError"
327+
c_ty = "int32_t"
328+
arr_ty = "uint32_t"
329+
fn_ty_arg = "I"
330+
fn_arg = fn_arg[8:].strip()
323331
else:
324332
ma = var_ty_regex.match(fn_arg)
325333
arr_ty = ma.group(1).strip()

java_strings.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,15 @@ def set_null_skip_free(self, var):
701701
def add_ref(self, holder, referent):
702702
return holder + ".ptrs_to.add(" + referent + ")"
703703

704+
def fully_qualified_hu_ty_path(self, ty):
705+
if ty.java_fn_ty_arg.startswith("L") and ty.java_fn_ty_arg.endswith(";"):
706+
return ty.java_fn_ty_arg.strip("L;").replace("/", ".")
707+
if ty.java_hu_ty == "UnqualifiedError" or ty.java_hu_ty == "UInt5":
708+
return "org.ldk.util." + ty.java_hu_ty
709+
if ty.rust_obj is not None and not "[]" in ty.java_hu_ty:
710+
return "org.ldk.structs." + ty.java_hu_ty
711+
return ty.java_hu_ty
712+
704713
def native_c_unitary_enum_map(self, struct_name, variants, enum_doc_comment):
705714
out_java_enum = "package org.ldk.enums;\n\n"
706715
out_java = ""
@@ -1166,20 +1175,19 @@ def map_complex_enum(self, struct_name, variant_list, camel_to_snake, enum_doc_c
11661175
if idx > 0:
11671176
init_meth_params = init_meth_params + ", "
11681177

1169-
if field_ty.java_hu_ty == var.var_name:
1170-
field_path = field_ty.java_fn_ty_arg.strip("L;").replace("/", ".")
1171-
out_java += "\t\t\tpublic " + field_path + " " + field_ty.arg_name + ";\n"
1172-
java_hu_subclasses = java_hu_subclasses + "\t\tpublic final " + field_path + " " + field_ty.arg_name + ";\n"
1173-
init_meth_params = init_meth_params + field_path + " " + field_ty.arg_name
1174-
else:
1175-
out_java += "\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n"
1176-
if field_docs is not None:
1177-
java_hu_subclasses += "\t\t/**\n\t\t * " + field_docs.replace("\n", "\n\t\t * ") + "\n\t\t*/\n"
1178-
java_hu_subclasses += "\t\t"
1179-
if field_ty.nullable:
1180-
java_hu_subclasses += "@Nullable "
1181-
java_hu_subclasses += "public final " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n"
1182-
init_meth_params = init_meth_params + field_ty.java_ty + " " + field_ty.arg_name
1178+
java_ty = field_ty.java_ty
1179+
if field_ty.java_fn_ty_arg.startswith("L") and field_ty.java_fn_ty_arg.endswith(";"):
1180+
# If this is a simple enum, we have to reference it in the low-level bindings differently:
1181+
java_ty = field_ty.java_fn_ty_arg.strip("L;").replace("/", ".")
1182+
out_java += "\t\t\tpublic " + java_ty + " " + field_ty.arg_name + ";\n"
1183+
if field_docs is not None:
1184+
java_hu_subclasses += "\t\t/**\n\t\t * " + field_docs.replace("\n", "\n\t\t * ") + "\n\t\t*/\n"
1185+
java_hu_subclasses += "\t\t"
1186+
if field_ty.nullable:
1187+
java_hu_subclasses += "@Nullable "
1188+
java_hu_subclasses += "public final " + self.fully_qualified_hu_ty_path(field_ty) + " " + field_ty.arg_name + ";\n"
1189+
init_meth_params = init_meth_params + java_ty + " " + field_ty.arg_name
1190+
11831191
init_meth_body = init_meth_body + "this." + field_ty.arg_name + " = " + field_ty.arg_name + "; "
11841192
if field_ty.to_hu_conv is not None:
11851193
hu_conv_body = hu_conv_body + "\t\t\t" + field_ty.java_ty + " " + field_ty.arg_name + " = obj." + field_ty.arg_name + ";\n"

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ public static class InvalidSerializedDataException extends Exception {
6262
@Nullable public InvoicePayer payer;
6363

6464
private final ChainMonitor chain_monitor;
65-
@Nullable private final NetworkGraph net_graph;
65+
66+
/**
67+
* The `NetworkGraph` deserialized from the byte given to the constructor when deserializing or the `NetworkGraph`
68+
* given explicitly to the new-object constructor.
69+
*/
70+
@Nullable public final NetworkGraph net_graph;
6671
@Nullable private final NetGraphMsgHandler graph_msg_handler;
6772
private final Logger logger;
6873

74+
private final byte[] router_rand_bytes;
75+
6976
/**
7077
* Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations
7178
*
@@ -75,7 +82,7 @@ public static class InvalidSerializedDataException extends Exception {
7582
*/
7683
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, UserConfig config,
7784
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
78-
@Nullable Filter filter, @Nullable NetworkGraph net_graph,
85+
@Nullable Filter filter, @Nullable byte[] net_graph_serialized,
7986
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
8087
final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
8188
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
@@ -95,15 +102,23 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
95102
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ res =
96103
UtilMethods.C2Tuple_BlockHashChannelManagerZ_read(channel_manager_serialized, keys_interface, fee_estimator, chain_monitor.as_Watch(), tx_broadcaster,
97104
logger, config, monitors);
98-
if (res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_Err) {
105+
if (!res.is_ok()) {
99106
throw new InvalidSerializedDataException("Serialized ChannelManager was corrupt");
100107
}
101108
this.channel_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.get_b();
102109
this.channel_manager_latest_block_hash = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.get_a();
103110
this.chain_monitor = chain_monitor;
104111
this.logger = logger;
105112
byte[] random_data = keys_interface.get_secure_random_bytes();
106-
this.net_graph = net_graph;
113+
if (net_graph_serialized != null) {
114+
Result_NetworkGraphDecodeErrorZ graph_res = NetworkGraph.read(net_graph_serialized);
115+
if (!graph_res.is_ok()) {
116+
throw new InvalidSerializedDataException("Serialized Network Graph was corrupt");
117+
}
118+
this.net_graph = ((Result_NetworkGraphDecodeErrorZ.Result_NetworkGraphDecodeErrorZ_OK)graph_res).res;
119+
} else {
120+
this.net_graph = null;
121+
}
107122
Result_SecretKeyNoneZ node_secret = keys_interface.get_node_secret(Recipient.LDKRecipient_Node);
108123
assert node_secret.is_ok();
109124
if (net_graph != null) {
@@ -131,6 +146,7 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
131146
monitor.load_outputs_to_watch(filter);
132147
}
133148
}
149+
router_rand_bytes = keys_interface.get_secure_random_bytes();
134150
}
135151

136152
/**
@@ -172,6 +188,7 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
172188
throw new IllegalStateException("We should never fail to construct nio objects unless we're on a platform that cannot run LDK.");
173189
}
174190
this.nio_peer_handler = nio_peer_handler;
191+
router_rand_bytes = keys_interface.get_secure_random_bytes();
175192
}
176193

177194
/**
@@ -181,6 +198,7 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
181198
public interface EventHandler {
182199
void handle_event(Event events);
183200
void persist_manager(byte[] channel_manager_bytes);
201+
void persist_network_graph(byte[] network_graph);
184202
}
185203

186204
BackgroundProcessor background_processor = null;
@@ -199,15 +217,24 @@ public void chain_sync_completed(EventHandler event_handler, @Nullable MultiThre
199217
}
200218
org.ldk.structs.EventHandler ldk_handler = org.ldk.structs.EventHandler.new_impl(event_handler::handle_event);
201219
if (this.net_graph != null && scorer != null) {
202-
Router router = DefaultRouter.of(net_graph, logger).as_Router();
220+
Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes).as_Router();
203221
this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, scorer, this.logger, ldk_handler, RetryAttempts.of(3));
204222
assert this.payer != null;
205223
ldk_handler = this.payer.as_EventHandler();
206224
}
207225

208-
background_processor = BackgroundProcessor.start(org.ldk.structs.ChannelManagerPersister.new_impl(channel_manager -> {
209-
event_handler.persist_manager(channel_manager.write());
210-
return Result_NoneErrorZ.ok();
226+
background_processor = BackgroundProcessor.start(Persister.new_impl(new Persister.PersisterInterface() {
227+
@Override
228+
public Result_NoneErrorZ persist_manager(ChannelManager channel_manager) {
229+
event_handler.persist_manager(channel_manager.write());
230+
return Result_NoneErrorZ.ok();
231+
}
232+
233+
@Override
234+
public Result_NoneErrorZ persist_graph(NetworkGraph network_graph) {
235+
event_handler.persist_network_graph(network_graph.write());
236+
return Result_NoneErrorZ.ok();
237+
}
211238
}), ldk_handler, this.chain_monitor, this.channel_manager, this.graph_msg_handler, this.peer_manager, this.logger);
212239
}
213240

0 commit comments

Comments
 (0)