Skip to content

Commit af6f994

Browse files
authored
Merge pull request #110 from TheBlueMatt/main
Update to LDK 0.0.110
2 parents 8a515be + e2bd922 commit af6f994

File tree

374 files changed

+10302
-1226
lines changed

Some content is hidden

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

374 files changed

+10302
-1226
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-109-java-bindings
42+
git checkout origin/2022-07-110-java-bindings
4343
cd ..
4444
git clone https://github.com/lightningdevkit/ldk-c-bindings
4545
cd ldk-c-bindings
46-
git checkout 0.0.109
46+
git checkout 0.0.110
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-109-java-bindings
133+
git checkout origin/2022-07-110-java-bindings
134134
cd ..
135135
git clone https://github.com/lightningdevkit/ldk-c-bindings
136136
cd ldk-c-bindings
137-
git checkout 0.0.109
137+
git checkout 0.0.110
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-109-java-bindings
188+
git checkout origin/2022-07-110-java-bindings
189189
cd ..
190190
git clone https://github.com/lightningdevkit/ldk-c-bindings
191191
cd ldk-c-bindings
192-
git checkout 0.0.109
192+
git checkout 0.0.110
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-109-java-bindings
291+
git checkout origin/2022-07-110-java-bindings
292292
cd ..
293293
git clone https://github.com/lightningdevkit/ldk-c-bindings
294294
cd ldk-c-bindings
295-
git checkout 0.0.109
295+
git checkout 0.0.110
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-109-java-bindings
371+
git checkout origin/2022-07-110-java-bindings
372372
cd ..
373373
git clone https://github.com/lightningdevkit/ldk-c-bindings
374374
cd ldk-c-bindings
375-
git checkout 0.0.109
375+
git checkout 0.0.110
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

src/main/java/org/ldk/impl/bindings.java

Lines changed: 186 additions & 33 deletions
Large diffs are not rendered by default.

src/main/java/org/ldk/structs/ChannelManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,20 @@ public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_
426426
return ret_hu_conv;
427427
}
428428

429+
/**
430+
* Send a payment that is probing the given route for liquidity. We calculate the
431+
* [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows
432+
* us to easily discern them from real payments.
433+
*/
434+
public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_probe(RouteHop[] hops) {
435+
long ret = bindings.ChannelManager_send_probe(this.ptr, hops != null ? Arrays.stream(hops).mapToLong(hops_conv_10 -> hops_conv_10 == null ? 0 : hops_conv_10.ptr & ~1).toArray() : null);
436+
Reference.reachabilityFence(this);
437+
Reference.reachabilityFence(hops);
438+
if (ret >= 0 && ret <= 4096) { return null; }
439+
Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
440+
return ret_hu_conv;
441+
}
442+
429443
/**
430444
* Call this upon creation of a funding transaction for the given channel.
431445
*
@@ -485,7 +499,7 @@ public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_chann
485499
* tying these addresses together and to this node. If you wish to preserve user privacy,
486500
* addresses should likely contain only Tor Onion addresses.
487501
*
488-
* Panics if `addresses` is absurdly large (more than 500).
502+
* Panics if `addresses` is absurdly large (more than 100).
489503
*
490504
* [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
491505
*/

src/main/java/org/ldk/structs/ChannelMonitor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ public Event[] get_and_clear_pending_events() {
176176
return ret_conv_7_arr;
177177
}
178178

