Skip to content

Commit 7297e13

Browse files
authored
Merge pull request #912 from TheBlueMatt/2021-05-more-chan-info
Add flags for if a channel is pub and funding txo in ChannelDetails
2 parents d2955be + 62f466a commit 7297e13

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

fuzz/src/router.rs

Lines changed: 7 additions & 1 deletion
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,17 @@ 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,
213-
is_live: true,
216+
is_outbound: true,
217+
is_funding_locked: true,
218+
is_usable: true,
219+
is_public: true,
214220
outbound_capacity_msat: 0,
215221
counterparty_forwarding_info: None,
216222
});

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,12 @@ pub struct ChannelDetails {
607607
/// Note that this means this value is *not* persistent - it can change once during the
608608
/// lifetime of the channel.
609609
pub channel_id: [u8; 32],
610+
/// The Channel's funding transaction output, if we've negotiated the funding transaction with
611+
/// our counterparty already.
612+
///
613+
/// Note that, if this has been set, `channel_id` will be equivalent to
614+
/// `funding_txo.unwrap().to_channel_id()`.
615+
pub funding_txo: Option<OutPoint>,
610616
/// The position of the funding transaction in the chain. None if the funding transaction has
611617
/// not yet been confirmed and the channel fully opened.
612618
pub short_channel_id: Option<u64>,
@@ -631,10 +637,21 @@ pub struct ChannelDetails {
631637
/// Note that there are some corner cases not fully handled here, so the actual available
632638
/// inbound capacity may be slightly higher than this.
633639
pub inbound_capacity_msat: u64,
640+
/// True if the channel was initiated (and thus funded) by us.
641+
pub is_outbound: bool,
642+
/// True if the channel is confirmed, funding_locked messages have been exchanged, and the
643+
/// channel is not currently being shut down. `funding_locked` message exchange implies the
644+
/// required confirmation count has been reached (and we were connected to the peer at some
645+
/// point after the funding transaction received enough confirmations).
646+
pub is_funding_locked: bool,
634647
/// True if the channel is (a) confirmed and funding_locked messages have been exchanged, (b)
635-
/// the peer is connected, and (c) no monitor update failure is pending resolution.
636-
pub is_live: bool,
637-
648+
/// the peer is connected, (c) no monitor update failure is pending resolution, and (d) the
649+
/// channel is not currently negotiating a shutdown.
650+
///
651+
/// This is a strict superset of `is_funding_locked`.
652+
pub is_usable: bool,
653+
/// True if this channel is (or will be) publicly-announced.
654+
pub is_public: bool,
638655
/// Information on the fees and requirements that the counterparty requires when forwarding
639656
/// payments to us through this channel.
640657
pub counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
@@ -957,14 +974,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
957974
let (inbound_capacity_msat, outbound_capacity_msat) = channel.get_inbound_outbound_available_balance_msat();
958975
res.push(ChannelDetails {
959976
channel_id: (*channel_id).clone(),
977+
funding_txo: channel.get_funding_txo(),
960978
short_channel_id: channel.get_short_channel_id(),
961979
remote_network_id: channel.get_counterparty_node_id(),
962980
counterparty_features: InitFeatures::empty(),
963981
channel_value_satoshis: channel.get_value_satoshis(),
964982
inbound_capacity_msat,
965983
outbound_capacity_msat,
966984
user_id: channel.get_user_id(),
967-
is_live: channel.is_live(),
985+
is_outbound: channel.is_outbound(),
986+
is_funding_locked: channel.is_usable(),
987+
is_usable: channel.is_live(),
988+
is_public: channel.should_announce(),
968989
counterparty_forwarding_info: channel.counterparty_forwarding_info(),
969990
});
970991
}
@@ -987,8 +1008,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
9871008
/// Gets the list of usable channels, in random order. Useful as an argument to
9881009
/// get_route to ensure non-announced channels are used.
9891010
///
990-
/// These are guaranteed to have their is_live value set to true, see the documentation for
991-
/// ChannelDetails::is_live for more info on exactly what the criteria are.
1011+
/// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
1012+
/// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
1013+
/// are.
9921014
pub fn list_usable_channels(&self) -> Vec<ChannelDetails> {
9931015
// Note we use is_live here instead of usable which leads to somewhat confused
9941016
// internal/external nomenclature, but that's ok cause that's probably what the user

lightning/src/routing/router.rs

Lines changed: 22 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,16 @@ 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_outbound: true, is_funding_locked: true,
1638+
is_usable: true, is_public: true,
16361639
counterparty_forwarding_info: None,
16371640
}];
16381641

