Skip to content

Commit

Permalink
Merge pull request #119 from TheBlueMatt/main
Browse files Browse the repository at this point in the history
Update to 0.0.111
  • Loading branch information
TheBlueMatt authored Oct 3, 2022
2 parents f385eff + 95f7528 commit 384d4ce
Show file tree
Hide file tree
Showing 441 changed files with 37,940 additions and 5,578 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
# Note this is a different endpoint, as we need one non-upstream commit!
git clone https://git.bitcoin.ninja/rust-lightning
cd rust-lightning
git checkout origin/2022-07-110-java-bindings
git checkout origin/2022-09-111-java-bindings
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.110
git checkout 0.0.111
- name: Rebuild C bindings without STD
run: |
cd ldk-c-bindings
Expand Down Expand Up @@ -130,11 +130,11 @@ jobs:
# Note this is a different endpoint, as we need one non-upstream commit!
git clone https://git.bitcoin.ninja/rust-lightning
cd rust-lightning
git checkout origin/2022-07-110-java-bindings
git checkout origin/2022-09-111-java-bindings
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.110
git checkout 0.0.111
- name: Rebuild C bindings, and check the sample app builds + links
run: |
cd ldk-c-bindings
Expand Down Expand Up @@ -185,11 +185,11 @@ jobs:
# Note this is a different endpoint, as we need one non-upstream commit!
git clone https://git.bitcoin.ninja/rust-lightning
cd rust-lightning
git checkout origin/2022-07-110-java-bindings
git checkout origin/2022-09-111-java-bindings
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.110
git checkout 0.0.111
- name: Rebuild C bindings, and check the sample app builds + links
run: |
cd ldk-c-bindings
Expand Down Expand Up @@ -288,11 +288,11 @@ jobs:
# Note this is a different endpoint, as we need one non-upstream commit!
git clone https://git.bitcoin.ninja/rust-lightning
cd rust-lightning
git checkout origin/2022-07-110-java-bindings
git checkout origin/2022-09-111-java-bindings
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.110
git checkout 0.0.111
- name: Checkout Android AAR binaries and artifacts
run: |
# Gitweb only allows snapshots of folders by providing the object hash, which we have to extract:
Expand Down Expand Up @@ -368,11 +368,11 @@ jobs:
# Note this is a different endpoint, as we need one non-upstream commit!
git clone https://git.bitcoin.ninja/rust-lightning
cd rust-lightning
git checkout origin/2022-07-110-java-bindings
git checkout origin/2022-09-111-java-bindings
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.110
git checkout 0.0.111
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
run: |
export PATH=`pwd`/clang+llvm-14.0.5-x86_64-apple-darwin/bin:$PATH
Expand Down
8 changes: 4 additions & 4 deletions gen_type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def _do_map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, hold
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,
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)

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

