Skip to content

Commit defd944

Browse files
authored
Merge pull request #133 from TheBlueMatt/main
[0.1 branch] Update to LDK 0.1.1
2 parents 30ecb65 + cb306dd commit defd944

File tree

6 files changed

+93
-18
lines changed

6 files changed

+93
-18
lines changed

genbindings.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ if [ "$CLANGPP" != "" -a "$LLD" != "" ]; then
637637
MANUAL_LINK_CFLAGS="$MANUAL_LINK_CFLAGS -C link-arg=$ARG"
638638
done
639639
# rustc appears to always look for rust-objcopy, though this may be fixed by
640-
# https://github.com/rust-lang/rust/pull/134240 in rust 1.85.
641-
if [ "$RUSTC_MINOR_VERSION" = 84 ]; then
640+
# https://github.com/rust-lang/rust/pull/134240 in rust 1.85 (it is not).
641+
if [ "$RUSTC_MINOR_VERSION" -ge 84 ]; then
642642
mkdir -p objcopy-bin
643643
ln -s `which llvm-objcopy` objcopy-bin/rust-objcopy
644644
PATH="$PATH:$(pwd)/objcopy-bin"

lightning-c-bindings/include/lightning.h

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11611,6 +11611,10 @@ typedef struct LDKPendingHTLCRouting_LDKForward_Body {
1161111611
* Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
1161211612
*/
1161311613
struct LDKBlindedForward blinded;
11614+
/**
11615+
* The absolute CLTV of the inbound HTLC
11616+
*/
11617+
struct LDKCOption_u32Z incoming_cltv_expiry;
1161411618
} LDKPendingHTLCRouting_LDKForward_Body;
1161511619