@@ -1943,14 +1946,16 @@ mod tests {
19431946
// If we specify a channel to node7, that overrides our local channel view and that gets used
19441947
let our_chans = vec![channelmanager::ChannelDetails {
19451948
channel_id: [0; 32],
1949+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
19461950
short_channel_id: Some(42),
19471951
remote_network_id: nodes[7].clone(),
19481952
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
19491953
channel_value_satoshis: 0,
19501954
user_id: 0,
19511955
outbound_capacity_msat: 250_000_000,
19521956
inbound_capacity_msat: 0,
1953-
is_live: true,
1957+
is_outbound: true, is_funding_locked: true,
1958+
is_usable: true, is_public: true,
19541959
counterparty_forwarding_info: None,
19551960
}];
19561961
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 +1996,16 @@ mod tests {
19911996
// If we specify a channel to node7, that overrides our local channel view and that gets used
19921997
let our_chans = vec![channelmanager::ChannelDetails {
19931998
channel_id: [0; 32],
1999+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
19942000
short_channel_id: Some(42),
19952001
remote_network_id: nodes[7].clone(),
19962002
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
19972003
channel_value_satoshis: 0,
19982004
user_id: 0,
19992005
outbound_capacity_msat: 250_000_000,
20002006
inbound_capacity_msat: 0,
2001-
is_live: true,
2007+
is_outbound: true, is_funding_locked: true,
2008+
is_usable: true, is_public: true,
20022009
counterparty_forwarding_info: None,
20032010
}];
20042011
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 +2063,16 @@ mod tests {
20562063
// If we specify a channel to node7, that overrides our local channel view and that gets used
20572064
let our_chans = vec![channelmanager::ChannelDetails {
20582065
channel_id: [0; 32],
2066+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
20592067
short_channel_id: Some(42),
20602068
remote_network_id: nodes[7].clone(),
20612069
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
20622070
channel_value_satoshis: 0,
20632071
user_id: 0,
20642072
outbound_capacity_msat: 250_000_000,
20652073
inbound_capacity_msat: 0,
2066-
is_live: true,
2074+
is_outbound: true, is_funding_locked: true,
2075+
is_usable: true, is_public: true,
20672076
counterparty_forwarding_info: None,
20682077
}];
20692078
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 +2202,16 @@ mod tests {
21932202
// Simple test with outbound channel to 4 to test that last_hops and first_hops connect
21942203
let our_chans = vec![channelmanager::ChannelDetails {
21952204
channel_id: [0; 32],
2205+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
21962206
short_channel_id: Some(42),
21972207
remote_network_id: nodes[3].clone(),
21982208
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
21992209
channel_value_satoshis: 0,
22002210
user_id: 0,
22012211
outbound_capacity_msat: 250_000_000,
22022212
inbound_capacity_msat: 0,
2203-
is_live: true,
2213+
is_outbound: true, is_funding_locked: true,
2214+
is_usable: true, is_public: true,
22042215
counterparty_forwarding_info: None,
22052216
}];
22062217
let mut last_hops = last_hops(&nodes);
@@ -2322,14 +2333,16 @@ mod tests {
23222333
}];
23232334
let our_chans = vec![channelmanager::ChannelDetails {
23242335
channel_id: [0; 32],
2336+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
23252337
short_channel_id: Some(42),
23262338
remote_network_id: middle_node_id,
23272339
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
23282340
channel_value_satoshis: 100000,
23292341
user_id: 0,
23302342
outbound_capacity_msat: 100000,
23312343
inbound_capacity_msat: 100000,
2332-
is_live: true,
2344+
is_outbound: true, is_funding_locked: true,
2345+
is_usable: true, is_public: true,
23332346
counterparty_forwarding_info: None,
23342347
}];
23352348
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 +2467,16 @@ mod tests {
24542467
// Now, limit the first_hop by the outbound_capacity_msat of 200_000 sats.
24552468
let our_chans = vec![channelmanager::ChannelDetails {
24562469
channel_id: [0; 32],
2470+
funding_txo: Some(OutPoint { txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(), index: 0 }),
24572471
short_channel_id: Some(42),
24582472
remote_network_id: nodes[0].clone(),
24592473
counterparty_features: InitFeatures::from_le_bytes(vec![0b11]),
24602474
channel_value_satoshis: 0,
24612475
user_id: 0,
24622476
outbound_capacity_msat: 200_000_000,
24632477
inbound_capacity_msat: 0,
2464-
is_live: true,
2478+
is_outbound: true, is_funding_locked: true,
2479+
is_usable: true, is_public: true,
24652480
counterparty_forwarding_info: None,
24662481
}];
24672482

0 commit comments

Comments
 (0)