Skip to content

Commit 384d4ce

Browse files
authored
Merge pull request #119 from TheBlueMatt/main
Update to 0.0.111
2 parents f385eff + 95f7528 commit 384d4ce

File tree

441 files changed

+37940
-5578
lines changed

Some content is hidden

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

441 files changed

+37940
-5578
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ jobs:
3939
# Note this is a different endpoint, as we need one non-upstream commit!
4040
git clone https://git.bitcoin.ninja/rust-lightning
4141
cd rust-lightning
42-
git checkout origin/2022-07-110-java-bindings
42+
git checkout origin/2022-09-111-java-bindings
4343
cd ..
4444
git clone https://github.com/lightningdevkit/ldk-c-bindings
4545
cd ldk-c-bindings
46-
git checkout 0.0.110
46+
git checkout 0.0.111
4747
- name: Rebuild C bindings without STD
4848
run: |
4949
cd ldk-c-bindings
@@ -130,11 +130,11 @@ jobs:
130130
# Note this is a different endpoint, as we need one non-upstream commit!
131131
git clone https://git.bitcoin.ninja/rust-lightning
132132
cd rust-lightning
133-
git checkout origin/2022-07-110-java-bindings
133+
git checkout origin/2022-09-111-java-bindings
134134
cd ..
135135
git clone https://github.com/lightningdevkit/ldk-c-bindings
136136
cd ldk-c-bindings
137-
git checkout 0.0.110
137+
git checkout 0.0.111
138138
- name: Rebuild C bindings, and check the sample app builds + links
139139
run: |
140140
cd ldk-c-bindings
@@ -185,11 +185,11 @@ jobs:
185185
# Note this is a different endpoint, as we need one non-upstream commit!
186186
git clone https://git.bitcoin.ninja/rust-lightning
187187
cd rust-lightning
188-
git checkout origin/2022-07-110-java-bindings
188+
git checkout origin/2022-09-111-java-bindings
189189
cd ..
190190
git clone https://github.com/lightningdevkit/ldk-c-bindings
191191
cd ldk-c-bindings
192-
git checkout 0.0.110
192+
git checkout 0.0.111
193193
- name: Rebuild C bindings, and check the sample app builds + links
194194
run: |
195195
cd ldk-c-bindings
@@ -288,11 +288,11 @@ jobs:
288288
# Note this is a different endpoint, as we need one non-upstream commit!
289289
git clone https://git.bitcoin.ninja/rust-lightning
290290
cd rust-lightning
291-
git checkout origin/2022-07-110-java-bindings
291+
git checkout origin/2022-09-111-java-bindings
292292
cd ..
293293
git clone https://github.com/lightningdevkit/ldk-c-bindings
294294
cd ldk-c-bindings
295-
git checkout 0.0.110
295+
git checkout 0.0.111
296296
- name: Checkout Android AAR binaries and artifacts
297297
run: |
298298
# Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
@@ -368,11 +368,11 @@ jobs:
368368
# Note this is a different endpoint, as we need one non-upstream commit!
369369
git clone https://git.bitcoin.ninja/rust-lightning
370370
cd rust-lightning
371-
git checkout origin/2022-07-110-java-bindings
371+
git checkout origin/2022-09-111-java-bindings
372372
cd ..
373373
git clone https://github.com/lightningdevkit/ldk-c-bindings
374374
cd ldk-c-bindings
375-
git checkout 0.0.110
375+
git checkout 0.0.111
376376
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
377377
run: |
378378
export PATH=`pwd`/clang+llvm-14.0.5-x86_64-apple-darwin/bin:$PATH

gen_type_mapping.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
489489
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,
490490
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)
491491

492-
# The manually-defined types - TxOut, u5, and Error
492+
# The manually-defined types - TxOut, BigEndianScalar, u5, and Error
493493
if ty_info.rust_obj == "LDKError":
494494
assert from_hu_conv is None
495495
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
@@ -506,12 +506,12 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
506506
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 + ")") + ";",
507507
to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".getVal()", ""))
508508

509-
assert ty_info.rust_obj == "LDKTxOut"
509+
assert ty_info.rust_obj == "LDKTxOut" or ty_info.rust_obj == "LDKBigEndianScalar"
510510
if not ty_info.is_ptr and not holds_ref:
511-
ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = MALLOC(sizeof(LDKTxOut), \"LDKTxOut\");\n*" + ty_info.var_name + "_ref = ", ";")
511+
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_ref = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_ref = ", ";")
512512
ret_conv_name = "tag_ptr(" + ty_info.var_name + "_ref, true)"
513513
else:
514-
ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = &", ";")
514+
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_ref = &", ";")
515515
ret_conv_name = "tag_ptr(" + ty_info.var_name + "_ref, false)"
516516
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
517517
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,

