X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fgossip.rs;h=10ce74b971e6eebd13054257826aa78cbec94276;hb=661b7343e8cb880f059a0f3d7ce60983919ce262;hp=1e3be5dde174d7e00042ca6d53f91e190063f2ca;hpb=21aff6f7016e9b9ae4cd21f7ce591dd2a5c39763;p=rust-lightning diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 1e3be5dd..10ce74b9 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -250,7 +250,7 @@ where C::Target: chain::Access, L::Target: Logger impl EventHandler for NetworkGraph where L::Target: Logger { fn handle_event(&self, event: &Event) { - if let Event::PaymentPathFailed { payment_hash: _, rejected_by_dest: _, network_update, .. } = event { + if let Event::PaymentPathFailed { network_update, .. } = event { if let Some(network_update) = network_update { match *network_update { NetworkUpdate::ChannelUpdateMessage { ref msg } => { @@ -745,13 +745,13 @@ impl<'a> DirectedChannelInfo<'a> { let (htlc_maximum_msat, effective_capacity) = match (htlc_maximum_msat, capacity_msat) { (Some(amount_msat), Some(capacity_msat)) => { let htlc_maximum_msat = cmp::min(amount_msat, capacity_msat); - (htlc_maximum_msat, EffectiveCapacity::Total { capacity_msat }) + (htlc_maximum_msat, EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat: Some(htlc_maximum_msat) }) }, (Some(amount_msat), None) => { (amount_msat, EffectiveCapacity::MaximumHTLC { amount_msat }) }, (None, Some(capacity_msat)) => { - (capacity_msat, EffectiveCapacity::Total { capacity_msat }) + (capacity_msat, EffectiveCapacity::Total { capacity_msat, htlc_maximum_msat: None }) }, (None, None) => (EffectiveCapacity::Unknown.as_msat(), EffectiveCapacity::Unknown), }; @@ -816,10 +816,6 @@ impl<'a> DirectedChannelInfoWithUpdate<'a> { /// Returns the [`EffectiveCapacity`] of the channel in the direction. #[inline] pub(super) fn effective_capacity(&self) -> EffectiveCapacity { self.inner.effective_capacity() } - - /// Returns the maximum HTLC amount allowed over the channel in the direction. - #[inline] - pub(super) fn htlc_maximum_msat(&self) -> u64 { self.inner.htlc_maximum_msat() } } impl<'a> fmt::Debug for DirectedChannelInfoWithUpdate<'a> { @@ -850,6 +846,8 @@ pub enum EffectiveCapacity { Total { /// The funding amount denominated in millisatoshi. capacity_msat: u64, + /// The maximum HTLC amount denominated in millisatoshi. + htlc_maximum_msat: Option }, /// A capacity sufficient to route any payment, typically used for private channels provided by /// an invoice. @@ -869,7 +867,7 @@ impl EffectiveCapacity { match self { EffectiveCapacity::ExactLiquidity { liquidity_msat } => *liquidity_msat, EffectiveCapacity::MaximumHTLC { amount_msat } => *amount_msat, - EffectiveCapacity::Total { capacity_msat } => *capacity_msat, + EffectiveCapacity::Total { capacity_msat, .. } => *capacity_msat, EffectiveCapacity::Infinite => u64::max_value(), EffectiveCapacity::Unknown => UNKNOWN_CHANNEL_CAPACITY_MSAT, } @@ -1647,6 +1645,11 @@ impl ReadOnlyNetworkGraph<'_> { &*self.channels } + /// Returns information on a channel with the given id. + pub fn channel(&self, short_channel_id: u64) -> Option<&ChannelInfo> { + self.channels.get(&short_channel_id) + } + /// Returns all known nodes' public keys along with announced node info. /// /// (C-not exported) because we have no mapping for `BTreeMap`s @@ -1654,6 +1657,11 @@ impl ReadOnlyNetworkGraph<'_> { &*self.nodes } + /// Returns information on a node with the given id. + pub fn node(&self, node_id: &NodeId) -> Option<&NodeInfo> { + self.nodes.get(node_id) + } + /// Get network addresses by node id. /// Returns None if the requested node is completely unknown, /// or if node announcement for the node was never received. @@ -1677,7 +1685,6 @@ mod tests { UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, ReplyChannelRange, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT}; use util::test_utils; - use util::logger::Logger; use util::ser::{ReadableArgs, Writeable}; use util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider}; use util::scid_utils::scid_from_parts; @@ -1874,7 +1881,7 @@ mod tests { #[test] fn handling_channel_announcements() { let secp_ctx = Secp256k1::new(); - let logger: Arc = Arc::new(test_utils::TestLogger::new()); + let logger = test_utils::TestLogger::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -1884,8 +1891,8 @@ mod tests { // Test if the UTXO lookups were not supported let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); - let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger)); - let mut gossip_sync = P2PGossipSync::new(&network_graph, None, Arc::clone(&logger)); + let network_graph = NetworkGraph::new(genesis_hash, &logger); + let mut gossip_sync = P2PGossipSync::new(&network_graph, None, &logger); match gossip_sync.handle_channel_announcement(&valid_announcement) { Ok(res) => assert!(res), _ => panic!() @@ -1906,10 +1913,10 @@ mod tests { }; // Test if an associated transaction were not on-chain (or not confirmed). - let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); + let chain_source = test_utils::TestChainSource::new(Network::Testnet); *chain_source.utxo_ret.lock().unwrap() = Err(chain::AccessError::UnknownTx); - let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger)); - gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); + let network_graph = NetworkGraph::new(genesis_hash, &logger); + gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 1; @@ -1990,11 +1997,11 @@ mod tests { #[test] fn handling_channel_update() { let secp_ctx = Secp256k1::new(); - let logger: Arc = Arc::new(test_utils::TestLogger::new()); - let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); + let logger = test_utils::TestLogger::new(); + let chain_source = test_utils::TestChainSource::new(Network::Testnet); let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); - let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger)); - let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), Arc::clone(&logger)); + let network_graph = NetworkGraph::new(genesis_hash, &logger); + let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); @@ -2196,10 +2203,10 @@ mod tests { fn test_channel_timeouts() { // Test the removal of channels with `remove_stale_channels`. let logger = test_utils::TestLogger::new(); - let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet)); + let chain_source = test_utils::TestChainSource::new(Network::Testnet); let genesis_hash = genesis_block(Network::Testnet).header.block_hash(); let network_graph = NetworkGraph::new(genesis_hash, &logger); - let gossip_sync = P2PGossipSync::new(&network_graph, Some(chain_source.clone()), &logger); + let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let secp_ctx = Secp256k1::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();