1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Manager which keeps track of a number of channels and sends messages to the appropriate
13 * channel, also tracking HTLC preimages and forwarding onion packets appropriately.
15 * Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
16 * to individual Channels.
18 * Implements Writeable to write out all channel state to disk. Implies peer_disconnected() for
19 * all peers during write/read (though does not modify this instance, only the instance being
20 * serialized). This will result in any channels which have not yet exchanged funding_created (ie
21 * called funding_transaction_generated for outbound channels).
23 * Note that you can be a bit lazier about writing out ChannelManager than you can be with
24 * ChannelMonitors. With ChannelMonitors you MUST write each monitor update out to disk before
25 * returning from chain::Watch::watch_/update_channel, with ChannelManagers, writing updates
26 * happens out-of-band (and will prevent any other ChannelManager operations from occurring during
27 * the serialization process). If the deserialized version is out-of-date compared to the
28 * ChannelMonitors passed by reference to read(), those channels will be force-closed based on the
29 * ChannelMonitor state and no funds will be lost (mod on-chain transaction fees).
31 * Note that the deserializer is only implemented for (BlockHash, ChannelManager), which
32 * tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
33 * the \"reorg path\" (ie call block_disconnected() until you get to a common block and then call
34 * block_connected() to step towards your best block) upon deserialization before using the
37 * Note that ChannelManager is responsible for tracking liveness of its channels and generating
38 * ChannelUpdate messages informing peers that the channel is temporarily disabled. To avoid
39 * spam due to quick disconnection/reconnection, updates are not sent until the channel has been
40 * offline for a full minute. In order to track this, you must call
41 * timer_tick_occurred roughly once per minute, though it doesn't have to be perfect.
43 * Rather than using a plain ChannelManager, it is preferable to use either a SimpleArcChannelManager
44 * a SimpleRefChannelManager, for conciseness. See their documentation for more details, but
45 * essentially you should default to using a SimpleRefChannelManager, and use a
46 * SimpleArcChannelManager when you require a ChannelManager with a static lifetime, such as when
47 * you're using lightning-net-tokio.
49 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
50 public class ChannelManager extends CommonBase {
51 ChannelManager(Object _dummy, long ptr) { super(ptr); }
52 @Override @SuppressWarnings("deprecation")
53 protected void finalize() throws Throwable {
55 if (ptr != 0) { bindings.ChannelManager_free(ptr); }
59 * Constructs a new ChannelManager to hold several channels and route between them.
61 * This is the main \"logic hub\" for all channel-related actions, and implements
62 * ChannelMessageHandler.
64 * Non-proportional fees are fixed according to our risk using the provided fee estimator.
66 * panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
68 * Users need to notify the new ChannelManager when a new block is connected or
69 * disconnected using its `block_connected` and `block_disconnected` methods, starting
70 * from after `params.latest_hash`.
72 public static ChannelManager of(FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, ChainParameters params) {
73 long ret = bindings.ChannelManager_new(fee_est == null ? 0 : fee_est.ptr, chain_monitor == null ? 0 : chain_monitor.ptr, tx_broadcaster == null ? 0 : tx_broadcaster.ptr, logger == null ? 0 : logger.ptr, keys_manager == null ? 0 : keys_manager.ptr, config == null ? 0 : config.ptr & ~1, params == null ? 0 : params.ptr & ~1);
74 Reference.reachabilityFence(fee_est);
75 Reference.reachabilityFence(chain_monitor);
76 Reference.reachabilityFence(tx_broadcaster);
77 Reference.reachabilityFence(logger);
78 Reference.reachabilityFence(keys_manager);
79 Reference.reachabilityFence(config);
80 Reference.reachabilityFence(params);
81 if (ret >= 0 && ret <= 4096) { return null; }
82 ChannelManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelManager(null, ret); }
83 ret_hu_conv.ptrs_to.add(ret_hu_conv);
84 ret_hu_conv.ptrs_to.add(fee_est);
85 ret_hu_conv.ptrs_to.add(chain_monitor);
86 ret_hu_conv.ptrs_to.add(tx_broadcaster);
87 ret_hu_conv.ptrs_to.add(logger);
88 ret_hu_conv.ptrs_to.add(keys_manager);
93 * Gets the current configuration applied to all new channels, as
95 public UserConfig get_current_default_configuration() {
96 long ret = bindings.ChannelManager_get_current_default_configuration(this.ptr);
97 Reference.reachabilityFence(this);
98 if (ret >= 0 && ret <= 4096) { return null; }
99 UserConfig ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new UserConfig(null, ret); }
100 ret_hu_conv.ptrs_to.add(this);
105 * Creates a new outbound channel to the given remote node and with the given value.
107 * `user_channel_id` will be provided back as in
108 * [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
109 * correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
110 * for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
111 * `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
114 * Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
115 * greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
117 * Note that we do not check if you are currently connected to the given peer. If no
118 * connection is available, the outbound `open_channel` message may fail to send, resulting in
119 * the channel eventually being silently forgotten (dropped on reload).
121 * Returns the new Channel's temporary `channel_id`. This ID will appear as
122 * [`Event::FundingGenerationReady::temporary_channel_id`] and in
123 * [`ChannelDetails::channel_id`] until after
124 * [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
125 * one derived from the funding transaction's TXID. If the counterparty rejects the channel
126 * immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
128 * [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
129 * [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
130 * [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
132 * Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
134 public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_channel_id, @Nullable UserConfig override_config) {
135 long ret = bindings.ChannelManager_create_channel(this.ptr, InternalUtils.check_arr_len(their_network_key, 33), channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr & ~1);
136 Reference.reachabilityFence(this);
137 Reference.reachabilityFence(their_network_key);
138 Reference.reachabilityFence(channel_value_satoshis);
139 Reference.reachabilityFence(push_msat);
140 Reference.reachabilityFence(user_channel_id);
141 Reference.reachabilityFence(override_config);
142 if (ret >= 0 && ret <= 4096) { return null; }
143 Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
148 * Gets the list of open channels, in random order. See ChannelDetail field documentation for
151 public ChannelDetails[] list_channels() {
152 long[] ret = bindings.ChannelManager_list_channels(this.ptr);
153 Reference.reachabilityFence(this);
154 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
155 for (int q = 0; q < ret.length; q++) {
156 long ret_conv_16 = ret[q];
157 ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new ChannelDetails(null, ret_conv_16); }
158 ret_conv_16_hu_conv.ptrs_to.add(this);
159 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
161 return ret_conv_16_arr;
165 * Gets the list of usable channels, in random order. Useful as an argument to
166 * get_route to ensure non-announced channels are used.
168 * These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
169 * documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
172 public ChannelDetails[] list_usable_channels() {
173 long[] ret = bindings.ChannelManager_list_usable_channels(this.ptr);
174 Reference.reachabilityFence(this);
175 ChannelDetails[] ret_conv_16_arr = new ChannelDetails[ret.length];
176 for (int q = 0; q < ret.length; q++) {
177 long ret_conv_16 = ret[q];
178 ChannelDetails ret_conv_16_hu_conv = null; if (ret_conv_16 < 0 || ret_conv_16 > 4096) { ret_conv_16_hu_conv = new ChannelDetails(null, ret_conv_16); }
179 ret_conv_16_hu_conv.ptrs_to.add(this);
180 ret_conv_16_arr[q] = ret_conv_16_hu_conv;
182 return ret_conv_16_arr;
186 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
187 * will be accepted on the given channel, and after additional timeout/the closing of all
188 * pending HTLCs, the channel will be closed on chain.
190 * If we are the channel initiator, we will pay between our [`Background`] and
191 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
193 * If our counterparty is the channel initiator, we will require a channel closing
194 * transaction feerate of at least our [`Background`] feerate or the feerate which
195 * would appear on a force-closure transaction, whichever is lower. We will allow our
196 * counterparty to pay as much fee as they'd like, however.
198 * May generate a SendShutdown message event on success, which should be relayed.
200 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
201 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
202 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
204 public Result_NoneAPIErrorZ close_channel(byte[] channel_id) {
205 long ret = bindings.ChannelManager_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32));
206 Reference.reachabilityFence(this);
207 Reference.reachabilityFence(channel_id);
208 if (ret >= 0 && ret <= 4096) { return null; }
209 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
214 * Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
215 * will be accepted on the given channel, and after additional timeout/the closing of all
216 * pending HTLCs, the channel will be closed on chain.
218 * `target_feerate_sat_per_1000_weight` has different meanings depending on if we initiated
219 * the channel being closed or not:
220 * If we are the channel initiator, we will pay at least this feerate on the closing
221 * transaction. The upper-bound is set by
222 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`] plus our [`Normal`] fee
223 * estimate (or `target_feerate_sat_per_1000_weight`, if it is greater).
224 * If our counterparty is the channel initiator, we will refuse to accept a channel closure
225 * transaction feerate below `target_feerate_sat_per_1000_weight` (or the feerate which
226 * will appear on a force-closure transaction, whichever is lower).
228 * May generate a SendShutdown message event on success, which should be relayed.
230 * [`ChannelConfig::force_close_avoidance_max_fee_satoshis`]: crate::util::config::ChannelConfig::force_close_avoidance_max_fee_satoshis
231 * [`Background`]: crate::chain::chaininterface::ConfirmationTarget::Background
232 * [`Normal`]: crate::chain::chaininterface::ConfirmationTarget::Normal
234 public Result_NoneAPIErrorZ close_channel_with_target_feerate(byte[] channel_id, int target_feerate_sats_per_1000_weight) {
235 long ret = bindings.ChannelManager_close_channel_with_target_feerate(this.ptr, InternalUtils.check_arr_len(channel_id, 32), target_feerate_sats_per_1000_weight);
236 Reference.reachabilityFence(this);
237 Reference.reachabilityFence(channel_id);
238 Reference.reachabilityFence(target_feerate_sats_per_1000_weight);
239 if (ret >= 0 && ret <= 4096) { return null; }
240 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
245 * Force closes a channel, immediately broadcasting the latest local commitment transaction to
246 * the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
248 public Result_NoneAPIErrorZ force_close_channel(byte[] channel_id) {
249 long ret = bindings.ChannelManager_force_close_channel(this.ptr, InternalUtils.check_arr_len(channel_id, 32));
250 Reference.reachabilityFence(this);
251 Reference.reachabilityFence(channel_id);
252 if (ret >= 0 && ret <= 4096) { return null; }
253 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
258 * Force close all channels, immediately broadcasting the latest local commitment transaction
259 * for each to the chain and rejecting new HTLCs on each.
261 public void force_close_all_channels() {
262 bindings.ChannelManager_force_close_all_channels(this.ptr);
263 Reference.reachabilityFence(this);
267 * Sends a payment along a given route.
269 * Value parameters are provided via the last hop in route, see documentation for RouteHop
270 * fields for more info.
272 * Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
273 * payment), we don't do anything to stop you! We always try to ensure that if the provided
274 * next hop knows the preimage to payment_hash they can claim an additional amount as
275 * specified in the last hop in the route! Thus, you should probably do your own
276 * payment_preimage tracking (which you should already be doing as they represent \"proof of
277 * payment\") and prevent double-sends yourself.
279 * May generate SendHTLCs message(s) event on success, which should be relayed.
281 * Each path may have a different return value, and PaymentSendValue may return a Vec with
282 * each entry matching the corresponding-index entry in the route paths, see
283 * PaymentSendFailure for more info.
285 * In general, a path may raise:
286 * APIError::RouteError when an invalid route or forwarding parameter (cltv_delta, fee,
287 * node public key) is specified.
288 * APIError::ChannelUnavailable if the next-hop channel is not available for updates
289 * (including due to previous monitor update failure or new permanent monitor update
291 * APIError::MonitorUpdateFailed if a new monitor update failure prevented sending the
294 * Note that depending on the type of the PaymentSendFailure the HTLC may have been
295 * irrevocably committed to on our end. In such a case, do NOT retry the payment with a
296 * different route unless you intend to pay twice!
298 * payment_secret is unrelated to payment_hash (or PaymentPreimage) and exists to authenticate
299 * the sender to the recipient and prevent payment-probing (deanonymization) attacks. For
300 * newer nodes, it will be provided to you in the invoice. If you do not have one, the Route
301 * must not contain multiple paths as multi-path payments require a recipient-provided
303 * If a payment_secret *is* provided, we assume that the invoice had the payment_secret feature
304 * bit set (either as required or as available). If multiple paths are present in the Route,
305 * we assume the invoice had the basic_mpp feature set.
307 * Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
309 public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
310 long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
311 Reference.reachabilityFence(this);
312 Reference.reachabilityFence(route);
313 Reference.reachabilityFence(payment_hash);
314 Reference.reachabilityFence(payment_secret);
315 if (ret >= 0 && ret <= 4096) { return null; }
316 Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
317 this.ptrs_to.add(route);
322 * Retries a payment along the given [`Route`].
324 * Errors returned are a superset of those returned from [`send_payment`], so see
325 * [`send_payment`] documentation for more details on errors. This method will also error if the
326 * retry amount puts the payment more than 10% over the payment's total amount, if the payment
327 * for the given `payment_id` cannot be found (likely due to timeout or success), or if
328 * further retries have been disabled with [`abandon_payment`].
330 * [`send_payment`]: [`ChannelManager::send_payment`]
331 * [`abandon_payment`]: [`ChannelManager::abandon_payment`]
333 public Result_NonePaymentSendFailureZ retry_payment(Route route, byte[] payment_id) {
334 long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_id, 32));
335 Reference.reachabilityFence(this);
336 Reference.reachabilityFence(route);
337 Reference.reachabilityFence(payment_id);
338 if (ret >= 0 && ret <= 4096) { return null; }
339 Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
340 this.ptrs_to.add(route);
345 * Signals that no further retries for the given payment will occur.
347 * After this method returns, any future calls to [`retry_payment`] for the given `payment_id`
348 * will fail with [`PaymentSendFailure::ParameterError`]. If no such event has been generated,
349 * an [`Event::PaymentFailed`] event will be generated as soon as there are no remaining
350 * pending HTLCs for this payment.
352 * Note that calling this method does *not* prevent a payment from succeeding. You must still
353 * wait until you receive either a [`Event::PaymentFailed`] or [`Event::PaymentSent`] event to
354 * determine the ultimate status of a payment.
356 * [`retry_payment`]: Self::retry_payment
357 * [`Event::PaymentFailed`]: events::Event::PaymentFailed
358 * [`Event::PaymentSent`]: events::Event::PaymentSent
360 public void abandon_payment(byte[] payment_id) {
361 bindings.ChannelManager_abandon_payment(this.ptr, InternalUtils.check_arr_len(payment_id, 32));
362 Reference.reachabilityFence(this);
363 Reference.reachabilityFence(payment_id);
367 * Send a spontaneous payment, which is a payment that does not require the recipient to have
368 * generated an invoice. Optionally, you may specify the preimage. If you do choose to specify
369 * the preimage, it must be a cryptographically secure random value that no intermediate node
370 * would be able to guess -- otherwise, an intermediate node may claim the payment and it will
371 * never reach the recipient.
373 * See [`send_payment`] documentation for more details on the return value of this function.
375 * Similar to regular payments, you MUST NOT reuse a `payment_preimage` value. See
376 * [`send_payment`] for more information about the risks of duplicate preimage usage.
378 * Note that `route` must have exactly one path.
380 * [`send_payment`]: Self::send_payment
382 * Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
384 public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
385 long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, InternalUtils.check_arr_len(payment_preimage, 32));
386 Reference.reachabilityFence(this);
387 Reference.reachabilityFence(route);
388 Reference.reachabilityFence(payment_preimage);
389 if (ret >= 0 && ret <= 4096) { return null; }
390 Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
391 this.ptrs_to.add(route);
396 * Call this upon creation of a funding transaction for the given channel.
398 * Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
399 * or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
401 * Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
402 * for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
404 * May panic if the output found in the funding transaction is duplicative with some other
405 * channel (note that this should be trivially prevented by using unique funding transaction
408 * Do NOT broadcast the funding transaction yourself. When we have safely received our
409 * counterparty's signature the funding transaction will automatically be broadcast via the
410 * [`BroadcasterInterface`] provided when this `ChannelManager` was constructed.
412 * Note that this includes RBF or similar transaction replacement strategies - lightning does
413 * not currently support replacing a funding transaction on an existing channel. Instead,
414 * create a new channel with a conflicting funding transaction.
416 * [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
417 * [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
419 public Result_NoneAPIErrorZ funding_transaction_generated(byte[] temporary_channel_id, byte[] funding_transaction) {
420 long ret = bindings.ChannelManager_funding_transaction_generated(this.ptr, InternalUtils.check_arr_len(temporary_channel_id, 32), funding_transaction);
421 Reference.reachabilityFence(this);
422 Reference.reachabilityFence(temporary_channel_id);
423 Reference.reachabilityFence(funding_transaction);
424 if (ret >= 0 && ret <= 4096) { return null; }
425 Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
430 * Regenerates channel_announcements and generates a signed node_announcement from the given
431 * arguments, providing them in corresponding events via
432 * [`get_and_clear_pending_msg_events`], if at least one public channel has been confirmed
433 * on-chain. This effectively re-broadcasts all channel announcements and sends our node
434 * announcement to ensure that the lightning P2P network is aware of the channels we have and
435 * our network addresses.
437 * `rgb` is a node \"color\" and `alias` is a printable human-readable string to describe this
438 * node to humans. They carry no in-protocol meaning.
440 * `addresses` represent the set (possibly empty) of socket addresses on which this node
441 * accepts incoming connections. These will be included in the node_announcement, publicly
442 * tying these addresses together and to this node. If you wish to preserve user privacy,
443 * addresses should likely contain only Tor Onion addresses.
445 * Panics if `addresses` is absurdly large (more than 500).
447 * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
449 public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) {
450 bindings.ChannelManager_broadcast_node_announcement(this.ptr, InternalUtils.check_arr_len(rgb, 3), InternalUtils.check_arr_len(alias, 32), addresses != null ? Arrays.stream(addresses).mapToLong(addresses_conv_12 -> addresses_conv_12.ptr).toArray() : null);
451 Reference.reachabilityFence(this);
452 Reference.reachabilityFence(rgb);
453 Reference.reachabilityFence(alias);
454 Reference.reachabilityFence(addresses);
458 * Processes HTLCs which are pending waiting on random forward delay.
460 * Should only really ever be called in response to a PendingHTLCsForwardable event.
461 * Will likely generate further events.
463 public void process_pending_htlc_forwards() {
464 bindings.ChannelManager_process_pending_htlc_forwards(this.ptr);
465 Reference.reachabilityFence(this);
469 * Performs actions which should happen on startup and roughly once per minute thereafter.
471 * This currently includes:
472 * Increasing or decreasing the on-chain feerate estimates for our outbound channels,
473 * Broadcasting `ChannelUpdate` messages if we've been disconnected from our peer for more
474 * than a minute, informing the network that they should no longer attempt to route over
477 * Note that this may cause reentrancy through `chain::Watch::update_channel` calls or feerate
480 public void timer_tick_occurred() {
481 bindings.ChannelManager_timer_tick_occurred(this.ptr);
482 Reference.reachabilityFence(this);
486 * Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
487 * after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
488 * along the path (including in our own channel on which we received it).
489 * Returns false if no payment was found to fail backwards, true if the process of failing the
490 * HTLC backwards has been started.
492 public boolean fail_htlc_backwards(byte[] payment_hash) {
493 boolean ret = bindings.ChannelManager_fail_htlc_backwards(this.ptr, InternalUtils.check_arr_len(payment_hash, 32));
494 Reference.reachabilityFence(this);
495 Reference.reachabilityFence(payment_hash);
500 * Provides a payment preimage in response to [`Event::PaymentReceived`], generating any
501 * [`MessageSendEvent`]s needed to claim the payment.
503 * Note that if you did not set an `amount_msat` when calling [`create_inbound_payment`] or
504 * [`create_inbound_payment_for_hash`] you must check that the amount in the `PaymentReceived`
505 * event matches your expectation. If you fail to do so and call this method, you may provide
506 * the sender \"proof-of-payment\" when they did not fulfill the full expected payment.
508 * Returns whether any HTLCs were claimed, and thus if any new [`MessageSendEvent`]s are now
509 * pending for processing via [`get_and_clear_pending_msg_events`].
511 * [`Event::PaymentReceived`]: crate::util::events::Event::PaymentReceived
512 * [`create_inbound_payment`]: Self::create_inbound_payment
513 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
514 * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events
516 public boolean claim_funds(byte[] payment_preimage) {
517 boolean ret = bindings.ChannelManager_claim_funds(this.ptr, InternalUtils.check_arr_len(payment_preimage, 32));
518 Reference.reachabilityFence(this);
519 Reference.reachabilityFence(payment_preimage);
524 * Gets the node_id held by this ChannelManager
526 public byte[] get_our_node_id() {
527 byte[] ret = bindings.ChannelManager_get_our_node_id(this.ptr);
528 Reference.reachabilityFence(this);
533 * Gets a payment secret and payment hash for use in an invoice given to a third party wishing
536 * This differs from [`create_inbound_payment_for_hash`] only in that it generates the
537 * [`PaymentHash`] and [`PaymentPreimage`] for you.
539 * The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
540 * will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
541 * passed directly to [`claim_funds`].
543 * See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
545 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
546 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
550 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
551 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
553 * Errors if `min_value_msat` is greater than total bitcoin supply.
555 * [`claim_funds`]: Self::claim_funds
556 * [`PaymentReceived`]: events::Event::PaymentReceived
557 * [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
558 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
560 public Result_C2Tuple_PaymentHashPaymentSecretZNoneZ create_inbound_payment(Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
561 long ret = bindings.ChannelManager_create_inbound_payment(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs);
562 Reference.reachabilityFence(this);
563 Reference.reachabilityFence(min_value_msat);
564 Reference.reachabilityFence(invoice_expiry_delta_secs);
565 if (ret >= 0 && ret <= 4096) { return null; }
566 Result_C2Tuple_PaymentHashPaymentSecretZNoneZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZNoneZ.constr_from_ptr(ret);
571 * Legacy version of [`create_inbound_payment`]. Use this method if you wish to share
572 * serialized state with LDK node(s) running 0.0.103 and earlier.
575 * This method is deprecated and will be removed soon.
577 * [`create_inbound_payment`]: Self::create_inbound_payment
579 public Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ create_inbound_payment_legacy(Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
580 long ret = bindings.ChannelManager_create_inbound_payment_legacy(this.ptr, min_value_msat.ptr, invoice_expiry_delta_secs);
581 Reference.reachabilityFence(this);
582 Reference.reachabilityFence(min_value_msat);
583 Reference.reachabilityFence(invoice_expiry_delta_secs);
584 if (ret >= 0 && ret <= 4096) { return null; }
585 Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ.constr_from_ptr(ret);
590 * Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
591 * stored external to LDK.
593 * A [`PaymentReceived`] event will only be generated if the [`PaymentSecret`] matches a
594 * payment secret fetched via this method or [`create_inbound_payment`], and which is at least
595 * the `min_value_msat` provided here, if one is provided.
597 * The [`PaymentHash`] (and corresponding [`PaymentPreimage`]) should be globally unique, though
598 * note that LDK will not stop you from registering duplicate payment hashes for inbound
601 * `min_value_msat` should be set if the invoice being generated contains a value. Any payment
602 * received for the returned [`PaymentHash`] will be required to be at least `min_value_msat`
603 * before a [`PaymentReceived`] event will be generated, ensuring that we do not provide the
604 * sender \"proof-of-payment\" unless they have paid the required amount.
606 * `invoice_expiry_delta_secs` describes the number of seconds that the invoice is valid for
607 * in excess of the current time. This should roughly match the expiry time set in the invoice.
608 * After this many seconds, we will remove the inbound payment, resulting in any attempts to
609 * pay the invoice failing. The BOLT spec suggests 3,600 secs as a default validity time for
610 * invoices when no timeout is set.
612 * Note that we use block header time to time-out pending inbound payments (with some margin
613 * to compensate for the inaccuracy of block header timestamps). Thus, in practice we will
614 * accept a payment and generate a [`PaymentReceived`] event for some time after the expiry.
615 * If you need exact expiry semantics, you should enforce them upon receipt of
616 * [`PaymentReceived`].
618 * May panic if `invoice_expiry_delta_secs` is greater than one year.
620 * Note that invoices generated for inbound payments should have their `min_final_cltv_expiry`
621 * set to at least [`MIN_FINAL_CLTV_EXPIRY`].
623 * Note that a malicious eavesdropper can intuit whether an inbound payment was created by
624 * `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
628 * If you register an inbound payment with this method, then serialize the `ChannelManager`, then
629 * deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
631 * Errors if `min_value_msat` is greater than total bitcoin supply.
633 * [`create_inbound_payment`]: Self::create_inbound_payment
634 * [`PaymentReceived`]: events::Event::PaymentReceived
636 public Result_PaymentSecretNoneZ create_inbound_payment_for_hash(byte[] payment_hash, Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
637 long ret = bindings.ChannelManager_create_inbound_payment_for_hash(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), min_value_msat.ptr, invoice_expiry_delta_secs);
638 Reference.reachabilityFence(this);
639 Reference.reachabilityFence(payment_hash);
640 Reference.reachabilityFence(min_value_msat);
641 Reference.reachabilityFence(invoice_expiry_delta_secs);
642 if (ret >= 0 && ret <= 4096) { return null; }
643 Result_PaymentSecretNoneZ ret_hu_conv = Result_PaymentSecretNoneZ.constr_from_ptr(ret);
648 * Legacy version of [`create_inbound_payment_for_hash`]. Use this method if you wish to share
649 * serialized state with LDK node(s) running 0.0.103 and earlier.
652 * This method is deprecated and will be removed soon.
654 * [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
656 public Result_PaymentSecretAPIErrorZ create_inbound_payment_for_hash_legacy(byte[] payment_hash, Option_u64Z min_value_msat, int invoice_expiry_delta_secs) {
657 long ret = bindings.ChannelManager_create_inbound_payment_for_hash_legacy(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), min_value_msat.ptr, invoice_expiry_delta_secs);
658 Reference.reachabilityFence(this);
659 Reference.reachabilityFence(payment_hash);
660 Reference.reachabilityFence(min_value_msat);
661 Reference.reachabilityFence(invoice_expiry_delta_secs);
662 if (ret >= 0 && ret <= 4096) { return null; }
663 Result_PaymentSecretAPIErrorZ ret_hu_conv = Result_PaymentSecretAPIErrorZ.constr_from_ptr(ret);
668 * Gets an LDK-generated payment preimage from a payment hash and payment secret that were
669 * previously returned from [`create_inbound_payment`].
671 * [`create_inbound_payment`]: Self::create_inbound_payment
673 public Result_PaymentPreimageAPIErrorZ get_payment_preimage(byte[] payment_hash, byte[] payment_secret) {
674 long ret = bindings.ChannelManager_get_payment_preimage(this.ptr, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32));
675 Reference.reachabilityFence(this);
676 Reference.reachabilityFence(payment_hash);
677 Reference.reachabilityFence(payment_secret);
678 if (ret >= 0 && ret <= 4096) { return null; }
679 Result_PaymentPreimageAPIErrorZ ret_hu_conv = Result_PaymentPreimageAPIErrorZ.constr_from_ptr(ret);
684 * Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
685 * This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
687 public MessageSendEventsProvider as_MessageSendEventsProvider() {
688 long ret = bindings.ChannelManager_as_MessageSendEventsProvider(this.ptr);
689 Reference.reachabilityFence(this);
690 if (ret >= 0 && ret <= 4096) { return null; }
691 MessageSendEventsProvider ret_hu_conv = new MessageSendEventsProvider(null, ret);
692 ret_hu_conv.ptrs_to.add(this);
697 * Constructs a new EventsProvider which calls the relevant methods on this_arg.
698 * This copies the `inner` pointer in this_arg and thus the returned EventsProvider must be freed before this_arg is
700 public EventsProvider as_EventsProvider() {
701 long ret = bindings.ChannelManager_as_EventsProvider(this.ptr);
702 Reference.reachabilityFence(this);
703 if (ret >= 0 && ret <= 4096) { return null; }
704 EventsProvider ret_hu_conv = new EventsProvider(null, ret);
705 ret_hu_conv.ptrs_to.add(this);
710 * Constructs a new Listen which calls the relevant methods on this_arg.
711 * This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
713 public Listen as_Listen() {
714 long ret = bindings.ChannelManager_as_Listen(this.ptr);
715 Reference.reachabilityFence(this);
716 if (ret >= 0 && ret <= 4096) { return null; }
717 Listen ret_hu_conv = new Listen(null, ret);
718 ret_hu_conv.ptrs_to.add(this);
723 * Constructs a new Confirm which calls the relevant methods on this_arg.
724 * This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
726 public Confirm as_Confirm() {
727 long ret = bindings.ChannelManager_as_Confirm(this.ptr);
728 Reference.reachabilityFence(this);
729 if (ret >= 0 && ret <= 4096) { return null; }
730 Confirm ret_hu_conv = new Confirm(null, ret);
731 ret_hu_conv.ptrs_to.add(this);
736 * Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
737 * indicating whether persistence is necessary. Only one listener on
738 * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
741 * Note that this method is not available with the `no-std` feature.
743 public boolean await_persistable_update_timeout(long max_wait) {
744 boolean ret = bindings.ChannelManager_await_persistable_update_timeout(this.ptr, max_wait);
745 Reference.reachabilityFence(this);
746 Reference.reachabilityFence(max_wait);
751 * Blocks until ChannelManager needs to be persisted. Only one listener on
752 * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
755 public void await_persistable_update() {
756 bindings.ChannelManager_await_persistable_update(this.ptr);
757 Reference.reachabilityFence(this);
761 * Gets the latest best block which was connected either via the [`chain::Listen`] or
762 * [`chain::Confirm`] interfaces.
764 public BestBlock current_best_block() {
765 long ret = bindings.ChannelManager_current_best_block(this.ptr);
766 Reference.reachabilityFence(this);
767 if (ret >= 0 && ret <= 4096) { return null; }
768 BestBlock ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new BestBlock(null, ret); }
769 ret_hu_conv.ptrs_to.add(this);
774 * Constructs a new ChannelMessageHandler which calls the relevant methods on this_arg.
775 * This copies the `inner` pointer in this_arg and thus the returned ChannelMessageHandler must be freed before this_arg is
777 public ChannelMessageHandler as_ChannelMessageHandler() {
778 long ret = bindings.ChannelManager_as_ChannelMessageHandler(this.ptr);
779 Reference.reachabilityFence(this);
780 if (ret >= 0 && ret <= 4096) { return null; }
781 ChannelMessageHandler ret_hu_conv = new ChannelMessageHandler(null, ret);
782 ret_hu_conv.ptrs_to.add(this);
787 * Serialize the ChannelManager object into a byte array which can be read by ChannelManager_read
789 public byte[] write() {
790 byte[] ret = bindings.ChannelManager_write(this.ptr);
791 Reference.reachabilityFence(this);
796 * Constructs a new Payer which calls the relevant methods on this_arg.
797 * This copies the `inner` pointer in this_arg and thus the returned Payer must be freed before this_arg is
799 public Payer as_Payer() {
800 long ret = bindings.ChannelManager_as_Payer(this.ptr);
801 Reference.reachabilityFence(this);
802 if (ret >= 0 && ret <= 4096) { return null; }
803 Payer ret_hu_conv = new Payer(null, ret);
804 ret_hu_conv.ptrs_to.add(this);