diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 135a9e7e..1271e26c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,6 +34,12 @@ jobs: run: | cargo update -p syn --precise "2.0.106" --verbose cargo update -p quote --precise "1.0.41" --verbose + cargo update -p libc --precise 0.2.183 --verbose + cargo update -p serde_json --precise "1.0.145" --verbose + cargo update -p proc-macro2 --precise "1.0.103" --verbose + cargo update -p itoa --precise 1.0.15 + cargo update -p unicode-ident --precise 1.0.22 + cargo update -p ryu --precise "1.0.20" - name: Sanity test bindings against Cargo.toml RL working-directory: lightning-c-bindings run: | @@ -54,6 +60,12 @@ jobs: git checkout 0.1-bindings cargo update -p syn --precise "2.0.106" --verbose cargo update -p quote --precise "1.0.41" --verbose + cargo update -p libc --precise 0.2.183 --verbose + cargo update -p serde_json --precise "1.0.145" --verbose + cargo update -p proc-macro2 --precise "1.0.103" --verbose + cargo update -p itoa --precise 1.0.15 + cargo update -p unicode-ident --precise 1.0.22 + cargo update -p ryu --precise "1.0.20" - name: Fix Github Actions to not be broken run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings - name: Pin proc-macro and quote to meet MSRV @@ -61,6 +73,7 @@ jobs: cd c-bindings-gen cargo update -p quote --precise "1.0.30" --verbose cargo update -p proc-macro2 --precise "1.0.65" --verbose + cargo update -p unicode-ident --precise 1.0.22 - name: Rebuild bindings without std, and check the sample app builds + links run: ./genbindings.sh ./rust-lightning false - name: Rebuild bindings, and check the sample app builds + links @@ -101,6 +114,12 @@ jobs: run: | cargo update -p syn --precise "2.0.106" --verbose cargo update -p quote --precise "1.0.41" --verbose + cargo update -p libc --precise 0.2.183 --verbose + cargo update -p serde_json --precise "1.0.145" --verbose + cargo update -p proc-macro2 --precise "1.0.103" --verbose + cargo update -p itoa --precise 1.0.15 + cargo update -p unicode-ident --precise 1.0.22 + cargo update -p ryu --precise "1.0.20" - name: Sanity test bindings against Cargo.toml RL working-directory: lightning-c-bindings run: | @@ -121,6 +140,12 @@ jobs: git checkout 0.1-bindings cargo update -p syn --precise "2.0.106" --verbose cargo update -p quote --precise "1.0.41" --verbose + cargo update -p libc --precise 0.2.183 --verbose + cargo update -p serde_json --precise "1.0.145" --verbose + cargo update -p proc-macro2 --precise "1.0.103" --verbose + cargo update -p itoa --precise 1.0.15 + cargo update -p unicode-ident --precise 1.0.22 + cargo update -p ryu --precise "1.0.20" - name: Fix Github Actions to not be broken run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings - name: Pin proc-macro and quote to meet MSRV @@ -128,6 +153,7 @@ jobs: cd c-bindings-gen cargo update -p quote --precise "1.0.30" --verbose cargo update -p proc-macro2 --precise "1.0.65" --verbose + cargo update -p unicode-ident --precise 1.0.22 - name: Fetch MacOS SDK run: | wget https://bitcoincore.org/depends-sources/sdks/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 6bbe5d69..526506e3 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -21065,7 +21065,8 @@ typedef struct LDKEvent_LDKPaymentSent_Body { * If the recipient or an intermediate node misbehaves and gives us free money, this may * overstate the amount paid, though this is unlikely. * - * This is only `None` for payments initiated on LDK versions prior to 0.0.103. + * This is only `None` for payments abandoned but ultimately claimed when using LDK versions + * prior to 0.3, 0.2.3, or 0.1.10. * * [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees */ @@ -29825,6 +29826,10 @@ extern const uintptr_t PAYER_NOTE_LIMIT; extern const uint64_t UNKNOWN_CHANNEL_CAPACITY_MSAT; +extern const uintptr_t CHAN_COUNT_ESTIMATE; + +extern const uintptr_t NODE_COUNT_ESTIMATE; + extern const uint32_t DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA; extern const uint8_t DEFAULT_MAX_PATH_COUNT; @@ -65271,13 +65276,16 @@ MUST_USE_RES struct LDKCOption_CVec_u8ZZ Bolt11Invoice_payment_metadata(const st MUST_USE_RES struct LDKBolt11InvoiceFeatures Bolt11Invoice_features(const struct LDKBolt11Invoice *NONNULL_PTR this_arg); /** - * Recover the payee's public key (only to be used if none was included in the invoice) + * Get the invoice's payee public key. + * + * This uses the explicitly included payee public key, if present, otherwise it recovers the + * payee public key from the signature. Prefer [`Self::get_payee_pub_key`] for clarity. */ MUST_USE_RES struct LDKPublicKey Bolt11Invoice_recover_payee_pub_key(const struct LDKBolt11Invoice *NONNULL_PTR this_arg); /** - * Recover the payee's public key if one was included in the invoice, otherwise return the - * recovered public key from the signature + * Get the invoice's payee public key, preferring an explicitly included payee public key and + * falling back to recovering the key from the signature. */ MUST_USE_RES struct LDKPublicKey Bolt11Invoice_get_payee_pub_key(const struct LDKBolt11Invoice *NONNULL_PTR this_arg); @@ -65625,6 +65633,10 @@ MUST_USE_RES struct LDKRapidGossipSync RapidGossipSync_new(const struct LDKNetwo * Sync gossip data from a file. * Returns the last sync timestamp to be used the next time rapid sync data is queried. * + * You should consider the gossip data source as semi-trusted. It is generally the case that it + * can DoS the client either by omitting data which leads to pathfinding failure or by bloating + * the graph such that it leads to eventual OOM on the client. + * * `network_graph`: The network graph to apply the updates to * * `sync_path`: Path to the file where the gossip update data is located @@ -65636,6 +65648,10 @@ MUST_USE_RES struct LDKCResult_u32GraphSyncErrorZ RapidGossipSync_sync_network_g * Update network graph from binary data. * Returns the last sync timestamp to be used the next time rapid sync data is queried. * + * You should consider the gossip data source as semi-trusted. It is generally the case that it + * can DoS the client either by omitting data which leads to pathfinding failure or by bloating + * the graph such that it leads to eventual OOM on the client. + * * `update_data`: `&[u8]` binary stream that comprises the update data */ MUST_USE_RES struct LDKCResult_u32GraphSyncErrorZ RapidGossipSync_update_network_graph(const struct LDKRapidGossipSync *NONNULL_PTR this_arg, struct LDKu8slice update_data); @@ -65644,6 +65660,10 @@ MUST_USE_RES struct LDKCResult_u32GraphSyncErrorZ RapidGossipSync_update_network * Update network graph from binary data. * Returns the last sync timestamp to be used the next time rapid sync data is queried. * + * You should consider the gossip data source as semi-trusted. It is generally the case that it + * can DoS the client either by omitting data which leads to pathfinding failure or by bloating + * the graph such that it leads to eventual OOM on the client. + * * `update_data`: `&[u8]` binary stream that comprises the update data * `current_time_unix`: `Option` optional current timestamp to verify data age */ diff --git a/lightning-c-bindings/src/lightning/events/mod.rs b/lightning-c-bindings/src/lightning/events/mod.rs index f1435b68..551ea05f 100644 --- a/lightning-c-bindings/src/lightning/events/mod.rs +++ b/lightning-c-bindings/src/lightning/events/mod.rs @@ -2119,7 +2119,8 @@ pub enum Event { /// If the recipient or an intermediate node misbehaves and gives us free money, this may /// overstate the amount paid, though this is unlikely. /// - /// This is only `None` for payments initiated on LDK versions prior to 0.0.103. + /// This is only `None` for payments abandoned but ultimately claimed when using LDK versions + /// prior to 0.3, 0.2.3, or 0.1.10. /// /// [`Route::get_total_fees`]: crate::routing::router::Route::get_total_fees fee_paid_msat: crate::c_types::derived::COption_u64Z, diff --git a/lightning-c-bindings/src/lightning/routing/gossip.rs b/lightning-c-bindings/src/lightning/routing/gossip.rs index 9f6a7789..b0676450 100644 --- a/lightning-c-bindings/src/lightning/routing/gossip.rs +++ b/lightning-c-bindings/src/lightning/routing/gossip.rs @@ -2243,6 +2243,20 @@ pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::li pub extern "C" fn NetworkGraph_to_str(o: &crate::lightning::routing::gossip::NetworkGraph) -> Str { alloc::format!("{}", o.get_native_ref()).into() } +/// In Jan, 2025 there were about 49K channels. +/// +/// We over-allocate by a bit because 20% more is better than the double we get if we're slightly +/// too low. + +#[no_mangle] +pub static CHAN_COUNT_ESTIMATE: usize = lightning::routing::gossip::CHAN_COUNT_ESTIMATE; +/// In Jan, 2025 there were about 15K nodes +/// +/// We over-allocate by a bit because 33% more is better than the double we get if we're slightly +/// too low. + +#[no_mangle] +pub static NODE_COUNT_ESTIMATE: usize = lightning::routing::gossip::NODE_COUNT_ESTIMATE; /// Creates a new, empty, network graph. #[must_use] #[no_mangle] diff --git a/lightning-c-bindings/src/lightning_invoice/mod.rs b/lightning-c-bindings/src/lightning_invoice/mod.rs index d9ebaa5b..42e067f1 100644 --- a/lightning-c-bindings/src/lightning_invoice/mod.rs +++ b/lightning-c-bindings/src/lightning_invoice/mod.rs @@ -2607,7 +2607,10 @@ pub extern "C" fn Bolt11Invoice_features(this_arg: &crate::lightning_invoice::Bo local_ret } -/// Recover the payee's public key (only to be used if none was included in the invoice) +/// Get the invoice's payee public key. +/// +/// This uses the explicitly included payee public key, if present, otherwise it recovers the +/// payee public key from the signature. Prefer [`Self::get_payee_pub_key`] for clarity. #[must_use] #[no_mangle] pub extern "C" fn Bolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey { @@ -2615,8 +2618,8 @@ pub extern "C" fn Bolt11Invoice_recover_payee_pub_key(this_arg: &crate::lightnin crate::c_types::PublicKey::from_rust(&ret) } -/// Recover the payee's public key if one was included in the invoice, otherwise return the -/// recovered public key from the signature +/// Get the invoice's payee public key, preferring an explicitly included payee public key and +/// falling back to recovering the key from the signature. #[must_use] #[no_mangle] pub extern "C" fn Bolt11Invoice_get_payee_pub_key(this_arg: &crate::lightning_invoice::Bolt11Invoice) -> crate::c_types::PublicKey { diff --git a/lightning-c-bindings/src/lightning_rapid_gossip_sync.rs b/lightning-c-bindings/src/lightning_rapid_gossip_sync.rs index d20f8725..04ba9700 100644 --- a/lightning-c-bindings/src/lightning_rapid_gossip_sync.rs +++ b/lightning-c-bindings/src/lightning_rapid_gossip_sync.rs @@ -268,6 +268,10 @@ pub extern "C" fn RapidGossipSync_new(network_graph: &crate::lightning::routing: /// Sync gossip data from a file. /// Returns the last sync timestamp to be used the next time rapid sync data is queried. /// +/// You should consider the gossip data source as semi-trusted. It is generally the case that it +/// can DoS the client either by omitting data which leads to pathfinding failure or by bloating +/// the graph such that it leads to eventual OOM on the client. +/// /// `network_graph`: The network graph to apply the updates to /// /// `sync_path`: Path to the file where the gossip update data is located @@ -283,6 +287,10 @@ pub extern "C" fn RapidGossipSync_sync_network_graph_with_file_path(this_arg: &c /// Update network graph from binary data. /// Returns the last sync timestamp to be used the next time rapid sync data is queried. /// +/// You should consider the gossip data source as semi-trusted. It is generally the case that it +/// can DoS the client either by omitting data which leads to pathfinding failure or by bloating +/// the graph such that it leads to eventual OOM on the client. +/// /// `update_data`: `&[u8]` binary stream that comprises the update data #[must_use] #[no_mangle] @@ -295,6 +303,10 @@ pub extern "C" fn RapidGossipSync_update_network_graph(this_arg: &crate::lightni /// Update network graph from binary data. /// Returns the last sync timestamp to be used the next time rapid sync data is queried. /// +/// You should consider the gossip data source as semi-trusted. It is generally the case that it +/// can DoS the client either by omitting data which leads to pathfinding failure or by bloating +/// the graph such that it leads to eventual OOM on the client. +/// /// `update_data`: `&[u8]` binary stream that comprises the update data /// `current_time_unix`: `Option` optional current timestamp to verify data age #[must_use] diff --git a/lightning-c-bindings/src/lightning_types/mod.rs b/lightning-c-bindings/src/lightning_types/mod.rs index a8154337..8e7e29f0 100644 --- a/lightning-c-bindings/src/lightning_types/mod.rs +++ b/lightning-c-bindings/src/lightning_types/mod.rs @@ -24,3 +24,15 @@ pub mod features; pub mod payment; pub mod routing; pub mod string; +mod unicode { + +use alloc::str::FromStr; +use alloc::string::String; +use core::ffi::c_void; +use core::convert::Infallible; +use bitcoin::hashes::Hash; +use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; + +}