X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Frouting%2Fgossip.rs;h=bef0af53db63e514ce89a10150fada96f1d32326;hb=3e46e1794f14640e35f09cc6da4169c152de34ce;hp=a035af6871e94f2bf8f756cd92eb76da40b771db;hpb=2f70a371708dbfde3fa6abfcc0315736d2795a01;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/routing/gossip.rs b/lightning-c-bindings/src/lightning/routing/gossip.rs index a035af6..bef0af5 100644 --- a/lightning-c-bindings/src/lightning/routing/gossip.rs +++ b/lightning-c-bindings/src/lightning/routing/gossip.rs @@ -6,9 +6,10 @@ // license as that which applies to the original source files from which this // source was automatically generated. -//! The top-level network map tracking logic lives here. +//! The [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers use alloc::str::FromStr; +use alloc::string::String; use core::ffi::c_void; use core::convert::Infallible; use bitcoin::hashes::Hash; @@ -103,7 +104,16 @@ pub extern "C" fn NodeId_as_slice(this_arg: &crate::lightning::routing::gossip:: local_ret } -/// Checks if two NodeIds contain equal inner contents. +/// Get the public key from this NodeId +#[must_use] +#[no_mangle] +pub extern "C" fn NodeId_as_pubkey(this_arg: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.as_pubkey(); + let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; + local_ret +} + +/// Generates a non-cryptographic 64-bit hash of the NodeId. #[no_mangle] pub extern "C" fn NodeId_hash(o: &NodeId) -> u64 { if o.inner.is_null() { return 0; } @@ -246,7 +256,7 @@ pub enum NetworkUpdate { msg: crate::lightning::ln::msgs::ChannelUpdate, }, /// An error indicating that a channel failed to route a payment, which should be applied via - /// [`NetworkGraph::channel_failed`]. + /// [`NetworkGraph::channel_failed_permanent`] if permanent. ChannelFailure { /// The short channel id of the closed channel. short_channel_id: u64, @@ -418,7 +428,7 @@ pub extern "C" fn NetworkUpdate_read(ser: crate::c_types::u8slice) -> crate::c_t } use lightning::routing::gossip::P2PGossipSync as nativeP2PGossipSyncImport; -pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph, crate::lightning::chain::Access, crate::lightning::util::logger::Logger>; +pub(crate) type nativeP2PGossipSync = nativeP2PGossipSyncImport<&'static lightning::routing::gossip::NetworkGraph, crate::lightning::routing::utxo::UtxoLookup, crate::lightning::util::logger::Logger>; /// Receives and validates network updates from peers, /// stores authentic and relevant data as a network graph. @@ -472,15 +482,14 @@ impl P2PGossipSync { } } /// Creates a new tracker of the actual state of the network of channels and nodes, -/// assuming an existing Network Graph. -/// Chain monitor is used to make sure announced channels exist on-chain, -/// channel data is correct, and that the announcement is signed with -/// channel owners' keys. +/// assuming an existing [`NetworkGraph`]. +/// UTXO lookup is used to make sure announced channels exist on-chain, channel data is +/// correct, and the announcement is signed with channel owners' keys. #[must_use] #[no_mangle] -pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut chain_access: crate::c_types::derived::COption_AccessZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::P2PGossipSync { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_chain_access, logger); +pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::P2PGossipSync { + let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} }; + let mut ret = lightning::routing::gossip::P2PGossipSync::new(network_graph.get_native_ref(), local_utxo_lookup, logger); crate::lightning::routing::gossip::P2PGossipSync { inner: ObjOps::heap_alloc(ret), is_owned: true } } @@ -488,19 +497,47 @@ pub extern "C" fn P2PGossipSync_new(network_graph: &crate::lightning::routing::g /// existing announcements unless they are updated. /// Add, update or remove the provider would replace the current one. #[no_mangle] -pub extern "C" fn P2PGossipSync_add_chain_access(this_arg: &mut crate::lightning::routing::gossip::P2PGossipSync, mut chain_access: crate::c_types::derived::COption_AccessZ) { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::gossip::nativeP2PGossipSync)) }.add_chain_access(local_chain_access) +pub extern "C" fn P2PGossipSync_add_utxo_lookup(this_arg: &crate::lightning::routing::gossip::P2PGossipSync, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) { + let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} }; + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.add_utxo_lookup(local_utxo_lookup) } /// Handles any network updates originating from [`Event`]s. /// -/// [`Event`]: crate::util::events::Event +/// [`Event`]: crate::events::Event #[no_mangle] pub extern "C" fn NetworkGraph_handle_network_update(this_arg: &crate::lightning::routing::gossip::NetworkGraph, network_update: &crate::lightning::routing::gossip::NetworkUpdate) { unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.handle_network_update(&network_update.to_native()) } +/// Gets the genesis hash for this network graph. +#[must_use] +#[no_mangle] +pub extern "C" fn NetworkGraph_get_genesis_hash(this_arg: &crate::lightning::routing::gossip::NetworkGraph) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_genesis_hash(); + crate::c_types::ThirtyTwoBytes { data: ret.into_inner() } +} + +/// Verifies the signature of a [`NodeAnnouncement`]. +/// +/// Returns an error if it is invalid. +#[no_mangle] +pub extern "C" fn verify_node_announcement(msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = lightning::routing::gossip::verify_node_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1); + 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::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_ret +} + +/// Verifies all signatures included in a [`ChannelAnnouncement`]. +/// +/// Returns an error if one of the signatures is invalid. +#[no_mangle] +pub extern "C" fn verify_channel_announcement(msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = lightning::routing::gossip::verify_channel_announcement(msg.get_native_ref(), secp256k1::global::SECP256K1); + 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::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_ret +} + impl From for crate::lightning::ln::msgs::RoutingMessageHandler { fn from(obj: nativeP2PGossipSync) -> Self { let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; @@ -528,9 +565,10 @@ pub extern "C" fn P2PGossipSync_as_RoutingMessageHandler(this_arg: &P2PGossipSyn handle_reply_short_channel_ids_end: P2PGossipSync_RoutingMessageHandler_handle_reply_short_channel_ids_end, handle_query_channel_range: P2PGossipSync_RoutingMessageHandler_handle_query_channel_range, handle_query_short_channel_ids: P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids, + processing_queue_high: P2PGossipSync_RoutingMessageHandler_processing_queue_high, provided_node_features: P2PGossipSync_RoutingMessageHandler_provided_node_features, provided_init_features: P2PGossipSync_RoutingMessageHandler_provided_init_features, - MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider { + MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events, @@ -563,15 +601,15 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_channel_announcement( local_ret } #[must_use] -extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::NodeAnnouncement { - let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref(); +extern "C" fn P2PGossipSync_RoutingMessageHandler_get_next_node_announcement(this_arg: *const c_void, mut starting_point: crate::lightning::routing::gossip::NodeId) -> crate::lightning::ln::msgs::NodeAnnouncement { + let mut local_starting_point = if starting_point.inner.is_null() { None } else { Some( { starting_point.get_native_ref() }) }; let mut ret = >::get_next_node_announcement(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, local_starting_point); let mut local_ret = crate::lightning::ln::msgs::NodeAnnouncement { inner: if ret.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((ret.unwrap())) } }, is_owned: true }; local_ret } #[must_use] -extern "C" fn P2PGossipSync_RoutingMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init) -> crate::c_types::derived::CResult_NoneNoneZ { - let mut ret = >::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init.get_native_ref()); +extern "C" fn P2PGossipSync_RoutingMessageHandler_peer_connected(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, mut inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ { + let mut ret = >::peer_connected(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, &their_node_id.into_rust(), init.get_native_ref(), inbound); 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 } @@ -600,6 +638,11 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_handle_query_short_channel_ids local_ret } #[must_use] +extern "C" fn P2PGossipSync_RoutingMessageHandler_processing_queue_high(this_arg: *const c_void) -> bool { + let mut ret = >::processing_queue_high(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); + ret +} +#[must_use] extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_node_features(this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures { let mut ret = >::provided_node_features(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); crate::lightning::ln::features::NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } @@ -610,7 +653,7 @@ extern "C" fn P2PGossipSync_RoutingMessageHandler_provided_init_features(this_ar crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -impl From for crate::lightning::util::events::MessageSendEventsProvider { +impl From for crate::lightning::events::MessageSendEventsProvider { fn from(obj: nativeP2PGossipSync) -> Self { let mut rust_obj = P2PGossipSync { inner: ObjOps::heap_alloc(obj), is_owned: true }; let mut ret = P2PGossipSync_as_MessageSendEventsProvider(&rust_obj); @@ -623,8 +666,8 @@ impl From for crate::lightning::util::events::MessageSendEv /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg. /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is #[no_mangle] -pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::util::events::MessageSendEventsProvider { - crate::lightning::util::events::MessageSendEventsProvider { +pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossipSync) -> crate::lightning::events::MessageSendEventsProvider { + crate::lightning::events::MessageSendEventsProvider { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, get_and_clear_pending_msg_events: P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events, @@ -633,8 +676,8 @@ pub extern "C" fn P2PGossipSync_as_MessageSendEventsProvider(this_arg: &P2PGossi #[must_use] extern "C" fn P2PGossipSync_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ { - let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); - let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); }; + let mut ret = >::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeP2PGossipSync) }, ); + let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::events::MessageSendEvent::native_into(item) }); }; local_ret.into() } @@ -781,6 +824,8 @@ pub extern "C" fn ChannelUpdateInfo_set_last_update_message(this_ptr: &mut Chann unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.last_update_message = local_val; } /// Constructs a new ChannelUpdateInfo given each field +/// +/// Note that last_update_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[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: u64, mut fees_arg: crate::lightning::routing::gossip::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> ChannelUpdateInfo { @@ -1164,7 +1209,7 @@ pub enum EffectiveCapacity { liquidity_msat: u64, }, /// The maximum HTLC amount in one direction as advertised on the gossip network. - MaximumHTLC { + AdvertisedMaxHTLC { /// The maximum HTLC amount denominated in millisatoshi. amount_msat: u64, }, @@ -1178,6 +1223,11 @@ pub enum EffectiveCapacity { /// A capacity sufficient to route any payment, typically used for private channels provided by /// an invoice. Infinite, + /// The maximum HTLC amount as provided by an invoice route hint. + HintMaxHTLC { + /// The maximum HTLC amount denominated in millisatoshi. + amount_msat: u64, + }, /// A capacity that is unknown possibly because either the chain state is unavailable to know /// the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network. Unknown, @@ -1195,9 +1245,9 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat_nonref, } }, - EffectiveCapacity::MaximumHTLC {ref amount_msat, } => { + EffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => { let mut amount_msat_nonref = Clone::clone(amount_msat); - nativeEffectiveCapacity::MaximumHTLC { + nativeEffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat_nonref, } }, @@ -1210,6 +1260,12 @@ impl EffectiveCapacity { } }, EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite, + EffectiveCapacity::HintMaxHTLC {ref amount_msat, } => { + let mut amount_msat_nonref = Clone::clone(amount_msat); + nativeEffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat_nonref, + } + }, EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown, } } @@ -1221,8 +1277,8 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat, } }, - EffectiveCapacity::MaximumHTLC {mut amount_msat, } => { - nativeEffectiveCapacity::MaximumHTLC { + EffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => { + nativeEffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat, } }, @@ -1233,6 +1289,11 @@ impl EffectiveCapacity { } }, EffectiveCapacity::Infinite => nativeEffectiveCapacity::Infinite, + EffectiveCapacity::HintMaxHTLC {mut amount_msat, } => { + nativeEffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat, + } + }, EffectiveCapacity::Unknown => nativeEffectiveCapacity::Unknown, } } @@ -1245,9 +1306,9 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat_nonref, } }, - nativeEffectiveCapacity::MaximumHTLC {ref amount_msat, } => { + nativeEffectiveCapacity::AdvertisedMaxHTLC {ref amount_msat, } => { let mut amount_msat_nonref = Clone::clone(amount_msat); - EffectiveCapacity::MaximumHTLC { + EffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat_nonref, } }, @@ -1260,6 +1321,12 @@ impl EffectiveCapacity { } }, nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite, + nativeEffectiveCapacity::HintMaxHTLC {ref amount_msat, } => { + let mut amount_msat_nonref = Clone::clone(amount_msat); + EffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat_nonref, + } + }, nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown, } } @@ -1271,8 +1338,8 @@ impl EffectiveCapacity { liquidity_msat: liquidity_msat, } }, - nativeEffectiveCapacity::MaximumHTLC {mut amount_msat, } => { - EffectiveCapacity::MaximumHTLC { + nativeEffectiveCapacity::AdvertisedMaxHTLC {mut amount_msat, } => { + EffectiveCapacity::AdvertisedMaxHTLC { amount_msat: amount_msat, } }, @@ -1283,6 +1350,11 @@ impl EffectiveCapacity { } }, nativeEffectiveCapacity::Infinite => EffectiveCapacity::Infinite, + nativeEffectiveCapacity::HintMaxHTLC {mut amount_msat, } => { + EffectiveCapacity::HintMaxHTLC { + amount_msat: amount_msat, + } + }, nativeEffectiveCapacity::Unknown => EffectiveCapacity::Unknown, } } @@ -1303,9 +1375,9 @@ pub extern "C" fn EffectiveCapacity_exact_liquidity(liquidity_msat: u64) -> Effe } } #[no_mangle] -/// Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity -pub extern "C" fn EffectiveCapacity_maximum_htlc(amount_msat: u64) -> EffectiveCapacity { - EffectiveCapacity::MaximumHTLC { +/// Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity +pub extern "C" fn EffectiveCapacity_advertised_max_htlc(amount_msat: u64) -> EffectiveCapacity { + EffectiveCapacity::AdvertisedMaxHTLC { amount_msat, } } @@ -1322,6 +1394,13 @@ pub extern "C" fn EffectiveCapacity_total(capacity_msat: u64, htlc_maximum_msat: pub extern "C" fn EffectiveCapacity_infinite() -> EffectiveCapacity { EffectiveCapacity::Infinite} #[no_mangle] +/// Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity +pub extern "C" fn EffectiveCapacity_hint_max_htlc(amount_msat: u64) -> EffectiveCapacity { + EffectiveCapacity::HintMaxHTLC { + amount_msat, + } +} +#[no_mangle] /// Utility method to constructs a new Unknown-variant EffectiveCapacity pub extern "C" fn EffectiveCapacity_unknown() -> EffectiveCapacity { EffectiveCapacity::Unknown} @@ -1389,13 +1468,13 @@ impl RoutingFees { ret } } -/// Flat routing fee in satoshis +/// Flat routing fee in millisatoshis. #[no_mangle] pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 { let mut inner_val = &mut this_ptr.get_native_mut_ref().base_msat; *inner_val } -/// Flat routing fee in satoshis +/// Flat routing fee in millisatoshis. #[no_mangle] pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_msat = val; @@ -1450,7 +1529,7 @@ pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees { orig.clone() } -/// Checks if two RoutingFeess contain equal inner contents. +/// Generates a non-cryptographic 64-bit hash of the RoutingFees. #[no_mangle] pub extern "C" fn RoutingFees_hash(o: &RoutingFees) -> u64 { if o.inner.is_null() { return 0; } @@ -1577,21 +1656,6 @@ pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::routing::gossip::NodeAlias) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = *unsafe { Box::from_raw(val.take_inner()) }; } -/// Internet-level addresses via which one can connect to the node -/// -/// Returns a copy of the field. -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_get_addresses(this_ptr: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_NetAddressZ { - let mut inner_val = this_ptr.get_native_mut_ref().addresses.clone(); - let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; - local_inner_val.into() -} -/// Internet-level addresses via which one can connect to the node -#[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) { - let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val; -} /// An initial announcement of the node /// Mostly redundant with the data we store in fields explicitly. /// Everything else is useful only for sending out for initial routing sync. @@ -1616,17 +1680,17 @@ pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut N unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_message = local_val; } /// Constructs a new NodeAnnouncementInfo given each field +/// +/// Note that announcement_message_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::lightning::routing::gossip::NodeAlias, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo { - let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); }; +pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::lightning::routing::gossip::NodeAlias, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo { let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) }; NodeAnnouncementInfo { inner: ObjOps::heap_alloc(nativeNodeAnnouncementInfo { features: *unsafe { Box::from_raw(features_arg.take_inner()) }, last_update: last_update_arg, rgb: rgb_arg.data, alias: *unsafe { Box::from_raw(alias_arg.take_inner()) }, - addresses: local_addresses_arg, announcement_message: local_announcement_message_arg, }), is_owned: true } } @@ -1658,6 +1722,15 @@ pub extern "C" fn NodeAnnouncementInfo_eq(a: &NodeAnnouncementInfo, b: &NodeAnno if a.inner.is_null() || b.inner.is_null() { return false; } if a.get_native_ref() == b.get_native_ref() { true } else { false } } +/// Internet-level addresses via which one can connect to the node +#[must_use] +#[no_mangle] +pub extern "C" fn NodeAnnouncementInfo_addresses(this_arg: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_SocketAddressZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.addresses(); + let mut local_ret_clone = Vec::new(); local_ret_clone.extend_from_slice(ret); let mut ret = local_ret_clone; let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; + local_ret.into() +} + #[no_mangle] /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read pub extern "C" fn NodeAnnouncementInfo_write(obj: &crate::lightning::routing::gossip::NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z { @@ -1855,27 +1928,6 @@ pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate: 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) }.channels = local_val; } -/// Lowest fees enabling routing via any of the enabled, known channels to a node. -/// The two fields (flat and proportional fee) are independent, -/// meaning they don't have to refer to the same channel. -/// -/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::gossip::RoutingFees { - let mut inner_val = &mut this_ptr.get_native_mut_ref().lowest_inbound_channel_fees; - let mut local_inner_val = crate::lightning::routing::gossip::RoutingFees { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::routing::gossip::RoutingFees<>) as *mut _ }, is_owned: false }; - local_inner_val -} -/// Lowest fees enabling routing via any of the enabled, known channels to a node. -/// The two fields (flat and proportional fee) are independent, -/// meaning they don't have to refer to the same channel. -/// -/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::gossip::RoutingFees) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.lowest_inbound_channel_fees = local_val; -} /// More information about a node from node_announcement. /// Optional because we store a Node entry after learning about it from /// a channel announcement, but before receiving a node announcement. @@ -1898,15 +1950,15 @@ pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut va unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.announcement_info = local_val; } /// Constructs a new NodeInfo given each field +/// +/// Note that announcement_info_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::gossip::RoutingFees, mut announcement_info_arg: crate::lightning::routing::gossip::NodeAnnouncementInfo) -> NodeInfo { +pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut announcement_info_arg: crate::lightning::routing::gossip::NodeAnnouncementInfo) -> NodeInfo { let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); }; - let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_inner()) } }) }; let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_inner()) } }) }; NodeInfo { inner: ObjOps::heap_alloc(nativeNodeInfo { channels: local_channels_arg, - lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg, announcement_info: local_announcement_info_arg, }), is_owned: true } } @@ -1974,8 +2026,8 @@ pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice, arg: crate::li /// Creates a new, empty, network graph. #[must_use] #[no_mangle] -pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph { - let mut ret = lightning::routing::gossip::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), logger); +pub extern "C" fn NetworkGraph_new(mut network: crate::bitcoin::network::Network, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::gossip::NetworkGraph { + let mut ret = lightning::routing::gossip::NetworkGraph::new(network.into_bitcoin(), logger); crate::lightning::routing::gossip::NetworkGraph { inner: ObjOps::heap_alloc(ret), is_owned: true } } @@ -2032,17 +2084,32 @@ pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: /// Store or update channel info from a channel announcement. /// -/// You probably don't want to call this directly, instead relying on a P2PGossipSync's -/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept +/// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s +/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// -/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify +/// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify /// the corresponding UTXO exists on chain and is correctly-formatted. #[must_use] #[no_mangle] -pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_chain_access); +pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement(msg.get_native_ref(), &local_utxo_lookup); + 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::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_ret +} + +/// Store or update channel info from a channel announcement. +/// +/// You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s +/// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept +/// routing messages from a source using a protocol other than the lightning P2P protocol. +/// +/// This will skip verification of if the channel is actually on-chain. +#[must_use] +#[no_mangle] +pub extern "C" fn NetworkGraph_update_channel_from_announcement_no_lookup(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_announcement_no_lookup(msg.get_native_ref()); 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::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; local_ret } @@ -2051,13 +2118,13 @@ pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &crate /// signatures. Because we aren't given the associated signatures here we cannot relay the /// channel announcement to any of our peers. /// -/// If a `chain::Access` object is provided via `chain_access`, it will be called to verify +/// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify /// the corresponding UTXO exists on chain and is correctly-formatted. #[must_use] #[no_mangle] -pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut chain_access: crate::c_types::derived::COption_AccessZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ { - let mut local_chain_access = { /* chain_access*/ let chain_access_opt = chain_access; { } if chain_access_opt.is_none() { None } else { Some({ chain_access_opt.take() }) } }; - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_chain_access); +pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &crate::lightning::routing::gossip::NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, mut utxo_lookup: crate::c_types::derived::COption_UtxoLookupZ) -> crate::c_types::derived::CResult_NoneLightningErrorZ { + let mut local_utxo_lookup = { /*utxo_lookup*/ let utxo_lookup_opt = utxo_lookup; if utxo_lookup_opt.is_none() { None } else { Some({ { { utxo_lookup_opt.take() } }})} }; + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.update_channel_from_unsigned_announcement(msg.get_native_ref(), &local_utxo_lookup); 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::msgs::LightningError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; local_ret } @@ -2076,13 +2143,12 @@ pub extern "C" fn NetworkGraph_add_channel_from_partial_announcement(this_arg: & local_ret } -/// Marks a channel in the graph as failed if a corresponding HTLC fail was sent. -/// If permanent, removes a channel from the local storage. -/// May cause the removal of nodes too, if this was their last channel. -/// If not permanent, makes channels unavailable for routing. +/// Marks a channel in the graph as failed permanently. +/// +/// The channel and any node for which this was their last channel are removed from the graph. #[no_mangle] -pub extern "C" fn NetworkGraph_channel_failed(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) { - unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed(short_channel_id, is_permanent) +pub extern "C" fn NetworkGraph_channel_failed_permanent(this_arg: &crate::lightning::routing::gossip::NetworkGraph, mut short_channel_id: u64) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_failed_permanent(short_channel_id) } /// Marks a node in the graph as permanently failed, effectively removing it and its channels @@ -2207,9 +2273,9 @@ pub extern "C" fn ReadOnlyNetworkGraph_list_nodes(this_arg: &crate::lightning::r /// or if node announcement for the node was never received. #[must_use] #[no_mangle] -pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_NetAddressZZ { +pub extern "C" fn ReadOnlyNetworkGraph_get_addresses(this_arg: &crate::lightning::routing::gossip::ReadOnlyNetworkGraph, mut pubkey: crate::c_types::PublicKey) -> crate::c_types::derived::COption_CVec_SocketAddressZZ { let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_addresses(&pubkey.into_rust()); - let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_NetAddressZZ::None } else { crate::c_types::derived::COption_CVec_NetAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; local_ret_0.into() }) }; + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_CVec_SocketAddressZZ::None } else { crate::c_types::derived::COption_CVec_SocketAddressZZ::Some( { let mut local_ret_0 = Vec::new(); for mut item in ret.unwrap().drain(..) { local_ret_0.push( { crate::lightning::ln::msgs::SocketAddress::native_into(item) }); }; local_ret_0.into() }) }; local_ret }