Skip to content

Commit 84a47ea

Browse files
committed
Store channel capacity if available
1 parent 59ce264 commit 84a47ea

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
8989
return Err(LightningError{err: "Channel announcement node had a channel with itself", action: ErrorAction::IgnoreError});
9090
}
9191

92-
let checked_utxo = match self.chain_monitor.get_chain_utxo(msg.contents.chain_hash, msg.contents.short_channel_id) {
93-
Ok((script_pubkey, _value)) => {
92+
let utxo_value = match self.chain_monitor.get_chain_utxo(msg.contents.chain_hash, msg.contents.short_channel_id) {
93+
Ok((script_pubkey, value)) => {
9494
let expected_script = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2)
9595
.push_slice(&msg.contents.bitcoin_key_1.serialize())
9696
.push_slice(&msg.contents.bitcoin_key_2.serialize())
@@ -101,11 +101,11 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
101101
}
102102
//TODO: Check if value is worth storing, use it to inform routing, and compare it
103103
//to the new HTLC max field in channel_update
104-
true
104+
Some(value)
105105
},
106106
Err(ChainError::NotSupported) => {
107107
// Tentatively accept, potentially exposing us to DoS attacks
108-
false
108+
None
109109
},
110110
Err(ChainError::NotWatched) => {
111111
return Err(LightningError{err: "Channel announced on an unknown chain", action: ErrorAction::IgnoreError});
@@ -114,7 +114,7 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
114114
return Err(LightningError{err: "Channel announced without corresponding UTXO entry", action: ErrorAction::IgnoreError});
115115
},
116116
};
117-
let result = self.network_graph.write().unwrap().update_channel_from_announcement(msg, checked_utxo, Some(&self.secp_ctx));
117+
let result = self.network_graph.write().unwrap().update_channel_from_announcement(msg, utxo_value, Some(&self.secp_ctx));
118118
log_trace!(self.logger, "Added channel_announcement for {}{}", msg.contents.short_channel_id, if !msg.contents.excess_data.is_empty() { " with excess uninterpreted data!" } else { "" });
119119
result
120120
}
@@ -256,6 +256,8 @@ pub struct ChannelInfo {
256256
pub node_two: PublicKey,
257257
/// Details about the second direction of a channel
258258
pub two_to_one: Option<DirectionalChannelInfo>,
259+
/// The channel capacity as seen on-chain, if chain lookup is available.
260+
pub capacity_sats: Option<u64>,
259261
/// An initial announcement of the channel
260262
/// Mostly redundant with the data we store in fields explicitly.
261263
/// Everything else is useful only for sending out for initial routing sync.
@@ -277,6 +279,7 @@ impl_writeable!(ChannelInfo, 0, {
277279
one_to_two,
278280
node_two,
279281
two_to_one,
282+
capacity_sats,
280283
announcement_message
281284
});
282285

@@ -554,7 +557,7 @@ impl NetworkGraph {
554557
/// which is probably result of a reorg. In that case, we update channel info only if the
555558
/// utxo was checked, otherwise stick to the existing update, to prevent DoS risks.
556559
/// Announcement signatures are checked here only if Secp256k1 object is provided.
557-
fn update_channel_from_announcement(&mut self, msg: &msgs::ChannelAnnouncement, checked_utxo: bool, secp_ctx: Option<&Secp256k1<secp256k1::VerifyOnly>>) -> Result<bool, LightningError> {
560+
fn update_channel_from_announcement(&mut self, msg: &msgs::ChannelAnnouncement, utxo_value: Option<u64>, secp_ctx: Option<&Secp256k1<secp256k1::VerifyOnly>>) -> Result<bool, LightningError> {
558561
if let Some(sig_verifier) = secp_ctx {
559562
let msg_hash = hash_to_message!(&Sha256dHash::hash(&msg.contents.encode()[..])[..]);
560563
secp_verify_sig!(sig_verifier, &msg_hash, &msg.node_signature_1, &msg.contents.node_id_1);
@@ -571,6 +574,7 @@ impl NetworkGraph {
571574
one_to_two: None,
572575
node_two: msg.contents.node_id_2.clone(),
573576
two_to_one: None,
577+
capacity_sats: utxo_value,
574578
announcement_message: if should_relay { Some(msg.clone()) } else { None },
575579
};
576580

@@ -579,7 +583,7 @@ impl NetworkGraph {
579583
//TODO: because asking the blockchain if short_channel_id is valid is only optional
580584
//in the blockchain API, we need to handle it smartly here, though it's unclear
581585
//exactly how...
582-
if checked_utxo {
586+
if utxo_value.is_some() {
583587
// Either our UTXO provider is busted, there was a reorg, or the UTXO provider
584588
// only sometimes returns results. In any case remove the previous entry. Note
585589
// that the spec expects us to "blacklist" the node_ids involved, but we can't

0 commit comments

Comments
 (0)