From: Matt Corallo Date: Wed, 27 Jul 2022 05:02:27 +0000 (+0000) Subject: Update auto-generated bindings to LDK 0.0.110 X-Git-Tag: v0.0.110.0^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f10bdbea94cd8c638a42ab637a52e86a7cfd8157;p=ldk-c-bindings Update auto-generated bindings to LDK 0.0.110 --- diff --git a/lightning-c-bindings/include/ldk_rust_types.h b/lightning-c-bindings/include/ldk_rust_types.h index 83c8f74..97f76fb 100644 --- a/lightning-c-bindings/include/ldk_rust_types.h +++ b/lightning-c-bindings/include/ldk_rust_types.h @@ -137,6 +137,8 @@ struct nativeUserConfigOpaque; typedef struct nativeUserConfigOpaque LDKnativeUserConfig; struct nativeBigSizeOpaque; typedef struct nativeBigSizeOpaque LDKnativeBigSize; +struct nativeHostnameOpaque; +typedef struct nativeHostnameOpaque LDKnativeHostname; struct nativeOutPointOpaque; typedef struct nativeOutPointOpaque LDKnativeOutPoint; struct nativeInvoicePayerOpaque; diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 1136242..7c95e08 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -1851,6 +1851,22 @@ typedef struct LDKCOption_u64Z { }; } LDKCOption_u64Z; +/** + * A dynamically-allocated array of u64s of arbitrary size. + * This corresponds to std::vector in C++ + */ +typedef struct LDKCVec_u64Z { + /** + * The elements in the array. + * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + */ + uint64_t *data; + /** + * The number of elements pointed to by `data`. + */ + uintptr_t datalen; +} LDKCVec_u64Z; + /** @@ -2353,6 +2369,133 @@ typedef struct LDKCResult_COption_ClosureReasonZDecodeErrorZ { bool result_ok; } LDKCResult_COption_ClosureReasonZDecodeErrorZ; +/** + * Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`]. + */ +typedef enum LDKHTLCDestination_Tag { + /** + * We tried forwarding to a channel but failed to do so. An example of such an instance is when + * there is insufficient capacity in our outbound channel. + */ + LDKHTLCDestination_NextHopChannel, + /** + * Scenario where we are unsure of the next node to forward the HTLC to. + */ + LDKHTLCDestination_UnknownNextHop, + /** + * Failure scenario where an HTLC may have been forwarded to be intended for us, + * but is invalid for some reason, so we reject it. + * + * Some of the reasons may include: + * * HTLC Timeouts + * * Expected MPP amount to claim does not equal HTLC total + * * Claimable amount does not match expected amount + */ + LDKHTLCDestination_FailedPayment, + /** + * Must be last for serialization purposes + */ + LDKHTLCDestination_Sentinel, +} LDKHTLCDestination_Tag; + +typedef struct LDKHTLCDestination_LDKNextHopChannel_Body { + /** + * The `node_id` of the next node. For backwards compatibility, this field is + * marked as optional, versions prior to 0.0.110 may not always be able to provide + * counterparty node information. + * + * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + struct LDKPublicKey node_id; + /** + * The outgoing `channel_id` between us and the next node. + */ + struct LDKThirtyTwoBytes channel_id; +} LDKHTLCDestination_LDKNextHopChannel_Body; + +typedef struct LDKHTLCDestination_LDKUnknownNextHop_Body { + /** + * Short channel id we are requesting to forward an HTLC to. + */ + uint64_t requested_forward_scid; +} LDKHTLCDestination_LDKUnknownNextHop_Body; + +typedef struct LDKHTLCDestination_LDKFailedPayment_Body { + /** + * The payment hash of the payment we attempted to process. + */ + struct LDKThirtyTwoBytes payment_hash; +} LDKHTLCDestination_LDKFailedPayment_Body; + +typedef struct MUST_USE_STRUCT LDKHTLCDestination { + LDKHTLCDestination_Tag tag; + union { + LDKHTLCDestination_LDKNextHopChannel_Body next_hop_channel; + LDKHTLCDestination_LDKUnknownNextHop_Body unknown_next_hop; + LDKHTLCDestination_LDKFailedPayment_Body failed_payment; + }; +} LDKHTLCDestination; + +/** + * An enum which can either contain a crate::lightning::util::events::HTLCDestination or not + */ +typedef enum LDKCOption_HTLCDestinationZ_Tag { + /** + * When we're in this state, this COption_HTLCDestinationZ contains a crate::lightning::util::events::HTLCDestination + */ + LDKCOption_HTLCDestinationZ_Some, + /** + * When we're in this state, this COption_HTLCDestinationZ contains nothing + */ + LDKCOption_HTLCDestinationZ_None, + /** + * Must be last for serialization purposes + */ + LDKCOption_HTLCDestinationZ_Sentinel, +} LDKCOption_HTLCDestinationZ_Tag; + +typedef struct LDKCOption_HTLCDestinationZ { + LDKCOption_HTLCDestinationZ_Tag tag; + union { + struct { + struct LDKHTLCDestination some; + }; + }; +} LDKCOption_HTLCDestinationZ; + +/** + * The contents of CResult_COption_HTLCDestinationZDecodeErrorZ + */ +typedef union LDKCResult_COption_HTLCDestinationZDecodeErrorZPtr { + /** + * A pointer to the contents in the success state. + * Reading from this pointer when `result_ok` is not set is undefined. + */ + struct LDKCOption_HTLCDestinationZ *result; + /** + * A pointer to the contents in the error state. + * Reading from this pointer when `result_ok` is set is undefined. + */ + struct LDKDecodeError *err; +} LDKCResult_COption_HTLCDestinationZDecodeErrorZPtr; + +/** + * A CResult_COption_HTLCDestinationZDecodeErrorZ represents the result of a fallible operation, + * containing a crate::c_types::derived::COption_HTLCDestinationZ on success and a crate::lightning::ln::msgs::DecodeError on failure. + * `result_ok` indicates the overall state, and the contents are provided via `contents`. + */ +typedef struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ { + /** + * The contents of this CResult_COption_HTLCDestinationZDecodeErrorZ, accessible via either + * `err` or `result` depending on the state of `result_ok`. + */ + union LDKCResult_COption_HTLCDestinationZDecodeErrorZPtr contents; + /** + * Whether this CResult_COption_HTLCDestinationZDecodeErrorZ represents a success state. + */ + bool result_ok; +} LDKCResult_COption_HTLCDestinationZDecodeErrorZ; + /** @@ -2756,6 +2899,14 @@ typedef enum LDKEvent_Tag { * [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed */ LDKEvent_PaymentPathFailed, + /** + * Indicates that a probe payment we sent returned successful, i.e., only failed at the destination. + */ + LDKEvent_ProbeSuccessful, + /** + * Indicates that a probe payment we sent failed at an intermediary node on the path. + */ + LDKEvent_ProbeFailed, /** * Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at * a time in the future. @@ -2800,6 +2951,21 @@ typedef enum LDKEvent_Tag { * [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels */ LDKEvent_OpenChannelRequest, + /** + * Indicates that the HTLC was accepted, but could not be processed when or after attempting to + * forward it. + * + * Some scenarios where this event may be sent include: + * * Insufficient capacity in the outbound channel + * * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes + * * When an unknown SCID is requested for forwarding a payment. + * * Claiming an amount for an MPP payment that exceeds the HTLC total + * * The HTLC has timed out + * + * This event, however, does not get generated if an HTLC fails to meet the forwarding + * requirements (i.e. insufficient fees paid, or a CLTV that is too soon). + */ + LDKEvent_HTLCHandlingFailed, /** * Must be last for serialization purposes */ @@ -3034,6 +3200,52 @@ typedef struct LDKEvent_LDKPaymentPathFailed_Body { struct LDKRouteParameters retry; } LDKEvent_LDKPaymentPathFailed_Body; +typedef struct LDKEvent_LDKProbeSuccessful_Body { + /** + * The id returned by [`ChannelManager::send_probe`]. + * + * [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + */ + struct LDKThirtyTwoBytes payment_id; + /** + * The hash generated by [`ChannelManager::send_probe`]. + * + * [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + */ + struct LDKThirtyTwoBytes payment_hash; + /** + * The payment path that was successful. + */ + struct LDKCVec_RouteHopZ path; +} LDKEvent_LDKProbeSuccessful_Body; + +typedef struct LDKEvent_LDKProbeFailed_Body { + /** + * The id returned by [`ChannelManager::send_probe`]. + * + * [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + */ + struct LDKThirtyTwoBytes payment_id; + /** + * The hash generated by [`ChannelManager::send_probe`]. + * + * [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + */ + struct LDKThirtyTwoBytes payment_hash; + /** + * The payment path that failed. + */ + struct LDKCVec_RouteHopZ path; + /** + * The channel responsible for the failed probe. + * + * Note that for route hints or for the first hop in a path this may be an SCID alias and + * may not refer to a channel in the public network graph. These aliases may also collide + * with channels in the public network graph. + */ + struct LDKCOption_u64Z short_channel_id; +} LDKEvent_LDKProbeFailed_Body; + typedef struct LDKEvent_LDKPendingHTLCsForwardable_Body { /** * The minimum amount of time that should be waited prior to calling @@ -3176,6 +3388,17 @@ typedef struct LDKEvent_LDKOpenChannelRequest_Body { struct LDKChannelTypeFeatures channel_type; } LDKEvent_LDKOpenChannelRequest_Body; +typedef struct LDKEvent_LDKHTLCHandlingFailed_Body { + /** + * The channel over which the HTLC was received. + */ + struct LDKThirtyTwoBytes prev_channel_id; + /** + * Destination of the HTLC that failed to be processed. + */ + struct LDKHTLCDestination failed_next_destination; +} LDKEvent_LDKHTLCHandlingFailed_Body; + typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_Tag tag; union { @@ -3186,12 +3409,15 @@ typedef struct MUST_USE_STRUCT LDKEvent { LDKEvent_LDKPaymentFailed_Body payment_failed; LDKEvent_LDKPaymentPathSuccessful_Body payment_path_successful; LDKEvent_LDKPaymentPathFailed_Body payment_path_failed; + LDKEvent_LDKProbeSuccessful_Body probe_successful; + LDKEvent_LDKProbeFailed_Body probe_failed; LDKEvent_LDKPendingHTLCsForwardable_Body pending_htl_cs_forwardable; LDKEvent_LDKSpendableOutputs_Body spendable_outputs; LDKEvent_LDKPaymentForwarded_Body payment_forwarded; LDKEvent_LDKChannelClosed_Body channel_closed; LDKEvent_LDKDiscardFunding_Body discard_funding; LDKEvent_LDKOpenChannelRequest_Body open_channel_request; + LDKEvent_LDKHTLCHandlingFailed_Body htlc_handling_failed; }; } LDKEvent; @@ -4306,9 +4532,9 @@ typedef struct LDKCVec_MonitorEventZ { } LDKCVec_MonitorEventZ; /** - * A tuple of 2 elements. See the individual fields for the types contained. + * A tuple of 3 elements. See the individual fields for the types contained. */ -typedef struct LDKC2Tuple_OutPointCVec_MonitorEventZZ { +typedef struct LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { /** * The element at position 0 */ @@ -4317,23 +4543,27 @@ typedef struct LDKC2Tuple_OutPointCVec_MonitorEventZZ { * The element at position 1 */ struct LDKCVec_MonitorEventZ b; -} LDKC2Tuple_OutPointCVec_MonitorEventZZ; + /** + * The element at position 2 + */ + struct LDKPublicKey c; +} LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ; /** - * A dynamically-allocated array of crate::c_types::derived::C2Tuple_OutPointCVec_MonitorEventZZs of arbitrary size. + * A dynamically-allocated array of crate::c_types::derived::C3Tuple_OutPointCVec_MonitorEventZPublicKeyZs of arbitrary size. * This corresponds to std::vector in C++ */ -typedef struct LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ { +typedef struct LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { /** * The elements in the array. * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). */ - struct LDKC2Tuple_OutPointCVec_MonitorEventZZ *data; + struct LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ *data; /** * The number of elements pointed to by `data`. */ uintptr_t datalen; -} LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ; +} LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ; /** * An enum which can either contain a crate::c_types::derived::C2Tuple_usizeTransactionZ or not @@ -5295,6 +5525,30 @@ typedef struct LDKTwelveBytes { uint8_t data[12]; } LDKTwelveBytes; + + +/** + * Represents a hostname for serialization purposes. + * Only the character set and length will be validated. + * The character set consists of ASCII alphanumeric characters, hyphens, and periods. + * Its length is guaranteed to be representable by a single byte. + * This serialization is used by BOLT 7 hostnames. + */ +typedef struct MUST_USE_STRUCT LDKHostname { + /** + * A pointer to the opaque Rust object. + * Nearly everywhere, inner must be non-null, however in places where + * the Rust equivalent takes an Option, it may be set to null to indicate None. + */ + LDKnativeHostname *inner; + /** + * Indicates that this is the only struct which contains the same pointer. + * Rust functions which take ownership of an object provided via an argument require + * this to be true and invalidate the object pointed to by inner. + */ + bool is_owned; +} LDKHostname; + /** * An address which can be used to connect to a remote peer */ @@ -5320,6 +5574,10 @@ typedef enum LDKNetAddress_Tag { * wrap as base32 and append \".onion\". */ LDKNetAddress_OnionV3, + /** + * A hostname/port on which the peer is listening. + */ + LDKNetAddress_Hostname, /** * Must be last for serialization purposes */ @@ -5367,6 +5625,17 @@ typedef struct LDKNetAddress_LDKOnionV3_Body { uint16_t port; } LDKNetAddress_LDKOnionV3_Body; +typedef struct LDKNetAddress_LDKHostname_Body { + /** + * The hostname on which the node is listening. + */ + struct LDKHostname hostname; + /** + * The port on which the node is listening. + */ + uint16_t port; +} LDKNetAddress_LDKHostname_Body; + typedef struct MUST_USE_STRUCT LDKNetAddress { LDKNetAddress_Tag tag; union { @@ -5376,6 +5645,7 @@ typedef struct MUST_USE_STRUCT LDKNetAddress { struct LDKTwelveBytes onion_v2; }; LDKNetAddress_LDKOnionV3_Body onion_v3; + LDKNetAddress_LDKHostname_Body hostname; }; } LDKNetAddress; @@ -5504,22 +5774,6 @@ typedef struct LDKCResult_NodeAliasDecodeErrorZ { bool result_ok; } LDKCResult_NodeAliasDecodeErrorZ; -/** - * A dynamically-allocated array of u64s of arbitrary size. - * This corresponds to std::vector in C++ - */ -typedef struct LDKCVec_u64Z { - /** - * The elements in the array. - * If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). - */ - uint64_t *data; - /** - * The number of elements pointed to by `data`. - */ - uintptr_t datalen; -} LDKCVec_u64Z; - /** @@ -7445,7 +7699,7 @@ typedef struct LDKWatch { * For details on asynchronous [`ChannelMonitor`] updating and returning * [`MonitorEvent::UpdateCompleted`] here, see [`ChannelMonitorUpdateErr::TemporaryFailure`]. */ - struct LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ (*release_pending_monitor_events)(const void *this_arg); + struct LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ (*release_pending_monitor_events)(const void *this_arg); /** * Frees any resources associated with this object given its this_arg pointer. * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. @@ -7589,12 +7843,12 @@ typedef struct LDKFeeEstimator { /** * Gets estimated satoshis of fee required per 1000 Weight-Units. * - * Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later - * round-downs don't put us below 1 satoshi-per-byte). + * LDK will wrap this method and ensure that the value returned is no smaller than 253 + * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte). * - * This method can be implemented with the following unit conversions: - * * max(satoshis-per-byte * 250, 253) - * * max(satoshis-per-kbyte / 4, 253) + * The following unit conversions can be used to convert to sats/KW: + * * satoshis-per-byte * 250 + * * satoshis-per-kbyte / 4 */ uint32_t (*get_est_sat_per_1000_weight)(const void *this_arg, enum LDKConfirmationTarget confirmation_target); /** @@ -11151,6 +11405,14 @@ typedef struct LDKScore { * Handles updating channel penalties after successfully routing along a path. */ void (*payment_path_successful)(void *this_arg, struct LDKCVec_RouteHopZ path); + /** + * Handles updating channel penalties after a probe over the given path failed. + */ + void (*probe_failed)(void *this_arg, struct LDKCVec_RouteHopZ path, uint64_t short_channel_id); + /** + * Handles updating channel penalties after a probe over the given path succeeded. + */ + void (*probe_successful)(void *this_arg, struct LDKCVec_RouteHopZ path); /** * Serialize the object into a byte array */ @@ -12396,6 +12658,9 @@ typedef struct LDKLockableScore { * * Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel * penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel). + * + * The penalty applied to any channel by the [`ProbabilisticScorer`] is the sum of each of the + * parameters here. */ typedef struct MUST_USE_STRUCT LDKProbabilisticScoringParameters { /** @@ -12819,6 +13084,8 @@ extern const uintptr_t MAX_BUF_SIZE; extern const uint64_t MIN_RELAY_FEE_SAT_PER_1000_WEIGHT; +extern const uint32_t FEERATE_FLOOR_SATS_PER_KW; + extern const uint64_t CLOSED_CHANNEL_UPDATE_ID; extern const uint32_t ANTI_REORG_DELAY; @@ -12835,7 +13102,7 @@ extern const uint64_t UNKNOWN_CHANNEL_CAPACITY_MSAT; extern const uint32_t DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA; -extern const uint8_t DEFAULT_MAX_MPP_PATH_COUNT; +extern const uint8_t DEFAULT_MAX_PATH_COUNT; extern const uint64_t MAX_TIMESTAMP; @@ -13547,6 +13814,11 @@ void COption_u64Z_free(struct LDKCOption_u64Z _res); */ struct LDKCOption_u64Z COption_u64Z_clone(const struct LDKCOption_u64Z *NONNULL_PTR orig); +/** + * Frees the buffer pointed to by `data` if `datalen` is non-0. + */ +void CVec_u64Z_free(struct LDKCVec_u64Z _res); + /** * Creates a new CResult_PaymentParametersDecodeErrorZ in the success state. */ @@ -13739,6 +14011,53 @@ void CResult_COption_ClosureReasonZDecodeErrorZ_free(struct LDKCResult_COption_C */ struct LDKCResult_COption_ClosureReasonZDecodeErrorZ CResult_COption_ClosureReasonZDecodeErrorZ_clone(const struct LDKCResult_COption_ClosureReasonZDecodeErrorZ *NONNULL_PTR orig); +/** + * Constructs a new COption_HTLCDestinationZ containing a crate::lightning::util::events::HTLCDestination + */ +struct LDKCOption_HTLCDestinationZ COption_HTLCDestinationZ_some(struct LDKHTLCDestination o); + +/** + * Constructs a new COption_HTLCDestinationZ containing nothing + */ +struct LDKCOption_HTLCDestinationZ COption_HTLCDestinationZ_none(void); + +/** + * Frees any resources associated with the crate::lightning::util::events::HTLCDestination, if we are in the Some state + */ +void COption_HTLCDestinationZ_free(struct LDKCOption_HTLCDestinationZ _res); + +/** + * Creates a new COption_HTLCDestinationZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCOption_HTLCDestinationZ COption_HTLCDestinationZ_clone(const struct LDKCOption_HTLCDestinationZ *NONNULL_PTR orig); + +/** + * Creates a new CResult_COption_HTLCDestinationZDecodeErrorZ in the success state. + */ +struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ CResult_COption_HTLCDestinationZDecodeErrorZ_ok(struct LDKCOption_HTLCDestinationZ o); + +/** + * Creates a new CResult_COption_HTLCDestinationZDecodeErrorZ in the error state. + */ +struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ CResult_COption_HTLCDestinationZDecodeErrorZ_err(struct LDKDecodeError e); + +/** + * Checks if the given object is currently in the success state + */ +bool CResult_COption_HTLCDestinationZDecodeErrorZ_is_ok(const struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ *NONNULL_PTR o); + +/** + * Frees any resources used by the CResult_COption_HTLCDestinationZDecodeErrorZ. + */ +void CResult_COption_HTLCDestinationZDecodeErrorZ_free(struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ _res); + +/** + * Creates a new CResult_COption_HTLCDestinationZDecodeErrorZ which has the same data as `orig` + * but with all dynamically-allocated buffers duplicated in new buffers. + */ +struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ CResult_COption_HTLCDestinationZDecodeErrorZ_clone(const struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ *NONNULL_PTR orig); + /** * Constructs a new COption_NetworkUpdateZ containing a crate::lightning::routing::gossip::NetworkUpdate */ @@ -13904,22 +14223,22 @@ void CVec_MonitorEventZ_free(struct LDKCVec_MonitorEventZ _res); * Creates a new tuple which has the same data as `orig` * but with all dynamically-allocated buffers duplicated in new buffers. */ -struct LDKC2Tuple_OutPointCVec_MonitorEventZZ C2Tuple_OutPointCVec_MonitorEventZZ_clone(const struct LDKC2Tuple_OutPointCVec_MonitorEventZZ *NONNULL_PTR orig); +struct LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_clone(const struct LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ *NONNULL_PTR orig); /** - * Creates a new C2Tuple_OutPointCVec_MonitorEventZZ from the contained elements. + * Creates a new C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ from the contained elements. */ -struct LDKC2Tuple_OutPointCVec_MonitorEventZZ C2Tuple_OutPointCVec_MonitorEventZZ_new(struct LDKOutPoint a, struct LDKCVec_MonitorEventZ b); +struct LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_new(struct LDKOutPoint a, struct LDKCVec_MonitorEventZ b, struct LDKPublicKey c); /** - * Frees any resources used by the C2Tuple_OutPointCVec_MonitorEventZZ. + * Frees any resources used by the C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ. */ -void C2Tuple_OutPointCVec_MonitorEventZZ_free(struct LDKC2Tuple_OutPointCVec_MonitorEventZZ _res); +void C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_free(struct LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ _res); /** * Frees the buffer pointed to by `data` if `datalen` is non-0. */ -void CVec_C2Tuple_OutPointCVec_MonitorEventZZZ_free(struct LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ _res); +void CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ_free(struct LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ _res); /** * Constructs a new COption_C2Tuple_usizeTransactionZZ containing a crate::c_types::derived::C2Tuple_usizeTransactionZ @@ -14440,11 +14759,6 @@ void CResult_NodeAliasDecodeErrorZ_free(struct LDKCResult_NodeAliasDecodeErrorZ */ struct LDKCResult_NodeAliasDecodeErrorZ CResult_NodeAliasDecodeErrorZ_clone(const struct LDKCResult_NodeAliasDecodeErrorZ *NONNULL_PTR orig); -/** - * Frees the buffer pointed to by `data` if `datalen` is non-0. - */ -void CVec_u64Z_free(struct LDKCVec_u64Z _res); - /** * Creates a new CResult_NodeInfoDecodeErrorZ in the success state. */ @@ -17210,6 +17524,41 @@ struct LDKCVec_u8Z ClosureReason_write(const struct LDKClosureReason *NONNULL_PT */ struct LDKCResult_COption_ClosureReasonZDecodeErrorZ ClosureReason_read(struct LDKu8slice ser); +/** + * Frees any resources used by the HTLCDestination + */ +void HTLCDestination_free(struct LDKHTLCDestination this_ptr); + +/** + * Creates a copy of the HTLCDestination + */ +struct LDKHTLCDestination HTLCDestination_clone(const struct LDKHTLCDestination *NONNULL_PTR orig); + +/** + * Utility method to constructs a new NextHopChannel-variant HTLCDestination + */ +struct LDKHTLCDestination HTLCDestination_next_hop_channel(struct LDKPublicKey node_id, struct LDKThirtyTwoBytes channel_id); + +/** + * Utility method to constructs a new UnknownNextHop-variant HTLCDestination + */ +struct LDKHTLCDestination HTLCDestination_unknown_next_hop(uint64_t requested_forward_scid); + +/** + * Utility method to constructs a new FailedPayment-variant HTLCDestination + */ +struct LDKHTLCDestination HTLCDestination_failed_payment(struct LDKThirtyTwoBytes payment_hash); + +/** + * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read + */ +struct LDKCVec_u8Z HTLCDestination_write(const struct LDKHTLCDestination *NONNULL_PTR obj); + +/** + * Read a HTLCDestination from a byte array, created by HTLCDestination_write + */ +struct LDKCResult_COption_HTLCDestinationZDecodeErrorZ HTLCDestination_read(struct LDKu8slice ser); + /** * Frees any resources used by the Event */ @@ -17255,6 +17604,16 @@ struct LDKEvent Event_payment_path_successful(struct LDKThirtyTwoBytes payment_i */ struct LDKEvent Event_payment_path_failed(struct LDKThirtyTwoBytes payment_id, struct LDKThirtyTwoBytes payment_hash, bool rejected_by_dest, struct LDKCOption_NetworkUpdateZ network_update, bool all_paths_failed, struct LDKCVec_RouteHopZ path, struct LDKCOption_u64Z short_channel_id, struct LDKRouteParameters retry); +/** + * Utility method to constructs a new ProbeSuccessful-variant Event + */ +struct LDKEvent Event_probe_successful(struct LDKThirtyTwoBytes payment_id, struct LDKThirtyTwoBytes payment_hash, struct LDKCVec_RouteHopZ path); + +/** + * Utility method to constructs a new ProbeFailed-variant Event + */ +struct LDKEvent Event_probe_failed(struct LDKThirtyTwoBytes payment_id, struct LDKThirtyTwoBytes payment_hash, struct LDKCVec_RouteHopZ path, struct LDKCOption_u64Z short_channel_id); + /** * Utility method to constructs a new PendingHTLCsForwardable-variant Event */ @@ -17285,6 +17644,11 @@ struct LDKEvent Event_discard_funding(struct LDKThirtyTwoBytes channel_id, struc */ struct LDKEvent Event_open_channel_request(struct LDKThirtyTwoBytes temporary_channel_id, struct LDKPublicKey counterparty_node_id, uint64_t funding_satoshis, uint64_t push_msat, struct LDKChannelTypeFeatures channel_type); +/** + * Utility method to constructs a new HTLCHandlingFailed-variant Event + */ +struct LDKEvent Event_htlchandling_failed(struct LDKThirtyTwoBytes prev_channel_id, struct LDKHTLCDestination failed_next_destination); + /** * Serialize the Event object into a byte array which can be read by Event_read */ @@ -17474,6 +17838,21 @@ void BigSize_set_a(struct LDKBigSize *NONNULL_PTR this_ptr, uint64_t val); */ MUST_USE_RES struct LDKBigSize BigSize_new(uint64_t a_arg); +/** + * Frees any resources used by the Hostname, if is_owned is set and inner is non-NULL. + */ +void Hostname_free(struct LDKHostname this_obj); + +/** + * Creates a copy of the Hostname + */ +struct LDKHostname Hostname_clone(const struct LDKHostname *NONNULL_PTR orig); + +/** + * Returns the length of the hostname. + */ +MUST_USE_RES uint8_t Hostname_len(const struct LDKHostname *NONNULL_PTR this_arg); + /** * Creates a digital signature of a message given a SecretKey, like the node's secret. * A receiver knowing the PublicKey (e.g. the node's id) and the message can be sure that the signature was generated by the caller. @@ -18933,7 +19312,7 @@ struct LDKCVec_u8Z ChannelMonitor_write(const struct LDKChannelMonitor *NONNULL_ * * panics if the given update is not the next update by update_id. */ -MUST_USE_RES struct LDKCResult_NoneNoneZ ChannelMonitor_update_monitor(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKChannelMonitorUpdate *NONNULL_PTR updates, const struct LDKBroadcasterInterface *NONNULL_PTR broadcaster, const struct LDKFeeEstimator *NONNULL_PTR fee_estimator, const struct LDKLogger *NONNULL_PTR logger); +MUST_USE_RES struct LDKCResult_NoneNoneZ ChannelMonitor_update_monitor(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKChannelMonitorUpdate *NONNULL_PTR updates, const struct LDKBroadcasterInterface *NONNULL_PTR broadcaster, struct LDKFeeEstimator fee_estimator, const struct LDKLogger *NONNULL_PTR logger); /** * Gets the update_id from the latest ChannelMonitorUpdate which was applied to this @@ -18975,6 +19354,16 @@ MUST_USE_RES struct LDKCVec_MonitorEventZ ChannelMonitor_get_and_clear_pending_m */ MUST_USE_RES struct LDKCVec_EventZ ChannelMonitor_get_and_clear_pending_events(const struct LDKChannelMonitor *NONNULL_PTR this_arg); +/** + * Gets the `node_id` of the counterparty for this channel. + * + * Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some` + * otherwise. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +MUST_USE_RES struct LDKPublicKey ChannelMonitor_get_counterparty_node_id(const struct LDKChannelMonitor *NONNULL_PTR this_arg); + /** * Used by ChannelManager deserialization to broadcast the latest holder state if its copy of * the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of @@ -20627,6 +21016,13 @@ void ChannelManager_abandon_payment(const struct LDKChannelManager *NONNULL_PTR */ MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ChannelManager_send_spontaneous_payment(const struct LDKChannelManager *NONNULL_PTR this_arg, const struct LDKRoute *NONNULL_PTR route, struct LDKThirtyTwoBytes payment_preimage); +/** + * Send a payment that is probing the given route for liquidity. We calculate the + * [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows + * us to easily discern them from real payments. + */ +MUST_USE_RES struct LDKCResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ChannelManager_send_probe(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKCVec_RouteHopZ hops); + /** * Call this upon creation of a funding transaction for the given channel. * @@ -20677,7 +21073,7 @@ MUST_USE_RES struct LDKCResult_NoneAPIErrorZ ChannelManager_funding_transaction_ * tying these addresses together and to this node. If you wish to preserve user privacy, * addresses should likely contain only Tor Onion addresses. * - * Panics if `addresses` is absurdly large (more than 500). + * Panics if `addresses` is absurdly large (more than 100). * * [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events */ @@ -22500,6 +22896,11 @@ struct LDKNetAddress NetAddress_onion_v2(struct LDKTwelveBytes a); */ struct LDKNetAddress NetAddress_onion_v3(struct LDKThirtyTwoBytes ed25519_pubkey, uint16_t checksum, uint8_t version, uint16_t port); +/** + * Utility method to constructs a new Hostname-variant NetAddress + */ +struct LDKNetAddress NetAddress_hostname(struct LDKHostname hostname, uint16_t port); + /** * Serialize the NetAddress object into a byte array which can be read by NetAddress_read */ @@ -22838,6 +23239,16 @@ uint64_t UnsignedChannelUpdate_get_htlc_minimum_msat(const struct LDKUnsignedCha */ void UnsignedChannelUpdate_set_htlc_minimum_msat(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint64_t val); +/** + * The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional. + */ +uint64_t UnsignedChannelUpdate_get_htlc_maximum_msat(const struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr); + +/** + * The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional. + */ +void UnsignedChannelUpdate_set_htlc_maximum_msat(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, uint64_t val); + /** * The base HTLC fee charged by sender, in milli-satoshi */ @@ -22865,6 +23276,11 @@ void UnsignedChannelUpdate_set_fee_proportional_millionths(struct LDKUnsignedCha */ void UnsignedChannelUpdate_set_excess_data(struct LDKUnsignedChannelUpdate *NONNULL_PTR this_ptr, struct LDKCVec_u8Z val); +/** + * Constructs a new UnsignedChannelUpdate given each field + */ +MUST_USE_RES struct LDKUnsignedChannelUpdate UnsignedChannelUpdate_new(struct LDKThirtyTwoBytes chain_hash_arg, uint64_t short_channel_id_arg, uint32_t timestamp_arg, uint8_t flags_arg, uint16_t cltv_expiry_delta_arg, uint64_t htlc_minimum_msat_arg, uint64_t htlc_maximum_msat_arg, uint32_t fee_base_msat_arg, uint32_t fee_proportional_millionths_arg, struct LDKCVec_u8Z excess_data_arg); + /** * Creates a copy of the UnsignedChannelUpdate */ @@ -23800,8 +24216,7 @@ MUST_USE_RES struct LDKCVec_PublicKeyZ PeerManager_get_peer_node_ids(const struc * peer using the init message. * The user should pass the remote network address of the host they are connected to. * - * Note that if an Err is returned here you MUST NOT call socket_disconnected for the new - * descriptor but must disconnect the connection immediately. + * If an `Err` is returned here you must disconnect the connection immediately. * * Returns a small number of bytes to send to the remote node (currently always 50). * @@ -23821,9 +24236,8 @@ MUST_USE_RES struct LDKCResult_CVec_u8ZPeerHandleErrorZ PeerManager_new_outbound * The user should pass the remote network address of the host they are connected to. * * May refuse the connection by returning an Err, but will never write bytes to the remote end - * (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT - * call socket_disconnected for the new descriptor but must disconnect the connection - * immediately. + * (outbound connector always speaks first). If an `Err` is returned here you must disconnect + * the connection immediately. * * Panics if descriptor is duplicative with some other descriptor which has not yet been * [`socket_disconnected()`]. @@ -25964,12 +26378,12 @@ void ChannelUpdateInfo_set_htlc_minimum_msat(struct LDKChannelUpdateInfo *NONNUL /** * The maximum value which may be relayed to the next hop via the channel. */ -struct LDKCOption_u64Z ChannelUpdateInfo_get_htlc_maximum_msat(const struct LDKChannelUpdateInfo *NONNULL_PTR this_ptr); +uint64_t ChannelUpdateInfo_get_htlc_maximum_msat(const struct LDKChannelUpdateInfo *NONNULL_PTR this_ptr); /** * The maximum value which may be relayed to the next hop via the channel. */ -void ChannelUpdateInfo_set_htlc_maximum_msat(struct LDKChannelUpdateInfo *NONNULL_PTR this_ptr, struct LDKCOption_u64Z val); +void ChannelUpdateInfo_set_htlc_maximum_msat(struct LDKChannelUpdateInfo *NONNULL_PTR this_ptr, uint64_t val); /** * Fees charged when the channel is used for routing @@ -26004,7 +26418,7 @@ void ChannelUpdateInfo_set_last_update_message(struct LDKChannelUpdateInfo *NONN /** * Constructs a new ChannelUpdateInfo given each field */ -MUST_USE_RES struct LDKChannelUpdateInfo ChannelUpdateInfo_new(uint32_t last_update_arg, bool enabled_arg, uint16_t cltv_expiry_delta_arg, uint64_t htlc_minimum_msat_arg, struct LDKCOption_u64Z htlc_maximum_msat_arg, struct LDKRoutingFees fees_arg, struct LDKChannelUpdate last_update_message_arg); +MUST_USE_RES struct LDKChannelUpdateInfo ChannelUpdateInfo_new(uint32_t last_update_arg, bool enabled_arg, uint16_t cltv_expiry_delta_arg, uint64_t htlc_minimum_msat_arg, uint64_t htlc_maximum_msat_arg, struct LDKRoutingFees fees_arg, struct LDKChannelUpdate last_update_message_arg); /** * Creates a copy of the ChannelUpdateInfo @@ -26611,6 +27025,20 @@ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel(c */ MUST_USE_RES struct LDKCResult_NoneLightningErrorZ NetworkGraph_update_channel_unsigned(const struct LDKNetworkGraph *NONNULL_PTR this_arg, const struct LDKUnsignedChannelUpdate *NONNULL_PTR msg); +/** + * Returns information on a channel with the given id. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +MUST_USE_RES struct LDKChannelInfo ReadOnlyNetworkGraph_channel(const struct LDKReadOnlyNetworkGraph *NONNULL_PTR this_arg, uint64_t short_channel_id); + +/** + * Returns information on a node with the given id. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ +MUST_USE_RES struct LDKNodeInfo ReadOnlyNetworkGraph_node(const struct LDKReadOnlyNetworkGraph *NONNULL_PTR this_arg, const struct LDKNodeId *NONNULL_PTR node_id); + /** * Get network addresses by node id. * Returns None if the requested node is completely unknown, @@ -26942,21 +27370,62 @@ uint32_t PaymentParameters_get_max_total_cltv_expiry_delta(const struct LDKPayme void PaymentParameters_set_max_total_cltv_expiry_delta(struct LDKPaymentParameters *NONNULL_PTR this_ptr, uint32_t val); /** - * The maximum number of paths that may be used by MPP payments. - * Defaults to [`DEFAULT_MAX_MPP_PATH_COUNT`]. + * The maximum number of paths that may be used by (MPP) payments. + * Defaults to [`DEFAULT_MAX_PATH_COUNT`]. + */ +uint8_t PaymentParameters_get_max_path_count(const struct LDKPaymentParameters *NONNULL_PTR this_ptr); + +/** + * The maximum number of paths that may be used by (MPP) payments. + * Defaults to [`DEFAULT_MAX_PATH_COUNT`]. + */ +void PaymentParameters_set_max_path_count(struct LDKPaymentParameters *NONNULL_PTR this_ptr, uint8_t val); + +/** + * Selects the maximum share of a channel's total capacity which will be sent over a channel, + * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas + * a lower value prefers to send larger MPP parts, potentially saturating channels and + * increasing failure probability for those paths. + * + * Note that this restriction will be relaxed during pathfinding after paths which meet this + * restriction have been found. While paths which meet this criteria will be searched for, it + * is ultimately up to the scorer to select them over other paths. + * + * A value of 0 will allow payments up to and including a channel's total announced usable + * capacity, a value of one will only use up to half its capacity, two 1/4, etc. + * + * Default value: 2 + */ +uint8_t PaymentParameters_get_max_channel_saturation_power_of_half(const struct LDKPaymentParameters *NONNULL_PTR this_ptr); + +/** + * Selects the maximum share of a channel's total capacity which will be sent over a channel, + * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas + * a lower value prefers to send larger MPP parts, potentially saturating channels and + * increasing failure probability for those paths. + * + * Note that this restriction will be relaxed during pathfinding after paths which meet this + * restriction have been found. While paths which meet this criteria will be searched for, it + * is ultimately up to the scorer to select them over other paths. + * + * A value of 0 will allow payments up to and including a channel's total announced usable + * capacity, a value of one will only use up to half its capacity, two 1/4, etc. + * + * Default value: 2 */ -uint8_t PaymentParameters_get_max_mpp_path_count(const struct LDKPaymentParameters *NONNULL_PTR this_ptr); +void PaymentParameters_set_max_channel_saturation_power_of_half(struct LDKPaymentParameters *NONNULL_PTR this_ptr, uint8_t val); /** - * The maximum number of paths that may be used by MPP payments. - * Defaults to [`DEFAULT_MAX_MPP_PATH_COUNT`]. + * A list of SCIDs which this payment was previously attempted over and which caused the + * payment to fail. Future attempts for the same payment shouldn't be relayed through any of + * these SCIDs. */ -void PaymentParameters_set_max_mpp_path_count(struct LDKPaymentParameters *NONNULL_PTR this_ptr, uint8_t val); +void PaymentParameters_set_previously_failed_channels(struct LDKPaymentParameters *NONNULL_PTR this_ptr, struct LDKCVec_u64Z val); /** * Constructs a new PaymentParameters given each field */ -MUST_USE_RES struct LDKPaymentParameters PaymentParameters_new(struct LDKPublicKey payee_pubkey_arg, struct LDKInvoiceFeatures features_arg, struct LDKCVec_RouteHintZ route_hints_arg, struct LDKCOption_u64Z expiry_time_arg, uint32_t max_total_cltv_expiry_delta_arg, uint8_t max_mpp_path_count_arg); +MUST_USE_RES struct LDKPaymentParameters PaymentParameters_new(struct LDKPublicKey payee_pubkey_arg, struct LDKInvoiceFeatures features_arg, struct LDKCVec_RouteHintZ route_hints_arg, struct LDKCOption_u64Z expiry_time_arg, uint32_t max_total_cltv_expiry_delta_arg, uint8_t max_path_count_arg, uint8_t max_channel_saturation_power_of_half_arg, struct LDKCVec_u64Z previously_failed_channels_arg); /** * Creates a copy of the PaymentParameters @@ -27303,6 +27772,38 @@ uint64_t ProbabilisticScoringParameters_get_base_penalty_msat(const struct LDKPr */ void ProbabilisticScoringParameters_set_base_penalty_msat(struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr, uint64_t val); +/** + * A multiplier used with the payment amount to calculate a fixed penalty applied to each + * channel, in excess of the [`base_penalty_msat`]. + * + * The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., + * fees plus penalty) for large payments. The penalty is computed as the product of this + * multiplier and `2^30`ths of the payment amount. + * + * ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30` + * + * Default value: 8,192 msat + * + * [`base_penalty_msat`]: Self::base_penalty_msat + */ +uint64_t ProbabilisticScoringParameters_get_base_penalty_amount_multiplier_msat(const struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr); + +/** + * A multiplier used with the payment amount to calculate a fixed penalty applied to each + * channel, in excess of the [`base_penalty_msat`]. + * + * The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., + * fees plus penalty) for large payments. The penalty is computed as the product of this + * multiplier and `2^30`ths of the payment amount. + * + * ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30` + * + * Default value: 8,192 msat + * + * [`base_penalty_msat`]: Self::base_penalty_msat + */ +void ProbabilisticScoringParameters_set_base_penalty_amount_multiplier_msat(struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr, uint64_t val); + /** * A multiplier used in conjunction with the negative `log10` of the channel's success * probability for a payment to determine the liquidity penalty. @@ -27380,7 +27881,7 @@ void ProbabilisticScoringParameters_set_liquidity_offset_half_life(struct LDKPro * multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the * success probability. * - * `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20` + * `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20` * * In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of * the amount will result in a penalty of the multiplier. And, as the success probability @@ -27390,7 +27891,7 @@ void ProbabilisticScoringParameters_set_liquidity_offset_half_life(struct LDKPro * * Default value: 256 msat */ -uint64_t ProbabilisticScoringParameters_get_amount_penalty_multiplier_msat(const struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr); +uint64_t ProbabilisticScoringParameters_get_liquidity_penalty_amount_multiplier_msat(const struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr); /** * A multiplier used in conjunction with a payment amount and the negative `log10` of the @@ -27401,7 +27902,7 @@ uint64_t ProbabilisticScoringParameters_get_amount_penalty_multiplier_msat(const * multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the * success probability. * - * `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20` + * `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20` * * In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of * the amount will result in a penalty of the multiplier. And, as the success probability @@ -27411,7 +27912,7 @@ uint64_t ProbabilisticScoringParameters_get_amount_penalty_multiplier_msat(const * * Default value: 256 msat */ -void ProbabilisticScoringParameters_set_amount_penalty_multiplier_msat(struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr, uint64_t val); +void ProbabilisticScoringParameters_set_liquidity_penalty_amount_multiplier_msat(struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr, uint64_t val); /** * This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the @@ -27433,6 +27934,48 @@ uint64_t ProbabilisticScoringParameters_get_anti_probing_penalty_msat(const stru */ void ProbabilisticScoringParameters_set_anti_probing_penalty_msat(struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr, uint64_t val); +/** + * This penalty is applied when the amount we're attempting to send over a channel exceeds our + * current estimate of the channel's available liquidity. + * + * Note that in this case all other penalties, including the + * [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based + * penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if + * applicable, are still included in the overall penalty. + * + * If you wish to avoid creating paths with such channels entirely, setting this to a value of + * `u64::max_value()` will guarantee that. + * + * Default value: 1_0000_0000_000 msat (1 Bitcoin) + * + * [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat + * [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat + * [`base_penalty_msat`]: Self::base_penalty_msat + * [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat + */ +uint64_t ProbabilisticScoringParameters_get_considered_impossible_penalty_msat(const struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr); + +/** + * This penalty is applied when the amount we're attempting to send over a channel exceeds our + * current estimate of the channel's available liquidity. + * + * Note that in this case all other penalties, including the + * [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based + * penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if + * applicable, are still included in the overall penalty. + * + * If you wish to avoid creating paths with such channels entirely, setting this to a value of + * `u64::max_value()` will guarantee that. + * + * Default value: 1_0000_0000_000 msat (1 Bitcoin) + * + * [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat + * [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat + * [`base_penalty_msat`]: Self::base_penalty_msat + * [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat + */ +void ProbabilisticScoringParameters_set_considered_impossible_penalty_msat(struct LDKProbabilisticScoringParameters *NONNULL_PTR this_ptr, uint64_t val); + /** * Creates a copy of the ProbabilisticScoringParameters */ @@ -27470,9 +28013,19 @@ void ProbabilisticScorer_add_banned(struct LDKProbabilisticScorer *NONNULL_PTR t void ProbabilisticScorer_remove_banned(struct LDKProbabilisticScorer *NONNULL_PTR this_arg, const struct LDKNodeId *NONNULL_PTR node_id); /** - * Clears the list of nodes that are avoided during path finding. + * Sets a manual penalty for the given node. + */ +void ProbabilisticScorer_set_manual_penalty(struct LDKProbabilisticScorer *NONNULL_PTR this_arg, const struct LDKNodeId *NONNULL_PTR node_id, uint64_t penalty); + +/** + * Removes the node with the given `node_id` from the list of manual penalties. + */ +void ProbabilisticScorer_remove_manual_penalty(struct LDKProbabilisticScorer *NONNULL_PTR this_arg, const struct LDKNodeId *NONNULL_PTR node_id); + +/** + * Clears the list of manual penalties that are applied during path finding. */ -void ProbabilisticScorer_clear_banned(struct LDKProbabilisticScorer *NONNULL_PTR this_arg); +void ProbabilisticScorer_clear_manual_penalties(struct LDKProbabilisticScorer *NONNULL_PTR this_arg); /** * Marks all nodes in the given list as banned, i.e., diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 1b383c0..006c783 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -30,6 +30,7 @@ class ConfirmationTarget; class FeeEstimator; class PaymentPurpose; class ClosureReason; +class HTLCDestination; class Event; class MessageSendEvent; class MessageSendEventsProvider; @@ -94,6 +95,7 @@ class ChannelConfig; class UserConfig; class APIError; class BigSize; +class Hostname; class OutPoint; class CustomMessageReader; class Type; @@ -250,12 +252,13 @@ class CVec_BalanceZ; class CResult_HTLCOutputInCommitmentDecodeErrorZ; class CResult_boolLightningErrorZ; class CResult_TxCreationKeysErrorZ; +class COption_HTLCDestinationZ; class CResult_NodeIdDecodeErrorZ; -class C2Tuple_BlockHashChannelMonitorZ; class CResult_ShutdownScriptInvalidShutdownScriptZ; class CResult_NodeAnnouncementInfoDecodeErrorZ; class CResult_COption_NetworkUpdateZDecodeErrorZ; class CResult_RecoverableSignatureNoneZ; +class C2Tuple_BlockHashChannelMonitorZ; class C3Tuple_RawInvoice_u832InvoiceSignatureZ; class CVec_UpdateFailMalformedHTLCZ; class CResult_FundingSignedDecodeErrorZ; @@ -286,7 +289,6 @@ class CResult_InitDecodeErrorZ; class CResult_OutPointDecodeErrorZ; class CVec_ChannelDetailsZ; class CResult_SignDecodeErrorZ; -class C2Tuple_OutPointCVec_MonitorEventZZ; class CVec_MessageSendEventZ; class COption_NetAddressZ; class C2Tuple_OutPointScriptZ; @@ -313,6 +315,7 @@ class CResult_DelayedPaymentOutputDescriptorDecodeErrorZ; class C2Tuple_PaymentHashPaymentIdZ; class CResult_C2Tuple_PaymentHashPaymentSecretZAPIErrorZ; class CResult_NoneErrorZ; +class CResult_COption_HTLCDestinationZDecodeErrorZ; class CResult_StringErrorZ; class C2Tuple_TxidCVec_C2Tuple_u32ScriptZZZ; class CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ; @@ -335,17 +338,18 @@ class CResult_DescriptionCreationErrorZ; class CResult_RoutingFeesDecodeErrorZ; class CResult_PayeePubKeyErrorZ; class CResult_COption_MonitorEventZDecodeErrorZ; +class C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ; class CVec_C2Tuple_PublicKeyTypeZZ; -class CResult_u32GraphSyncErrorZ; class CResult_InvoiceSemanticErrorZ; +class CResult_u32GraphSyncErrorZ; class CResult_UpdateAddHTLCDecodeErrorZ; -class CResult_QueryShortChannelIdsDecodeErrorZ; class CResult_CounterpartyChannelTransactionParametersDecodeErrorZ; class CResult_NoneAPIErrorZ; class CVec_NetAddressZ; class CResult_ChannelDetailsDecodeErrorZ; class CVec_PublicKeyZ; class CVec_C2Tuple_usizeTransactionZZ; +class CResult_QueryShortChannelIdsDecodeErrorZ; class CVec_PhantomRouteHintsZ; class COption_MonitorEventZ; class C2Tuple_u64u64Z; @@ -369,6 +373,7 @@ class CVec_C2Tuple_u32ScriptZZ; class CResult_NoneChannelMonitorUpdateErrZ; class CResult_COption_ClosureReasonZDecodeErrorZ; class CResult_PublicKeyErrorZ; +class CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ; class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ; class CResult_NoneNoneZ; class CResult_RouteParametersDecodeErrorZ; @@ -391,9 +396,8 @@ class C2Tuple_u32ScriptZ; class CResult_RouteDecodeErrorZ; class CResult_BuiltCommitmentTransactionDecodeErrorZ; class COption_NoneZ; -class CVec_TxOutZ; class CResult_ChannelUpdateInfoDecodeErrorZ; -class CVec_C2Tuple_OutPointCVec_MonitorEventZZZ; +class CVec_TxOutZ; class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ; class CVec_UpdateFailHTLCZ; class CResult_ReplyShortChannelIdsEndDecodeErrorZ; @@ -808,12 +812,12 @@ public: /** * Gets estimated satoshis of fee required per 1000 Weight-Units. * - * Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later - * round-downs don't put us below 1 satoshi-per-byte). + * LDK will wrap this method and ensure that the value returned is no smaller than 253 + * (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte). * - * This method can be implemented with the following unit conversions: - * * max(satoshis-per-byte * 250, 253) - * * max(satoshis-per-kbyte / 4, 253) + * The following unit conversions can be used to convert to sats/KW: + * * satoshis-per-byte * 250 + * * satoshis-per-kbyte / 4 */ inline uint32_t get_est_sat_per_1000_weight(enum LDKConfirmationTarget confirmation_target); }; @@ -847,6 +851,21 @@ public: const LDKClosureReason* operator &() const { return &self; } const LDKClosureReason* operator ->() const { return &self; } }; +class HTLCDestination { +private: + LDKHTLCDestination self; +public: + HTLCDestination(const HTLCDestination&) = delete; + HTLCDestination(HTLCDestination&& o) : self(o.self) { memset(&o, 0, sizeof(HTLCDestination)); } + HTLCDestination(LDKHTLCDestination&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHTLCDestination)); } + operator LDKHTLCDestination() && { LDKHTLCDestination res = self; memset(&self, 0, sizeof(LDKHTLCDestination)); return res; } + ~HTLCDestination() { HTLCDestination_free(self); } + HTLCDestination& operator=(HTLCDestination&& o) { HTLCDestination_free(self); self = o.self; memset(&o, 0, sizeof(HTLCDestination)); return *this; } + LDKHTLCDestination* operator &() { return &self; } + LDKHTLCDestination* operator ->() { return &self; } + const LDKHTLCDestination* operator &() const { return &self; } + const LDKHTLCDestination* operator ->() const { return &self; } +}; class Event { private: LDKEvent self; @@ -1149,7 +1168,7 @@ public: * For details on asynchronous [`ChannelMonitor`] updating and returning * [`MonitorEvent::UpdateCompleted`] here, see [`ChannelMonitorUpdateErr::TemporaryFailure`]. */ - inline LDK::CVec_C2Tuple_OutPointCVec_MonitorEventZZZ release_pending_monitor_events(); + inline LDK::CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ release_pending_monitor_events(); }; class Filter { private: @@ -1231,6 +1250,14 @@ public: * Handles updating channel penalties after successfully routing along a path. */ inline void payment_path_successful(struct LDKCVec_RouteHopZ path); + /** + * Handles updating channel penalties after a probe over the given path failed. + */ + inline void probe_failed(struct LDKCVec_RouteHopZ path, uint64_t short_channel_id); + /** + * Handles updating channel penalties after a probe over the given path succeeded. + */ + inline void probe_successful(struct LDKCVec_RouteHopZ path); }; class LockableScore { private: @@ -2204,6 +2231,21 @@ public: const LDKBigSize* operator &() const { return &self; } const LDKBigSize* operator ->() const { return &self; } }; +class Hostname { +private: + LDKHostname self; +public: + Hostname(const Hostname&) = delete; + Hostname(Hostname&& o) : self(o.self) { memset(&o, 0, sizeof(Hostname)); } + Hostname(LDKHostname&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKHostname)); } + operator LDKHostname() && { LDKHostname res = self; memset(&self, 0, sizeof(LDKHostname)); return res; } + ~Hostname() { Hostname_free(self); } + Hostname& operator=(Hostname&& o) { Hostname_free(self); self = o.self; memset(&o, 0, sizeof(Hostname)); return *this; } + LDKHostname* operator &() { return &self; } + LDKHostname* operator ->() { return &self; } + const LDKHostname* operator &() const { return &self; } + const LDKHostname* operator ->() const { return &self; } +}; class OutPoint { private: LDKOutPoint self; @@ -4846,6 +4888,21 @@ public: const LDKCResult_TxCreationKeysErrorZ* operator &() const { return &self; } const LDKCResult_TxCreationKeysErrorZ* operator ->() const { return &self; } }; +class COption_HTLCDestinationZ { +private: + LDKCOption_HTLCDestinationZ self; +public: + COption_HTLCDestinationZ(const COption_HTLCDestinationZ&) = delete; + COption_HTLCDestinationZ(COption_HTLCDestinationZ&& o) : self(o.self) { memset(&o, 0, sizeof(COption_HTLCDestinationZ)); } + COption_HTLCDestinationZ(LDKCOption_HTLCDestinationZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCOption_HTLCDestinationZ)); } + operator LDKCOption_HTLCDestinationZ() && { LDKCOption_HTLCDestinationZ res = self; memset(&self, 0, sizeof(LDKCOption_HTLCDestinationZ)); return res; } + ~COption_HTLCDestinationZ() { COption_HTLCDestinationZ_free(self); } + COption_HTLCDestinationZ& operator=(COption_HTLCDestinationZ&& o) { COption_HTLCDestinationZ_free(self); self = o.self; memset(&o, 0, sizeof(COption_HTLCDestinationZ)); return *this; } + LDKCOption_HTLCDestinationZ* operator &() { return &self; } + LDKCOption_HTLCDestinationZ* operator ->() { return &self; } + const LDKCOption_HTLCDestinationZ* operator &() const { return &self; } + const LDKCOption_HTLCDestinationZ* operator ->() const { return &self; } +}; class CResult_NodeIdDecodeErrorZ { private: LDKCResult_NodeIdDecodeErrorZ self; @@ -4861,21 +4918,6 @@ public: const LDKCResult_NodeIdDecodeErrorZ* operator &() const { return &self; } const LDKCResult_NodeIdDecodeErrorZ* operator ->() const { return &self; } }; -class C2Tuple_BlockHashChannelMonitorZ { -private: - LDKC2Tuple_BlockHashChannelMonitorZ self; -public: - C2Tuple_BlockHashChannelMonitorZ(const C2Tuple_BlockHashChannelMonitorZ&) = delete; - C2Tuple_BlockHashChannelMonitorZ(C2Tuple_BlockHashChannelMonitorZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_BlockHashChannelMonitorZ)); } - C2Tuple_BlockHashChannelMonitorZ(LDKC2Tuple_BlockHashChannelMonitorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_BlockHashChannelMonitorZ)); } - operator LDKC2Tuple_BlockHashChannelMonitorZ() && { LDKC2Tuple_BlockHashChannelMonitorZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_BlockHashChannelMonitorZ)); return res; } - ~C2Tuple_BlockHashChannelMonitorZ() { C2Tuple_BlockHashChannelMonitorZ_free(self); } - C2Tuple_BlockHashChannelMonitorZ& operator=(C2Tuple_BlockHashChannelMonitorZ&& o) { C2Tuple_BlockHashChannelMonitorZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_BlockHashChannelMonitorZ)); return *this; } - LDKC2Tuple_BlockHashChannelMonitorZ* operator &() { return &self; } - LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() { return &self; } - const LDKC2Tuple_BlockHashChannelMonitorZ* operator &() const { return &self; } - const LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() const { return &self; } -}; class CResult_ShutdownScriptInvalidShutdownScriptZ { private: LDKCResult_ShutdownScriptInvalidShutdownScriptZ self; @@ -4936,6 +4978,21 @@ public: const LDKCResult_RecoverableSignatureNoneZ* operator &() const { return &self; } const LDKCResult_RecoverableSignatureNoneZ* operator ->() const { return &self; } }; +class C2Tuple_BlockHashChannelMonitorZ { +private: + LDKC2Tuple_BlockHashChannelMonitorZ self; +public: + C2Tuple_BlockHashChannelMonitorZ(const C2Tuple_BlockHashChannelMonitorZ&) = delete; + C2Tuple_BlockHashChannelMonitorZ(C2Tuple_BlockHashChannelMonitorZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_BlockHashChannelMonitorZ)); } + C2Tuple_BlockHashChannelMonitorZ(LDKC2Tuple_BlockHashChannelMonitorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_BlockHashChannelMonitorZ)); } + operator LDKC2Tuple_BlockHashChannelMonitorZ() && { LDKC2Tuple_BlockHashChannelMonitorZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_BlockHashChannelMonitorZ)); return res; } + ~C2Tuple_BlockHashChannelMonitorZ() { C2Tuple_BlockHashChannelMonitorZ_free(self); } + C2Tuple_BlockHashChannelMonitorZ& operator=(C2Tuple_BlockHashChannelMonitorZ&& o) { C2Tuple_BlockHashChannelMonitorZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_BlockHashChannelMonitorZ)); return *this; } + LDKC2Tuple_BlockHashChannelMonitorZ* operator &() { return &self; } + LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() { return &self; } + const LDKC2Tuple_BlockHashChannelMonitorZ* operator &() const { return &self; } + const LDKC2Tuple_BlockHashChannelMonitorZ* operator ->() const { return &self; } +}; class C3Tuple_RawInvoice_u832InvoiceSignatureZ { private: LDKC3Tuple_RawInvoice_u832InvoiceSignatureZ self; @@ -5386,21 +5443,6 @@ public: const LDKCResult_SignDecodeErrorZ* operator &() const { return &self; } const LDKCResult_SignDecodeErrorZ* operator ->() const { return &self; } }; -class C2Tuple_OutPointCVec_MonitorEventZZ { -private: - LDKC2Tuple_OutPointCVec_MonitorEventZZ self; -public: - C2Tuple_OutPointCVec_MonitorEventZZ(const C2Tuple_OutPointCVec_MonitorEventZZ&) = delete; - C2Tuple_OutPointCVec_MonitorEventZZ(C2Tuple_OutPointCVec_MonitorEventZZ&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_OutPointCVec_MonitorEventZZ)); } - C2Tuple_OutPointCVec_MonitorEventZZ(LDKC2Tuple_OutPointCVec_MonitorEventZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_OutPointCVec_MonitorEventZZ)); } - operator LDKC2Tuple_OutPointCVec_MonitorEventZZ() && { LDKC2Tuple_OutPointCVec_MonitorEventZZ res = self; memset(&self, 0, sizeof(LDKC2Tuple_OutPointCVec_MonitorEventZZ)); return res; } - ~C2Tuple_OutPointCVec_MonitorEventZZ() { C2Tuple_OutPointCVec_MonitorEventZZ_free(self); } - C2Tuple_OutPointCVec_MonitorEventZZ& operator=(C2Tuple_OutPointCVec_MonitorEventZZ&& o) { C2Tuple_OutPointCVec_MonitorEventZZ_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_OutPointCVec_MonitorEventZZ)); return *this; } - LDKC2Tuple_OutPointCVec_MonitorEventZZ* operator &() { return &self; } - LDKC2Tuple_OutPointCVec_MonitorEventZZ* operator ->() { return &self; } - const LDKC2Tuple_OutPointCVec_MonitorEventZZ* operator &() const { return &self; } - const LDKC2Tuple_OutPointCVec_MonitorEventZZ* operator ->() const { return &self; } -}; class CVec_MessageSendEventZ { private: LDKCVec_MessageSendEventZ self; @@ -5791,6 +5833,21 @@ public: const LDKCResult_NoneErrorZ* operator &() const { return &self; } const LDKCResult_NoneErrorZ* operator ->() const { return &self; } }; +class CResult_COption_HTLCDestinationZDecodeErrorZ { +private: + LDKCResult_COption_HTLCDestinationZDecodeErrorZ self; +public: + CResult_COption_HTLCDestinationZDecodeErrorZ(const CResult_COption_HTLCDestinationZDecodeErrorZ&) = delete; + CResult_COption_HTLCDestinationZDecodeErrorZ(CResult_COption_HTLCDestinationZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_COption_HTLCDestinationZDecodeErrorZ)); } + CResult_COption_HTLCDestinationZDecodeErrorZ(LDKCResult_COption_HTLCDestinationZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_COption_HTLCDestinationZDecodeErrorZ)); } + operator LDKCResult_COption_HTLCDestinationZDecodeErrorZ() && { LDKCResult_COption_HTLCDestinationZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_COption_HTLCDestinationZDecodeErrorZ)); return res; } + ~CResult_COption_HTLCDestinationZDecodeErrorZ() { CResult_COption_HTLCDestinationZDecodeErrorZ_free(self); } + CResult_COption_HTLCDestinationZDecodeErrorZ& operator=(CResult_COption_HTLCDestinationZDecodeErrorZ&& o) { CResult_COption_HTLCDestinationZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_COption_HTLCDestinationZDecodeErrorZ)); return *this; } + LDKCResult_COption_HTLCDestinationZDecodeErrorZ* operator &() { return &self; } + LDKCResult_COption_HTLCDestinationZDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_COption_HTLCDestinationZDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_COption_HTLCDestinationZDecodeErrorZ* operator ->() const { return &self; } +}; class CResult_StringErrorZ { private: LDKCResult_StringErrorZ self; @@ -6121,6 +6178,21 @@ public: const LDKCResult_COption_MonitorEventZDecodeErrorZ* operator &() const { return &self; } const LDKCResult_COption_MonitorEventZDecodeErrorZ* operator ->() const { return &self; } }; +class C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { +private: + LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ self; +public: + C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ(const C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ&) = delete; + C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ(C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ&& o) : self(o.self) { memset(&o, 0, sizeof(C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ)); } + C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ(LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ)); } + operator LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ() && { LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ res = self; memset(&self, 0, sizeof(LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ)); return res; } + ~C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ() { C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_free(self); } + C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ& operator=(C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ&& o) { C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_free(self); self = o.self; memset(&o, 0, sizeof(C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ)); return *this; } + LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ* operator &() { return &self; } + LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ* operator ->() { return &self; } + const LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ* operator &() const { return &self; } + const LDKC3Tuple_OutPointCVec_MonitorEventZPublicKeyZ* operator ->() const { return &self; } +}; class CVec_C2Tuple_PublicKeyTypeZZ { private: LDKCVec_C2Tuple_PublicKeyTypeZZ self; @@ -6136,21 +6208,6 @@ public: const LDKCVec_C2Tuple_PublicKeyTypeZZ* operator &() const { return &self; } const LDKCVec_C2Tuple_PublicKeyTypeZZ* operator ->() const { return &self; } }; -class CResult_u32GraphSyncErrorZ { -private: - LDKCResult_u32GraphSyncErrorZ self; -public: - CResult_u32GraphSyncErrorZ(const CResult_u32GraphSyncErrorZ&) = delete; - CResult_u32GraphSyncErrorZ(CResult_u32GraphSyncErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_u32GraphSyncErrorZ)); } - CResult_u32GraphSyncErrorZ(LDKCResult_u32GraphSyncErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_u32GraphSyncErrorZ)); } - operator LDKCResult_u32GraphSyncErrorZ() && { LDKCResult_u32GraphSyncErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_u32GraphSyncErrorZ)); return res; } - ~CResult_u32GraphSyncErrorZ() { CResult_u32GraphSyncErrorZ_free(self); } - CResult_u32GraphSyncErrorZ& operator=(CResult_u32GraphSyncErrorZ&& o) { CResult_u32GraphSyncErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_u32GraphSyncErrorZ)); return *this; } - LDKCResult_u32GraphSyncErrorZ* operator &() { return &self; } - LDKCResult_u32GraphSyncErrorZ* operator ->() { return &self; } - const LDKCResult_u32GraphSyncErrorZ* operator &() const { return &self; } - const LDKCResult_u32GraphSyncErrorZ* operator ->() const { return &self; } -}; class CResult_InvoiceSemanticErrorZ { private: LDKCResult_InvoiceSemanticErrorZ self; @@ -6166,6 +6223,21 @@ public: const LDKCResult_InvoiceSemanticErrorZ* operator &() const { return &self; } const LDKCResult_InvoiceSemanticErrorZ* operator ->() const { return &self; } }; +class CResult_u32GraphSyncErrorZ { +private: + LDKCResult_u32GraphSyncErrorZ self; +public: + CResult_u32GraphSyncErrorZ(const CResult_u32GraphSyncErrorZ&) = delete; + CResult_u32GraphSyncErrorZ(CResult_u32GraphSyncErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_u32GraphSyncErrorZ)); } + CResult_u32GraphSyncErrorZ(LDKCResult_u32GraphSyncErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_u32GraphSyncErrorZ)); } + operator LDKCResult_u32GraphSyncErrorZ() && { LDKCResult_u32GraphSyncErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_u32GraphSyncErrorZ)); return res; } + ~CResult_u32GraphSyncErrorZ() { CResult_u32GraphSyncErrorZ_free(self); } + CResult_u32GraphSyncErrorZ& operator=(CResult_u32GraphSyncErrorZ&& o) { CResult_u32GraphSyncErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_u32GraphSyncErrorZ)); return *this; } + LDKCResult_u32GraphSyncErrorZ* operator &() { return &self; } + LDKCResult_u32GraphSyncErrorZ* operator ->() { return &self; } + const LDKCResult_u32GraphSyncErrorZ* operator &() const { return &self; } + const LDKCResult_u32GraphSyncErrorZ* operator ->() const { return &self; } +}; class CResult_UpdateAddHTLCDecodeErrorZ { private: LDKCResult_UpdateAddHTLCDecodeErrorZ self; @@ -6181,21 +6253,6 @@ public: const LDKCResult_UpdateAddHTLCDecodeErrorZ* operator &() const { return &self; } const LDKCResult_UpdateAddHTLCDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_QueryShortChannelIdsDecodeErrorZ { -private: - LDKCResult_QueryShortChannelIdsDecodeErrorZ self; -public: - CResult_QueryShortChannelIdsDecodeErrorZ(const CResult_QueryShortChannelIdsDecodeErrorZ&) = delete; - CResult_QueryShortChannelIdsDecodeErrorZ(CResult_QueryShortChannelIdsDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_QueryShortChannelIdsDecodeErrorZ)); } - CResult_QueryShortChannelIdsDecodeErrorZ(LDKCResult_QueryShortChannelIdsDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ)); } - operator LDKCResult_QueryShortChannelIdsDecodeErrorZ() && { LDKCResult_QueryShortChannelIdsDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ)); return res; } - ~CResult_QueryShortChannelIdsDecodeErrorZ() { CResult_QueryShortChannelIdsDecodeErrorZ_free(self); } - CResult_QueryShortChannelIdsDecodeErrorZ& operator=(CResult_QueryShortChannelIdsDecodeErrorZ&& o) { CResult_QueryShortChannelIdsDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_QueryShortChannelIdsDecodeErrorZ)); return *this; } - LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator &() { return &self; } - LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator ->() const { return &self; } -}; class CResult_CounterpartyChannelTransactionParametersDecodeErrorZ { private: LDKCResult_CounterpartyChannelTransactionParametersDecodeErrorZ self; @@ -6286,6 +6343,21 @@ public: const LDKCVec_C2Tuple_usizeTransactionZZ* operator &() const { return &self; } const LDKCVec_C2Tuple_usizeTransactionZZ* operator ->() const { return &self; } }; +class CResult_QueryShortChannelIdsDecodeErrorZ { +private: + LDKCResult_QueryShortChannelIdsDecodeErrorZ self; +public: + CResult_QueryShortChannelIdsDecodeErrorZ(const CResult_QueryShortChannelIdsDecodeErrorZ&) = delete; + CResult_QueryShortChannelIdsDecodeErrorZ(CResult_QueryShortChannelIdsDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_QueryShortChannelIdsDecodeErrorZ)); } + CResult_QueryShortChannelIdsDecodeErrorZ(LDKCResult_QueryShortChannelIdsDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ)); } + operator LDKCResult_QueryShortChannelIdsDecodeErrorZ() && { LDKCResult_QueryShortChannelIdsDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ)); return res; } + ~CResult_QueryShortChannelIdsDecodeErrorZ() { CResult_QueryShortChannelIdsDecodeErrorZ_free(self); } + CResult_QueryShortChannelIdsDecodeErrorZ& operator=(CResult_QueryShortChannelIdsDecodeErrorZ&& o) { CResult_QueryShortChannelIdsDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_QueryShortChannelIdsDecodeErrorZ)); return *this; } + LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator &() { return &self; } + LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_QueryShortChannelIdsDecodeErrorZ* operator ->() const { return &self; } +}; class CVec_PhantomRouteHintsZ { private: LDKCVec_PhantomRouteHintsZ self; @@ -6631,6 +6703,21 @@ public: const LDKCResult_PublicKeyErrorZ* operator &() const { return &self; } const LDKCResult_PublicKeyErrorZ* operator ->() const { return &self; } }; +class CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { +private: + LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ self; +public: + CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ(const CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ&) = delete; + CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ(CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ)); } + CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ(LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ)); } + operator LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ() && { LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ res = self; memset(&self, 0, sizeof(LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ)); return res; } + ~CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ() { CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ_free(self); } + CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ& operator=(CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ&& o) { CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ)); return *this; } + LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ* operator &() { return &self; } + LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ* operator ->() { return &self; } + const LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ* operator &() const { return &self; } + const LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ* operator ->() const { return &self; } +}; class C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ { private: LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ self; @@ -6961,21 +7048,6 @@ public: const LDKCOption_NoneZ* operator &() const { return &self; } const LDKCOption_NoneZ* operator ->() const { return &self; } }; -class CVec_TxOutZ { -private: - LDKCVec_TxOutZ self; -public: - CVec_TxOutZ(const CVec_TxOutZ&) = delete; - CVec_TxOutZ(CVec_TxOutZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_TxOutZ)); } - CVec_TxOutZ(LDKCVec_TxOutZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_TxOutZ)); } - operator LDKCVec_TxOutZ() && { LDKCVec_TxOutZ res = self; memset(&self, 0, sizeof(LDKCVec_TxOutZ)); return res; } - ~CVec_TxOutZ() { CVec_TxOutZ_free(self); } - CVec_TxOutZ& operator=(CVec_TxOutZ&& o) { CVec_TxOutZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_TxOutZ)); return *this; } - LDKCVec_TxOutZ* operator &() { return &self; } - LDKCVec_TxOutZ* operator ->() { return &self; } - const LDKCVec_TxOutZ* operator &() const { return &self; } - const LDKCVec_TxOutZ* operator ->() const { return &self; } -}; class CResult_ChannelUpdateInfoDecodeErrorZ { private: LDKCResult_ChannelUpdateInfoDecodeErrorZ self; @@ -6991,20 +7063,20 @@ public: const LDKCResult_ChannelUpdateInfoDecodeErrorZ* operator &() const { return &self; } const LDKCResult_ChannelUpdateInfoDecodeErrorZ* operator ->() const { return &self; } }; -class CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { +class CVec_TxOutZ { private: - LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ self; + LDKCVec_TxOutZ self; public: - CVec_C2Tuple_OutPointCVec_MonitorEventZZZ(const CVec_C2Tuple_OutPointCVec_MonitorEventZZZ&) = delete; - CVec_C2Tuple_OutPointCVec_MonitorEventZZZ(CVec_C2Tuple_OutPointCVec_MonitorEventZZZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_C2Tuple_OutPointCVec_MonitorEventZZZ)); } - CVec_C2Tuple_OutPointCVec_MonitorEventZZZ(LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ)); } - operator LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ() && { LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ res = self; memset(&self, 0, sizeof(LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ)); return res; } - ~CVec_C2Tuple_OutPointCVec_MonitorEventZZZ() { CVec_C2Tuple_OutPointCVec_MonitorEventZZZ_free(self); } - CVec_C2Tuple_OutPointCVec_MonitorEventZZZ& operator=(CVec_C2Tuple_OutPointCVec_MonitorEventZZZ&& o) { CVec_C2Tuple_OutPointCVec_MonitorEventZZZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_C2Tuple_OutPointCVec_MonitorEventZZZ)); return *this; } - LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ* operator &() { return &self; } - LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ* operator ->() { return &self; } - const LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ* operator &() const { return &self; } - const LDKCVec_C2Tuple_OutPointCVec_MonitorEventZZZ* operator ->() const { return &self; } + CVec_TxOutZ(const CVec_TxOutZ&) = delete; + CVec_TxOutZ(CVec_TxOutZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_TxOutZ)); } + CVec_TxOutZ(LDKCVec_TxOutZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_TxOutZ)); } + operator LDKCVec_TxOutZ() && { LDKCVec_TxOutZ res = self; memset(&self, 0, sizeof(LDKCVec_TxOutZ)); return res; } + ~CVec_TxOutZ() { CVec_TxOutZ_free(self); } + CVec_TxOutZ& operator=(CVec_TxOutZ&& o) { CVec_TxOutZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_TxOutZ)); return *this; } + LDKCVec_TxOutZ* operator &() { return &self; } + LDKCVec_TxOutZ* operator ->() { return &self; } + const LDKCVec_TxOutZ* operator &() const { return &self; } + const LDKCVec_TxOutZ* operator ->() const { return &self; } }; class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { private: @@ -7103,8 +7175,8 @@ inline LDK::CResult_NoneChannelMonitorUpdateErrZ Watch::update_channel(struct LD LDK::CResult_NoneChannelMonitorUpdateErrZ ret = (self.update_channel)(self.this_arg, funding_txo, update); return ret; } -inline LDK::CVec_C2Tuple_OutPointCVec_MonitorEventZZZ Watch::release_pending_monitor_events() { - LDK::CVec_C2Tuple_OutPointCVec_MonitorEventZZZ ret = (self.release_pending_monitor_events)(self.this_arg); +inline LDK::CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ Watch::release_pending_monitor_events() { + LDK::CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ ret = (self.release_pending_monitor_events)(self.this_arg); return ret; } inline void Filter::register_tx(const uint8_t (*txid)[32], struct LDKu8slice script_pubkey) { @@ -7124,6 +7196,12 @@ inline void Score::payment_path_failed(struct LDKCVec_RouteHopZ path, uint64_t s inline void Score::payment_path_successful(struct LDKCVec_RouteHopZ path) { (self.payment_path_successful)(self.this_arg, path); } +inline void Score::probe_failed(struct LDKCVec_RouteHopZ path, uint64_t short_channel_id) { + (self.probe_failed)(self.this_arg, path, short_channel_id); +} +inline void Score::probe_successful(struct LDKCVec_RouteHopZ path) { + (self.probe_successful)(self.this_arg, path); +} inline LDK::Score LockableScore::lock() { LDK::Score ret = (self.lock)(self.this_arg); return ret; diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index dd62ebe..eb22b5a 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -2349,6 +2349,52 @@ pub extern "C" fn COption_u64Z_free(_res: COption_u64Z) { } /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn COption_u64Z_clone(orig: &COption_u64Z) -> COption_u64Z { Clone::clone(&orig) } #[repr(C)] +/// A dynamically-allocated array of u64s of arbitrary size. +/// This corresponds to std::vector in C++ +pub struct CVec_u64Z { + /// The elements in the array. + /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). + pub data: *mut u64, + /// The number of elements pointed to by `data`. + pub datalen: usize +} +impl CVec_u64Z { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { + if self.datalen == 0 { return Vec::new(); } + let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); + self.data = core::ptr::null_mut(); + self.datalen = 0; + ret + } + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[u64] { + unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } + } +} +impl From> for CVec_u64Z { + fn from(v: Vec) -> Self { + let datalen = v.len(); + let data = Box::into_raw(v.into_boxed_slice()); + Self { datalen, data: unsafe { (*data).as_mut_ptr() } } + } +} +#[no_mangle] +/// Frees the buffer pointed to by `data` if `datalen` is non-0. +pub extern "C" fn CVec_u64Z_free(_res: CVec_u64Z) { } +impl Drop for CVec_u64Z { + fn drop(&mut self) { + if self.datalen == 0 { return; } + unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }; + } +} +impl Clone for CVec_u64Z { + fn clone(&self) -> Self { + let mut res = Vec::new(); + if self.datalen == 0 { return Self::from(res); } + res.extend_from_slice(unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) }); + Self::from(res) + } +} +#[repr(C)] /// The contents of CResult_PaymentParametersDecodeErrorZ pub union CResult_PaymentParametersDecodeErrorZPtr { /// A pointer to the contents in the success state. @@ -3101,6 +3147,139 @@ impl Clone for CResult_COption_ClosureReasonZDecodeErrorZ { pub extern "C" fn CResult_COption_ClosureReasonZDecodeErrorZ_clone(orig: &CResult_COption_ClosureReasonZDecodeErrorZ) -> CResult_COption_ClosureReasonZDecodeErrorZ { Clone::clone(&orig) } #[repr(C)] #[derive(Clone)] +/// An enum which can either contain a crate::lightning::util::events::HTLCDestination or not +pub enum COption_HTLCDestinationZ { + /// When we're in this state, this COption_HTLCDestinationZ contains a crate::lightning::util::events::HTLCDestination + Some(crate::lightning::util::events::HTLCDestination), + /// When we're in this state, this COption_HTLCDestinationZ contains nothing + None +} +impl COption_HTLCDestinationZ { + #[allow(unused)] pub(crate) fn is_some(&self) -> bool { + if let Self::None = self { false } else { true } + } + #[allow(unused)] pub(crate) fn is_none(&self) -> bool { + !self.is_some() + } + #[allow(unused)] pub(crate) fn take(mut self) -> crate::lightning::util::events::HTLCDestination { + if let Self::Some(v) = self { v } else { unreachable!() } + } +} +#[no_mangle] +/// Constructs a new COption_HTLCDestinationZ containing a crate::lightning::util::events::HTLCDestination +pub extern "C" fn COption_HTLCDestinationZ_some(o: crate::lightning::util::events::HTLCDestination) -> COption_HTLCDestinationZ { + COption_HTLCDestinationZ::Some(o) +} +#[no_mangle] +/// Constructs a new COption_HTLCDestinationZ containing nothing +pub extern "C" fn COption_HTLCDestinationZ_none() -> COption_HTLCDestinationZ { + COption_HTLCDestinationZ::None +} +#[no_mangle] +/// Frees any resources associated with the crate::lightning::util::events::HTLCDestination, if we are in the Some state +pub extern "C" fn COption_HTLCDestinationZ_free(_res: COption_HTLCDestinationZ) { } +#[no_mangle] +/// Creates a new COption_HTLCDestinationZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn COption_HTLCDestinationZ_clone(orig: &COption_HTLCDestinationZ) -> COption_HTLCDestinationZ { Clone::clone(&orig) } +#[repr(C)] +/// The contents of CResult_COption_HTLCDestinationZDecodeErrorZ +pub union CResult_COption_HTLCDestinationZDecodeErrorZPtr { + /// A pointer to the contents in the success state. + /// Reading from this pointer when `result_ok` is not set is undefined. + pub result: *mut crate::c_types::derived::COption_HTLCDestinationZ, + /// A pointer to the contents in the error state. + /// Reading from this pointer when `result_ok` is set is undefined. + pub err: *mut crate::lightning::ln::msgs::DecodeError, +} +#[repr(C)] +/// A CResult_COption_HTLCDestinationZDecodeErrorZ represents the result of a fallible operation, +/// containing a crate::c_types::derived::COption_HTLCDestinationZ on success and a crate::lightning::ln::msgs::DecodeError on failure. +/// `result_ok` indicates the overall state, and the contents are provided via `contents`. +pub struct CResult_COption_HTLCDestinationZDecodeErrorZ { + /// The contents of this CResult_COption_HTLCDestinationZDecodeErrorZ, accessible via either + /// `err` or `result` depending on the state of `result_ok`. + pub contents: CResult_COption_HTLCDestinationZDecodeErrorZPtr, + /// Whether this CResult_COption_HTLCDestinationZDecodeErrorZ represents a success state. + pub result_ok: bool, +} +#[no_mangle] +/// Creates a new CResult_COption_HTLCDestinationZDecodeErrorZ in the success state. +pub extern "C" fn CResult_COption_HTLCDestinationZDecodeErrorZ_ok(o: crate::c_types::derived::COption_HTLCDestinationZ) -> CResult_COption_HTLCDestinationZDecodeErrorZ { + CResult_COption_HTLCDestinationZDecodeErrorZ { + contents: CResult_COption_HTLCDestinationZDecodeErrorZPtr { + result: Box::into_raw(Box::new(o)), + }, + result_ok: true, + } +} +#[no_mangle] +/// Creates a new CResult_COption_HTLCDestinationZDecodeErrorZ in the error state. +pub extern "C" fn CResult_COption_HTLCDestinationZDecodeErrorZ_err(e: crate::lightning::ln::msgs::DecodeError) -> CResult_COption_HTLCDestinationZDecodeErrorZ { + CResult_COption_HTLCDestinationZDecodeErrorZ { + contents: CResult_COption_HTLCDestinationZDecodeErrorZPtr { + err: Box::into_raw(Box::new(e)), + }, + result_ok: false, + } +} +/// Checks if the given object is currently in the success state +#[no_mangle] +pub extern "C" fn CResult_COption_HTLCDestinationZDecodeErrorZ_is_ok(o: &CResult_COption_HTLCDestinationZDecodeErrorZ) -> bool { + o.result_ok +} +#[no_mangle] +/// Frees any resources used by the CResult_COption_HTLCDestinationZDecodeErrorZ. +pub extern "C" fn CResult_COption_HTLCDestinationZDecodeErrorZ_free(_res: CResult_COption_HTLCDestinationZDecodeErrorZ) { } +impl Drop for CResult_COption_HTLCDestinationZDecodeErrorZ { + fn drop(&mut self) { + if self.result_ok { + if unsafe { !(self.contents.result as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.result) }; + } + } else { + if unsafe { !(self.contents.err as *mut ()).is_null() } { + let _ = unsafe { Box::from_raw(self.contents.err) }; + } + } + } +} +impl From> for CResult_COption_HTLCDestinationZDecodeErrorZ { + fn from(mut o: crate::c_types::CResultTempl) -> Self { + let contents = if o.result_ok { + let result = unsafe { o.contents.result }; + unsafe { o.contents.result = core::ptr::null_mut() }; + CResult_COption_HTLCDestinationZDecodeErrorZPtr { result } + } else { + let err = unsafe { o.contents.err }; + unsafe { o.contents.err = core::ptr::null_mut(); } + CResult_COption_HTLCDestinationZDecodeErrorZPtr { err } + }; + Self { + contents, + result_ok: o.result_ok, + } + } +} +impl Clone for CResult_COption_HTLCDestinationZDecodeErrorZ { + fn clone(&self) -> Self { + if self.result_ok { + Self { result_ok: true, contents: CResult_COption_HTLCDestinationZDecodeErrorZPtr { + result: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.result }))) + } } + } else { + Self { result_ok: false, contents: CResult_COption_HTLCDestinationZDecodeErrorZPtr { + err: Box::into_raw(Box::new(::clone(unsafe { &*self.contents.err }))) + } } + } + } +} +#[no_mangle] +/// Creates a new CResult_COption_HTLCDestinationZDecodeErrorZ which has the same data as `orig` +/// but with all dynamically-allocated buffers duplicated in new buffers. +pub extern "C" fn CResult_COption_HTLCDestinationZDecodeErrorZ_clone(orig: &CResult_COption_HTLCDestinationZDecodeErrorZ) -> CResult_COption_HTLCDestinationZDecodeErrorZ { Clone::clone(&orig) } +#[repr(C)] +#[derive(Clone)] /// An enum which can either contain a crate::lightning::routing::gossip::NetworkUpdate or not pub enum COption_NetworkUpdateZ { /// When we're in this state, this COption_NetworkUpdateZ contains a crate::lightning::routing::gossip::NetworkUpdate @@ -3730,71 +3909,75 @@ impl Clone for CVec_MonitorEventZ { } } #[repr(C)] -/// A tuple of 2 elements. See the individual fields for the types contained. -pub struct C2Tuple_OutPointCVec_MonitorEventZZ { +/// A tuple of 3 elements. See the individual fields for the types contained. +pub struct C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { /// The element at position 0 pub a: crate::lightning::chain::transaction::OutPoint, /// The element at position 1 pub b: crate::c_types::derived::CVec_MonitorEventZ, + /// The element at position 2 + pub c: crate::c_types::PublicKey, } -impl From<(crate::lightning::chain::transaction::OutPoint, crate::c_types::derived::CVec_MonitorEventZ)> for C2Tuple_OutPointCVec_MonitorEventZZ { - fn from (tup: (crate::lightning::chain::transaction::OutPoint, crate::c_types::derived::CVec_MonitorEventZ)) -> Self { +impl From<(crate::lightning::chain::transaction::OutPoint, crate::c_types::derived::CVec_MonitorEventZ, crate::c_types::PublicKey)> for C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { + fn from (tup: (crate::lightning::chain::transaction::OutPoint, crate::c_types::derived::CVec_MonitorEventZ, crate::c_types::PublicKey)) -> Self { Self { a: tup.0, b: tup.1, + c: tup.2, } } } -impl C2Tuple_OutPointCVec_MonitorEventZZ { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::lightning::chain::transaction::OutPoint, crate::c_types::derived::CVec_MonitorEventZ) { - (self.a, self.b) +impl C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { + #[allow(unused)] pub(crate) fn to_rust(mut self) -> (crate::lightning::chain::transaction::OutPoint, crate::c_types::derived::CVec_MonitorEventZ, crate::c_types::PublicKey) { + (self.a, self.b, self.c) } } -impl Clone for C2Tuple_OutPointCVec_MonitorEventZZ { +impl Clone for C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { fn clone(&self) -> Self { Self { a: Clone::clone(&self.a), b: Clone::clone(&self.b), + c: Clone::clone(&self.c), } } } #[no_mangle] /// Creates a new tuple which has the same data as `orig` /// but with all dynamically-allocated buffers duplicated in new buffers. -pub extern "C" fn C2Tuple_OutPointCVec_MonitorEventZZ_clone(orig: &C2Tuple_OutPointCVec_MonitorEventZZ) -> C2Tuple_OutPointCVec_MonitorEventZZ { Clone::clone(&orig) } -/// Creates a new C2Tuple_OutPointCVec_MonitorEventZZ from the contained elements. +pub extern "C" fn C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_clone(orig: &C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ) -> C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { Clone::clone(&orig) } +/// Creates a new C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ from the contained elements. #[no_mangle] -pub extern "C" fn C2Tuple_OutPointCVec_MonitorEventZZ_new(a: crate::lightning::chain::transaction::OutPoint, b: crate::c_types::derived::CVec_MonitorEventZ) -> C2Tuple_OutPointCVec_MonitorEventZZ { - C2Tuple_OutPointCVec_MonitorEventZZ { a, b, } +pub extern "C" fn C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_new(a: crate::lightning::chain::transaction::OutPoint, b: crate::c_types::derived::CVec_MonitorEventZ, c: crate::c_types::PublicKey) -> C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { + C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ { a, b, c, } } #[no_mangle] -/// Frees any resources used by the C2Tuple_OutPointCVec_MonitorEventZZ. -pub extern "C" fn C2Tuple_OutPointCVec_MonitorEventZZ_free(_res: C2Tuple_OutPointCVec_MonitorEventZZ) { } +/// Frees any resources used by the C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ. +pub extern "C" fn C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ_free(_res: C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ) { } #[repr(C)] -/// A dynamically-allocated array of crate::c_types::derived::C2Tuple_OutPointCVec_MonitorEventZZs of arbitrary size. +/// A dynamically-allocated array of crate::c_types::derived::C3Tuple_OutPointCVec_MonitorEventZPublicKeyZs of arbitrary size. /// This corresponds to std::vector in C++ -pub struct CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { +pub struct CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { /// The elements in the array. /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). - pub data: *mut crate::c_types::derived::C2Tuple_OutPointCVec_MonitorEventZZ, + pub data: *mut crate::c_types::derived::C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ, /// The number of elements pointed to by `data`. pub datalen: usize } -impl CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { +impl CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { + #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { if self.datalen == 0 { return Vec::new(); } let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); self.data = core::ptr::null_mut(); self.datalen = 0; ret } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C2Tuple_OutPointCVec_MonitorEventZZ] { + #[allow(unused)] pub(crate) fn as_slice(&self) -> &[crate::c_types::derived::C3Tuple_OutPointCVec_MonitorEventZPublicKeyZ] { unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } } } -impl From> for CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { - fn from(v: Vec) -> Self { +impl From> for CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { + fn from(v: Vec) -> Self { let datalen = v.len(); let data = Box::into_raw(v.into_boxed_slice()); Self { datalen, data: unsafe { (*data).as_mut_ptr() } } @@ -3802,14 +3985,14 @@ impl From> for } #[no_mangle] /// Frees the buffer pointed to by `data` if `datalen` is non-0. -pub extern "C" fn CVec_C2Tuple_OutPointCVec_MonitorEventZZZ_free(_res: CVec_C2Tuple_OutPointCVec_MonitorEventZZZ) { } -impl Drop for CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { +pub extern "C" fn CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ_free(_res: CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ) { } +impl Drop for CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { fn drop(&mut self) { if self.datalen == 0 { return; } unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }; } } -impl Clone for CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { +impl Clone for CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { fn clone(&self) -> Self { let mut res = Vec::new(); if self.datalen == 0 { return Self::from(res); } @@ -5711,52 +5894,6 @@ impl Clone for CResult_NodeAliasDecodeErrorZ { /// but with all dynamically-allocated buffers duplicated in new buffers. pub extern "C" fn CResult_NodeAliasDecodeErrorZ_clone(orig: &CResult_NodeAliasDecodeErrorZ) -> CResult_NodeAliasDecodeErrorZ { Clone::clone(&orig) } #[repr(C)] -/// A dynamically-allocated array of u64s of arbitrary size. -/// This corresponds to std::vector in C++ -pub struct CVec_u64Z { - /// The elements in the array. - /// If datalen is non-0 this must be a valid, non-NULL pointer allocated by malloc(). - pub data: *mut u64, - /// The number of elements pointed to by `data`. - pub datalen: usize -} -impl CVec_u64Z { - #[allow(unused)] pub(crate) fn into_rust(&mut self) -> Vec { - if self.datalen == 0 { return Vec::new(); } - let ret = unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }.into(); - self.data = core::ptr::null_mut(); - self.datalen = 0; - ret - } - #[allow(unused)] pub(crate) fn as_slice(&self) -> &[u64] { - unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) } - } -} -impl From> for CVec_u64Z { - fn from(v: Vec) -> Self { - let datalen = v.len(); - let data = Box::into_raw(v.into_boxed_slice()); - Self { datalen, data: unsafe { (*data).as_mut_ptr() } } - } -} -#[no_mangle] -/// Frees the buffer pointed to by `data` if `datalen` is non-0. -pub extern "C" fn CVec_u64Z_free(_res: CVec_u64Z) { } -impl Drop for CVec_u64Z { - fn drop(&mut self) { - if self.datalen == 0 { return; } - unsafe { Box::from_raw(core::slice::from_raw_parts_mut(self.data, self.datalen)) }; - } -} -impl Clone for CVec_u64Z { - fn clone(&self) -> Self { - let mut res = Vec::new(); - if self.datalen == 0 { return Self::from(res); } - res.extend_from_slice(unsafe { core::slice::from_raw_parts_mut(self.data, self.datalen) }); - Self::from(res) - } -} -#[repr(C)] /// The contents of CResult_NodeInfoDecodeErrorZ pub union CResult_NodeInfoDecodeErrorZPtr { /// A pointer to the contents in the success state. diff --git a/lightning-c-bindings/src/lightning/chain/chaininterface.rs b/lightning-c-bindings/src/lightning/chain/chaininterface.rs index 40406be..2c1d281 100644 --- a/lightning-c-bindings/src/lightning/chain/chaininterface.rs +++ b/lightning-c-bindings/src/lightning/chain/chaininterface.rs @@ -153,12 +153,12 @@ pub struct FeeEstimator { pub this_arg: *mut c_void, /// Gets estimated satoshis of fee required per 1000 Weight-Units. /// - /// Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later - /// round-downs don't put us below 1 satoshi-per-byte). + /// LDK will wrap this method and ensure that the value returned is no smaller than 253 + /// (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte). /// - /// This method can be implemented with the following unit conversions: - /// * max(satoshis-per-byte * 250, 253) - /// * max(satoshis-per-kbyte / 4, 253) + /// The following unit conversions can be used to convert to sats/KW: + /// * satoshis-per-byte * 250 + /// * satoshis-per-kbyte / 4 #[must_use] pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32, /// Frees any resources associated with this object given its this_arg pointer. @@ -206,3 +206,9 @@ impl Drop for FeeEstimator { #[no_mangle] pub static MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = lightning::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT; +/// Minimum feerate that takes a sane approach to bitcoind weight-to-vbytes rounding. +/// See the following Core Lightning commit for an explanation: +/// + +#[no_mangle] +pub static FEERATE_FLOOR_SATS_PER_KW: u32 = lightning::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW; diff --git a/lightning-c-bindings/src/lightning/chain/chainmonitor.rs b/lightning-c-bindings/src/lightning/chain/chainmonitor.rs index f51444f..53a63bd 100644 --- a/lightning-c-bindings/src/lightning/chain/chainmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/chainmonitor.rs @@ -549,9 +549,9 @@ extern "C" fn ChainMonitor_Watch_update_channel(this_arg: *const c_void, mut fun local_ret } #[must_use] -extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_OutPointCVec_MonitorEventZZZ { +extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ { let mut ret = >::release_pending_monitor_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); }; let mut local_ret_0 = (crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1.into()).into(); local_ret_0 }); }; + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.drain(..) { local_orig_ret_0_1.push( { crate::lightning::chain::channelmonitor::MonitorEvent::native_into(item) }); }; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(orig_ret_0_2.unwrap())) } }; let mut local_ret_0 = (crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(orig_ret_0_0), is_owned: true }, local_orig_ret_0_1.into(), local_orig_ret_0_2).into(); local_ret_0 }); }; local_ret.into() } diff --git a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs index df25ef6..1391178 100644 --- a/lightning-c-bindings/src/lightning/chain/channelmonitor.rs +++ b/lightning-c-bindings/src/lightning/chain/channelmonitor.rs @@ -757,7 +757,7 @@ pub(crate) extern "C" fn ChannelMonitor_write_void(obj: *const c_void) -> crate: /// panics if the given update is not the next update by update_id. #[must_use] #[no_mangle] -pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, fee_estimator: &crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ { +pub extern "C" fn ChannelMonitor_update_monitor(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, updates: &crate::lightning::chain::channelmonitor::ChannelMonitorUpdate, broadcaster: &crate::lightning::chain::chaininterface::BroadcasterInterface, mut fee_estimator: crate::lightning::chain::chaininterface::FeeEstimator, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_NoneNoneZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_monitor(updates.get_native_ref(), broadcaster, fee_estimator, logger); let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() }; local_ret @@ -823,6 +823,20 @@ pub extern "C" fn ChannelMonitor_get_and_clear_pending_events(this_arg: &crate:: local_ret.into() } +/// Gets the `node_id` of the counterparty for this channel. +/// +/// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some` +/// otherwise. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelMonitor_get_counterparty_node_id(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::PublicKey { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_counterparty_node_id(); + let mut local_ret = if ret.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(ret.unwrap())) } }; + local_ret +} + /// Used by ChannelManager deserialization to broadcast the latest holder state if its copy of /// the Channel was out-of-date. You may use it to get a broadcastable holder toxic tx in case of /// fallen-behind, i.e when receiving a channel_reestablish with a proof that our counterparty side knows diff --git a/lightning-c-bindings/src/lightning/chain/mod.rs b/lightning-c-bindings/src/lightning/chain/mod.rs index b2c7a02..4cd85a2 100644 --- a/lightning-c-bindings/src/lightning/chain/mod.rs +++ b/lightning-c-bindings/src/lightning/chain/mod.rs @@ -638,7 +638,7 @@ pub struct Watch { /// For details on asynchronous [`ChannelMonitor`] updating and returning /// [`MonitorEvent::UpdateCompleted`] here, see [`ChannelMonitorUpdateErr::TemporaryFailure`]. #[must_use] - pub release_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C2Tuple_OutPointCVec_MonitorEventZZZ, + pub release_pending_monitor_events: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, @@ -668,9 +668,9 @@ impl rustWatch for Watch { let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })}; local_ret } - fn release_pending_monitor_events(&self) -> Vec<(lightning::chain::transaction::OutPoint, Vec)> { + fn release_pending_monitor_events(&self) -> Vec<(lightning::chain::transaction::OutPoint, Vec, Option)> { let mut ret = (self.release_pending_monitor_events)(self.this_arg); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1) = item.to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_native() }); }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1); local_ret_0 }); }; + let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_native() }); }; let mut local_orig_ret_0_2 = if orig_ret_0_2.is_null() { None } else { Some( { orig_ret_0_2.into_rust() }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }); }; local_ret } } diff --git a/lightning-c-bindings/src/lightning/ln/channelmanager.rs b/lightning-c-bindings/src/lightning/ln/channelmanager.rs index e0d04cf..e67d890 100644 --- a/lightning-c-bindings/src/lightning/ln/channelmanager.rs +++ b/lightning-c-bindings/src/lightning/ln/channelmanager.rs @@ -1819,6 +1819,18 @@ pub extern "C" fn ChannelManager_send_spontaneous_payment(this_arg: &crate::ligh local_ret } +/// Send a payment that is probing the given route for liquidity. We calculate the +/// [`PaymentHash`] of probes based on a static secret and a random [`PaymentId`], which allows +/// us to easily discern them from real payments. +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelManager_send_probe(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut hops: crate::c_types::derived::CVec_RouteHopZ) -> crate::c_types::derived::CResult_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ { + let mut local_hops = Vec::new(); for mut item in hops.into_rust().drain(..) { local_hops.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_probe(local_hops); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::channelmanager::PaymentSendFailure::native_into(e) }).into() }; + local_ret +} + /// Call this upon creation of a funding transaction for the given channel. /// /// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs @@ -1872,7 +1884,7 @@ pub extern "C" fn ChannelManager_funding_transaction_generated(this_arg: &crate: /// tying these addresses together and to this node. If you wish to preserve user privacy, /// addresses should likely contain only Tor Onion addresses. /// -/// Panics if `addresses` is absurdly large (more than 500). +/// Panics if `addresses` is absurdly large (more than 100). /// /// [`get_and_clear_pending_msg_events`]: MessageSendEventsProvider::get_and_clear_pending_msg_events #[no_mangle] diff --git a/lightning-c-bindings/src/lightning/ln/msgs.rs b/lightning-c-bindings/src/lightning/ln/msgs.rs index a9f83a9..36cf43f 100644 --- a/lightning-c-bindings/src/lightning/ln/msgs.rs +++ b/lightning-c-bindings/src/lightning/ln/msgs.rs @@ -2983,6 +2983,13 @@ pub enum NetAddress { /// The port on which the node is listening port: u16, }, + /// A hostname/port on which the peer is listening. + Hostname { + /// The hostname on which the node is listening. + hostname: crate::lightning::util::ser::Hostname, + /// The port on which the node is listening. + port: u16, + }, } use lightning::ln::msgs::NetAddress as NetAddressImport; pub(crate) type nativeNetAddress = NetAddressImport; @@ -3025,6 +3032,14 @@ impl NetAddress { port: port_nonref, } }, + NetAddress::Hostname {ref hostname, ref port, } => { + let mut hostname_nonref = (*hostname).clone(); + let mut port_nonref = (*port).clone(); + nativeNetAddress::Hostname { + hostname: *unsafe { Box::from_raw(hostname_nonref.take_inner()) }, + port: port_nonref, + } + }, } } #[allow(unused)] @@ -3055,6 +3070,12 @@ impl NetAddress { port: port, } }, + NetAddress::Hostname {mut hostname, mut port, } => { + nativeNetAddress::Hostname { + hostname: *unsafe { Box::from_raw(hostname.take_inner()) }, + port: port, + } + }, } } #[allow(unused)] @@ -3094,6 +3115,14 @@ impl NetAddress { port: port_nonref, } }, + nativeNetAddress::Hostname {ref hostname, ref port, } => { + let mut hostname_nonref = (*hostname).clone(); + let mut port_nonref = (*port).clone(); + NetAddress::Hostname { + hostname: crate::lightning::util::ser::Hostname { inner: ObjOps::heap_alloc(hostname_nonref), is_owned: true }, + port: port_nonref, + } + }, } } #[allow(unused)] @@ -3124,6 +3153,12 @@ impl NetAddress { port: port, } }, + nativeNetAddress::Hostname {mut hostname, mut port, } => { + NetAddress::Hostname { + hostname: crate::lightning::util::ser::Hostname { inner: ObjOps::heap_alloc(hostname), is_owned: true }, + port: port, + } + }, } } } @@ -3167,6 +3202,14 @@ pub extern "C" fn NetAddress_onion_v3(ed25519_pubkey: crate::c_types::ThirtyTwoB } } #[no_mangle] +/// Utility method to constructs a new Hostname-variant NetAddress +pub extern "C" fn NetAddress_hostname(hostname: crate::lightning::util::ser::Hostname, port: u16) -> NetAddress { + NetAddress::Hostname { + hostname, + port, + } +} +#[no_mangle] /// Serialize the NetAddress object into a byte array which can be read by NetAddress_read pub extern "C" fn NetAddress_write(obj: &crate::lightning::ln::msgs::NetAddress) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) @@ -3829,6 +3872,17 @@ pub extern "C" fn UnsignedChannelUpdate_get_htlc_minimum_msat(this_ptr: &Unsigne pub extern "C" fn UnsignedChannelUpdate_set_htlc_minimum_msat(this_ptr: &mut UnsignedChannelUpdate, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; } +/// The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_get_htlc_maximum_msat(this_ptr: &UnsignedChannelUpdate) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat; + *inner_val +} +/// The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_set_htlc_maximum_msat(this_ptr: &mut UnsignedChannelUpdate, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val; +} /// The base HTLC fee charged by sender, in milli-satoshi #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_get_fee_base_msat(this_ptr: &UnsignedChannelUpdate) -> u32 { @@ -3859,6 +3913,24 @@ pub extern "C" fn UnsignedChannelUpdate_set_excess_data(this_ptr: &mut UnsignedC let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_data = local_val; } +/// Constructs a new UnsignedChannelUpdate given each field +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut timestamp_arg: u32, mut flags_arg: u8, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedChannelUpdate { + let mut local_excess_data_arg = Vec::new(); for mut item in excess_data_arg.into_rust().drain(..) { local_excess_data_arg.push( { item }); }; + UnsignedChannelUpdate { inner: ObjOps::heap_alloc(nativeUnsignedChannelUpdate { + chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + short_channel_id: short_channel_id_arg, + timestamp: timestamp_arg, + flags: flags_arg, + cltv_expiry_delta: cltv_expiry_delta_arg, + htlc_minimum_msat: htlc_minimum_msat_arg, + htlc_maximum_msat: htlc_maximum_msat_arg, + fee_base_msat: fee_base_msat_arg, + fee_proportional_millionths: fee_proportional_millionths_arg, + excess_data: local_excess_data_arg, + }), is_owned: true } +} impl Clone for UnsignedChannelUpdate { fn clone(&self) -> Self { Self { diff --git a/lightning-c-bindings/src/lightning/ln/peer_handler.rs b/lightning-c-bindings/src/lightning/ln/peer_handler.rs index 1de59bc..f184b1e 100644 --- a/lightning-c-bindings/src/lightning/ln/peer_handler.rs +++ b/lightning-c-bindings/src/lightning/ln/peer_handler.rs @@ -958,8 +958,7 @@ pub extern "C" fn PeerManager_get_peer_node_ids(this_arg: &crate::lightning::ln: /// peer using the init message. /// The user should pass the remote network address of the host they are connected to. /// -/// Note that if an Err is returned here you MUST NOT call socket_disconnected for the new -/// descriptor but must disconnect the connection immediately. +/// If an `Err` is returned here you must disconnect the connection immediately. /// /// Returns a small number of bytes to send to the remote node (currently always 50). /// @@ -984,9 +983,8 @@ pub extern "C" fn PeerManager_new_outbound_connection(this_arg: &crate::lightnin /// The user should pass the remote network address of the host they are connected to. /// /// May refuse the connection by returning an Err, but will never write bytes to the remote end -/// (outbound connector always speaks first). Note that if an Err is returned here you MUST NOT -/// call socket_disconnected for the new descriptor but must disconnect the connection -/// immediately. +/// (outbound connector always speaks first). If an `Err` is returned here you must disconnect +/// the connection immediately. /// /// Panics if descriptor is duplicative with some other descriptor which has not yet been /// [`socket_disconnected()`]. diff --git a/lightning-c-bindings/src/lightning/routing/gossip.rs b/lightning-c-bindings/src/lightning/routing/gossip.rs index 6b67812..af68151 100644 --- a/lightning-c-bindings/src/lightning/routing/gossip.rs +++ b/lightning-c-bindings/src/lightning/routing/gossip.rs @@ -736,16 +736,14 @@ pub extern "C" fn ChannelUpdateInfo_set_htlc_minimum_msat(this_ptr: &mut Channel } /// The maximum value which may be relayed to the next hop via the channel. #[no_mangle] -pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> crate::c_types::derived::COption_u64Z { +pub extern "C" fn ChannelUpdateInfo_get_htlc_maximum_msat(this_ptr: &ChannelUpdateInfo) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) }; - local_inner_val + *inner_val } /// The maximum value which may be relayed to the next hop via the channel. #[no_mangle] -pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: crate::c_types::derived::COption_u64Z) { - let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = local_val; +pub extern "C" fn ChannelUpdateInfo_set_htlc_maximum_msat(this_ptr: &mut ChannelUpdateInfo, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val; } /// Fees charged when the channel is used for routing #[no_mangle] @@ -784,15 +782,14 @@ pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut Chann /// Constructs a new ChannelUpdateInfo given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelUpdateInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo { - let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None }; +pub extern "C" fn ChannelUpdateInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo { let mut local_last_update_message_arg = if last_update_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(last_update_message_arg.take_inner()) } }) }; ChannelUpdateInfo { inner: ObjOps::heap_alloc(nativeChannelUpdateInfo { last_update: last_update_arg, enabled: enabled_arg, cltv_expiry_delta: cltv_expiry_delta_arg, htlc_minimum_msat: htlc_minimum_msat_arg, - htlc_maximum_msat: local_htlc_maximum_msat_arg, + htlc_maximum_msat: htlc_maximum_msat_arg, fees: *unsafe { Box::from_raw(fees_arg.take_inner()) }, last_update_message: local_last_update_message_arg, }), is_owned: true } @@ -2109,6 +2106,28 @@ pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &crate::lightni local_ret } +/// Returns information on a channel with the given id. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn ReadOnlyNetworkGraph_channel(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut short_channel_id: u64) -> crate::lightning::routing::gossip::ChannelInfo { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel(short_channel_id); + let mut local_ret = crate::lightning::routing::gossip::ChannelInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::ChannelInfo<>) as *mut _ }, is_owned: false }; + local_ret +} + +/// Returns information on a node with the given id. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn ReadOnlyNetworkGraph_node(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, node_id: &crate::lightning::routing::gossip::NodeId) -> crate::lightning::routing::gossip::NodeInfo { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.node(node_id.get_native_ref()); + let mut local_ret = crate::lightning::routing::gossip::NodeInfo { inner: unsafe { (if ret.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (ret.unwrap()) }) } as *const lightning::routing::gossip::NodeInfo<>) as *mut _ }, is_owned: false }; + local_ret +} + /// Get network addresses by node id. /// Returns None if the requested node is completely unknown, /// or if node announcement for the node was never received. diff --git a/lightning-c-bindings/src/lightning/routing/router.rs b/lightning-c-bindings/src/lightning/routing/router.rs index 62dd226..48da60e 100644 --- a/lightning-c-bindings/src/lightning/routing/router.rs +++ b/lightning-c-bindings/src/lightning/routing/router.rs @@ -533,10 +533,10 @@ pub extern "C" fn RouteParameters_read(ser: crate::c_types::u8slice) -> crate::c #[no_mangle] pub static DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA: u32 = lightning::routing::router::DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA; -/// Maximum number of paths we allow an MPP payment to have. +/// Maximum number of paths we allow an (MPP) payment to have. #[no_mangle] -pub static DEFAULT_MAX_MPP_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_MPP_PATH_COUNT; +pub static DEFAULT_MAX_PATH_COUNT: u8 = lightning::routing::router::DEFAULT_MAX_PATH_COUNT; use lightning::routing::router::PaymentParameters as nativePaymentParametersImport; pub(crate) type nativePaymentParameters = nativePaymentParametersImport; @@ -665,33 +665,79 @@ pub extern "C" fn PaymentParameters_get_max_total_cltv_expiry_delta(this_ptr: &P pub extern "C" fn PaymentParameters_set_max_total_cltv_expiry_delta(this_ptr: &mut PaymentParameters, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_total_cltv_expiry_delta = val; } -/// The maximum number of paths that may be used by MPP payments. -/// Defaults to [`DEFAULT_MAX_MPP_PATH_COUNT`]. +/// The maximum number of paths that may be used by (MPP) payments. +/// Defaults to [`DEFAULT_MAX_PATH_COUNT`]. #[no_mangle] -pub extern "C" fn PaymentParameters_get_max_mpp_path_count(this_ptr: &PaymentParameters) -> u8 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().max_mpp_path_count; +pub extern "C" fn PaymentParameters_get_max_path_count(this_ptr: &PaymentParameters) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().max_path_count; *inner_val } -/// The maximum number of paths that may be used by MPP payments. -/// Defaults to [`DEFAULT_MAX_MPP_PATH_COUNT`]. +/// The maximum number of paths that may be used by (MPP) payments. +/// Defaults to [`DEFAULT_MAX_PATH_COUNT`]. #[no_mangle] -pub extern "C" fn PaymentParameters_set_max_mpp_path_count(this_ptr: &mut PaymentParameters, mut val: u8) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_mpp_path_count = val; +pub extern "C" fn PaymentParameters_set_max_path_count(this_ptr: &mut PaymentParameters, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_path_count = val; +} +/// Selects the maximum share of a channel's total capacity which will be sent over a channel, +/// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas +/// a lower value prefers to send larger MPP parts, potentially saturating channels and +/// increasing failure probability for those paths. +/// +/// Note that this restriction will be relaxed during pathfinding after paths which meet this +/// restriction have been found. While paths which meet this criteria will be searched for, it +/// is ultimately up to the scorer to select them over other paths. +/// +/// A value of 0 will allow payments up to and including a channel's total announced usable +/// capacity, a value of one will only use up to half its capacity, two 1/4, etc. +/// +/// Default value: 2 +#[no_mangle] +pub extern "C" fn PaymentParameters_get_max_channel_saturation_power_of_half(this_ptr: &PaymentParameters) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().max_channel_saturation_power_of_half; + *inner_val +} +/// Selects the maximum share of a channel's total capacity which will be sent over a channel, +/// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas +/// a lower value prefers to send larger MPP parts, potentially saturating channels and +/// increasing failure probability for those paths. +/// +/// Note that this restriction will be relaxed during pathfinding after paths which meet this +/// restriction have been found. While paths which meet this criteria will be searched for, it +/// is ultimately up to the scorer to select them over other paths. +/// +/// A value of 0 will allow payments up to and including a channel's total announced usable +/// capacity, a value of one will only use up to half its capacity, two 1/4, etc. +/// +/// Default value: 2 +#[no_mangle] +pub extern "C" fn PaymentParameters_set_max_channel_saturation_power_of_half(this_ptr: &mut PaymentParameters, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_channel_saturation_power_of_half = val; +} +/// A list of SCIDs which this payment was previously attempted over and which caused the +/// payment to fail. Future attempts for the same payment shouldn't be relayed through any of +/// these SCIDs. +#[no_mangle] +pub extern "C" fn PaymentParameters_set_previously_failed_channels(this_ptr: &mut PaymentParameters, mut val: crate::c_types::derived::CVec_u64Z) { + let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.previously_failed_channels = local_val; } /// Constructs a new PaymentParameters given each field #[must_use] #[no_mangle] -pub extern "C" fn PaymentParameters_new(mut payee_pubkey_arg: crate::c_types::PublicKey, mut features_arg: crate::lightning::ln::features::InvoiceFeatures, mut route_hints_arg: crate::c_types::derived::CVec_RouteHintZ, mut expiry_time_arg: crate::c_types::derived::COption_u64Z, mut max_total_cltv_expiry_delta_arg: u32, mut max_mpp_path_count_arg: u8) -> PaymentParameters { +pub extern "C" fn PaymentParameters_new(mut payee_pubkey_arg: crate::c_types::PublicKey, mut features_arg: crate::lightning::ln::features::InvoiceFeatures, mut route_hints_arg: crate::c_types::derived::CVec_RouteHintZ, mut expiry_time_arg: crate::c_types::derived::COption_u64Z, mut max_total_cltv_expiry_delta_arg: u32, mut max_path_count_arg: u8, mut max_channel_saturation_power_of_half_arg: u8, mut previously_failed_channels_arg: crate::c_types::derived::CVec_u64Z) -> PaymentParameters { let mut local_features_arg = if features_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(features_arg.take_inner()) } }) }; let mut local_route_hints_arg = Vec::new(); for mut item in route_hints_arg.into_rust().drain(..) { local_route_hints_arg.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; let mut local_expiry_time_arg = if expiry_time_arg.is_some() { Some( { expiry_time_arg.take() }) } else { None }; + let mut local_previously_failed_channels_arg = Vec::new(); for mut item in previously_failed_channels_arg.into_rust().drain(..) { local_previously_failed_channels_arg.push( { item }); }; PaymentParameters { inner: ObjOps::heap_alloc(nativePaymentParameters { payee_pubkey: payee_pubkey_arg.into_rust(), features: local_features_arg, route_hints: local_route_hints_arg, expiry_time: local_expiry_time_arg, max_total_cltv_expiry_delta: max_total_cltv_expiry_delta_arg, - max_mpp_path_count: max_mpp_path_count_arg, + max_path_count: max_path_count_arg, + max_channel_saturation_power_of_half: max_channel_saturation_power_of_half_arg, + previously_failed_channels: local_previously_failed_channels_arg, }), is_owned: true } } impl Clone for PaymentParameters { diff --git a/lightning-c-bindings/src/lightning/routing/scoring.rs b/lightning-c-bindings/src/lightning/routing/scoring.rs index 7b1f824..9a77d6f 100644 --- a/lightning-c-bindings/src/lightning/routing/scoring.rs +++ b/lightning-c-bindings/src/lightning/routing/scoring.rs @@ -83,6 +83,10 @@ pub struct Score { pub payment_path_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64), /// Handles updating channel penalties after successfully routing along a path. pub payment_path_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ), + /// Handles updating channel penalties after a probe over the given path failed. + pub probe_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64), + /// Handles updating channel penalties after a probe over the given path succeeded. + pub probe_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ), /// Serialize the object into a byte array pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, /// Frees any resources associated with this object given its this_arg pointer. @@ -98,6 +102,8 @@ pub(crate) extern "C" fn Score_clone_fields(orig: &Score) -> Score { channel_penalty_msat: Clone::clone(&orig.channel_penalty_msat), payment_path_failed: Clone::clone(&orig.payment_path_failed), payment_path_successful: Clone::clone(&orig.payment_path_successful), + probe_failed: Clone::clone(&orig.probe_failed), + probe_successful: Clone::clone(&orig.probe_successful), write: Clone::clone(&orig.write), free: Clone::clone(&orig.free), } @@ -123,6 +129,14 @@ impl rustScore for Score { let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; (self.payment_path_successful)(self.this_arg, local_path.into()) } + fn probe_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) { + let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; + (self.probe_failed)(self.this_arg, local_path.into(), short_channel_id) + } + fn probe_successful(&mut self, mut path: &[&lightning::routing::router::RouteHop]) { + let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; + (self.probe_successful)(self.this_arg, local_path.into()) + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -482,6 +496,8 @@ pub extern "C" fn FixedPenaltyScorer_as_Score(this_arg: &FixedPenaltyScorer) -> channel_penalty_msat: FixedPenaltyScorer_Score_channel_penalty_msat, payment_path_failed: FixedPenaltyScorer_Score_payment_path_failed, payment_path_successful: FixedPenaltyScorer_Score_payment_path_successful, + probe_failed: FixedPenaltyScorer_Score_probe_failed, + probe_successful: FixedPenaltyScorer_Score_probe_successful, write: FixedPenaltyScorer_write_void, } } @@ -499,6 +515,14 @@ extern "C" fn FixedPenaltyScorer_Score_payment_path_successful(this_arg: *mut c_ let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..]) } +extern "C" fn FixedPenaltyScorer_Score_probe_failed(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ, mut _short_channel_id: u64) { + let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; + >::probe_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..], _short_channel_id) +} +extern "C" fn FixedPenaltyScorer_Score_probe_successful(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; + >::probe_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..]) +} #[no_mangle] /// Serialize the FixedPenaltyScorer object into a byte array which can be read by FixedPenaltyScorer_read @@ -597,6 +621,9 @@ pub(crate) type nativeProbabilisticScoringParameters = nativeProbabilisticScorin /// /// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel /// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel). +/// +/// The penalty applied to any channel by the [`ProbabilisticScorer`] is the sum of each of the +/// parameters here. #[must_use] #[repr(C)] pub struct ProbabilisticScoringParameters { @@ -658,6 +685,39 @@ pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_msat(this_ptr: pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val; } +/// A multiplier used with the payment amount to calculate a fixed penalty applied to each +/// channel, in excess of the [`base_penalty_msat`]. +/// +/// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., +/// fees plus penalty) for large payments. The penalty is computed as the product of this +/// multiplier and `2^30`ths of the payment amount. +/// +/// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30` +/// +/// Default value: 8,192 msat +/// +/// [`base_penalty_msat`]: Self::base_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_amount_multiplier_msat; + *inner_val +} +/// A multiplier used with the payment amount to calculate a fixed penalty applied to each +/// channel, in excess of the [`base_penalty_msat`]. +/// +/// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., +/// fees plus penalty) for large payments. The penalty is computed as the product of this +/// multiplier and `2^30`ths of the payment amount. +/// +/// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30` +/// +/// Default value: 8,192 msat +/// +/// [`base_penalty_msat`]: Self::base_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_amount_multiplier_msat = val; +} /// A multiplier used in conjunction with the negative `log10` of the channel's success /// probability for a payment to determine the liquidity penalty. /// @@ -736,7 +796,7 @@ pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_offset_half_life( /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the /// success probability. /// -/// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20` +/// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20` /// /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of /// the amount will result in a penalty of the multiplier. And, as the success probability @@ -746,8 +806,8 @@ pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_offset_half_life( /// /// Default value: 256 msat #[no_mangle] -pub extern "C" fn ProbabilisticScoringParameters_get_amount_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_penalty_multiplier_msat; +pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_amount_multiplier_msat; *inner_val } /// A multiplier used in conjunction with a payment amount and the negative `log10` of the @@ -758,7 +818,7 @@ pub extern "C" fn ProbabilisticScoringParameters_get_amount_penalty_multiplier_m /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the /// success probability. /// -/// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20` +/// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20` /// /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of /// the amount will result in a penalty of the multiplier. And, as the success probability @@ -768,8 +828,8 @@ pub extern "C" fn ProbabilisticScoringParameters_get_amount_penalty_multiplier_m /// /// Default value: 256 msat #[no_mangle] -pub extern "C" fn ProbabilisticScoringParameters_set_amount_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_penalty_multiplier_msat = val; +pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_amount_multiplier_msat = val; } /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We @@ -792,6 +852,49 @@ pub extern "C" fn ProbabilisticScoringParameters_get_anti_probing_penalty_msat(t pub extern "C" fn ProbabilisticScoringParameters_set_anti_probing_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.anti_probing_penalty_msat = val; } +/// This penalty is applied when the amount we're attempting to send over a channel exceeds our +/// current estimate of the channel's available liquidity. +/// +/// Note that in this case all other penalties, including the +/// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based +/// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if +/// applicable, are still included in the overall penalty. +/// +/// If you wish to avoid creating paths with such channels entirely, setting this to a value of +/// `u64::max_value()` will guarantee that. +/// +/// Default value: 1_0000_0000_000 msat (1 Bitcoin) +/// +/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat +/// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat +/// [`base_penalty_msat`]: Self::base_penalty_msat +/// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_considered_impossible_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().considered_impossible_penalty_msat; + *inner_val +} +/// This penalty is applied when the amount we're attempting to send over a channel exceeds our +/// current estimate of the channel's available liquidity. +/// +/// Note that in this case all other penalties, including the +/// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based +/// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if +/// applicable, are still included in the overall penalty. +/// +/// If you wish to avoid creating paths with such channels entirely, setting this to a value of +/// `u64::max_value()` will guarantee that. +/// +/// Default value: 1_0000_0000_000 msat (1 Bitcoin) +/// +/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat +/// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat +/// [`base_penalty_msat`]: Self::base_penalty_msat +/// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_considered_impossible_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.considered_impossible_penalty_msat = val; +} impl Clone for ProbabilisticScoringParameters { fn clone(&self) -> Self { Self { @@ -852,10 +955,22 @@ pub extern "C" fn ProbabilisticScorer_remove_banned(this_arg: &mut crate::lightn unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_banned(node_id.get_native_ref()) } -/// Clears the list of nodes that are avoided during path finding. +/// Sets a manual penalty for the given node. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_set_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId, mut penalty: u64) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.set_manual_penalty(node_id.get_native_ref(), penalty) +} + +/// Removes the node with the given `node_id` from the list of manual penalties. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_remove_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_manual_penalty(node_id.get_native_ref()) +} + +/// Clears the list of manual penalties that are applied during path finding. #[no_mangle] -pub extern "C" fn ProbabilisticScorer_clear_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer) { - unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.clear_banned() +pub extern "C" fn ProbabilisticScorer_clear_manual_penalties(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.clear_manual_penalties() } /// Marks all nodes in the given list as banned, i.e., @@ -892,6 +1007,8 @@ pub extern "C" fn ProbabilisticScorer_as_Score(this_arg: &ProbabilisticScorer) - channel_penalty_msat: ProbabilisticScorer_Score_channel_penalty_msat, payment_path_failed: ProbabilisticScorer_Score_payment_path_failed, payment_path_successful: ProbabilisticScorer_Score_payment_path_successful, + probe_failed: ProbabilisticScorer_Score_probe_failed, + probe_successful: ProbabilisticScorer_Score_probe_successful, write: ProbabilisticScorer_write_void, } } @@ -909,6 +1026,14 @@ extern "C" fn ProbabilisticScorer_Score_payment_path_successful(this_arg: *mut c let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..]) } +extern "C" fn ProbabilisticScorer_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..], short_channel_id) +} +extern "C" fn ProbabilisticScorer_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..]) +} mod approx { diff --git a/lightning-c-bindings/src/lightning/util/events.rs b/lightning-c-bindings/src/lightning/util/events.rs index 42d334b..9704995 100644 --- a/lightning-c-bindings/src/lightning/util/events.rs +++ b/lightning-c-bindings/src/lightning/util/events.rs @@ -363,6 +363,183 @@ pub extern "C" fn ClosureReason_read(ser: crate::c_types::u8slice) -> crate::c_t let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_ClosureReasonZ::None } else { crate::c_types::derived::COption_ClosureReasonZ::Some( { crate::lightning::util::events::ClosureReason::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; local_res } +/// Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`]. +#[derive(Clone)] +#[must_use] +#[repr(C)] +pub enum HTLCDestination { + /// We tried forwarding to a channel but failed to do so. An example of such an instance is when + /// there is insufficient capacity in our outbound channel. + NextHopChannel { + /// The `node_id` of the next node. For backwards compatibility, this field is + /// marked as optional, versions prior to 0.0.110 may not always be able to provide + /// counterparty node information. + /// + /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None + node_id: crate::c_types::PublicKey, + /// The outgoing `channel_id` between us and the next node. + channel_id: crate::c_types::ThirtyTwoBytes, + }, + /// Scenario where we are unsure of the next node to forward the HTLC to. + UnknownNextHop { + /// Short channel id we are requesting to forward an HTLC to. + requested_forward_scid: u64, + }, + /// Failure scenario where an HTLC may have been forwarded to be intended for us, + /// but is invalid for some reason, so we reject it. + /// + /// Some of the reasons may include: + /// * HTLC Timeouts + /// * Expected MPP amount to claim does not equal HTLC total + /// * Claimable amount does not match expected amount + FailedPayment { + /// The payment hash of the payment we attempted to process. + payment_hash: crate::c_types::ThirtyTwoBytes, + }, +} +use lightning::util::events::HTLCDestination as HTLCDestinationImport; +pub(crate) type nativeHTLCDestination = HTLCDestinationImport; + +impl HTLCDestination { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeHTLCDestination { + match self { + HTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => { + let mut node_id_nonref = (*node_id).clone(); + let mut local_node_id_nonref = if node_id_nonref.is_null() { None } else { Some( { node_id_nonref.into_rust() }) }; + let mut channel_id_nonref = (*channel_id).clone(); + nativeHTLCDestination::NextHopChannel { + node_id: local_node_id_nonref, + channel_id: channel_id_nonref.data, + } + }, + HTLCDestination::UnknownNextHop {ref requested_forward_scid, } => { + let mut requested_forward_scid_nonref = (*requested_forward_scid).clone(); + nativeHTLCDestination::UnknownNextHop { + requested_forward_scid: requested_forward_scid_nonref, + } + }, + HTLCDestination::FailedPayment {ref payment_hash, } => { + let mut payment_hash_nonref = (*payment_hash).clone(); + nativeHTLCDestination::FailedPayment { + payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + } + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeHTLCDestination { + match self { + HTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => { + let mut local_node_id = if node_id.is_null() { None } else { Some( { node_id.into_rust() }) }; + nativeHTLCDestination::NextHopChannel { + node_id: local_node_id, + channel_id: channel_id.data, + } + }, + HTLCDestination::UnknownNextHop {mut requested_forward_scid, } => { + nativeHTLCDestination::UnknownNextHop { + requested_forward_scid: requested_forward_scid, + } + }, + HTLCDestination::FailedPayment {mut payment_hash, } => { + nativeHTLCDestination::FailedPayment { + payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + } + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeHTLCDestination) -> Self { + match native { + nativeHTLCDestination::NextHopChannel {ref node_id, ref channel_id, } => { + let mut node_id_nonref = (*node_id).clone(); + let mut local_node_id_nonref = if node_id_nonref.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id_nonref.unwrap())) } }; + let mut channel_id_nonref = (*channel_id).clone(); + HTLCDestination::NextHopChannel { + node_id: local_node_id_nonref, + channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id_nonref }, + } + }, + nativeHTLCDestination::UnknownNextHop {ref requested_forward_scid, } => { + let mut requested_forward_scid_nonref = (*requested_forward_scid).clone(); + HTLCDestination::UnknownNextHop { + requested_forward_scid: requested_forward_scid_nonref, + } + }, + nativeHTLCDestination::FailedPayment {ref payment_hash, } => { + let mut payment_hash_nonref = (*payment_hash).clone(); + HTLCDestination::FailedPayment { + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, + } + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeHTLCDestination) -> Self { + match native { + nativeHTLCDestination::NextHopChannel {mut node_id, mut channel_id, } => { + let mut local_node_id = if node_id.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(node_id.unwrap())) } }; + HTLCDestination::NextHopChannel { + node_id: local_node_id, + channel_id: crate::c_types::ThirtyTwoBytes { data: channel_id }, + } + }, + nativeHTLCDestination::UnknownNextHop {mut requested_forward_scid, } => { + HTLCDestination::UnknownNextHop { + requested_forward_scid: requested_forward_scid, + } + }, + nativeHTLCDestination::FailedPayment {mut payment_hash, } => { + HTLCDestination::FailedPayment { + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, + } + }, + } + } +} +/// Frees any resources used by the HTLCDestination +#[no_mangle] +pub extern "C" fn HTLCDestination_free(this_ptr: HTLCDestination) { } +/// Creates a copy of the HTLCDestination +#[no_mangle] +pub extern "C" fn HTLCDestination_clone(orig: &HTLCDestination) -> HTLCDestination { + orig.clone() +} +#[no_mangle] +/// Utility method to constructs a new NextHopChannel-variant HTLCDestination +pub extern "C" fn HTLCDestination_next_hop_channel(node_id: crate::c_types::PublicKey, channel_id: crate::c_types::ThirtyTwoBytes) -> HTLCDestination { + HTLCDestination::NextHopChannel { + node_id, + channel_id, + } +} +#[no_mangle] +/// Utility method to constructs a new UnknownNextHop-variant HTLCDestination +pub extern "C" fn HTLCDestination_unknown_next_hop(requested_forward_scid: u64) -> HTLCDestination { + HTLCDestination::UnknownNextHop { + requested_forward_scid, + } +} +#[no_mangle] +/// Utility method to constructs a new FailedPayment-variant HTLCDestination +pub extern "C" fn HTLCDestination_failed_payment(payment_hash: crate::c_types::ThirtyTwoBytes) -> HTLCDestination { + HTLCDestination::FailedPayment { + payment_hash, + } +} +#[no_mangle] +/// Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read +pub extern "C" fn HTLCDestination_write(obj: &crate::lightning::util::events::HTLCDestination) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) +} +#[no_mangle] +/// Read a HTLCDestination from a byte array, created by HTLCDestination_write +pub extern "C" fn HTLCDestination_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_HTLCDestinationZDecodeErrorZ { + let res: Result, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_HTLCDestinationZ::None } else { crate::c_types::derived::COption_HTLCDestinationZ::Some( { crate::lightning::util::events::HTLCDestination::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_res +} /// An Event which you should probably take some action in response to. /// /// Note that while Writeable and Readable are implemented for Event, you probably shouldn't use @@ -599,6 +776,38 @@ pub enum Event { /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None retry: crate::lightning::routing::router::RouteParameters, }, + /// Indicates that a probe payment we sent returned successful, i.e., only failed at the destination. + ProbeSuccessful { + /// The id returned by [`ChannelManager::send_probe`]. + /// + /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + payment_id: crate::c_types::ThirtyTwoBytes, + /// The hash generated by [`ChannelManager::send_probe`]. + /// + /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + payment_hash: crate::c_types::ThirtyTwoBytes, + /// The payment path that was successful. + path: crate::c_types::derived::CVec_RouteHopZ, + }, + /// Indicates that a probe payment we sent failed at an intermediary node on the path. + ProbeFailed { + /// The id returned by [`ChannelManager::send_probe`]. + /// + /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + payment_id: crate::c_types::ThirtyTwoBytes, + /// The hash generated by [`ChannelManager::send_probe`]. + /// + /// [`ChannelManager::send_probe`]: crate::ln::channelmanager::ChannelManager::send_probe + payment_hash: crate::c_types::ThirtyTwoBytes, + /// The payment path that failed. + path: crate::c_types::derived::CVec_RouteHopZ, + /// The channel responsible for the failed probe. + /// + /// Note that for route hints or for the first hop in a path this may be an SCID alias and + /// may not refer to a channel in the public network graph. These aliases may also collide + /// with channels in the public network graph. + short_channel_id: crate::c_types::derived::COption_u64Z, + }, /// Used to indicate that [`ChannelManager::process_pending_htlc_forwards`] should be called at /// a time in the future. /// @@ -729,6 +938,24 @@ pub enum Event { /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager channel_type: crate::lightning::ln::features::ChannelTypeFeatures, }, + /// Indicates that the HTLC was accepted, but could not be processed when or after attempting to + /// forward it. + /// + /// Some scenarios where this event may be sent include: + /// * Insufficient capacity in the outbound channel + /// * While waiting to forward the HTLC, the channel it is meant to be forwarded through closes + /// * When an unknown SCID is requested for forwarding a payment. + /// * Claiming an amount for an MPP payment that exceeds the HTLC total + /// * The HTLC has timed out + /// + /// This event, however, does not get generated if an HTLC fails to meet the forwarding + /// requirements (i.e. insufficient fees paid, or a CLTV that is too soon). + HTLCHandlingFailed { + /// The channel over which the HTLC was received. + prev_channel_id: crate::c_types::ThirtyTwoBytes, + /// Destination of the HTLC that failed to be processed. + failed_next_destination: crate::lightning::util::events::HTLCDestination, + }, } use lightning::util::events::Event as EventImport; pub(crate) type nativeEvent = EventImport; @@ -830,6 +1057,31 @@ impl Event { retry: local_retry_nonref, } }, + Event::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + let mut path_nonref = (*path).clone(); + let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + nativeEvent::ProbeSuccessful { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + path: local_path_nonref, + } + }, + Event::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + let mut path_nonref = (*path).clone(); + let mut local_path_nonref = Vec::new(); for mut item in path_nonref.into_rust().drain(..) { local_path_nonref.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + let mut short_channel_id_nonref = (*short_channel_id).clone(); + let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_some() { Some( { short_channel_id_nonref.take() }) } else { None }; + nativeEvent::ProbeFailed { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id_nonref.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash_nonref.data), + path: local_path_nonref, + short_channel_id: local_short_channel_id_nonref, + } + }, Event::PendingHTLCsForwardable {ref time_forwardable, } => { let mut time_forwardable_nonref = (*time_forwardable).clone(); nativeEvent::PendingHTLCsForwardable { @@ -890,6 +1142,14 @@ impl Event { channel_type: *unsafe { Box::from_raw(channel_type_nonref.take_inner()) }, } }, + Event::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => { + let mut prev_channel_id_nonref = (*prev_channel_id).clone(); + let mut failed_next_destination_nonref = (*failed_next_destination).clone(); + nativeEvent::HTLCHandlingFailed { + prev_channel_id: prev_channel_id_nonref.data, + failed_next_destination: failed_next_destination_nonref.into_native(), + } + }, } } #[allow(unused)] @@ -960,6 +1220,24 @@ impl Event { retry: local_retry, } }, + Event::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => { + let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + nativeEvent::ProbeSuccessful { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + path: local_path, + } + }, + Event::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => { + let mut local_path = Vec::new(); for mut item in path.into_rust().drain(..) { local_path.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + let mut local_short_channel_id = if short_channel_id.is_some() { Some( { short_channel_id.take() }) } else { None }; + nativeEvent::ProbeFailed { + payment_id: ::lightning::ln::channelmanager::PaymentId(payment_id.data), + payment_hash: ::lightning::ln::PaymentHash(payment_hash.data), + path: local_path, + short_channel_id: local_short_channel_id, + } + }, Event::PendingHTLCsForwardable {mut time_forwardable, } => { nativeEvent::PendingHTLCsForwardable { time_forwardable: core::time::Duration::from_secs(time_forwardable), @@ -1004,6 +1282,12 @@ impl Event { channel_type: *unsafe { Box::from_raw(channel_type.take_inner()) }, } }, + Event::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => { + nativeEvent::HTLCHandlingFailed { + prev_channel_id: prev_channel_id.data, + failed_next_destination: failed_next_destination.into_native(), + } + }, } } #[allow(unused)] @@ -1102,6 +1386,31 @@ impl Event { retry: local_retry_nonref, } }, + nativeEvent::ProbeSuccessful {ref payment_id, ref payment_hash, ref path, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + let mut path_nonref = (*path).clone(); + let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + Event::ProbeSuccessful { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, + path: local_path_nonref.into(), + } + }, + nativeEvent::ProbeFailed {ref payment_id, ref payment_hash, ref path, ref short_channel_id, } => { + let mut payment_id_nonref = (*payment_id).clone(); + let mut payment_hash_nonref = (*payment_hash).clone(); + let mut path_nonref = (*path).clone(); + let mut local_path_nonref = Vec::new(); for mut item in path_nonref.drain(..) { local_path_nonref.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + let mut short_channel_id_nonref = (*short_channel_id).clone(); + let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) }; + Event::ProbeFailed { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id_nonref.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 }, + path: local_path_nonref.into(), + short_channel_id: local_short_channel_id_nonref, + } + }, nativeEvent::PendingHTLCsForwardable {ref time_forwardable, } => { let mut time_forwardable_nonref = (*time_forwardable).clone(); Event::PendingHTLCsForwardable { @@ -1162,6 +1471,14 @@ impl Event { channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type_nonref), is_owned: true }, } }, + nativeEvent::HTLCHandlingFailed {ref prev_channel_id, ref failed_next_destination, } => { + let mut prev_channel_id_nonref = (*prev_channel_id).clone(); + let mut failed_next_destination_nonref = (*failed_next_destination).clone(); + Event::HTLCHandlingFailed { + prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id_nonref }, + failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination_nonref), + } + }, } } #[allow(unused)] @@ -1232,6 +1549,24 @@ impl Event { retry: local_retry, } }, + nativeEvent::ProbeSuccessful {mut payment_id, mut payment_hash, mut path, } => { + let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + Event::ProbeSuccessful { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, + path: local_path.into(), + } + }, + nativeEvent::ProbeFailed {mut payment_id, mut payment_hash, mut path, mut short_channel_id, } => { + let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); }; + let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) }; + Event::ProbeFailed { + payment_id: crate::c_types::ThirtyTwoBytes { data: payment_id.0 }, + payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 }, + path: local_path.into(), + short_channel_id: local_short_channel_id, + } + }, nativeEvent::PendingHTLCsForwardable {mut time_forwardable, } => { Event::PendingHTLCsForwardable { time_forwardable: time_forwardable.as_secs(), @@ -1276,6 +1611,12 @@ impl Event { channel_type: crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(channel_type), is_owned: true }, } }, + nativeEvent::HTLCHandlingFailed {mut prev_channel_id, mut failed_next_destination, } => { + Event::HTLCHandlingFailed { + prev_channel_id: crate::c_types::ThirtyTwoBytes { data: prev_channel_id }, + failed_next_destination: crate::lightning::util::events::HTLCDestination::native_into(failed_next_destination), + } + }, } } } @@ -1358,6 +1699,25 @@ pub extern "C" fn Event_payment_path_failed(payment_id: crate::c_types::ThirtyTw } } #[no_mangle] +/// Utility method to constructs a new ProbeSuccessful-variant Event +pub extern "C" fn Event_probe_successful(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ) -> Event { + Event::ProbeSuccessful { + payment_id, + payment_hash, + path, + } +} +#[no_mangle] +/// Utility method to constructs a new ProbeFailed-variant Event +pub extern "C" fn Event_probe_failed(payment_id: crate::c_types::ThirtyTwoBytes, payment_hash: crate::c_types::ThirtyTwoBytes, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: crate::c_types::derived::COption_u64Z) -> Event { + Event::ProbeFailed { + payment_id, + payment_hash, + path, + short_channel_id, + } +} +#[no_mangle] /// Utility method to constructs a new PendingHTLCsForwardable-variant Event pub extern "C" fn Event_pending_htlcs_forwardable(time_forwardable: u64) -> Event { Event::PendingHTLCsForwardable { @@ -1410,6 +1770,14 @@ pub extern "C" fn Event_open_channel_request(temporary_channel_id: crate::c_type } } #[no_mangle] +/// Utility method to constructs a new HTLCHandlingFailed-variant Event +pub extern "C" fn Event_htlchandling_failed(prev_channel_id: crate::c_types::ThirtyTwoBytes, failed_next_destination: crate::lightning::util::events::HTLCDestination) -> Event { + Event::HTLCHandlingFailed { + prev_channel_id, + failed_next_destination, + } +} +#[no_mangle] /// Serialize the Event object into a byte array which can be read by Event_read pub extern "C" fn Event_write(obj: &crate::lightning::util::events::Event) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) diff --git a/lightning-c-bindings/src/lightning/util/ser.rs b/lightning-c-bindings/src/lightning/util/ser.rs index da3023f..23890d8 100644 --- a/lightning-c-bindings/src/lightning/util/ser.rs +++ b/lightning-c-bindings/src/lightning/util/ser.rs @@ -95,3 +95,85 @@ pub extern "C" fn BigSize_new(mut a_arg: u64) -> BigSize { a_arg, )), is_owned: true } } + +use lightning::util::ser::Hostname as nativeHostnameImport; +pub(crate) type nativeHostname = nativeHostnameImport; + +/// Represents a hostname for serialization purposes. +/// Only the character set and length will be validated. +/// The character set consists of ASCII alphanumeric characters, hyphens, and periods. +/// Its length is guaranteed to be representable by a single byte. +/// This serialization is used by BOLT 7 hostnames. +#[must_use] +#[repr(C)] +pub struct Hostname { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeHostname, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for Hostname { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeHostname>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the Hostname, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Hostname_free(this_obj: Hostname) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Hostname_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeHostname); } +} +#[allow(unused)] +impl Hostname { + pub(crate) fn get_native_ref(&self) -> &'static nativeHostname { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHostname { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + } + /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy + pub(crate) fn take_inner(mut self) -> *mut nativeHostname { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +impl Clone for Hostname { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeHostname>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Hostname_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeHostname)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the Hostname +pub extern "C" fn Hostname_clone(orig: &Hostname) -> Hostname { + orig.clone() +} +/// Returns the length of the hostname. +#[must_use] +#[no_mangle] +pub extern "C" fn Hostname_len(this_arg: &crate::lightning::util::ser::Hostname) -> u8 { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.len(); + ret +} + diff --git a/lightning-c-bindings/src/lightning_invoice/payment.rs b/lightning-c-bindings/src/lightning_invoice/payment.rs index d8213e3..3bc29f3 100644 --- a/lightning-c-bindings/src/lightning_invoice/payment.rs +++ b/lightning-c-bindings/src/lightning_invoice/payment.rs @@ -93,6 +93,8 @@ //! # ) -> u64 { 0 } //! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} //! # fn payment_path_successful(&mut self, _path: &[&RouteHop]) {} +//! # fn probe_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} +//! # fn probe_successful(&mut self, _path: &[&RouteHop]) {} //! # } //! # //! # struct FakeLogger {}