From: Arik Sosman Date: Sun, 21 Mar 2021 06:03:50 +0000 (-0700) Subject: Merge pull request #5 from TheBlueMatt/2021-03-bump-listen X-Git-Tag: v0.0.98~21 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=commitdiff_plain;h=4d85902c5191f9139c2d0be26c040ada0f19117f;hp=ca9a66ef1da417c82b0190542cc5ceb353922ba1 Merge pull request #5 from TheBlueMatt/2021-03-bump-listen Bump to latest upstream --- diff --git a/lightning-c-bindings/Cargo.toml b/lightning-c-bindings/Cargo.toml index ef2d873..7791348 100644 --- a/lightning-c-bindings/Cargo.toml +++ b/lightning-c-bindings/Cargo.toml @@ -18,7 +18,7 @@ crate-type = ["staticlib" bitcoin = "0.26" secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] } # Note that the following line is matched by genbindings to update the path -lightning = { git = "https://github.com/rust-bitcoin/rust-lightning", rev = "fba204b02ee4faece07a2ddf152f34507773ad4d" } +lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "8a8c75a8fc96e5c8ed59e6d80a517bc59215b4d6" } [patch.crates-io] # Rust-Secp256k1 PR 279. Should be dropped once merged. diff --git a/lightning-c-bindings/demo.cpp b/lightning-c-bindings/demo.cpp index c6dc496..230e334 100644 --- a/lightning-c-bindings/demo.cpp +++ b/lightning-c-bindings/demo.cpp @@ -49,15 +49,13 @@ const uint8_t valid_node_announcement[] = { // A simple block containing only one transaction (which is the channel-open transaction for the // channel we'll create). This was originally created by printing additional data in a simple // rust-lightning unit test. -const uint8_t channel_open_header[80] = { +const uint8_t channel_open_block[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa2, 0x47, 0xd2, 0xf8, 0xd4, 0xe0, 0x6a, 0x3f, 0xf9, 0x7a, 0x9a, 0x34, 0xbb, 0xa9, 0x96, 0xde, 0x63, 0x84, 0x5a, 0xce, 0xcf, 0x98, 0xb8, 0xbb, 0x75, 0x4c, 0x4f, 0x7d, 0xee, 0x4c, 0xa9, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -const uint8_t channel_open_tx[] = { + 0x01, // transaction count 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -74,19 +72,21 @@ const uint8_t channel_open_txid[] = { }; // Two blocks built on top of channel_open_block: -const uint8_t header_1[80] = { - 0x01, 0x00, 0x00, 0x00, 0x65, 0x8e, 0xf1, 0x90, 0x88, 0xfa, 0x13, 0x9c, 0x6a, 0xea, 0xf7, 0xc1, - 0x5a, 0xdd, 0x52, 0x4d, 0x3c, 0x48, 0x03, 0xb3, 0x9b, 0x25, 0x4f, 0x02, 0x79, 0x05, 0x90, 0xe0, - 0xc4, 0x8d, 0xa0, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +const uint8_t block_1[81] = { + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x7a, 0xc2, 0xdc, 0x08, 0xaf, 0x40, 0x7d, 0x58, 0x81, 0x9b, 0x44, + 0xc7, 0xe0, 0x0f, 0x78, 0xc0, 0xd1, 0x01, 0xa2, 0x03, 0x16, 0x4a, 0x8d, 0x92, 0x66, 0x4e, 0xaf, + 0x7f, 0xfc, 0x6e, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, // transaction count }; -const uint8_t header_2[80] = { - 0x01, 0x00, 0x00, 0x00, 0xf2, 0x08, 0x87, 0x51, 0xcb, 0xb1, 0x1a, 0x51, 0x76, 0x01, 0x6c, 0x5d, - 0x76, 0x26, 0x54, 0x6f, 0xd9, 0xbd, 0xa6, 0xa5, 0xe9, 0x4b, 0x21, 0x6e, 0xda, 0xa3, 0x64, 0x23, - 0xcd, 0xf1, 0xe2, 0xe2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +const uint8_t block_2[81] = { + 0x01, 0x00, 0x00, 0x00, 0x36, 0x0b, 0xf5, 0x46, 0x4a, 0xc7, 0x26, 0x4c, 0x4b, 0x36, 0xa6, 0x9d, + 0x0e, 0xf0, 0x14, 0xfb, 0x8a, 0xcb, 0x20, 0x84, 0x18, 0xf3, 0xaa, 0x77, 0x32, 0x2d, 0xf7, 0x48, + 0x62, 0x92, 0xb1, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, // transaction count }; const LDKThirtyTwoBytes payment_preimage_1 = { @@ -137,7 +137,7 @@ struct NodeMonitors { void ConnectBlock(const uint8_t (*header)[80], uint32_t height, LDKCVec_C2Tuple_usizeTransactionZZ tx_data, LDKBroadcasterInterface broadcast, LDKFeeEstimator fee_est) { std::unique_lock l(mut); for (auto& mon : mons) { - LDK::CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ res = ChannelMonitor_block_connected(&mon.second, &header_2, tx_data, height, broadcast, fee_est, *logger); + LDK::CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ res = ChannelMonitor_block_connected(&mon.second, header, tx_data, height, broadcast, fee_est, *logger); } } }; @@ -288,6 +288,13 @@ public: }; int main() { + uint8_t channel_open_header[80]; + uint8_t header_1[80]; + uint8_t header_2[80]; + memcpy(channel_open_header, channel_open_block, 80); + memcpy(header_1, block_1, 80); + memcpy(header_2, block_2, 80); + LDKPublicKey null_pk; memset(&null_pk, 0, sizeof(null_pk)); @@ -429,7 +436,7 @@ int main() { assert(events->data[0].funding_generation_ready.user_channel_id == 42); assert(events->data[0].funding_generation_ready.channel_value_satoshis == 40000); assert(events->data[0].funding_generation_ready.output_script.datalen == 34); - assert(!memcmp(events->data[0].funding_generation_ready.output_script.data, channel_open_tx + 58, 34)); + assert(!memcmp(events->data[0].funding_generation_ready.output_script.data, channel_open_block + 58 + 81, 34)); LDKThirtyTwoBytes txid; for (int i = 0; i < 32; i++) { txid.data[i] = channel_open_txid[31-i]; } LDK::OutPoint outp = OutPoint_new(txid, 0); @@ -452,29 +459,27 @@ int main() { std::this_thread::yield(); } - LDKCVec_C2Tuple_usizeTransactionZZ txdata { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; - *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); - ChannelManager_block_connected(&cm1, &channel_open_header, txdata, 1); + LDK::Listen listener1 = ChannelManager_as_Listen(&cm1); + listener1->block_connected(listener1->this_arg, LDKu8slice { .data = channel_open_block, .datalen = sizeof(channel_open_block) }, 1); - txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; - *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); - ChannelManager_block_connected(&cm2, &channel_open_header, txdata, 1); + LDK::Listen listener2 = ChannelManager_as_Listen(&cm2); + listener2->block_connected(listener2->this_arg, LDKu8slice { .data = channel_open_block, .datalen = sizeof(channel_open_block) }, 1); - txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; - *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); + LDKCVec_C2Tuple_usizeTransactionZZ txdata { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; + *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_block + 81, .datalen = sizeof(channel_open_block) - 81, .data_is_owned = false }); mons1.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est); txdata = LDKCVec_C2Tuple_usizeTransactionZZ { .data = (LDKC2Tuple_usizeTransactionZ*)malloc(sizeof(LDKC2Tuple_usizeTransactionZ)), .datalen = 1 }; - *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_tx, .datalen = sizeof(channel_open_tx), .data_is_owned = false }); + *txdata.data = C2Tuple_usizeTransactionZ_new(0, LDKTransaction { .data = (uint8_t*)channel_open_block + 81, .datalen = sizeof(channel_open_block) - 81, .data_is_owned = false }); mons2.ConnectBlock(&channel_open_header, 1, txdata, broadcast, fee_est); - ChannelManager_block_connected(&cm1, &header_1, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 2); - ChannelManager_block_connected(&cm2, &header_1, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 2); + listener1->block_connected(listener1->this_arg, LDKu8slice { .data = block_1, .datalen = sizeof(block_1) }, 2); + listener2->block_connected(listener2->this_arg, LDKu8slice { .data = block_1, .datalen = sizeof(block_1) }, 2); mons1.ConnectBlock(&header_1, 2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); mons2.ConnectBlock(&header_1, 2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); - ChannelManager_block_connected(&cm1, &header_2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 3); - ChannelManager_block_connected(&cm2, &header_2, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, 3); + listener1->block_connected(listener1->this_arg, LDKu8slice { .data = block_2, .datalen = sizeof(block_1) }, 3); + listener2->block_connected(listener2->this_arg, LDKu8slice { .data = block_2, .datalen = sizeof(block_1) }, 3); mons1.ConnectBlock(&header_2, 3, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); mons2.ConnectBlock(&header_2, 3, LDKCVec_C2Tuple_usizeTransactionZZ { .data = NULL, .datalen = 0 }, broadcast, fee_est); diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index c85ac58..fddd4de 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -4959,6 +4959,8 @@ extern const uint64_t CLOSED_CHANNEL_UPDATE_ID; extern const uint16_t BREAKDOWN_TIMEOUT; +extern const uint16_t MIN_CLTV_EXPIRY_DELTA; + extern const uintptr_t REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH; void Transaction_free(struct LDKTransaction _res); @@ -5787,34 +5789,40 @@ uint32_t ChannelHandshakeConfig_get_minimum_depth(const struct LDKChannelHandsha void ChannelHandshakeConfig_set_minimum_depth(struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr, uint32_t val); /** - * Set to the amount of time we require our counterparty to wait to claim their money. + * Set to the number of blocks we require our counterparty to wait to claim their money (ie + * the number of blocks we have to punish our counterparty if they broadcast a revoked + * transaction). * - * It's one of the main parameter of our security model. We (or one of our watchtowers) MUST - * be online to check for peer having broadcast a revoked transaction to steal our funds - * at least once every our_to_self_delay blocks. + * This is one of the main parameters of our security model. We (or one of our watchtowers) MUST + * be online to check for revoked transactions on-chain at least once every our_to_self_delay + * blocks (minus some margin to allow us enough time to broadcast and confirm a transaction, + * possibly with time in between to RBF the spending transaction). * * Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in * case of an honest unilateral channel close, which implicitly decrease the economic value of * our channel. * - * Default value: [`BREAKDOWN_TIMEOUT`] (currently 144), we enforce it as a minimum at channel - * opening so you can tweak config to ask for more security, not less. + * Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you + * can tweak config to ask for more security, not less. */ uint16_t ChannelHandshakeConfig_get_our_to_self_delay(const struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr); /** - * Set to the amount of time we require our counterparty to wait to claim their money. + * Set to the number of blocks we require our counterparty to wait to claim their money (ie + * the number of blocks we have to punish our counterparty if they broadcast a revoked + * transaction). * - * It's one of the main parameter of our security model. We (or one of our watchtowers) MUST - * be online to check for peer having broadcast a revoked transaction to steal our funds - * at least once every our_to_self_delay blocks. + * This is one of the main parameters of our security model. We (or one of our watchtowers) MUST + * be online to check for revoked transactions on-chain at least once every our_to_self_delay + * blocks (minus some margin to allow us enough time to broadcast and confirm a transaction, + * possibly with time in between to RBF the spending transaction). * * Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in * case of an honest unilateral channel close, which implicitly decrease the economic value of * our channel. * - * Default value: [`BREAKDOWN_TIMEOUT`] (currently 144), we enforce it as a minimum at channel - * opening so you can tweak config to ask for more security, not less. + * Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you + * can tweak config to ask for more security, not less. */ void ChannelHandshakeConfig_set_our_to_self_delay(struct LDKChannelHandshakeConfig *NONNULL_PTR this_ptr, uint16_t val); @@ -6084,6 +6092,52 @@ uint32_t ChannelConfig_get_fee_proportional_millionths(const struct LDKChannelCo */ void ChannelConfig_set_fee_proportional_millionths(struct LDKChannelConfig *NONNULL_PTR this_ptr, uint32_t val); +/** + * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + * the channel this config applies to. + * + * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight + * HTLC balance when a channel appears on-chain whereas + * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining + * (non-HTLC-encumbered) balance. + * + * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, + * we (or one of our watchtowers) MUST be online to check for broadcast of the current + * commitment transaction at least once per this many blocks (minus some margin to allow us + * enough time to broadcast and confirm a transaction, possibly with time in between to RBF + * the spending transaction). + * + * Default value: 72 (12 hours at an average of 6 blocks/hour). + * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as + * [`MIN_CLTV_EXPIRY_DELTA`] instead. + * + * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA + */ +uint16_t ChannelConfig_get_cltv_expiry_delta(const struct LDKChannelConfig *NONNULL_PTR this_ptr); + +/** + * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + * the channel this config applies to. + * + * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight + * HTLC balance when a channel appears on-chain whereas + * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining + * (non-HTLC-encumbered) balance. + * + * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, + * we (or one of our watchtowers) MUST be online to check for broadcast of the current + * commitment transaction at least once per this many blocks (minus some margin to allow us + * enough time to broadcast and confirm a transaction, possibly with time in between to RBF + * the spending transaction). + * + * Default value: 72 (12 hours at an average of 6 blocks/hour). + * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as + * [`MIN_CLTV_EXPIRY_DELTA`] instead. + * + * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA + */ +void ChannelConfig_set_cltv_expiry_delta(struct LDKChannelConfig *NONNULL_PTR this_ptr, uint16_t val); + /** * Set to announce the channel publicly and notify all nodes that they can route via this * channel. @@ -6147,7 +6201,7 @@ void ChannelConfig_set_commit_upfront_shutdown_pubkey(struct LDKChannelConfig *N /** * Constructs a new ChannelConfig given each field */ -MUST_USE_RES struct LDKChannelConfig ChannelConfig_new(uint32_t fee_proportional_millionths_arg, bool announced_channel_arg, bool commit_upfront_shutdown_pubkey_arg); +MUST_USE_RES struct LDKChannelConfig ChannelConfig_new(uint32_t fee_proportional_millionths_arg, uint16_t cltv_expiry_delta_arg, bool announced_channel_arg, bool commit_upfront_shutdown_pubkey_arg); /** * Creates a copy of the ChannelConfig diff --git a/lightning-c-bindings/src/ln/channelmanager.rs b/lightning-c-bindings/src/ln/channelmanager.rs index a5551a6..2ab0c9f 100644 --- a/lightning-c-bindings/src/ln/channelmanager.rs +++ b/lightning-c-bindings/src/ln/channelmanager.rs @@ -206,6 +206,15 @@ pub extern "C" fn ChainParameters_new(mut network_arg: crate::bitcoin::network:: #[no_mangle] pub static BREAKDOWN_TIMEOUT: u16 = lightning::ln::channelmanager::BREAKDOWN_TIMEOUT; +/// The minimum number of blocks between an inbound HTLC's CLTV and the corresponding outbound +/// HTLC's CLTV. The current default represents roughly six hours of blocks at six blocks/hour. +/// +/// This can be increased (but not decreased) through [`ChannelConfig::cltv_expiry_delta`] +/// +/// [`ChannelConfig::cltv_expiry_delta`]: crate::util::config::ChannelConfig::cltv_expiry_delta + +#[no_mangle] +pub static MIN_CLTV_EXPIRY_DELTA: u16 = lightning::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA; use lightning::ln::channelmanager::ChannelDetails as nativeChannelDetailsImport; type nativeChannelDetails = nativeChannelDetailsImport; diff --git a/lightning-c-bindings/src/util/config.rs b/lightning-c-bindings/src/util/config.rs index d1d3f1b..1d1cb15 100644 --- a/lightning-c-bindings/src/util/config.rs +++ b/lightning-c-bindings/src/util/config.rs @@ -79,35 +79,41 @@ pub extern "C" fn ChannelHandshakeConfig_get_minimum_depth(this_ptr: &ChannelHan pub extern "C" fn ChannelHandshakeConfig_set_minimum_depth(this_ptr: &mut ChannelHandshakeConfig, mut val: u32) { unsafe { &mut *this_ptr.inner }.minimum_depth = val; } -/// Set to the amount of time we require our counterparty to wait to claim their money. +/// Set to the number of blocks we require our counterparty to wait to claim their money (ie +/// the number of blocks we have to punish our counterparty if they broadcast a revoked +/// transaction). /// -/// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST -/// be online to check for peer having broadcast a revoked transaction to steal our funds -/// at least once every our_to_self_delay blocks. +/// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST +/// be online to check for revoked transactions on-chain at least once every our_to_self_delay +/// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction, +/// possibly with time in between to RBF the spending transaction). /// /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in /// case of an honest unilateral channel close, which implicitly decrease the economic value of /// our channel. /// -/// Default value: [`BREAKDOWN_TIMEOUT`] (currently 144), we enforce it as a minimum at channel -/// opening so you can tweak config to ask for more security, not less. +/// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you +/// can tweak config to ask for more security, not less. #[no_mangle] pub extern "C" fn ChannelHandshakeConfig_get_our_to_self_delay(this_ptr: &ChannelHandshakeConfig) -> u16 { let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.our_to_self_delay; (*inner_val) } -/// Set to the amount of time we require our counterparty to wait to claim their money. +/// Set to the number of blocks we require our counterparty to wait to claim their money (ie +/// the number of blocks we have to punish our counterparty if they broadcast a revoked +/// transaction). /// -/// It's one of the main parameter of our security model. We (or one of our watchtowers) MUST -/// be online to check for peer having broadcast a revoked transaction to steal our funds -/// at least once every our_to_self_delay blocks. +/// This is one of the main parameters of our security model. We (or one of our watchtowers) MUST +/// be online to check for revoked transactions on-chain at least once every our_to_self_delay +/// blocks (minus some margin to allow us enough time to broadcast and confirm a transaction, +/// possibly with time in between to RBF the spending transaction). /// /// Meanwhile, asking for a too high delay, we bother peer to freeze funds for nothing in /// case of an honest unilateral channel close, which implicitly decrease the economic value of /// our channel. /// -/// Default value: [`BREAKDOWN_TIMEOUT`] (currently 144), we enforce it as a minimum at channel -/// opening so you can tweak config to ask for more security, not less. +/// Default value: [`BREAKDOWN_TIMEOUT`], we enforce it as a minimum at channel opening so you +/// can tweak config to ask for more security, not less. #[no_mangle] pub extern "C" fn ChannelHandshakeConfig_set_our_to_self_delay(this_ptr: &mut ChannelHandshakeConfig, mut val: u16) { unsafe { &mut *this_ptr.inner }.our_to_self_delay = val; @@ -528,6 +534,53 @@ pub extern "C" fn ChannelConfig_get_fee_proportional_millionths(this_ptr: &Chann pub extern "C" fn ChannelConfig_set_fee_proportional_millionths(this_ptr: &mut ChannelConfig, mut val: u32) { unsafe { &mut *this_ptr.inner }.fee_proportional_millionths = val; } +/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over +/// the channel this config applies to. +/// +/// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight +/// HTLC balance when a channel appears on-chain whereas +/// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining +/// (non-HTLC-encumbered) balance. +/// +/// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, +/// we (or one of our watchtowers) MUST be online to check for broadcast of the current +/// commitment transaction at least once per this many blocks (minus some margin to allow us +/// enough time to broadcast and confirm a transaction, possibly with time in between to RBF +/// the spending transaction). +/// +/// Default value: 72 (12 hours at an average of 6 blocks/hour). +/// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as +/// [`MIN_CLTV_EXPIRY_DELTA`] instead. +/// +/// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA +#[no_mangle] +pub extern "C" fn ChannelConfig_get_cltv_expiry_delta(this_ptr: &ChannelConfig) -> u16 { + let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta; + (*inner_val) +} +/// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over +/// the channel this config applies to. +/// +/// This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight +/// HTLC balance when a channel appears on-chain whereas +/// [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining +/// (non-HTLC-encumbered) balance. +/// +/// Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, +/// we (or one of our watchtowers) MUST be online to check for broadcast of the current +/// commitment transaction at least once per this many blocks (minus some margin to allow us +/// enough time to broadcast and confirm a transaction, possibly with time in between to RBF +/// the spending transaction). +/// +/// Default value: 72 (12 hours at an average of 6 blocks/hour). +/// Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as +/// [`MIN_CLTV_EXPIRY_DELTA`] instead. +/// +/// [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA +#[no_mangle] +pub extern "C" fn ChannelConfig_set_cltv_expiry_delta(this_ptr: &mut ChannelConfig, mut val: u16) { + unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val; +} /// Set to announce the channel publicly and notify all nodes that they can route via this /// channel. /// @@ -593,9 +646,10 @@ pub extern "C" fn ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr: &mu /// Constructs a new ChannelConfig given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig { +pub extern "C" fn ChannelConfig_new(mut fee_proportional_millionths_arg: u32, mut cltv_expiry_delta_arg: u16, mut announced_channel_arg: bool, mut commit_upfront_shutdown_pubkey_arg: bool) -> ChannelConfig { ChannelConfig { inner: Box::into_raw(Box::new(nativeChannelConfig { fee_proportional_millionths: fee_proportional_millionths_arg, + cltv_expiry_delta: cltv_expiry_delta_arg, announced_channel: announced_channel_arg, commit_upfront_shutdown_pubkey: commit_upfront_shutdown_pubkey_arg, })), is_owned: true }