179+
/**
180+
* Gets the `node_id` of the counterparty for this channel.
181+
*
182+
* Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
183+
* otherwise.
184+
*
185+
* Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
186+
*/
187+
@Nullable
188+
public byte[] get_counterparty_node_id() {
189+
byte[] ret = bindings.ChannelMonitor_get_counterparty_node_id(this.ptr);
190+
Reference.reachabilityFence(this);
191+
return ret;
192+
}
193+
179194
/**
180195
* Used by ChannelManager deserialization to broadcast the latest holder state if its copy of
181196
* the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of

src/main/java/org/ldk/structs/ChannelUpdateInfo.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,17 @@ public void set_htlc_minimum_msat(long val) {
9797
/**
9898
* The maximum value which may be relayed to the next hop via the channel.
9999
*/
100-
public Option_u64Z get_htlc_maximum_msat() {
100+
public long get_htlc_maximum_msat() {
101101
long ret = bindings.ChannelUpdateInfo_get_htlc_maximum_msat(this.ptr);
102102
Reference.reachabilityFence(this);
103-
if (ret >= 0 && ret <= 4096) { return null; }
104-
org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
105-
ret_hu_conv.ptrs_to.add(this);
106-
return ret_hu_conv;
103+
return ret;
107104
}
108105

109106
/**
110107
* The maximum value which may be relayed to the next hop via the channel.
111108
*/
112-
public void set_htlc_maximum_msat(Option_u64Z val) {
113-
bindings.ChannelUpdateInfo_set_htlc_maximum_msat(this.ptr, val.ptr);
109+
public void set_htlc_maximum_msat(long val) {
110+
bindings.ChannelUpdateInfo_set_htlc_maximum_msat(this.ptr, val);
114111
Reference.reachabilityFence(this);
115112
Reference.reachabilityFence(val);
116113
}
@@ -171,8 +168,8 @@ public void set_last_update_message(@Nullable ChannelUpdate val) {
171168
/**
172169
* Constructs a new ChannelUpdateInfo given each field
173170
*/
174-
public static ChannelUpdateInfo of(int last_update_arg, boolean enabled_arg, short cltv_expiry_delta_arg, long htlc_minimum_msat_arg, Option_u64Z htlc_maximum_msat_arg, RoutingFees fees_arg, ChannelUpdate last_update_message_arg) {
175-
long ret = bindings.ChannelUpdateInfo_new(last_update_arg, enabled_arg, cltv_expiry_delta_arg, htlc_minimum_msat_arg, htlc_maximum_msat_arg.ptr, fees_arg == null ? 0 : fees_arg.ptr & ~1, last_update_message_arg == null ? 0 : last_update_message_arg.ptr & ~1);
171+
public static ChannelUpdateInfo of(int last_update_arg, boolean enabled_arg, short cltv_expiry_delta_arg, long htlc_minimum_msat_arg, long htlc_maximum_msat_arg, RoutingFees fees_arg, ChannelUpdate last_update_message_arg) {
172+
long ret = bindings.ChannelUpdateInfo_new(last_update_arg, enabled_arg, cltv_expiry_delta_arg, htlc_minimum_msat_arg, htlc_maximum_msat_arg, fees_arg == null ? 0 : fees_arg.ptr & ~1, last_update_message_arg == null ? 0 : last_update_message_arg.ptr & ~1);
176173
Reference.reachabilityFence(last_update_arg);
177174
Reference.reachabilityFence(enabled_arg);
178175
Reference.reachabilityFence(cltv_expiry_delta_arg);

src/main/java/org/ldk/structs/Event.java

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ static Event constr_from_ptr(long ptr) {
4646
if (raw_val.getClass() == bindings.LDKEvent.PaymentPathFailed.class) {
4747
return new PaymentPathFailed(ptr, (bindings.LDKEvent.PaymentPathFailed)raw_val);
4848
}
49+
if (raw_val.getClass() == bindings.LDKEvent.ProbeSuccessful.class) {
50+
return new ProbeSuccessful(ptr, (bindings.LDKEvent.ProbeSuccessful)raw_val);
51+
}
52+
if (raw_val.getClass() == bindings.LDKEvent.ProbeFailed.class) {
53+
return new ProbeFailed(ptr, (bindings.LDKEvent.ProbeFailed)raw_val);
54+
}
4955
if (raw_val.getClass() == bindings.LDKEvent.PendingHTLCsForwardable.class) {
5056
return new PendingHTLCsForwardable(ptr, (bindings.LDKEvent.PendingHTLCsForwardable)raw_val);
5157
}
@@ -64,6 +70,9 @@ static Event constr_from_ptr(long ptr) {
6470
if (raw_val.getClass() == bindings.LDKEvent.OpenChannelRequest.class) {
6571
return new OpenChannelRequest(ptr, (bindings.LDKEvent.OpenChannelRequest)raw_val);
6672
}
73+
if (raw_val.getClass() == bindings.LDKEvent.HTLCHandlingFailed.class) {
74+
return new HTLCHandlingFailed(ptr, (bindings.LDKEvent.HTLCHandlingFailed)raw_val);
75+
}
6776
assert false; return null; // Unreachable without extending the (internal) bindings interface
6877
}
6978

@@ -449,6 +458,90 @@ private PaymentPathFailed(long ptr, bindings.LDKEvent.PaymentPathFailed obj) {
449458
this.retry = retry_hu_conv;
450459
}
451460
}
461+
/**
462+
* Indicates that a probe payment we sent returned successful, i.e., only failed at the destination.
463+
*/
464+
public final static class ProbeSuccessful extends Event {
465+
/**
466+
* The id returned by [`ChannelManager::send_probe`].
467+
*
468+
* [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
469+
*/
470+
public final byte[] payment_id;
471+
/**
472+
* The hash generated by [`ChannelManager::send_probe`].
473+
*
474+
* [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
475+
*/
476+
public final byte[] payment_hash;
477+
/**
478+
* The payment path that was successful.
479+
*/
480+
public final RouteHop[] path;
481+
private ProbeSuccessful(long ptr, bindings.LDKEvent.ProbeSuccessful obj) {
482+
super(null, ptr);
483+
this.payment_id = obj.payment_id;
484+
this.payment_hash = obj.payment_hash;
485+
long[] path = obj.path;
486+
int path_conv_10_len = path.length;
487+
RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
488+
for (int k = 0; k < path_conv_10_len; k++) {
489+
long path_conv_10 = path[k];
490+
org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
491+
path_conv_10_hu_conv.ptrs_to.add(this);
492+
path_conv_10_arr[k] = path_conv_10_hu_conv;
493+
}
494+
this.path = path_conv_10_arr;
495+
}
496+
}
497+
/**
498+
* Indicates that a probe payment we sent failed at an intermediary node on the path.
499+
*/
500+
public final static class ProbeFailed extends Event {
501+
/**
502+
* The id returned by [`ChannelManager::send_probe`].
503+
*
504+
* [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
505+
*/
506+
public final byte[] payment_id;
507+
/**
508+
* The hash generated by [`ChannelManager::send_probe`].
509+
*
510+
* [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe
511+
*/
512+
public final byte[] payment_hash;
513+
/**
514+
* The payment path that failed.
515+
*/
516+
public final RouteHop[] path;
517+
/**
518+
* The channel responsible for the failed probe.
519+
*
520+
* Note that for route hints or for the first hop in a path this may be an SCID alias and
521+
* may not refer to a channel in the public network graph. These aliases may also collide
522+
* with channels in the public network graph.
523+
*/
524+
public final org.ldk.structs.Option_u64Z short_channel_id;
525+
private ProbeFailed(long ptr, bindings.LDKEvent.ProbeFailed obj) {
526+
super(null, ptr);
527+
this.payment_id = obj.payment_id;
528+
this.payment_hash = obj.payment_hash;
529+
long[] path = obj.path;
530+
int path_conv_10_len = path.length;
531+
RouteHop[] path_conv_10_arr = new RouteHop[path_conv_10_len];
532+
for (int k = 0; k < path_conv_10_len; k++) {
533+
long path_conv_10 = path[k];
534+
org.ldk.structs.RouteHop path_conv_10_hu_conv = null; if (path_conv_10 < 0 || path_conv_10 > 4096) { path_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, path_conv_10); }
535+
path_conv_10_hu_conv.ptrs_to.add(this);
536+
path_conv_10_arr[k] = path_conv_10_hu_conv;
537+
}
538+
this.path = path_conv_10_arr;
539+
long short_channel_id = obj.short_channel_id;
540+
org.ldk.structs.Option_u64Z short_channel_id_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(short_channel_id);
541+
short_channel_id_hu_conv.ptrs_to.add(this);
542+
this.short_channel_id = short_channel_id_hu_conv;
543+
}
544+
}
452545
/**
453546
* Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at
454547
* a time in the future.
@@ -675,6 +768,38 @@ private OpenChannelRequest(long ptr, bindings.LDKEvent.OpenChannelRequest obj) {
675768
this.channel_type = channel_type_hu_conv;
676769
}
677770
}
771+
/**
772+
* Indicates that the HTLC was accepted, but could not be processed when or after attempting to
773+
* forward it.
774+
*
775+
* Some scenarios where this event may be sent include:
776+
* Insufficient capacity in the outbound channel
777+
* While waiting to forward the HTLC, the channel it is meant to be forwarded through closes
778+
* When an unknown SCID is requested for forwarding a payment.
779+
* Claiming an amount for an MPP payment that exceeds the HTLC total
780+
* The HTLC has timed out
781+
*
782+
* This event, however, does not get generated if an HTLC fails to meet the forwarding
783+
* requirements (i.e. insufficient fees paid, or a CLTV that is too soon).
784+
*/
785+
public final static class HTLCHandlingFailed extends Event {
786+
/**
787+
* The channel over which the HTLC was received.
788+
*/
789+
public final byte[] prev_channel_id;
790+
/**
791+
* Destination of the HTLC that failed to be processed.
792+
*/
793+
public final org.ldk.structs.HTLCDestination failed_next_destination;
794+
private HTLCHandlingFailed(long ptr, bindings.LDKEvent.HTLCHandlingFailed obj) {
795+
super(null, ptr);
796+
this.prev_channel_id = obj.prev_channel_id;
797+
long failed_next_destination = obj.failed_next_destination;
798+
org.ldk.structs.HTLCDestination failed_next_destination_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(failed_next_destination);
799+
failed_next_destination_hu_conv.ptrs_to.add(this);
800+
this.failed_next_destination = failed_next_destination_hu_conv;
801+
}
802+
}
678803
long clone_ptr() {
679804
long ret = bindings.Event_clone_ptr(this.ptr);
680805
Reference.reachabilityFence(this);
@@ -798,6 +923,35 @@ public static Event payment_path_failed(byte[] payment_id, byte[] payment_hash,
798923
return ret_hu_conv;
799924
}
800925

926+
/**
927+
* Utility method to constructs a new ProbeSuccessful-variant Event
928+
*/
929+
public static Event probe_successful(byte[] payment_id, byte[] payment_hash, RouteHop[] path) {
930+
long ret = bindings.Event_probe_successful(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32), path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null);
931+
Reference.reachabilityFence(payment_id);
932+
Reference.reachabilityFence(payment_hash);
933+
Reference.reachabilityFence(path);
934+
if (ret >= 0 && ret <= 4096) { return null; }
935+
org.ldk.structs.Event ret_hu_conv = org.ldk.structs.Event.constr_from_ptr(ret);
936+
ret_hu_conv.ptrs_to.add(ret_hu_conv);
937+
return ret_hu_conv;
938+
}
939+
940+
/**
941+
* Utility method to constructs a new ProbeFailed-variant Event
942+
*/
943+
public static Event probe_failed(byte[] payment_id, byte[] payment_hash, RouteHop[] path, Option_u64Z short_channel_id) {
944+
long ret = bindings.Event_probe_failed(InternalUtils.check_arr_len(payment_id, 32), InternalUtils.check_arr_len(payment_hash, 32), path != null ? Arrays.stream(path).mapToLong(path_conv_10 -> path_conv_10 == null ? 0 : path_conv_10.ptr & ~1).toArray() : null, short_channel_id.ptr);
945+
Reference.reachabilityFence(payment_id);
946+
Reference.reachabilityFence(payment_hash);
947+
Reference.reachabilityFence(path);
948+
Reference.reachabilityFence(short_channel_id);
949+
if (ret >= 0 && ret <= 4096) { return null; }
950+
org.ldk.structs.Event ret_hu_conv = org.ldk.structs.Event.constr_from_ptr(ret);
951+
ret_hu_conv.ptrs_to.add(ret_hu_conv);
952+
return ret_hu_conv;
953+
}
954+
801955
/**
802956
* Utility method to constructs a new PendingHTLCsForwardable-variant Event
803957
*/
@@ -880,6 +1034,19 @@ public static Event open_channel_request(byte[] temporary_channel_id, byte[] cou
8801034
return ret_hu_conv;
8811035
}
8821036

1037+
/**
1038+
* Utility method to constructs a new HTLCHandlingFailed-variant Event
1039+
*/
1040+
public static Event htlchandling_failed(byte[] prev_channel_id, HTLCDestination failed_next_destination) {
1041+
long ret = bindings.Event_htlchandling_failed(InternalUtils.check_arr_len(prev_channel_id, 32), failed_next_destination.ptr);
1042+
Reference.reachabilityFence(prev_channel_id);
1043+
Reference.reachabilityFence(failed_next_destination);
1044+
if (ret >= 0 && ret <= 4096) { return null; }
1045+
org.ldk.structs.Event ret_hu_conv = org.ldk.structs.Event.constr_from_ptr(ret);
1046+
ret_hu_conv.ptrs_to.add(ret_hu_conv);
1047+
return ret_hu_conv;
1048+
}
1049+
8831050
/**
8841051
* Serialize the Event object into a byte array which can be read by Event_read
8851052
*/

0 commit comments

Comments
 (0)