genbindings.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def map_fn_with_ref_option(line, re_match, ret_arr_len, c_call_string, doc_comme
607607
expected_struct in complex_enums or expected_struct in complex_enums or
608608
expected_struct in result_types or expected_struct in tuple_types) and not is_free
609609
impl_on_utils = not impl_on_struct and (not is_free and not method_name.endswith("_clone") and
610-
not method_name.startswith("TxOut") and
610+
not method_name.startswith("TxOut") and not method_name.startswith("BigEndianScalar") and
611611
not method_name.startswith("_") and
612612
method_name != "check_platform" and method_name != "Result_read" and
613613
not expected_struct in unitary_enums and
@@ -756,9 +756,8 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines, trait_doc_comment):
756756
else:
757757
(nullable_params, ret_nullable) = doc_to_params_ret_nullable(fn_docs)
758758
if ret_nullable:
759-
assert False # This isn't yet handled on the Java side
760-
ret_ty_info.nullable = True
761759
ret_ty_info = type_mapping_generator.map_nullable_type(fn_line.group(2).strip() + " ret", True, None, False, False)
760+
ret_ty_info.nullable = True
762761
else:
763762
ret_ty_info = type_mapping_generator.map_type(fn_line.group(2).strip() + " ret", True, None, False, False)
764763
is_const = fn_line.group(4) is not None
@@ -1054,8 +1053,27 @@ def map_tuple(struct_name, field_lines):
10541053
write_c("\treturn thing->value;")
10551054
write_c("}")
10561055
map_fn(fn_line + "\n", re.compile("(.*) (TxOut_get_value) \((.*)\)").match(fn_line), None, None, None)
1056+
elif struct_name == "LDKBigEndianScalar":
1057+
with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct:
1058+
out_java_struct.write(consts.hu_struct_file_prefix)
1059+
out_java_struct.write(consts.scalar_defn)
1060+
fn_line = "struct LDKThirtyTwoBytes BigEndianScalar_get_bytes (struct LDKBigEndianScalar* thing)"
1061+
write_c(fn_line + " {\n")
1062+
write_c("\tLDKThirtyTwoBytes ret = { .data = *thing->big_endian_bytes };\n")
1063+
write_c("\treturn ret;\n")
1064+
write_c("}\n")
1065+
map_fn(fn_line + "\n", re.compile("(.*) (BigEndianScalar_get_bytes) \((.*)\)").match(fn_line), None, None, None)
1066+
1067+
# We need to be able to FREE a heap-allocated BigEndianScalar, but because
1068+
# there's nothing heap-allocated inside it the C bindings don't bother
1069+
# exposing a `_free` method. Instead, we have to manually write one here,
1070+
# though it doesn't need to do anything, the autogenerated wrapper will do
1071+
# the required FREE.
1072+
fn_line = "static void BigEndianScalar_free (struct LDKBigEndianScalar thing)"
1073+
write_c(fn_line + " {}\n")
1074+
map_fn(fn_line + "\n", re.compile("static (.*) (BigEndianScalar_free) \((.*)\)").match(fn_line), None, None, None)
10571075
else:
1058-
pass # Everything remaining is a byte[] or some form
1076+
pass # Everything remaining is a byte[] of some form
10591077
cur_block_obj = None
10601078
else:
10611079
fn_ptr = fn_ptr_regex.match(line)

java_strings.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ class CommonBase {
151151
}
152152
}"""
153153

154+
self.scalar_defn = """public class BigEndianScalar extends CommonBase {
155+
/** The bytes of the scalar value, in big endian */
156+
public final byte[] scalar_bytes;
157+
158+
BigEndianScalar(java.lang.Object _dummy, long ptr) {
159+
super(ptr);
160+
this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
161+
}
162+
public BigEndianScalar(byte[] scalar_bytes) {
163+
super(bindings.BigEndianScalar_new(scalar_bytes));
164+
this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
165+
}
166+
167+
@Override @SuppressWarnings(\"deprecation\")
168+
protected void finalize() throws Throwable {
169+
super.finalize();
170+
if (ptr != 0) { bindings.BigEndianScalar_free(ptr); }
171+
}
172+
}"""
173+
174+
154175
self.c_file_pfx = """#include <jni.h>
155176
// On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
156177
#define int64_t jlong

node-net/test/test.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ const rng_seed = new Uint8Array(32);
2525
const routing_handler = ldk.IgnoringMessageHandler.constructor_new().as_RoutingMessageHandler();
2626
const chan_handler = ldk.ErroringMessageHandler.constructor_new().as_ChannelMessageHandler();
2727
const cust_handler = ldk.IgnoringMessageHandler.constructor_new().as_CustomMessageHandler();
28+
const onion_handler = ldk.IgnoringMessageHandler.constructor_new().as_OnionMessageHandler();
2829

29-
const a_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, node_a_secret, rng_seed, logger_a, cust_handler);
30+
const a_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, onion_handler, node_a_secret, 0xdeadbeefn, rng_seed, logger_a, cust_handler);
3031
const a_net_handler = new node_net.NodeLDKNet(a_pm);
3132
var port = 10000;
3233
for (; port < 11000; port++) {
@@ -37,7 +38,7 @@ for (; port < 11000; port++) {
3738
} catch(_) {}
3839
}
3940

