Skip to content

Test Upstream PR 838 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
- name: Rebuild C bindings, and check the sample app builds + links
run: cd ldk-c-bindings && ./genbindings.sh ../rust-lightning && cd ..
run: cd ldk-c-bindings && ./genbindings.sh ../rust-lightning true && cd ..
- name: Build Java/TS Debug Bindings
run: ./genbindings.sh ./ldk-c-bindings/ "-I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/" true false
- name: Run Java Tests against Debug Bindings
Expand Down
5 changes: 5 additions & 0 deletions genbindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def java_c_types(fn_arg, ret_arr_len):
assert var_is_arr_regex.match(fn_arg[8:])
rust_obj = "LDKThirtyTwoBytes"
arr_access = "data"
elif fn_arg.startswith("LDKTxid"):
fn_arg = "uint8_t (*" + fn_arg[8:] + ")[32]"
assert var_is_arr_regex.match(fn_arg[8:])
rust_obj = "LDKThirtyTwoBytes"
arr_access = "data"
elif fn_arg.startswith("LDKPublicKey"):
fn_arg = "uint8_t (*" + fn_arg[13:] + ")[33]"
assert var_is_arr_regex.match(fn_arg[8:])
Expand Down
Binary file modified liblightningjni_debug.so
Binary file not shown.
Binary file modified liblightningjni_release.so
Binary file not shown.
71 changes: 62 additions & 9 deletions src/main/java/org/ldk/batteries/ChannelManagerConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class InvalidSerializedDataException extends Exception {}
*/
public final TwoTuple<ChannelMonitor, byte[]>[] channel_monitors;

private final Watch chain_watch;
private final ChainMonitor chain_monitor;

