Skip to content

Commit d92b9f2

Browse files
authored
Merge pull request #39 from TheBlueMatt/main
v0.0.100.0
2 parents db1a110 + 1d0c372 commit d92b9f2

Some content is hidden

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

47 files changed

+6096
-369
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 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.99
38+
git checkout 0.0.100
3939
- name: Rebuild C bindings without STD for WASM
4040
run: |
4141
cd ldk-c-bindings
@@ -163,7 +163,7 @@ jobs:
163163
cd ..
164164
git clone https://github.com/lightningdevkit/ldk-c-bindings
165165
cd ldk-c-bindings
166-
git checkout 0.0.99
166+
git checkout 0.0.100
167167
- name: Detect current git version
168168
run: |
169169
# We assume the top commit is just a bindings update commit, so we
@@ -243,7 +243,7 @@ jobs:
243243
cd ..
244244
git clone https://github.com/lightningdevkit/ldk-c-bindings
245245
cd ldk-c-bindings
246-
git checkout 0.0.99
246+
git checkout 0.0.100
247247
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
248248
run: |
249249
cd ldk-c-bindings

gen_type_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_re
297297
if not is_free:
298298
needs_full_clone = not is_free and (not ty_info.is_ptr and not holds_ref or ty_info.requires_clone == True) and ty_info.requires_clone != False
299299
if needs_full_clone and (ty_info.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns:
300-
base_conv = base_conv + "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(" + ty_info.var_name + ");"
300+
base_conv = base_conv + "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(&" + ty_info.var_name + "_conv);"
301301
else:
302302
base_conv = base_conv + self.consts.trait_struct_inc_refcnt(ty_info)
303303
if needs_full_clone:

java_strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ def native_c_map_trait(self, struct_name, field_vars, flattened_field_vars, fiel
849849
elif not fn_line.ret_ty_info.passed_as_ptr:
850850
out_c += "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
851851
else:
852-
out_c = out_c + "\t" + fn_line.ret_ty_info.rust_obj + "* ret = (" + fn_line.ret_ty_info.rust_obj + "*)(*env)->CallLongMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
852+
out_c = out_c + "\tuint64_t ret = (*env)->CallLongMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
853853

854854
for idx, arg_info in enumerate(fn_line.args_ty):
855855
if arg_info.ret_conv is not None:

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

Lines changed: 163 additions & 14 deletions
Large diffs are not rendered by default.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ static APIError constr_from_ptr(long ptr) {
3636
if (raw_val.getClass() == bindings.LDKAPIError.MonitorUpdateFailed.class) {
3737
return new MonitorUpdateFailed(ptr, (bindings.LDKAPIError.MonitorUpdateFailed)raw_val);
3838
}
39+
if (raw_val.getClass() == bindings.LDKAPIError.IncompatibleShutdownScript.class) {
40+
return new IncompatibleShutdownScript(ptr, (bindings.LDKAPIError.IncompatibleShutdownScript)raw_val);
41+
}
3942
assert false; return null; // Unreachable without extending the (internal) bindings interface
4043
}
4144

@@ -89,6 +92,19 @@ private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed o
8992
super(null, ptr);
9093
}
9194
}
95+
public final static class IncompatibleShutdownScript extends APIError {
96+
/**
97+
* The incompatible shutdown script.
98+
*/
99+
public final ShutdownScript script;
100+
private IncompatibleShutdownScript(long ptr, bindings.LDKAPIError.IncompatibleShutdownScript obj) {
101+
super(null, ptr);
102+
long script = obj.script;
103+
ShutdownScript script_hu_conv = new ShutdownScript(null, script);
104+
script_hu_conv.ptrs_to.add(this);
105+
this.script = script_hu_conv;
106+
}
107+
}
92108
/**
93109
* Creates a copy of the APIError
94110
*/
@@ -155,4 +171,16 @@ public static APIError monitor_update_failed() {
155171
return ret_hu_conv;
156172
}
157173