assert ty_info.rust_obj == "LDKTxOut"
assert ty_info.rust_obj == "LDKTxOut" or ty_info.rust_obj == "LDKBigEndianScalar"
if not ty_info.is_ptr and not holds_ref:
ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = MALLOC(sizeof(LDKTxOut), \"LDKTxOut\");\n*" + ty_info.var_name + "_ref = ", ";")
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 = ", ";")
ret_conv_name = "tag_ptr(" + ty_info.var_name + "_ref, true)"
else:
ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = &", ";")
ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_ref = &", ";")
ret_conv_name = "tag_ptr(" + ty_info.var_name + "_ref, false)"
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
Expand Down
26 changes: 22 additions & 4 deletions genbindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def map_fn_with_ref_option(line, re_match, ret_arr_len, c_call_string, doc_comme
expected_struct in complex_enums or expected_struct in complex_enums or
expected_struct in result_types or expected_struct in tuple_types) and not is_free
impl_on_utils = not impl_on_struct and (not is_free and not method_name.endswith("_clone") and
not method_name.startswith("TxOut") and
not method_name.startswith("TxOut") and not method_name.startswith("BigEndianScalar") and
not method_name.startswith("_") and
method_name != "check_platform" and method_name != "Result_read" and
not expected_struct in unitary_enums and
Expand Down Expand Up @@ -756,9 +756,8 @@ def map_trait(struct_name, field_var_lines, trait_fn_lines, trait_doc_comment):
else:
(nullable_params, ret_nullable) = doc_to_params_ret_nullable(fn_docs)
if ret_nullable:
assert False # This isn't yet handled on the Java side
ret_ty_info.nullable = True
ret_ty_info = type_mapping_generator.map_nullable_type(fn_line.group(2).strip() + " ret", True, None, False, False)
ret_ty_info.nullable = True
else:
ret_ty_info = type_mapping_generator.map_type(fn_line.group(2).strip() + " ret", True, None, False, False)
is_const = fn_line.group(4) is not None
Expand Down Expand Up @@ -1054,8 +1053,27 @@ def map_tuple(struct_name, field_lines):
write_c("\treturn thing->value;")
write_c("}")
map_fn(fn_line + "\n", re.compile("(.*) (TxOut_get_value) \((.*)\)").match(fn_line), None, None, None)
elif struct_name == "LDKBigEndianScalar":
with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct:
out_java_struct.write(consts.hu_struct_file_prefix)
out_java_struct.write(consts.scalar_defn)
fn_line = "struct LDKThirtyTwoBytes BigEndianScalar_get_bytes (struct LDKBigEndianScalar* thing)"
write_c(fn_line + " {\n")
write_c("\tLDKThirtyTwoBytes ret = { .data = *thing->big_endian_bytes };\n")
write_c("\treturn ret;\n")
write_c("}\n")
map_fn(fn_line + "\n", re.compile("(.*) (BigEndianScalar_get_bytes) \((.*)\)").match(fn_line), None, None, None)

# We need to be able to FREE a heap-allocated BigEndianScalar, but because
# there's nothing heap-allocated inside it the C bindings don't bother
# exposing a `_free` method. Instead, we have to manually write one here,
# though it doesn't need to do anything, the autogenerated wrapper will do
# the required FREE.
fn_line = "static void BigEndianScalar_free (struct LDKBigEndianScalar thing)"
write_c(fn_line + " {}\n")
map_fn(fn_line + "\n", re.compile("static (.*) (BigEndianScalar_free) \((.*)\)").match(fn_line), None, None, None)
else:
pass # Everything remaining is a byte[] or some form
pass # Everything remaining is a byte[] of some form
cur_block_obj = None
else:
fn_ptr = fn_ptr_regex.match(line)
Expand Down
21 changes: 21 additions & 0 deletions java_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ class CommonBase {
}
}"""

self.scalar_defn = """public class BigEndianScalar extends CommonBase {
/** The bytes of the scalar value, in big endian */
public final byte[] scalar_bytes;
BigEndianScalar(java.lang.Object _dummy, long ptr) {
super(ptr);
this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
}
public BigEndianScalar(byte[] scalar_bytes) {
super(bindings.BigEndianScalar_new(scalar_bytes));
this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
}
@Override @SuppressWarnings(\"deprecation\")
protected void finalize() throws Throwable {
super.finalize();
if (ptr != 0) { bindings.BigEndianScalar_free(ptr); }
}
}"""


self.c_file_pfx = """#include <jni.h>
// On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
#define int64_t jlong
Expand Down
5 changes: 3 additions & 2 deletions node-net/test/test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const rng_seed = new Uint8Array(32);
const routing_handler = ldk.IgnoringMessageHandler.constructor_new().as_RoutingMessageHandler();
const chan_handler = ldk.ErroringMessageHandler.constructor_new().as_ChannelMessageHandler();
const cust_handler = ldk.IgnoringMessageHandler.constructor_new().as_CustomMessageHandler();
const onion_handler = ldk.IgnoringMessageHandler.constructor_new().as_OnionMessageHandler();

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

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

Expand Down
41 changes: 28 additions & 13 deletions src/main/java/org/ldk/batteries/ChannelManagerConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
@Nullable Filter filter, @Nullable byte[] net_graph_serialized,
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
this.channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[monitors.length];
HashSet<OutPoint> monitor_funding_set = new HashSet();
Expand Down Expand Up @@ -130,13 +130,18 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
this.graph_msg_handler = P2PGossipSync.of(net_graph, Option_AccessZ.none(), logger);
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
graph_msg_handler.as_RoutingMessageHandler(),
ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
random_data, logger, no_custom_messages.as_CustomMessageHandler());
System.currentTimeMillis() / 1000,
random_data, logger, ignoring_handler.as_CustomMessageHandler());
} else {
this.graph_msg_handler = null;
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
ignoring_handler.as_RoutingMessageHandler(),
ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
random_data, logger, no_custom_messages.as_CustomMessageHandler());
System.currentTimeMillis() / 1000,
random_data, logger, ignoring_handler.as_CustomMessageHandler());
}
NioPeerHandler nio_peer_handler = null;
try {
Expand All @@ -160,7 +165,7 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
@Nullable NetworkGraph net_graph,
BroadcasterInterface tx_broadcaster, Logger logger) {
final IgnoringMessageHandler no_custom_messages = IgnoringMessageHandler.of();
final IgnoringMessageHandler ignoring_handler = IgnoringMessageHandler.of();
channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[0];
channel_manager_latest_block_hash = null;
this.chain_monitor = chain_monitor;
Expand All @@ -177,13 +182,18 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
this.graph_msg_handler = P2PGossipSync.of(net_graph, Option_AccessZ.none(), logger);
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
graph_msg_handler.as_RoutingMessageHandler(),
ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
random_data, logger, no_custom_messages.as_CustomMessageHandler());
System.currentTimeMillis() / 1000,
random_data, logger, ignoring_handler.as_CustomMessageHandler());
} else {
this.graph_msg_handler = null;
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(), no_custom_messages.as_RoutingMessageHandler(),
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
ignoring_handler.as_RoutingMessageHandler(),
ignoring_handler.as_OnionMessageHandler(),
((Result_SecretKeyNoneZ.Result_SecretKeyNoneZ_OK)node_secret).res,
random_data, logger, no_custom_messages.as_CustomMessageHandler());
System.currentTimeMillis() / 1000,
random_data, logger, ignoring_handler.as_CustomMessageHandler());
}
NioPeerHandler nio_peer_handler = null;
try {
Expand Down Expand Up @@ -222,9 +232,8 @@ public void chain_sync_completed(EventHandler event_handler, @Nullable MultiThre
}
org.ldk.structs.EventHandler ldk_handler = org.ldk.structs.EventHandler.new_impl(event_handler::handle_event);
if (this.net_graph != null && scorer != null) {
Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes).as_Router();
this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, scorer, this.logger, ldk_handler, Retry.attempts(3));
assert this.payer != null;
Router router = DefaultRouter.of(net_graph, logger, router_rand_bytes, scorer.as_LockableScore()).as_Router();
this.payer = InvoicePayer.of(this.channel_manager.as_Payer(), router, this.logger, ldk_handler, Retry.attempts(3));
ldk_handler = this.payer.as_EventHandler();
}

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

Option_WriteableScoreZ writeable_score;
if (scorer != null)
writeable_score = Option_WriteableScoreZ.some(scorer.as_WriteableScore());
else
writeable_score = Option_WriteableScoreZ.none();

background_processor = BackgroundProcessor.start(Persister.new_impl(new Persister.PersisterInterface() {
@Override
public Result_NoneErrorZ persist_manager(ChannelManager channel_manager) {
Expand All @@ -248,11 +263,11 @@ public Result_NoneErrorZ persist_graph(NetworkGraph network_graph) {
}

@Override
public Result_NoneErrorZ persist_scorer(MultiThreadedLockableScore scorer) {
public Result_NoneErrorZ persist_scorer(WriteableScore scorer) {
event_handler.persist_scorer(scorer.write());
return Result_NoneErrorZ.ok();
}
}), ldk_handler, this.chain_monitor, this.channel_manager, gossip_sync, this.peer_manager, this.logger, scorer);
}), ldk_handler, this.chain_monitor, this.channel_manager, gossip_sync, this.peer_manager, this.logger, writeable_score);
}

/**
Expand Down
Loading

0 comments on commit 384d4ce

Please sign in to comment.