1161611620
typedef struct LDKPendingHTLCRouting_LDKReceive_Body {
@@ -23412,7 +23416,11 @@ typedef enum LDKOutputSpendStatus_Tag {
2341223416
LDKOutputSpendStatus_PendingFirstConfirmation,
2341323417
/**
2341423418
* A transaction spending the output has been confirmed on-chain but will be tracked until it
23415-
* reaches [`ANTI_REORG_DELAY`] confirmations.
23419+
* reaches at least [`PRUNE_DELAY_BLOCKS`] confirmations to ensure [`Event::SpendableOutputs`]
23420+
* stemming from lingering [`ChannelMonitor`]s can safely be replayed.
23421+
*
23422+
* [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
23423+
* [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
2341623424
*/
2341723425
LDKOutputSpendStatus_PendingThresholdConfirmations,
2341823426
/**
@@ -27873,12 +27881,16 @@ extern const uint64_t MAX_SCID_TX_INDEX;
2787327881

2787427882
extern const uint64_t MAX_SCID_VOUT_INDEX;
2787527883

27884+
extern const uint32_t PRUNE_DELAY_BLOCKS;
27885+
2787627886
extern const uint64_t MIN_RELAY_FEE_SAT_PER_1000_WEIGHT;
2787727887

2787827888
extern const uint32_t FEERATE_FLOOR_SATS_PER_KW;
2787927889

2788027890
extern const uint32_t ANTI_REORG_DELAY;
2788127891

27892+
extern const uint32_t ARCHIVAL_DELAY_BLOCKS;
27893+
2788227894
extern const uint16_t BREAKDOWN_TIMEOUT;
2788327895

2788427896
extern const uint16_t MIN_CLTV_EXPIRY_DELTA;
@@ -39984,10 +39996,11 @@ MUST_USE_RES struct LDKCVec_SpendableOutputDescriptorZ ChannelMonitor_get_spenda
3998439996
*
3998539997
* This function returns a tuple of two booleans, the first indicating whether the monitor is
3998639998
* fully resolved, and the second whether the monitor needs persistence to ensure it is
39987-
* reliably marked as resolved within 4032 blocks.
39999+
* reliably marked as resolved within [`ARCHIVAL_DELAY_BLOCKS`] blocks.
3998840000
*
39989-
* The first boolean is true only if [`Self::get_claimable_balances`] has been empty for at least
39990-
* 4032 blocks as an additional protection against any bugs resulting in spuriously empty balance sets.
40001+
* The first boolean is true only if [`Self::get_claimable_balances`] has been empty for at
40002+
* least [`ARCHIVAL_DELAY_BLOCKS`] blocks as an additional protection against any bugs
40003+
* resulting in spuriously empty balance sets.
3999140004
*/
3999240005
MUST_USE_RES struct LDKC2Tuple_boolboolZ ChannelMonitor_check_and_update_full_resolution_status(const struct LDKChannelMonitor *NONNULL_PTR this_arg, const struct LDKLogger *NONNULL_PTR logger);
3999340006

@@ -40161,7 +40174,7 @@ struct LDKPendingHTLCRouting PendingHTLCRouting_clone(const struct LDKPendingHTL
4016140174
/**
4016240175
* Utility method to constructs a new Forward-variant PendingHTLCRouting
4016340176
*/
40164-
struct LDKPendingHTLCRouting PendingHTLCRouting_forward(struct LDKOnionPacket onion_packet, uint64_t short_channel_id, struct LDKBlindedForward blinded);
40177+
struct LDKPendingHTLCRouting PendingHTLCRouting_forward(struct LDKOnionPacket onion_packet, uint64_t short_channel_id, struct LDKBlindedForward blinded, struct LDKCOption_u32Z incoming_cltv_expiry);
4016540178

4016640179
/**
4016740180
* Utility method to constructs a new Receive-variant PendingHTLCRouting
@@ -40771,6 +40784,14 @@ void ChannelManager_force_close_all_channels_broadcasting_latest_txn(const struc
4077140784
*/
4077240785
void ChannelManager_force_close_all_channels_without_broadcasting_txn(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKStr error_message);
4077340786

40787+
/**
40788+
* Sends a payment along a given route. See [`Self::send_payment`] for more info.
40789+
*
40790+
* LDK will not automatically retry this payment, though it may be manually re-sent after an
40791+
* [`Event::PaymentFailed`] is generated.
40792+
*/
40793+
MUST_USE_RES struct LDKCResult_NoneRetryableSendFailureZ ChannelManager_send_payment_with_route(const struct LDKChannelManager *NONNULL_PTR this_arg, struct LDKRoute route, struct LDKThirtyTwoBytes payment_hash, struct LDKRecipientOnionFields recipient_onion, struct LDKThirtyTwoBytes payment_id);
40794+
4077440795
/**
4077540796
* Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
4077640797
* payment paths based on the provided `Retry`.
@@ -40798,7 +40819,8 @@ void ChannelManager_force_close_all_channels_without_broadcasting_txn(const stru
4079840819
* [`ChannelManager::list_recent_payments`] for more information.
4079940820
*
4080040821
* Routes are automatically found using the [`Router] provided on startup. To fix a route for a
40801-
* particular payment, match the [`PaymentId`] passed to [`Router::find_route_with_id`].
40822+
* particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to
40823+
* [`Router::find_route_with_id`].
4080240824
*
4080340825
* [`Event::PaymentSent`]: events::Event::PaymentSent
4080440826
* [`Event::PaymentFailed`]: events::Event::PaymentFailed
@@ -56126,6 +56148,11 @@ struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ SpendableOutputDescripto
5612656148
*/
5612756149
MUST_USE_RES struct LDKCResult_C2Tuple_CVec_u8Zu64ZNoneZ SpendableOutputDescriptor_create_spendable_outputs_psbt(struct LDKCVec_SpendableOutputDescriptorZ descriptors, struct LDKCVec_TxOutZ outputs, struct LDKCVec_u8Z change_destination_script, uint32_t feerate_sat_per_1000_weight, struct LDKCOption_u32Z locktime);
5612856150

56151+
/**
56152+
* Returns the outpoint of the spendable output.
56153+
*/
56154+
MUST_USE_RES struct LDKOutPoint SpendableOutputDescriptor_spendable_outpoint(const struct LDKSpendableOutputDescriptor *NONNULL_PTR this_arg);
56155+
5612956156
/**
5613056157
* Frees any resources used by the ChannelDerivationParameters, if is_owned is set and inner is non-NULL.
5613156158
*/

lightning-c-bindings/src/lightning/chain/channelmonitor.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ pub extern "C" fn HTLCUpdate_read(ser: crate::c_types::u8slice) -> crate::c_type
560560
561561
#[no_mangle]
562562
pub static ANTI_REORG_DELAY: u32 = lightning::chain::channelmonitor::ANTI_REORG_DELAY;
563+
/// Number of blocks we wait before assuming a [`ChannelMonitor`] to be fully resolved and
564+
/// considering it be safely archived.
565+
566+
#[no_mangle]
567+
pub static ARCHIVAL_DELAY_BLOCKS: u32 = lightning::chain::channelmonitor::ARCHIVAL_DELAY_BLOCKS;
563568
/// Indicates whether the balance is derived from a cooperative close, a force-close
564569
/// (for holder or counterparty), or whether it is for an HTLC.
565570
#[derive(Clone)]
@@ -1580,10 +1585,11 @@ pub extern "C" fn ChannelMonitor_get_spendable_outputs(this_arg: &crate::lightni
15801585
///
15811586
/// This function returns a tuple of two booleans, the first indicating whether the monitor is
15821587
/// fully resolved, and the second whether the monitor needs persistence to ensure it is
1583-
/// reliably marked as resolved within 4032 blocks.
1588+
/// reliably marked as resolved within [`ARCHIVAL_DELAY_BLOCKS`] blocks.
15841589
///
1585-
/// The first boolean is true only if [`Self::get_claimable_balances`] has been empty for at least
1586-
/// 4032 blocks as an additional protection against any bugs resulting in spuriously empty balance sets.
1590+
/// The first boolean is true only if [`Self::get_claimable_balances`] has been empty for at
1591+
/// least [`ARCHIVAL_DELAY_BLOCKS`] blocks as an additional protection against any bugs
1592+
/// resulting in spuriously empty balance sets.
15871593
#[must_use]
15881594
#[no_mangle]
15891595
pub extern "C" fn ChannelMonitor_check_and_update_full_resolution_status(this_arg: &crate::lightning::chain::channelmonitor::ChannelMonitor, logger: &crate::lightning::util::logger::Logger) -> crate::c_types::derived::C2Tuple_boolboolZ {

lightning-c-bindings/src/lightning/ln/channelmanager.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub enum PendingHTLCRouting {
4545
///
4646
/// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
4747
blinded: crate::lightning::ln::channelmanager::BlindedForward,
48+
/// The absolute CLTV of the inbound HTLC
49+
incoming_cltv_expiry: crate::c_types::derived::COption_u32Z,
4850
},
4951
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
5052
///
@@ -129,15 +131,18 @@ impl PendingHTLCRouting {
129131
#[allow(unused)]
130132
pub(crate) fn to_native(&self) -> nativePendingHTLCRouting {
131133
match self {
132-
PendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
134+
PendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, ref incoming_cltv_expiry, } => {
133135
let mut onion_packet_nonref = Clone::clone(onion_packet);
134136
let mut short_channel_id_nonref = Clone::clone(short_channel_id);
135137
let mut blinded_nonref = Clone::clone(blinded);
136138
let mut local_blinded_nonref = if blinded_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded_nonref.take_inner()) } }) };
139+
let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
140+
let mut local_incoming_cltv_expiry_nonref = if incoming_cltv_expiry_nonref.is_some() { Some( { incoming_cltv_expiry_nonref.take() }) } else { None };
137141
nativePendingHTLCRouting::Forward {
138142
onion_packet: *unsafe { Box::from_raw(onion_packet_nonref.take_inner()) },
139143
short_channel_id: short_channel_id_nonref,
140144
blinded: local_blinded_nonref,
145+
incoming_cltv_expiry: local_incoming_cltv_expiry_nonref,
141146
}
142147
},
143148
PendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref payment_context, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
@@ -188,12 +193,14 @@ impl PendingHTLCRouting {
188193
#[allow(unused)]
189194
pub(crate) fn into_native(self) -> nativePendingHTLCRouting {
190195
match self {
191-
PendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
196+
PendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, mut incoming_cltv_expiry, } => {
192197
let mut local_blinded = if blinded.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(blinded.take_inner()) } }) };
198+
let mut local_incoming_cltv_expiry = if incoming_cltv_expiry.is_some() { Some( { incoming_cltv_expiry.take() }) } else { None };
193199
nativePendingHTLCRouting::Forward {
194200
onion_packet: *unsafe { Box::from_raw(onion_packet.take_inner()) },
195201
short_channel_id: short_channel_id,
196202
blinded: local_blinded,
203+
incoming_cltv_expiry: local_incoming_cltv_expiry,
197204
}
198205
},
199206
PendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut payment_context, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
@@ -231,15 +238,18 @@ impl PendingHTLCRouting {
231238
pub(crate) fn from_native(native: &PendingHTLCRoutingImport) -> Self {
232239
let native = unsafe { &*(native as *const _ as *const c_void as *const nativePendingHTLCRouting) };
233240
match native {
234-
nativePendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, } => {
241+
nativePendingHTLCRouting::Forward {ref onion_packet, ref short_channel_id, ref blinded, ref incoming_cltv_expiry, } => {
235242
let mut onion_packet_nonref = Clone::clone(onion_packet);
236243
let mut short_channel_id_nonref = Clone::clone(short_channel_id);
237244
let mut blinded_nonref = Clone::clone(blinded);
238245
let mut local_blinded_nonref = crate::lightning::ln::channelmanager::BlindedForward { inner: if blinded_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((blinded_nonref.unwrap())) } }, is_owned: true };
246+
let mut incoming_cltv_expiry_nonref = Clone::clone(incoming_cltv_expiry);
247+
let mut local_incoming_cltv_expiry_nonref = if incoming_cltv_expiry_nonref.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { incoming_cltv_expiry_nonref.unwrap() }) };
239248
PendingHTLCRouting::Forward {
240249
onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet_nonref), is_owned: true },
241250
short_channel_id: short_channel_id_nonref,
242251
blinded: local_blinded_nonref,
252+
incoming_cltv_expiry: local_incoming_cltv_expiry_nonref,
243253
}
244254
},
245255
nativePendingHTLCRouting::Receive {ref payment_data, ref payment_metadata, ref payment_context, ref incoming_cltv_expiry, ref phantom_shared_secret, ref custom_tlvs, ref requires_blinded_error, } => {
@@ -290,12 +300,14 @@ impl PendingHTLCRouting {
290300
#[allow(unused)]
291301
pub(crate) fn native_into(native: nativePendingHTLCRouting) -> Self {
292302
match native {
293-
nativePendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, } => {
303+
nativePendingHTLCRouting::Forward {mut onion_packet, mut short_channel_id, mut blinded, mut incoming_cltv_expiry, } => {
294304
let mut local_blinded = crate::lightning::ln::channelmanager::BlindedForward { inner: if blinded.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((blinded.unwrap())) } }, is_owned: true };
305+
let mut local_incoming_cltv_expiry = if incoming_cltv_expiry.is_none() { crate::c_types::derived::COption_u32Z::None } else { crate::c_types::derived::COption_u32Z::Some( { incoming_cltv_expiry.unwrap() }) };
295306
PendingHTLCRouting::Forward {
296307
onion_packet: crate::lightning::ln::msgs::OnionPacket { inner: ObjOps::heap_alloc(onion_packet), is_owned: true },
297308
short_channel_id: short_channel_id,
298309
blinded: local_blinded,
310+
incoming_cltv_expiry: local_incoming_cltv_expiry,
299311
}
300312
},
301313
nativePendingHTLCRouting::Receive {mut payment_data, mut payment_metadata, mut payment_context, mut incoming_cltv_expiry, mut phantom_shared_secret, mut custom_tlvs, mut requires_blinded_error, } => {
@@ -350,11 +362,12 @@ pub(crate) extern "C" fn PendingHTLCRouting_free_void(this_ptr: *mut c_void) {
350362
}
351363
#[no_mangle]
352364
/// Utility method to constructs a new Forward-variant PendingHTLCRouting
353-
pub extern "C" fn PendingHTLCRouting_forward(onion_packet: crate::lightning::ln::msgs::OnionPacket, short_channel_id: u64, blinded: crate::lightning::ln::channelmanager::BlindedForward) -> PendingHTLCRouting {
365+
pub extern "C" fn PendingHTLCRouting_forward(onion_packet: crate::lightning::ln::msgs::OnionPacket, short_channel_id: u64, blinded: crate::lightning::ln::channelmanager::BlindedForward, incoming_cltv_expiry: crate::c_types::derived::COption_u32Z) -> PendingHTLCRouting {
354366
PendingHTLCRouting::Forward {
355367
onion_packet,
356368
short_channel_id,
357369
blinded,
370+
incoming_cltv_expiry,
358371
}
359372
}
360373
#[no_mangle]
@@ -2673,6 +2686,18 @@ pub extern "C" fn ChannelManager_force_close_all_channels_without_broadcasting_t
26732686
unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.force_close_all_channels_without_broadcasting_txn(error_message.into_string())
26742687
}
26752688

2689+
/// Sends a payment along a given route. See [`Self::send_payment`] for more info.
2690+
///
2691+
/// LDK will not automatically retry this payment, though it may be manually re-sent after an
2692+
/// [`Event::PaymentFailed`] is generated.
2693+
#[must_use]
2694+
#[no_mangle]
2695+
pub extern "C" fn ChannelManager_send_payment_with_route(this_arg: &crate::lightning::ln::channelmanager::ChannelManager, mut route: crate::lightning::routing::router::Route, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut recipient_onion: crate::lightning::ln::outbound_payment::RecipientOnionFields, mut payment_id: crate::c_types::ThirtyTwoBytes) -> crate::c_types::derived::CResult_NoneRetryableSendFailureZ {
2696+
let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.send_payment_with_route(*unsafe { Box::from_raw(route.take_inner()) }, ::lightning::types::payment::PaymentHash(payment_hash.data), *unsafe { Box::from_raw(recipient_onion.take_inner()) }, ::lightning::ln::channelmanager::PaymentId(payment_id.data));
2697+
let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::outbound_payment::RetryableSendFailure::native_into(e) }).into() };
2698+
local_ret
2699+
}
2700+
26762701
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
26772702
/// payment paths based on the provided `Retry`.
26782703
///
@@ -2699,7 +2724,8 @@ pub extern "C" fn ChannelManager_force_close_all_channels_without_broadcasting_t
26992724
/// [`ChannelManager::list_recent_payments`] for more information.
27002725
///
27012726
/// Routes are automatically found using the [`Router] provided on startup. To fix a route for a
2702-
/// particular payment, match the [`PaymentId`] passed to [`Router::find_route_with_id`].
2727+
/// particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to
2728+
/// [`Router::find_route_with_id`].
27032729
///
27042730
/// [`Event::PaymentSent`]: events::Event::PaymentSent
27052731
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed

