Skip to content

Commit 1d0c372

Browse files
author
Matt Corallo
committed
Update auto-generated files
1 parent b9db185 commit 1d0c372

Some content is hidden

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

41 files changed

+6084
-360
lines changed

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);

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

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,19 @@ public ChannelDetails[] list_usable_channels() {
164164
* will be accepted on the given channel, and after additional timeout/the closing of all
165165
* pending HTLCs, the channel will be closed on chain.
166166
*
167+
* If we are the channel initiator, we will pay between our [`Background`] and
168+
* [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
169+
* estimate.
170+
* If our counterparty is the channel initiator, we will require a channel closing
171+
* transaction feerate of at least our [`Background`] feerate or the feerate which
172+
* would appear on a force-closure transaction, whichever is lower. We will allow our
173+
* counterparty to pay as much fee as they'd like, however.
174+
*
167175
* May generate a SendShutdown message event on success, which should be relayed.
176+
*
177+
* [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
178+
* [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
179+
* [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
168180
*/
169181
public Result_NoneAPIErrorZ close_channel(byte[] channel_id) {
170182
long ret = bindings.ChannelManager_close_channel(this.ptr, channel_id);
@@ -173,6 +185,34 @@ public Result_NoneAPIErrorZ close_channel(byte[] channel_id) {
173185
return ret_hu_conv;
174186
}
175187

188+
/**
189+
* Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
190+
* will be accepted on the given channel, and after additional timeout/the closing of all
191+
* pending HTLCs, the channel will be closed on chain.
192+
*
193+
* `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
194+
* the channel being closed or not:
195+
* If we are the channel initiator, we will pay at least this feerate on the closing
196+
* transaction. The upper-bound is set by
197+
* [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
198+
* estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
199+
* If our counterparty is the channel initiator, we will refuse to accept a channel closure
200+
* transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
201+
* will appear on a force-closure transaction, whichever is lower).
202+
*
203+
* May generate a SendShutdown message event on success, which should be relayed.
204+
*
205+
* [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
206+
* [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
207+
* [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
208+
*/
209+
public Result_NoneAPIErrorZ close_channel_with_target_feerate(byte[] channel_id, int target_feerate_sats_per_1000_weight) {
210+
long ret = bindings.ChannelManager_close_channel_with_target_feerate(this.ptr, channel_id, target_feerate_sats_per_1000_weight);
211+
if (ret < 1024) { return null; }
212+
Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
213+
return ret_hu_conv;
214+
}
215+
176216
/**
177217
* Force closes a channel, immediately broadcasting the latest local commitment transaction to
178218
* the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
@@ -243,6 +283,32 @@ public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_h
243283
return ret_hu_conv;
244284
}
245285

286+
/**
287+
* Send a spontaneous payment, which is a payment that does not require the recipient to have
288+
* generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
289+
* the preimage, it must be a cryptographically secure random value that no intermediate node
290+
* would be able to guess -- otherwise, an intermediate node may claim the payment and it will
291+
* never reach the recipient.
292+
*
293+
* See [`send_payment`] documentation for more details on the return value of this function.
294+
*
295+
* Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
296+
* [`send_payment`] for more information about the risks of duplicate preimage usage.
297+
*
298+
* Note that `route` must have exactly one path.
299+
*
300+
* [`send_payment`]: Self::send_payment
301+
*
302+
* Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
303+
*/
304+
public Result_PaymentHashPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
305+
long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_preimage);
306+
if (ret < 1024) { return null; }
307+
Result_PaymentHashPaymentSendFailureZ ret_hu_conv = Result_PaymentHashPaymentSendFailureZ.constr_from_ptr(ret);
308+
this.ptrs_to.add(route);
309+
return ret_hu_conv;
310+
}
311+
246312
/**
247313
* Call this upon creation of a funding transaction for the given channel.
248314
*
@@ -308,13 +374,16 @@ public void process_pending_htlc_forwards() {
308374
}
309375

310376
/**
311-
* If a peer is disconnected we mark any channels with that peer as 'disabled'.
312-
* After some time, if channels are still disabled we need to broadcast a ChannelUpdate
313-
* to inform the network about the uselessness of these channels.
377+
* Performs actions which should happen on startup and roughly once per minute thereafter.
314378
*
315-
* This method handles all the details, and must be called roughly once per minute.
379+
* This currently includes:
380+
* Increasing or decreasing the on-chain feerate estimates for our outbound channels,
381+
* Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
382+
* than a minute, informing the network that they should no longer attempt to route over
383+
* the channel.
316384
*
317-
* Note that in some rare cases this may generate a `chain::Watch::update_channel` call.
385+
* Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
386+
* estimate fetches.
318387
*/
319388
public void timer_tick_occurred() {
320389
bindings.ChannelManager_timer_tick_occurred(this.ptr);
@@ -427,7 +496,7 @@ public TwoTuple<byte[], byte[]> create_inbound_payment(Option_u64Z min_value_msa
427496
* The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) must be globally unique. This
428497
* method may return an Err if another payment with the same payment_hash is still pending.
429498
*
430-
* `user_payment_id` will be provided back in [`PaymentReceived::user_payment_id`] events to
499+
* `user_payment_id` will be provided back in [`PaymentPurpose::InvoicePayment::user_payment_id`] events to
431500
* allow tracking of which events correspond with which calls to this and
432501
* [`create_inbound_payment`]. `user_payment_id` has no meaning inside of LDK, it is simply
433502
* copied to events and otherwise ignored. It may be used to correlate PaymentReceived events
@@ -461,7 +530,7 @@ public TwoTuple<byte[], byte[]> create_inbound_payment(Option_u64Z min_value_msa
461530
*
462531
* [`create_inbound_payment`]: Self::create_inbound_payment
463532
* [`PaymentReceived`]: events::Event::PaymentReceived
464-
* [`PaymentReceived::user_payment_id`]: events::Event::PaymentReceived::user_payment_id
533+
* [`PaymentPurpose::InvoicePayment::user_payment_id`]: events::PaymentPurpose::InvoicePayment::user_payment_id
465534
*/
466535
public Result_PaymentSecretAPIErrorZ create_inbound_payment_for_hash(byte[] payment_hash, Option_u64Z min_value_msat, int invoice_expiry_delta_secs, long user_payment_id) {
467536
long ret = bindings.ChannelManager_create_inbound_payment_for_hash(this.ptr, payment_hash, min_value_msat.ptr, invoice_expiry_delta_secs, user_payment_id);

0 commit comments

Comments
 (0)