Skip to content

Commit 0f76ff4

Browse files
committed
Add flags for if a channel is pub and funding txo in ChannelDetails
1 parent c60543c commit 0f76ff4

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

fuzz/src/router.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use bitcoin::blockdata::transaction::TxOut;
1212
use bitcoin::hash_types::BlockHash;
1313

1414
use lightning::chain;
15+
use lightning::chain::transaction::OutPoint;
1516
use lightning::ln::channelmanager::ChannelDetails;
1617
use lightning::ln::features::InitFeatures;
1718
use lightning::ln::msgs;
@@ -20,6 +21,7 @@ use lightning::util::logger::Logger;
2021
use lightning::util::ser::Readable;
2122
use lightning::routing::network_graph::{NetworkGraph, RoutingFees};
2223

24+
use bitcoin::hashes::Hash;
2325
use bitcoin::secp256k1::key::PublicKey;
2426
use bitcoin::network::constants::Network;
2527
use bitcoin::blockdata::constants::genesis_block;
@@ -204,13 +206,15 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
204206
let rnid = node_pks.iter().skip(slice_to_be16(get_slice!(2))as usize % node_pks.len()).next().unwrap();
205207
first_hops_vec.push(ChannelDetails {
206208
channel_id: [0; 32],
209+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
207210
short_channel_id: Some(scid),
208211
remote_network_id: *rnid,
209212
counterparty_features: InitFeatures::known(),
210213
channel_value_satoshis: slice_to_be64(get_slice!(8)),
211214
user_id: 0,
212215
inbound_capacity_msat: 0,
213216
is_live: true,
217+
is_public: true,
214218
outbound_capacity_msat: 0,
215219
counterparty_forwarding_info: None,
216220
});

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ pub struct ChannelDetails {
604604
/// Note that this means this value is *not* persistent - it can change once during the
605605
/// lifetime of the channel.
606606
pub channel_id: [u8; 32],
607+
/// The Channel's funding transaction output, if we've negotiated the funding transaction with
608+
/// our counterparty already.
609+
///
610+
/// Note that, if this has been set, `channel_id` will be equivalent to
611+
/// `funding_txo.unwrap().to_channel_id()`.
612+
pub funding_txo: Option<OutPoint>,
607613
/// The position of the funding transaction in the chain. None if the funding transaction has
608614
/// not yet been confirmed and the channel fully opened.
609615
pub short_channel_id: Option<u64>,
@@ -631,7 +637,8 @@ pub struct ChannelDetails {
631637
/// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
632638
/// the peer is connected, and (c) no monitor update failure is pending resolution.
633639
pub is_live: bool,
634-
640+
/// True if this channel is (or will be) publicly-announced.
641+
pub is_public: bool,
635642
/// Information on the fees and requirements that the counterparty requires when forwarding
636643
/// payments to us through this channel.
637644
pub counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
@@ -954,6 +961,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
954961
let (inbound_capacity_msat, outbound_capacity_msat) = channel.get_inbound_outbound_available_balance_msat();
955962
res.push(ChannelDetails {
956963
channel_id: (*channel_id).clone(),
964+
funding_txo: channel.get_funding_txo(),
957965
short_channel_id: channel.get_short_channel_id(),
958966
remote_network_id: channel.get_counterparty_node_id(),
959967
counterparty_features: InitFeatures::empty(),
@@ -962,6 +970,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
962970
outbound_capacity_msat,
963971
user_id: channel.get_user_id(),
964972
is_live: channel.is_live(),
973+
is_public: channel.should_announce(),
965974
counterparty_forwarding_info: channel.counterparty_forwarding_info(),
966975
});
967976
}

lightning/src/routing/router.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
11651165
mod tests {
11661166
use routing::router::{get_route, RouteHintHop, RoutingFees};
11671167
use routing::network_graph::{NetworkGraph, NetGraphMsgHandler};
1168+
use chain::transaction::OutPoint;
11681169
use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
11691170
use ln::msgs::{ErrorAction, LightningError, OptionalField, UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
11701171
NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate};
@@ -1625,14 +1626,15 @@ mod tests {
16251626

16261627
let our_chans = vec![channelmanager::ChannelDetails {
16271628
channel_id: [0; 32],
1629+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
16281630
short_channel_id: Some(2),
16291631
remote_network_id: our_id,
16301632
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
16311633
channel_value_satoshis: 100000,
16321634
user_id: 0,
16331635
outbound_capacity_msat: 100000,
16341636
inbound_capacity_msat: 100000,
1635-
is_live: true,
1637+
is_live: true, is_public: true,
16361638
counterparty_forwarding_info: None,
16371639
}];
16381640

@@ -1943,14 +1945,15 @@ mod tests {
19431945
// If we specify a channel to node7, that overrides our local channel view and that gets used
19441946
let our_chans = vec![channelmanager::ChannelDetails {
19451947
channel_id: [0; 32],
1948+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
19461949
short_channel_id: Some(42),
19471950
remote_network_id: nodes[7].clone(),
19481951
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
19491952
channel_value_satoshis: 0,
19501953
user_id: 0,
19511954
outbound_capacity_msat: 250_000_000,
19521955
inbound_capacity_msat: 0,
1953-
is_live: true,
1956+
is_live: true, is_public: true,
19541957
counterparty_forwarding_info: None,
19551958
}];
19561959
let route = get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &nodes[2], None, Some(&our_chans.iter().collect::<Vec<_>>()), &Vec::new(), 100, 42, Arc::clone(&logger)).unwrap();
@@ -1991,14 +1994,15 @@ mod tests {
19911994
// If we specify a channel to node7, that overrides our local channel view and that gets used
19921995
let our_chans = vec![channelmanager::ChannelDetails {
19931996
channel_id: [0; 32],
1997+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
19941998
short_channel_id: Some(42),
19951999
remote_network_id: nodes[7].clone(),
19962000
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
19972001
channel_value_satoshis: 0,
19982002
user_id: 0,
19992003
outbound_capacity_msat: 250_000_000,
20002004
inbound_capacity_msat: 0,
2001-
is_live: true,
2005+
is_live: true, is_public: true,
20022006
counterparty_forwarding_info: None,
20032007
}];
20042008
let route = get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &nodes[2], None, Some(&our_chans.iter().collect::<Vec<_>>()), &Vec::new(), 100, 42, Arc::clone(&logger)).unwrap();
@@ -2056,14 +2060,15 @@ mod tests {
20562060
// If we specify a channel to node7, that overrides our local channel view and that gets used
20572061
let our_chans = vec![channelmanager::ChannelDetails {
20582062
channel_id: [0; 32],
2063+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
20592064
short_channel_id: Some(42),
20602065
remote_network_id: nodes[7].clone(),
20612066
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
20622067
channel_value_satoshis: 0,
20632068
user_id: 0,
20642069
outbound_capacity_msat: 250_000_000,
20652070
inbound_capacity_msat: 0,
2066-
is_live: true,
2071+
is_live: true, is_public: true,
20672072
counterparty_forwarding_info: None,
20682073
}];
20692074
let route = get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &nodes[2], None, Some(&our_chans.iter().collect::<Vec<_>>()), &Vec::new(), 100, 42, Arc::clone(&logger)).unwrap();
@@ -2193,14 +2198,15 @@ mod tests {
21932198
// Simple test with outbound channel to 4 to test that last_hops and first_hops connect
21942199
let our_chans = vec![channelmanager::ChannelDetails {
21952200
channel_id: [0; 32],
2201+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
21962202
short_channel_id: Some(42),
21972203
remote_network_id: nodes[3].clone(),
21982204
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
21992205
channel_value_satoshis: 0,
22002206
user_id: 0,
22012207
outbound_capacity_msat: 250_000_000,
22022208
inbound_capacity_msat: 0,
2203-
is_live: true,
2209+
is_live: true, is_public: true,
22042210
counterparty_forwarding_info: None,
22052211
}];
22062212
let mut last_hops = last_hops(&nodes);
@@ -2322,14 +2328,15 @@ mod tests {
23222328
}];
23232329
let our_chans = vec![channelmanager::ChannelDetails {
23242330
channel_id: [0; 32],
2331+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
23252332
short_channel_id: Some(42),
23262333
remote_network_id: middle_node_id,
23272334
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
23282335
channel_value_satoshis: 100000,
23292336
user_id: 0,
23302337
outbound_capacity_msat: 100000,
23312338
inbound_capacity_msat: 100000,
2332-
is_live: true,
2339+
is_live: true, is_public: true,
23332340
counterparty_forwarding_info: None,
23342341
}];
23352342
let route = get_route(&source_node_id, &NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()), &target_node_id, None, Some(&our_chans.iter().collect::<Vec<_>>()), &last_hops.iter().collect::<Vec<_>>(), 100, 42, Arc::new(test_utils::TestLogger::new())).unwrap();
@@ -2454,14 +2461,15 @@ mod tests {
24542461
// Now, limit the first_hop by the outbound_capacity_msat of 200_000 sats.
24552462
let our_chans = vec![channelmanager::ChannelDetails {
24562463
channel_id: [0; 32],
2464+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
24572465
short_channel_id: Some(42),
24582466
remote_network_id: nodes[0].clone(),
24592467
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
24602468
channel_value_satoshis: 0,
24612469
user_id: 0,
24622470
outbound_capacity_msat: 200_000_000,
24632471
inbound_capacity_msat: 0,
2464-
is_live: true,
2472+
is_live: true, is_public: true,
24652473
counterparty_forwarding_info: None,
24662474
}];
24672475

0 commit comments

Comments
 (0)