Skip to content

Commit c804edb

Browse files
committed
Store channel capacity if available
1 parent bf8307a commit c804edb

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
@@ -90,8 +90,8 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
9090
return Err(LightningError{err: "Channel announcement node had a channel with itself".to_owned(), action: ErrorAction::IgnoreError});
9191
}
9292

93-
let checked_utxo = match self.chain_monitor.get_chain_utxo(msg.contents.chain_hash, msg.contents.short_channel_id) {
94-
Ok((script_pubkey, _value)) => {
93+
let utxo_value = match self.chain_monitor.get_chain_utxo(msg.contents.chain_hash, msg.contents.short_channel_id) {
94+
Ok((script_pubkey, value)) => {
9595
let expected_script = Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_2)
9696
.push_slice(&msg.contents.bitcoin_key_1.serialize())
9797
.push_slice(&msg.contents.bitcoin_key_2.serialize())
@@ -102,11 +102,11 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
102102
}
103103
//TODO: Check if value is worth storing, use it to inform routing, and compare it
104104
//to the new HTLC max field in channel_update
105-
true
105+
Some(value)
106106
},
107107
Err(ChainError::NotSupported) => {
108108
// Tentatively accept, potentially exposing us to DoS attacks
109-
false
109+
None
110110
},
111111
Err(ChainError::NotWatched) => {
112112
return Err(LightningError{err: format!("Channel announced on an unknown chain ({})", msg.contents.chain_hash.encode().to_hex()), action: ErrorAction::IgnoreError});
@@ -115,7 +115,7 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
115115
return Err(LightningError{err: "Channel announced without corresponding UTXO entry".to_owned(), action: ErrorAction::IgnoreError});
116116
},
117117
};
118-
let result = self.network_graph.write().unwrap().update_channel_from_announcement(msg, checked_utxo, Some(&self.secp_ctx));
118+
let result = self.network_graph.write().unwrap().update_channel_from_announcement(msg, utxo_value, Some(&self.secp_ctx));
119119
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 { "" });
120120
result
121121
}
@@ -257,6 +257,8 @@ pub struct ChannelInfo {
257257
pub node_two: PublicKey,
258258
/// Details about the second direction of a channel
259259
pub two_to_one: Option<DirectionalChannelInfo>,
260+
/// The channel capacity as seen on-chain, if chain lookup is available.
261+
pub capacity_sats: Option<u64>,
260262
/// An initial announcement of the channel
261263
/// Mostly redundant with the data we store in fields explicitly.
262264
/// Everything else is useful only for sending out for initial routing sync.
@@ -278,6 +280,7 @@ impl_writeable!(ChannelInfo, 0, {
278280
one_to_two,
279281
node_two,
280282
two_to_one,
283+
capacity_sats,
281284
announcement_message
282285
});
283286

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

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

0 commit comments

Comments
 (0)