Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / chaininterface.rs
index 47caccbf61a4a301b74ee68185eb36e472caacb8..e85a87eeb45c3721acbd6033a1b5977157543530 100644 (file)
@@ -39,7 +39,7 @@ pub struct BroadcasterInterface {
        /// be sure to manage both cases correctly.
        ///
        /// Bitcoin transaction packages are defined in BIP 331 and here:
-       /// https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md
+       /// <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md>
        pub broadcast_transactions: extern "C" fn (this_arg: *const c_void, txs: crate::c_types::derived::CVec_TransactionZ),
        /// 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.
@@ -98,23 +98,6 @@ pub enum ConfirmationTarget {
        /// to low hundreds of blocks to get our transaction on-chain, but we shouldn't risk too low a
        /// fee - this should be a relatively high priority feerate.
        OnChainSweep,
-       /// The highest feerate we will allow our channel counterparty to have in a non-anchor channel.
-       ///
-       /// This is the feerate on the transaction which we (or our counterparty) will broadcast in
-       /// order to close the channel unilaterally. Because our counterparty must ensure they can
-       /// always broadcast the latest state, this value being too low will cause immediate
-       /// force-closures.
-       ///
-       /// Allowing this value to be too high can allow our counterparty to burn our HTLC outputs to
-       /// dust, which can result in HTLCs failing or force-closures (when the dust HTLCs exceed
-       /// [`ChannelConfig::max_dust_htlc_exposure`]).
-       ///
-       /// Because most nodes use a feerate estimate which is based on a relatively high priority
-       /// transaction entering the current mempool, setting this to a small multiple of your current
-       /// high priority feerate estimate should suffice.
-       ///
-       /// [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure
-       MaxAllowedNonAnchorChannelRemoteFee,
        /// This is the lowest feerate we will allow our channel counterparty to have in an anchor
        /// channel in order to close the channel if a channel party goes away.
        ///
@@ -185,6 +168,17 @@ pub enum ConfirmationTarget {
        ///
        /// [`ChannelManager::close_channel_with_feerate_and_script`]: crate::ln::channelmanager::ChannelManager::close_channel_with_feerate_and_script
        ChannelCloseMinimum,
+       /// The feerate [`OutputSweeper`] will use on transactions spending
+       /// [`SpendableOutputDescriptor`]s after a channel closure.
+       ///
+       /// Generally spending these outputs is safe as long as they eventually confirm, so a value
+       /// (slightly above) the mempool minimum should suffice. However, as this value will influence
+       /// how long funds will be unavailable after channel closure, [`FeeEstimator`] implementors
+       /// might want to choose a higher feerate to regain control over funds faster.
+       ///
+       /// [`OutputSweeper`]: crate::util::sweep::OutputSweeper
+       /// [`SpendableOutputDescriptor`]: crate::sign::SpendableOutputDescriptor
+       OutputSpendingFee,
 }
 use lightning::chain::chaininterface::ConfirmationTarget as ConfirmationTargetImport;
 pub(crate) type nativeConfirmationTarget = ConfirmationTargetImport;
@@ -194,48 +188,49 @@ impl ConfirmationTarget {
        pub(crate) fn to_native(&self) -> nativeConfirmationTarget {
                match self {
                        ConfirmationTarget::OnChainSweep => nativeConfirmationTarget::OnChainSweep,
-                       ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
                        ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
                        ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
                        ConfirmationTarget::AnchorChannelFee => nativeConfirmationTarget::AnchorChannelFee,
                        ConfirmationTarget::NonAnchorChannelFee => nativeConfirmationTarget::NonAnchorChannelFee,
                        ConfirmationTarget::ChannelCloseMinimum => nativeConfirmationTarget::ChannelCloseMinimum,
+                       ConfirmationTarget::OutputSpendingFee => nativeConfirmationTarget::OutputSpendingFee,
                }
        }
        #[allow(unused)]
        pub(crate) fn into_native(self) -> nativeConfirmationTarget {
                match self {
                        ConfirmationTarget::OnChainSweep => nativeConfirmationTarget::OnChainSweep,
-                       ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
                        ConfirmationTarget::MinAllowedAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
                        ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
                        ConfirmationTarget::AnchorChannelFee => nativeConfirmationTarget::AnchorChannelFee,
                        ConfirmationTarget::NonAnchorChannelFee => nativeConfirmationTarget::NonAnchorChannelFee,
                        ConfirmationTarget::ChannelCloseMinimum => nativeConfirmationTarget::ChannelCloseMinimum,
+                       ConfirmationTarget::OutputSpendingFee => nativeConfirmationTarget::OutputSpendingFee,
                }
        }
        #[allow(unused)]
-       pub(crate) fn from_native(native: &nativeConfirmationTarget) -> Self {
+       pub(crate) fn from_native(native: &ConfirmationTargetImport) -> Self {
+               let native = unsafe { &*(native as *const _ as *const c_void as *const nativeConfirmationTarget) };
                match native {
                        nativeConfirmationTarget::OnChainSweep => ConfirmationTarget::OnChainSweep,
-                       nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
                        nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
                        nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
                        nativeConfirmationTarget::AnchorChannelFee => ConfirmationTarget::AnchorChannelFee,
                        nativeConfirmationTarget::NonAnchorChannelFee => ConfirmationTarget::NonAnchorChannelFee,
                        nativeConfirmationTarget::ChannelCloseMinimum => ConfirmationTarget::ChannelCloseMinimum,
+                       nativeConfirmationTarget::OutputSpendingFee => ConfirmationTarget::OutputSpendingFee,
                }
        }
        #[allow(unused)]
        pub(crate) fn native_into(native: nativeConfirmationTarget) -> Self {
                match native {
                        nativeConfirmationTarget::OnChainSweep => ConfirmationTarget::OnChainSweep,
-                       nativeConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee,
                        nativeConfirmationTarget::MinAllowedAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
                        nativeConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee => ConfirmationTarget::MinAllowedNonAnchorChannelRemoteFee,
                        nativeConfirmationTarget::AnchorChannelFee => ConfirmationTarget::AnchorChannelFee,
                        nativeConfirmationTarget::NonAnchorChannelFee => ConfirmationTarget::NonAnchorChannelFee,
                        nativeConfirmationTarget::ChannelCloseMinimum => ConfirmationTarget::ChannelCloseMinimum,
+                       nativeConfirmationTarget::OutputSpendingFee => ConfirmationTarget::OutputSpendingFee,
                }
        }
 }
@@ -259,10 +254,6 @@ pub(crate) extern "C" fn ConfirmationTarget_free_void(this_ptr: *mut c_void) {
 pub extern "C" fn ConfirmationTarget_on_chain_sweep() -> ConfirmationTarget {
        ConfirmationTarget::OnChainSweep}
 #[no_mangle]
-/// Utility method to constructs a new MaxAllowedNonAnchorChannelRemoteFee-variant ConfirmationTarget
-pub extern "C" fn ConfirmationTarget_max_allowed_non_anchor_channel_remote_fee() -> ConfirmationTarget {
-       ConfirmationTarget::MaxAllowedNonAnchorChannelRemoteFee}
-#[no_mangle]
 /// Utility method to constructs a new MinAllowedAnchorChannelRemoteFee-variant ConfirmationTarget
 pub extern "C" fn ConfirmationTarget_min_allowed_anchor_channel_remote_fee() -> ConfirmationTarget {
        ConfirmationTarget::MinAllowedAnchorChannelRemoteFee}
@@ -282,6 +273,13 @@ pub extern "C" fn ConfirmationTarget_non_anchor_channel_fee() -> ConfirmationTar
 /// Utility method to constructs a new ChannelCloseMinimum-variant ConfirmationTarget
 pub extern "C" fn ConfirmationTarget_channel_close_minimum() -> ConfirmationTarget {
        ConfirmationTarget::ChannelCloseMinimum}
+#[no_mangle]
+/// Utility method to constructs a new OutputSpendingFee-variant ConfirmationTarget
+pub extern "C" fn ConfirmationTarget_output_spending_fee() -> ConfirmationTarget {
+       ConfirmationTarget::OutputSpendingFee}
+/// Get a string which allows debug introspection of a ConfirmationTarget object
+pub extern "C" fn ConfirmationTarget_debug_str_void(o: *const c_void) -> Str {
+       alloc::format!("{:?}", unsafe { o as *const crate::lightning::chain::chaininterface::ConfirmationTarget }).into()}
 /// Generates a non-cryptographic 64-bit hash of the ConfirmationTarget.
 #[no_mangle]
 pub extern "C" fn ConfirmationTarget_hash(o: &ConfirmationTarget) -> u64 {
@@ -307,6 +305,10 @@ pub extern "C" fn ConfirmationTarget_eq(a: &ConfirmationTarget, b: &Confirmation
 ///
 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
 /// called from inside the library in response to chain events, P2P events, or timer events).
+///
+/// LDK may generate a substantial number of fee-estimation calls in some cases. You should
+/// pre-calculate and cache the fee estimate results to ensure you don't substantially slow HTLC
+/// handling.
 #[repr(C)]
 pub struct FeeEstimator {
        /// An opaque pointer which is passed to your function implementations as an argument.