Skip to content

Commit db55d4e

Browse files
authored
Merge pull request #50 from TheBlueMatt/main
v0.0.102.0
2 parents e6173a7 + 2a3bb81 commit db55d4e

Some content is hidden

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

59 files changed

+12405
-6558
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
cd ..
3636
git clone https://github.com/lightningdevkit/ldk-c-bindings
3737
cd ldk-c-bindings
38-
git checkout 0.0.101
38+
git checkout 0.0.102
3939
- name: Rebuild C bindings without STD for WASM
4040
run: |
4141
cd ldk-c-bindings
@@ -153,7 +153,7 @@ jobs:
153153
cd ..
154154
git clone https://github.com/lightningdevkit/ldk-c-bindings
155155
cd ldk-c-bindings
156-
git checkout 0.0.101
156+
git checkout 0.0.102
157157
- name: Checkout Android AAR binaries and artifacts
158158
run: git clone --depth 1 https://git.bitcoin.ninja/ldk-java-bins
159159
- name: Build Android aar
@@ -193,14 +193,14 @@ jobs:
193193
run: rustup target install aarch64-apple-darwin
194194
- name: Fetch upstream LLVM/clang snapshot
195195
run: |
196-
wget -O clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
197-
if [ "$(shasum -a 256 clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "7bc2259bf75c003f644882460fc8e844ddb23b27236fe43a2787870a4cd8ab50" ]; then
196+
wget -O clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz
197+
if [ "$(shasum -a 256 clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "d051234eca1db1f5e4bc08c64937c879c7098900f7a0370f3ceb7544816a8b09" ]; then
198198
echo "Bad hash"
199199
exit 1
200200
fi
201201
- name: Unpack upstream LLVM+clang and use it by default
202202
run: |
203-
tar xvvf clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
203+
tar xvvf clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz
204204
- name: Checkout source code
205205
uses: actions/checkout@v2
206206
with:
@@ -218,11 +218,11 @@ jobs:
218218
cd ..
219219
git clone https://github.com/lightningdevkit/ldk-c-bindings
220220
cd ldk-c-bindings
221-
git checkout 0.0.101
221+
git checkout 0.0.102
222222
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
223223
run: |
224224
cd ldk-c-bindings
225-
export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
225+
export PATH=`pwd`/clang+llvm-13.0.0-x86_64-apple-darwin/bin:$PATH
226226
CC=clang ./genbindings.sh ../rust-lightning true
227227
cd ..
228228
- name: Fetch OpenJDK 16
@@ -247,7 +247,7 @@ jobs:
247247
# genbindings.sh always fails as there is no wasm32-wasi library
248248
# available, so instead we check that the expected JNI library
249249
# is created.
250-
export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
250+
export PATH=`pwd`/clang+llvm-13.0.0-x86_64-apple-darwin/bin:$PATH
251251
./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false || echo
252252
cat src/main/resources/liblightningjni_MacOSX-x86_64.nativelib > /dev/null
253253
if [ "${{ matrix.platform }}" = "macos-11" ]; then

genbindings.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.clas
8686

8787
IS_MAC=false
8888
[ "$($CC --version | grep apple-darwin)" != "" ] && IS_MAC=true
89+
IS_APPLE_CLANG=false
90+
[ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true
8991

9092
echo "Building Java bindings..."
9193
COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -ldl -shared -fPIC"
9294
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--no-undefined"
9395
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
96+
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && COMPILE="$COMPILE -fuse-ld=lld"
97+
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
9498
[ "$IS_MAC" = "false" -a "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
9599
if [ "$3" = "true" ]; then
96100
$COMPILE -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm

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

Lines changed: 304 additions & 158 deletions
Large diffs are not rendered by default.

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@ public Balance[] get_claimable_balances(ChannelDetails[] ignored_channels) {
7171
return ret_conv_9_arr;
7272
}
7373

74+
/**
75+
* Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no
76+
* such [`ChannelMonitor`] is currently being monitored for.
77+
*
78+
* Note that the result holds a mutex over our monitor set, and should not be held
79+
* indefinitely.
80+
*/
81+
public Result_LockedChannelMonitorNoneZ get_monitor(OutPoint funding_txo) {
82+
long ret = bindings.ChainMonitor_get_monitor(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1);
83+
if (ret >= 0 && ret < 1024) { return null; }
84+
Result_LockedChannelMonitorNoneZ ret_hu_conv = Result_LockedChannelMonitorNoneZ.constr_from_ptr(ret);
85+
return ret_hu_conv;
86+
}
87+
88+
/**
89+
* Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
90+
*
91+
* Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
92+
* monitoring for on-chain state resolutions.
93+
*/
94+
public OutPoint[] list_monitors() {
95+
long[] ret = bindings.ChainMonitor_list_monitors(this.ptr);
96+
OutPoint[] ret_conv_10_arr = new OutPoint[ret.length];
97+
for (int k = 0; k < ret.length; k++) {
98+
long ret_conv_10 = ret[k];
99+
OutPoint ret_conv_10_hu_conv = new OutPoint(null, ret_conv_10);
100+
ret_conv_10_hu_conv.ptrs_to.add(this);
101+
ret_conv_10_arr[k] = ret_conv_10_hu_conv;
102+
}
103+
return ret_conv_10_arr;
104+
}
105+
74106
/**
75107
* Constructs a new Listen which calls the relevant methods on this_arg.
76108
* This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,18 @@ public void set_unspendable_punishment_reserve(Option_u64Z val) {
159159
}
160160

161161
/**
162-
* The user_id passed in to create_channel, or 0 if the channel was inbound.
162+
* The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
163163
*/
164-
public long get_user_id() {
165-
long ret = bindings.ChannelDetails_get_user_id(this.ptr);
164+
public long get_user_channel_id() {
165+
long ret = bindings.ChannelDetails_get_user_channel_id(this.ptr);
166166
return ret;
167167
}
168168

169169
/**
170-
* The user_id passed in to create_channel, or 0 if the channel was inbound.
170+
* The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
171171
*/
172-
public void set_user_id(long val) {
173-
bindings.ChannelDetails_set_user_id(this.ptr, val);
172+
public void set_user_channel_id(long val) {
173+
bindings.ChannelDetails_set_user_channel_id(this.ptr, val);
174174
}
175175

176176
/**
@@ -382,8 +382,8 @@ public void set_is_public(boolean val) {
382382
/**
383383
* Constructs a new ChannelDetails given each field
384384
*/
385-
public static ChannelDetails of(byte[] channel_id_arg, ChannelCounterparty counterparty_arg, OutPoint funding_txo_arg, Option_u64Z short_channel_id_arg, long channel_value_satoshis_arg, Option_u64Z unspendable_punishment_reserve_arg, long user_id_arg, long outbound_capacity_msat_arg, long inbound_capacity_msat_arg, Option_u32Z confirmations_required_arg, Option_u16Z force_close_spend_delay_arg, boolean is_outbound_arg, boolean is_funding_locked_arg, boolean is_usable_arg, boolean is_public_arg) {
386-
long ret = bindings.ChannelDetails_new(channel_id_arg, counterparty_arg == null ? 0 : counterparty_arg.ptr & ~1, funding_txo_arg == null ? 0 : funding_txo_arg.ptr & ~1, short_channel_id_arg.ptr, channel_value_satoshis_arg, unspendable_punishment_reserve_arg.ptr, user_id_arg, outbound_capacity_msat_arg, inbound_capacity_msat_arg, confirmations_required_arg.ptr, force_close_spend_delay_arg.ptr, is_outbound_arg, is_funding_locked_arg, is_usable_arg, is_public_arg);
385+
public static ChannelDetails of(byte[] channel_id_arg, ChannelCounterparty counterparty_arg, OutPoint funding_txo_arg, Option_u64Z short_channel_id_arg, long channel_value_satoshis_arg, Option_u64Z unspendable_punishment_reserve_arg, long user_channel_id_arg, long outbound_capacity_msat_arg, long inbound_capacity_msat_arg, Option_u32Z confirmations_required_arg, Option_u16Z force_close_spend_delay_arg, boolean is_outbound_arg, boolean is_funding_locked_arg, boolean is_usable_arg, boolean is_public_arg) {
386+
long ret = bindings.ChannelDetails_new(channel_id_arg, counterparty_arg == null ? 0 : counterparty_arg.ptr & ~1, funding_txo_arg == null ? 0 : funding_txo_arg.ptr & ~1, short_channel_id_arg.ptr, channel_value_satoshis_arg, unspendable_punishment_reserve_arg.ptr, user_channel_id_arg, outbound_capacity_msat_arg, inbound_capacity_msat_arg, confirmations_required_arg.ptr, force_close_spend_delay_arg.ptr, is_outbound_arg, is_funding_locked_arg, is_usable_arg, is_public_arg);
387387
if (ret >= 0 && ret < 1024) { return null; }
388388
ChannelDetails ret_hu_conv = new ChannelDetails(null, ret);
389389
ret_hu_conv.ptrs_to.add(ret_hu_conv);

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,19 @@ public void set_features(ChannelFeatures val) {
4141
/**
4242
* Source node of the first direction of a channel
4343
*/
44-
public byte[] get_node_one() {
45-
byte[] ret = bindings.ChannelInfo_get_node_one(this.ptr);
46-
return ret;
44+
public NodeId get_node_one() {
45+
long ret = bindings.ChannelInfo_get_node_one(this.ptr);
46+
if (ret >= 0 && ret < 1024) { return null; }
47+
NodeId ret_hu_conv = new NodeId(null, ret);
48+
ret_hu_conv.ptrs_to.add(this);
49+
return ret_hu_conv;
4750
}
4851

4952
/**
5053
* Source node of the first direction of a channel
5154
*/
52-
public void set_node_one(byte[] val) {
53-
bindings.ChannelInfo_set_node_one(this.ptr, val);
55+
public void set_node_one(NodeId val) {
56+
bindings.ChannelInfo_set_node_one(this.ptr, val == null ? 0 : val.ptr & ~1);
5457
}
5558

5659
/**
@@ -79,16 +82,19 @@ public void set_one_to_two(@Nullable DirectionalChannelInfo val) {
7982
/**
8083
* Source node of the second direction of a channel
8184
*/
82-
public byte[] get_node_two() {
83-
byte[] ret = bindings.ChannelInfo_get_node_two(this.ptr);
84-
return ret;
85+
public NodeId get_node_two() {
86+
long ret = bindings.ChannelInfo_get_node_two(this.ptr);
87+
if (ret >= 0 && ret < 1024) { return null; }
88+
NodeId ret_hu_conv = new NodeId(null, ret);
89+
ret_hu_conv.ptrs_to.add(this);
90+
return ret_hu_conv;
8591
}
8692

8793
/**
8894
* Source node of the second direction of a channel
8995
*/
90-
public void set_node_two(byte[] val) {
91-
bindings.ChannelInfo_set_node_two(this.ptr, val);
96+
public void set_node_two(NodeId val) {
97+
bindings.ChannelInfo_set_node_two(this.ptr, val == null ? 0 : val.ptr & ~1);
9298
}
9399

94100
/**
@@ -164,8 +170,8 @@ public void set_announcement_message(@Nullable ChannelAnnouncement val) {
164170
/**
165171
* Constructs a new ChannelInfo given each field
166172
*/
167-
public static ChannelInfo of(ChannelFeatures features_arg, byte[] node_one_arg, DirectionalChannelInfo one_to_two_arg, byte[] node_two_arg, DirectionalChannelInfo two_to_one_arg, Option_u64Z capacity_sats_arg, ChannelAnnouncement announcement_message_arg) {
168-
long ret = bindings.ChannelInfo_new(features_arg == null ? 0 : features_arg.ptr & ~1, node_one_arg, one_to_two_arg == null ? 0 : one_to_two_arg.ptr & ~1, node_two_arg, two_to_one_arg == null ? 0 : two_to_one_arg.ptr & ~1, capacity_sats_arg.ptr, announcement_message_arg == null ? 0 : announcement_message_arg.ptr & ~1);
173+
public static ChannelInfo of(ChannelFeatures features_arg, NodeId node_one_arg, DirectionalChannelInfo one_to_two_arg, NodeId node_two_arg, DirectionalChannelInfo two_to_one_arg, Option_u64Z capacity_sats_arg, ChannelAnnouncement announcement_message_arg) {
174+
long ret = bindings.ChannelInfo_new(features_arg == null ? 0 : features_arg.ptr & ~1, node_one_arg == null ? 0 : node_one_arg.ptr & ~1, one_to_two_arg == null ? 0 : one_to_two_arg.ptr & ~1, node_two_arg == null ? 0 : node_two_arg.ptr & ~1, two_to_one_arg == null ? 0 : two_to_one_arg.ptr & ~1, capacity_sats_arg.ptr, announcement_message_arg == null ? 0 : announcement_message_arg.ptr & ~1);
169175
if (ret >= 0 && ret < 1024) { return null; }
170176
ChannelInfo ret_hu_conv = new ChannelInfo(null, ret);
171177
ret_hu_conv.ptrs_to.add(ret_hu_conv);

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

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,28 +95,37 @@ public UserConfig get_current_default_configuration() {
9595
/**
9696
* Creates a new outbound channel to the given remote node and with the given value.
9797
*
98-
* user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
99-
* tracking of which events correspond with which create_channel call. Note that the
100-
* user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
101-
* user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
102-
* otherwise ignored.
98+
* `user_channel_id` will be provided back as in
99+
* [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
100+
* correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
101+
* for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
102+
* `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
103+
* ignored.
103104
*
104-
* If successful, will generate a SendOpenChannel message event, so you should probably poll
105-
* PeerManager::process_events afterwards.
106-
*
107-
* Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
108-
* greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
105+
* Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
106+
* greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
109107
*
110108
* Note that we do not check if you are currently connected to the given peer. If no
111109
* connection is available, the outbound `open_channel` message may fail to send, resulting in
112-
* the channel eventually being silently forgotten.
110+
* the channel eventually being silently forgotten (dropped on reload).
111+
*
112+
* Returns the new Channel's temporary `channel_id`. This ID will appear as
113+
* [`Event::FundingGenerationReady::temporary_channel_id`] and in
114+
* [`ChannelDetails::channel_id`] until after
115+
* [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
116+
* one derived from the funding transaction's TXID. If the counterparty rejects the channel
117+
* immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
118+
*
119+
* [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
120+
* [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
121+
* [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
113122
*
114123
* Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
115124
*/
116-
public Result_NoneAPIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_id, @Nullable UserConfig override_config) {
117-
long ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_id, override_config == null ? 0 : override_config.ptr & ~1);
125+
public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_channel_id, @Nullable UserConfig override_config) {
126+
long ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr & ~1);
118127
if (ret >= 0 && ret < 1024) { return null; }
119-
Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
128+
Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
120129
return ret_hu_conv;
121130
}
122131

@@ -272,9 +281,27 @@ public void force_close_all_channels() {
272281
*
273282
* Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
274283
*/
275-
public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
284+
public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
276285
long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_hash, payment_secret);
277286
if (ret >= 0 && ret < 1024) { return null; }
287+
Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
288+
this.ptrs_to.add(route);
289+
return ret_hu_conv;
290+
}
291+
292+
/**
293+
* Retries a payment along the given [`Route`].
294+
*
295+
* Errors returned are a superset of those returned from [`send_payment`], so see
296+
* [`send_payment`] documentation for more details on errors. This method will also error if the
297+
* retry amount puts the payment more than 10% over the payment's total amount, or if the payment
298+
* for the given `payment_id` cannot be found (likely due to timeout or success).
299+
*
300+
* [`send_payment`]: [`ChannelManager::send_payment`]
301+
*/
302+
public Result_NonePaymentSendFailureZ retry_payment(Route route, PaymentId payment_id) {
303+
long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_id == null ? 0 : payment_id.ptr & ~1);
304+
if (ret >= 0 && ret < 1024) { return null; }
278305
Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
279306
this.ptrs_to.add(route);
280307
return ret_hu_conv;
@@ -298,10 +325,10 @@ public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_h
298325
*
299326
* Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
300327
*/
301-
public Result_PaymentHashPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
328+
public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
302329
long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_preimage);
303330
if (ret >= 0 && ret < 1024) { return null; }
304-
Result_PaymentHashPaymentSendFailureZ ret_hu_conv = Result_PaymentHashPaymentSendFailureZ.constr_from_ptr(ret);
331+
Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
305332
this.ptrs_to.add(route);
306333
return ret_hu_conv;
307334
}

0 commit comments

Comments
 (0)