174+
/**
175+
* Utility method to constructs a new IncompatibleShutdownScript-variant APIError
176+
*/
177+
public static APIError incompatible_shutdown_script(ShutdownScript script) {
178+
long ret = bindings.APIError_incompatible_shutdown_script(script == null ? 0 : script.ptr & ~1);
179+
if (ret < 1024) { return null; }
180+
APIError ret_hu_conv = APIError.constr_from_ptr(ret);
181+
ret_hu_conv.ptrs_to.add(ret_hu_conv);
182+
ret_hu_conv.ptrs_to.add(script);
183+
return ret_hu_conv;
184+
}
185+
158186
}

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

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* then there is a risk of channels force-closing on startup when the manager realizes it's
2323
* outdated. However, as long as `ChannelMonitor` backups are sound, no funds besides those used
2424
* for unilateral chain closure fees are at risk.
25+
* BackgroundProcessor will immediately stop on drop. It should be stored until shutdown.
2526
*/
2627
@SuppressWarnings("unchecked") // We correctly assign various generic arrays
2728
public class BackgroundProcessor extends CommonBase {
@@ -33,21 +34,25 @@ protected void finalize() throws Throwable {
3334
}
3435

3536
/**
36-
* Start a background thread that takes care of responsibilities enumerated in the top-level
37-
* documentation.
37+
* Start a background thread that takes care of responsibilities enumerated in the [top-level
38+
* documentation].
3839
*
39-
* If `persist_manager` returns an error, then this thread will return said error (and
40-
* `start()` will need to be called again to restart the `BackgroundProcessor`). Users should
41-
* wait on [`thread_handle`]'s `join()` method to be able to tell if and when an error is
42-
* returned, or implement `persist_manager` such that an error is never returned to the
43-
* `BackgroundProcessor`
40+
* The thread runs indefinitely unless the object is dropped, [`stop`] is called, or
41+
* `persist_manager` returns an error. In case of an error, the error is retrieved by calling
42+
* either [`join`] or [`stop`].
43+
*
44+
* Typically, users should either implement [`ChannelManagerPersister`] to never return an
45+
* error or call [`join`] and handle any error that may arise. For the latter case, the
46+
* `BackgroundProcessor` must be restarted by calling `start` again after handling the error.
4447
*
4548
* `persist_manager` is responsible for writing out the [`ChannelManager`] to disk, and/or
4649
* uploading to one or more backup services. See [`ChannelManager::write`] for writing out a
4750
* [`ChannelManager`]. See [`FilesystemPersister::persist_manager`] for Rust-Lightning's
4851
* provided implementation.
4952
*
50-
* [`thread_handle`]: BackgroundProcessor::thread_handle
53+
* [top-level documentation]: Self
54+
* [`join`]: Self::join
55+
* [`stop`]: Self::stop
5156
* [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
5257
* [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
5358
* [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
@@ -67,7 +72,42 @@ public static BackgroundProcessor start(ChannelManagerPersister persister, Event
6772
}
6873

6974
/**
70-
* Stop `BackgroundProcessor`'s thread.
75+
* Join `BackgroundProcessor`'s thread, returning any error that occurred while persisting
76+
* [`ChannelManager`].
77+
*
78+
* # Panics
79+
*
80+
* This function panics if the background thread has panicked such as while persisting or
81+
* handling events.
82+
*
83+
* [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
84+
*/
85+
public Result_NoneErrorZ join() {
86+
long ret = bindings.BackgroundProcessor_join(this.ptr);
87+
if (ret < 1024) { return null; }
88+
Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
89+
this.ptrs_to.add(this);
90+
// Due to rust's strict-ownership memory model, in some cases we need to "move"
91+
// an object to pass exclusive ownership to the function being called.
92+
// In most cases, we avoid this being visible in GC'd languages by cloning the object
93+
// at the FFI layer, creating a new object which Rust can claim ownership of
94+
// However, in some cases (eg here), there is no way to clone an object, and thus
95+
// we actually have to pass full ownership to Rust.
96+
// Thus, after this call, this is reset to null and is now a dummy object.
97+
this.ptr = 0;
98+
return ret_hu_conv;
99+
}
100+
101+
/**
102+
* Stop `BackgroundProcessor`'s thread, returning any error that occurred while persisting
103+
* [`ChannelManager`].
104+
*
105+
* # Panics
106+
*
107+
* This function panics if the background thread has panicked such as while persisting or
108+
* handling events.
109+
*
110+
* [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
71111
*/
72112
public Result_NoneErrorZ stop() {
73113
long ret = bindings.BackgroundProcessor_stop(this.ptr);

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

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,111 @@ public void set_commit_upfront_shutdown_pubkey(boolean val) {
203203
bindings.ChannelConfig_set_commit_upfront_shutdown_pubkey(this.ptr, val);
204204
}
205205

206+
/**
207+
* Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
208+
* small to claim on-chain.
209+
*
210+
* When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
211+
* not be claimable on-chain, instead being turned into additional miner fees if either
212+
* party force-closes the channel. Because the threshold is per-HTLC, our total exposure
213+
* to such payments may be sustantial if there are many dust HTLCs present when the
214+
* channel is force-closed.
215+
*
216+
* This limit is applied for sent, forwarded, and received HTLCs and limits the total
217+
* exposure across all three types per-channel. Setting this too low may prevent the
218+
* sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
219+
* important to prevent stealing of dust HTLCs by miners.
220+
*
221+
* Default value: 5_000_000 msat.
222+
*/
223+
public long get_max_dust_htlc_exposure_msat() {
224+
long ret = bindings.ChannelConfig_get_max_dust_htlc_exposure_msat(this.ptr);
225+
return ret;
226+
}
227+
228+
/**
229+
* Limit our total exposure to in-flight HTLCs which are burned to fees as they are too
230+
* small to claim on-chain.
231+
*
232+
* When an HTLC present in one of our channels is below a \"dust\" threshold, the HTLC will
233+
* not be claimable on-chain, instead being turned into additional miner fees if either
234+
* party force-closes the channel. Because the threshold is per-HTLC, our total exposure
235+
* to such payments may be sustantial if there are many dust HTLCs present when the
236+
* channel is force-closed.
237+
*
238+
* This limit is applied for sent, forwarded, and received HTLCs and limits the total
239+
* exposure across all three types per-channel. Setting this too low may prevent the
240+
* sending or receipt of low-value HTLCs on high-traffic nodes, and this limit is very
241+
* important to prevent stealing of dust HTLCs by miners.
242+
*
243+
* Default value: 5_000_000 msat.
244+
*/
245+
public void set_max_dust_htlc_exposure_msat(long val) {
246+
bindings.ChannelConfig_set_max_dust_htlc_exposure_msat(this.ptr, val);
247+
}
248+
249+
/**
250+
* The additional fee we're willing to pay to avoid waiting for the counterparty's
251+
* `to_self_delay` to reclaim funds.
252+
*
253+
* When we close a channel cooperatively with our counterparty, we negotiate a fee for the
254+
* closing transaction which both sides find acceptable, ultimately paid by the channel
255+
* funder/initiator.
256+
*
257+
* When we are the funder, because we have to pay the channel closing fee, we bound the
258+
* acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
259+
* this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
260+
* [`Normal`] feerate during normal operation, this value represents the additional fee we're
261+
* willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
262+
* funds.
263+
*
264+
* When we are not the funder, we require the closing transaction fee pay at least our
265+
* [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
266+
* Thus, this value is ignored when we are not the funder.
267+
*
268+
* Default value: 1000 satoshis.
269+
*
270+
* [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
271+
* [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
272+
*/
273+
public long get_force_close_avoidance_max_fee_satoshis() {
274+
long ret = bindings.ChannelConfig_get_force_close_avoidance_max_fee_satoshis(this.ptr);
275+
return ret;
276+
}
277+
278+
/**
279+
* The additional fee we're willing to pay to avoid waiting for the counterparty's
280+
* `to_self_delay` to reclaim funds.
281+
*
282+
* When we close a channel cooperatively with our counterparty, we negotiate a fee for the
283+
* closing transaction which both sides find acceptable, ultimately paid by the channel
284+
* funder/initiator.
285+
*
286+
* When we are the funder, because we have to pay the channel closing fee, we bound the
287+
* acceptable fee by our [`Background`] and [`Normal`] fees, with the upper bound increased by
288+
* this value. Because the on-chain fee we'd pay to force-close the channel is kept near our
289+
* [`Normal`] feerate during normal operation, this value represents the additional fee we're
290+
* willing to pay in order to avoid waiting for our counterparty's to_self_delay to reclaim our
291+
* funds.
292+
*
293+
* When we are not the funder, we require the closing transaction fee pay at least our
294+
* [`Background`] fee estimate, but allow our counterparty to pay as much fee as they like.
295+
* Thus, this value is ignored when we are not the funder.
296+
*
297+
* Default value: 1000 satoshis.
298+
*
299+
* [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
300+
* [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
301+
*/
302+
public void set_force_close_avoidance_max_fee_satoshis(long val) {
303+
bindings.ChannelConfig_set_force_close_avoidance_max_fee_satoshis(this.ptr, val);
304+
}
305+
206306
/**
207307
* Constructs a new ChannelConfig given each field
208308
*/
209-
public static ChannelConfig of(int forwarding_fee_proportional_millionths_arg, int forwarding_fee_base_msat_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg) {
210-
long ret = bindings.ChannelConfig_new(forwarding_fee_proportional_millionths_arg, forwarding_fee_base_msat_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
309+
public static ChannelConfig of(int forwarding_fee_proportional_millionths_arg, int forwarding_fee_base_msat_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg, long max_dust_htlc_exposure_msat_arg, long force_close_avoidance_max_fee_satoshis_arg) {
310+
long ret = bindings.ChannelConfig_new(forwarding_fee_proportional_millionths_arg, forwarding_fee_base_msat_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg, max_dust_htlc_exposure_msat_arg, force_close_avoidance_max_fee_satoshis_arg);
211311
if (ret < 1024) { return null; }
212312
ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
213313
ret_hu_conv.ptrs_to.add(ret_hu_conv);

0 commit comments

Comments
 (0)