/**
* Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations
Expand All @@ -44,7 +44,7 @@ public static class InvalidSerializedDataException extends Exception {}
* outputs will be loaded when chain_sync_completed is called.
*/
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized,
KeysInterface keys_interface, FeeEstimator fee_estimator, Watch chain_watch, @Nullable Filter filter,
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor, @Nullable Filter filter,
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
final ChannelMonitor[] monitors = new ChannelMonitor[channel_monitors_serialized.length];
this.channel_monitors = new TwoTuple[monitors.length];
Expand All @@ -57,14 +57,14 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
this.channel_monitors[i] = new TwoTuple<>(monitors[i], ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK)res).res.a);
}
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ res =
UtilMethods.constructor_BlockHashChannelManagerZ_read(channel_manager_serialized, keys_interface, fee_estimator, chain_watch, tx_broadcaster,
UtilMethods.constructor_BlockHashChannelManagerZ_read(channel_manager_serialized, keys_interface, fee_estimator, chain_monitor.as_Watch(), tx_broadcaster,
logger, UserConfig.constructor_default(), monitors);
if (res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_Err) {
throw new InvalidSerializedDataException();
}
this.channel_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.b;
this.channel_manager_latest_block_hash = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK)res).res.a;
this.chain_watch = chain_watch;
this.chain_monitor = chain_monitor;
if (filter != null) {
for (ChannelMonitor monitor : monitors) {
monitor.load_outputs_to_watch(filter);
Expand All @@ -76,21 +76,74 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
* Constructs a channel manager from the given interface implementations
*/
public ChannelManagerConstructor(LDKNetwork network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height,
KeysInterface keys_interface, FeeEstimator fee_estimator, Watch chain_watch,
KeysInterface keys_interface, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
channel_monitors = new TwoTuple[0];
channel_manager_latest_block_hash = null;
this.chain_watch = chain_watch;
channel_manager = ChannelManager.constructor_new(fee_estimator, chain_watch, tx_broadcaster, logger, keys_interface, config, network, current_blockchain_tip_hash, current_blockchain_tip_height);
this.chain_monitor = chain_monitor;
channel_manager = ChannelManager.constructor_new(fee_estimator, chain_monitor.as_Watch(), tx_broadcaster, logger, keys_interface, config, network, current_blockchain_tip_hash, current_blockchain_tip_height);
}

/**
* Abstract interface which should handle Events and persist the ChannelManager. When you call chain_sync_completed
* a background thread is started which will automatically call these methods for you when events occur.
*/
public interface ChannelManagerPersister {
void handle_events(Event[] events);
void persist_manager(byte[] channel_manager_bytes);
}

Thread persister_thread = null;
volatile boolean shutdown = false;

/**
* Utility which adds all of the deserialized ChannelMonitors to the chain watch so that further updates from the
* ChannelManager are processed as normal.
*
* This also spawns a background thread which will call the appropriate methods on the provided
* ChannelManagerPersister as required.
*/
public void chain_sync_completed() {
public void chain_sync_completed(ChannelManagerPersister persister) {
if (persister_thread != null) { return; }
for (TwoTuple<ChannelMonitor, byte[]> monitor: channel_monitors) {
this.chain_watch.watch_channel(monitor.a.get_funding_txo().a, monitor.a);
this.chain_monitor.as_Watch().watch_channel(monitor.a.get_funding_txo().a, monitor.a);
}
persister_thread = new Thread(() -> {
long lastTimerTick = System.currentTimeMillis();
while (true) {
boolean need_persist = this.channel_manager.await_persistable_update_timeout(1);
Event[] events = this.channel_manager.as_EventsProvider().get_and_clear_pending_events();
if (events.length != 0) {
persister.handle_events(events);
need_persist = true;
}
events = this.chain_monitor.as_EventsProvider().get_and_clear_pending_events();
if (events.length != 0) {
persister.handle_events(events);
need_persist = true;
}
if (need_persist) {
persister.persist_manager(this.channel_manager.write());
}
if (shutdown) {
return;
}
if (lastTimerTick < System.currentTimeMillis() - 60 * 1000) {
this.channel_manager.timer_chan_freshness_every_min();
lastTimerTick = System.currentTimeMillis();
}
}
}, "NioPeerHandler NIO Thread");
persister_thread.start();
}

/**
* Interrupt the background thread, stopping the background handling of
*/
public void interrupt() {
shutdown = true;
try {
persister_thread.join();
} catch (InterruptedException ignored) { }
}
}
27 changes: 16 additions & 11 deletions src/main/java/org/ldk/impl/bindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,6 @@ public final static class FundingGenerationReady extends LDKEvent {
public long user_channel_id;
FundingGenerationReady(byte[] temporary_channel_id, long channel_value_satoshis, byte[] output_script, long user_channel_id) { this.temporary_channel_id = temporary_channel_id; this.channel_value_satoshis = channel_value_satoshis; this.output_script = output_script; this.user_channel_id = user_channel_id; }
}
public final static class FundingBroadcastSafe extends LDKEvent {
public long funding_txo;
public long user_channel_id;
FundingBroadcastSafe(long funding_txo, long user_channel_id) { this.funding_txo = funding_txo; this.user_channel_id = user_channel_id; }
}
public final static class PaymentReceived extends LDKEvent {
public byte[] payment_hash;
public byte[] payment_secret;
Expand Down Expand Up @@ -1297,6 +1292,8 @@ public interface LDKSocketDescriptor {
public static native void CResult_NonePaymentSendFailureZ_free(long _res);
// struct LDKCResult_NonePaymentSendFailureZ CResult_NonePaymentSendFailureZ_clone(const struct LDKCResult_NonePaymentSendFailureZ *NONNULL_PTR orig);
public static native long CResult_NonePaymentSendFailureZ_clone(long orig);
// void CVec_TxidZ_free(struct LDKCVec_TxidZ _res);
public static native void CVec_TxidZ_free(byte[][] _res);
// void CVec_ChannelMonitorZ_free(struct LDKCVec_ChannelMonitorZ _res);
public static native void CVec_ChannelMonitorZ_free(long[] _res);
// struct LDKC2Tuple_BlockHashChannelManagerZ C2Tuple_BlockHashChannelManagerZ_new(struct LDKThirtyTwoBytes a, struct LDKChannelManager b);
Expand Down Expand Up @@ -2123,6 +2120,8 @@ public interface LDKSocketDescriptor {
public static native long PaymentSendFailure_clone(long orig);
// MUST_USE_RES struct LDKChannelManager ChannelManager_new(struct LDKFeeEstimator fee_est, struct LDKWatch chain_monitor, struct LDKBroadcasterInterface tx_broadcaster, struct LDKLogger logger, struct LDKKeysInterface keys_manager, struct LDKUserConfig config, struct LDKChainParameters params);
public static native long ChannelManager_new(long fee_est, long chain_monitor, long tx_broadcaster, long logger, long keys_manager, long config, long params);
// MUST_USE_RES struct LDKUserConfig ChannelManager_get_current_default_configuration(const struct LDKChannelManager *NONNULL_PTR this_arg);
public static native long ChannelManager_get_current_default_configuration(long this_arg);
// MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_create_channel(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKPublicKey their_network_key, uint64_t channel_value_satoshis, uint64_t push_msat, uint64_t user_id, struct LDKUserConfig override_config);
public static native long ChannelManager_create_channel(long this_arg, byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_id, long override_config);
// MUST_USE_RES struct LDKCVec_ChannelDetailsZ ChannelManager_list_channels(const struct LDKChannelManager *NONNULL_PTR this_arg);
Expand All @@ -2137,8 +2136,8 @@ public interface LDKSocketDescriptor {
public static native void ChannelManager_force_close_all_channels(long this_arg);
// MUST_USE_RES struct LDKCResult_NonePaymentSendFailureZ ChannelManager_send_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_hash, struct LDKThirtyTwoBytes payment_secret);
public static native long ChannelManager_send_payment(long this_arg, long route, byte[] payment_hash, byte[] payment_secret);
// void ChannelManager_funding_transaction_generated(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKOutPoint funding_txo);
public static native void ChannelManager_funding_transaction_generated(long this_arg, byte[] temporary_channel_id, long funding_txo);
// MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_funding_transaction_generated(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*temporary_channel_id)[32], struct LDKTransaction funding_transaction, uint16_t output_index);
public static native long ChannelManager_funding_transaction_generated(long this_arg, byte[] temporary_channel_id, byte[] funding_transaction, short output_index);
// void ChannelManager_broadcast_node_announcement(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKThreeBytes rgb, struct LDKThirtyTwoBytes alias, struct LDKCVec_NetAddressZ addresses);
public static native void ChannelManager_broadcast_node_announcement(long this_arg, byte[] rgb, byte[] alias, long[] addresses);
// void ChannelManager_process_pending_htlc_forwards(const struct LDKChannelManager *NONNULL_PTR this_arg);
Expand All @@ -2159,10 +2158,16 @@ public interface LDKSocketDescriptor {
public static native long ChannelManager_as_EventsProvider(long this_arg);
// struct LDKListen ChannelManager_as_Listen(const struct LDKChannelManager *NONNULL_PTR this_arg);
public static native long ChannelManager_as_Listen(long this_arg);
// void ChannelManager_block_connected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], struct LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height);
public static native void ChannelManager_block_connected(long this_arg, byte[] header, long[] txdata, int height);
// void ChannelManager_block_disconnected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80]);
public static native void ChannelManager_block_disconnected(long this_arg, byte[] header);
// void ChannelManager_transactions_confirmed(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height, struct LDKCVec_C2Tuple_usizeTransactionZZ txdata);
public static native void ChannelManager_transactions_confirmed(long this_arg, byte[] header, int height, long[] txdata);
// void ChannelManager_update_best_block(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80], uint32_t height);
public static native void ChannelManager_update_best_block(long this_arg, byte[] header, int height);
// MUST_USE_RES struct LDKCVec_TxidZ ChannelManager_get_relevant_txids(const struct LDKChannelManager *NONNULL_PTR this_arg);
public static native byte[][] ChannelManager_get_relevant_txids(long this_arg);
// void ChannelManager_transaction_unconfirmed(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*txid)[32]);
public static native void ChannelManager_transaction_unconfirmed(long this_arg, byte[] txid);
// MUST_USE_RES bool ChannelManager_await_persistable_update_timeout(const struct LDKChannelManager *NONNULL_PTR this_arg, uint64_t max_wait);
public static native boolean ChannelManager_await_persistable_update_timeout(long this_arg, long max_wait);
// void ChannelManager_await_persistable_update(const struct LDKChannelManager *NONNULL_PTR this_arg);
public static native void ChannelManager_await_persistable_update(long this_arg);
// struct LDKChannelMessageHandler ChannelManager_as_ChannelMessageHandler(const struct LDKChannelManager *NONNULL_PTR this_arg);
Expand Down
Loading