40-
const b_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, node_b_secret, rng_seed, logger_b, cust_handler);
41+
const b_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, onion_handler, node_b_secret, 0xdeadbeefn, rng_seed, logger_b, cust_handler);
4142
const b_net_handler = new node_net.NodeLDKNet(b_pm);
4243
await b_net_handler.connect_peer("127.0.0.1", port, node_a_pk);
4344

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
8888
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
8989
@Nullable Filter filter, @Nullable byte[] net_graph_serialized,
9090
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
91-
final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
91+
final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
9292
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
9393
this.channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[monitors.length];
9494
HashSet<OutPoint> monitor_funding_set = new HashSet();
@@ -130,13 +130,18 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
130130
this.graph_msg_handler = P2PGossipSync.of(net_graph, Option_AccessZ.none(), logger);
131131
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
132132
graph_msg_handler.as_RoutingMessageHandler(),
133+
ignoring_handler.as_OnionMessageHandler(),
133134
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
134-
random_data, logger, no_custom_messages.as_CustomMessageHandler());
135+
System.currentTimeMillis() / 1000,
136+
random_data, logger, ignoring_handler.as_CustomMessageHandler());
135137
} else {
136138
this.graph_msg_handler = null;
137-
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
139+
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
140+
ignoring_handler.as_RoutingMessageHandler(),
141+
ignoring_handler.as_OnionMessageHandler(),
138142
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
139-
random_data, logger, no_custom_messages.as_CustomMessageHandler());
143+
System.currentTimeMillis() / 1000,
144+
random_data, logger, ignoring_handler.as_CustomMessageHandler());
140145
}
141146
NioPeerHandler nio_peer_handler = null;
142147
try {
@@ -160,7 +165,7 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
160165
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
161166
@Nullable NetworkGraph net_graph,
162167
BroadcasterInterface tx_broadcaster, Logger logger) {
163-
final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
168+
final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
164169
channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[0];
165170
channel_manager_latest_block_hash = null;
166171
this.chain_monitor = chain_monitor;
@@ -177,13 +182,18 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
177182
this.graph_msg_handler = P2PGossipSync.of(net_graph, Option_AccessZ.none(), logger);
178183
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
179184
graph_msg_handler.as_RoutingMessageHandler(),
185+
ignoring_handler.as_OnionMessageHandler(),
180186
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
181-
random_data, logger, no_custom_messages.as_CustomMessageHandler());
187+
System.currentTimeMillis() / 1000,
188+
random_data, logger, ignoring_handler.as_CustomMessageHandler());
182189
} else {
183190
this.graph_msg_handler = null;
184-
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
191+
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
192+
ignoring_handler.as_RoutingMessageHandler(),
193+
ignoring_handler.as_OnionMessageHandler(),
185194
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
186-
random_data, logger, no_custom_messages.as_CustomMessageHandler());
195+
System.currentTimeMillis() / 1000,
196+
random_data, logger, ignoring_handler.as_CustomMessageHandler());
187197
}
188198
NioPeerHandler nio_peer_handler = null;
189199
try {
@@ -222,9 +232,8 @@ public void chain_sync_completed(EventHandler event_handler, @Nullable MultiThre
222232
}
223233
org.ldk.structs.EventHandler ldk_handler = org.ldk.structs.EventHandler.new_impl(event_handler::handle_event);
224234
if (this.net_graph != null && scorer != null) {
225-
Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes).as_Router();
226-
this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, scorer, this.logger, ldk_handler, Retry.attempts(3));
227-
assert this.payer != null;
235+
Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes, scorer.as_LockableScore()).as_Router();
236+
this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, this.logger, ldk_handler, Retry.attempts(3));
228237
ldk_handler = this.payer.as_EventHandler();
229238
}
230239

@@ -234,6 +243,12 @@ public void chain_sync_completed(EventHandler event_handler, @Nullable MultiThre
234243
else
235244
gossip_sync = GossipSync.p2_p(this.graph_msg_handler);
236245

246+
Option_WriteableScoreZ writeable_score;
247+
if (scorer != null)
248+
writeable_score = Option_WriteableScoreZ.some(scorer.as_WriteableScore());
249+
else
250+
writeable_score = Option_WriteableScoreZ.none();
251+
237252
background_processor = BackgroundProcessor.start(Persister.new_impl(new Persister.PersisterInterface() {
238253
@Override
239254
public Result_NoneErrorZ persist_manager(ChannelManager channel_manager) {
@@ -248,11 +263,11 @@ public Result_NoneErrorZ persist_graph(NetworkGraph network_graph) {
248263
}
249264

250265
@Override
251-
public Result_NoneErrorZ persist_scorer(MultiThreadedLockableScore scorer) {
266+
public Result_NoneErrorZ persist_scorer(WriteableScore scorer) {
252267
event_handler.persist_scorer(scorer.write());
253268
return Result_NoneErrorZ.ok();
254269
}
255-
}), ldk_handler, this.chain_monitor, this.channel_manager, gossip_sync, this.peer_manager, this.logger, scorer);
270+
}), ldk_handler, this.chain_monitor, this.channel_manager, gossip_sync, this.peer_manager, this.logger, writeable_score);
256271
}
257272

258273
/**

0 commit comments

Comments
 (0)