lightning-c-bindings/src/lightning/sign/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,14 @@ pub extern "C" fn SpendableOutputDescriptor_create_spendable_outputs_psbt(mut de
805805
local_ret
806806
}
807807

808+
/// Returns the outpoint of the spendable output.
809+
#[must_use]
810+
#[no_mangle]
811+
pub extern "C" fn SpendableOutputDescriptor_spendable_outpoint(this_arg: &crate::lightning::sign::SpendableOutputDescriptor) -> crate::lightning::chain::transaction::OutPoint {
812+
let mut ret = this_arg.to_native().spendable_outpoint();
813+
crate::lightning::chain::transaction::OutPoint { inner: ObjOps::heap_alloc(ret), is_owned: true }
814+
}
815+
808816

809817
use lightning::sign::ChannelDerivationParameters as nativeChannelDerivationParametersImport;
810818
pub(crate) type nativeChannelDerivationParameters = nativeChannelDerivationParametersImport;

lightning-c-bindings/src/lightning/util/sweep.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use crate::c_types::*;
1919
#[cfg(feature="no-std")]
2020
use alloc::{vec::Vec, boxed::Box};
2121

22+
/// The number of blocks we wait before we prune the tracked spendable outputs.
23+
24+
#[no_mangle]
25+
pub static PRUNE_DELAY_BLOCKS: u32 = lightning::util::sweep::PRUNE_DELAY_BLOCKS;
2226

2327
use lightning::util::sweep::TrackedSpendableOutput as nativeTrackedSpendableOutputImport;
2428
pub(crate) type nativeTrackedSpendableOutput = nativeTrackedSpendableOutputImport;
@@ -211,7 +215,11 @@ pub enum OutputSpendStatus {
211215
latest_spending_tx: crate::c_types::Transaction,
212216
},
213217
/// A transaction spending the output has been confirmed on-chain but will be tracked until it
214-
/// reaches [`ANTI_REORG_DELAY`] confirmations.
218+
/// reaches at least [`PRUNE_DELAY_BLOCKS`] confirmations to ensure [`Event::SpendableOutputs`]
219+
/// stemming from lingering [`ChannelMonitor`]s can safely be replayed.
220+
///
221+
/// [`Event::SpendableOutputs`]: crate::events::Event::SpendableOutputs
222+
/// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
215223
PendingThresholdConfirmations {
216224
/// The hash of the chain tip when we first broadcast a transaction spending this output.
217225
first_broadcast_hash: crate::c_types::ThirtyTwoBytes,

0 commit comments

Comments
 (0)