@@ -89,8 +89,8 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
89
89
return Err ( LightningError { err : "Channel announcement node had a channel with itself" , action : ErrorAction :: IgnoreError } ) ;
90
90
}
91
91
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 ) ) => {
94
94
let expected_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHNUM_2 )
95
95
. push_slice ( & msg. contents . bitcoin_key_1 . serialize ( ) )
96
96
. push_slice ( & msg. contents . bitcoin_key_2 . serialize ( ) )
@@ -101,11 +101,11 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
101
101
}
102
102
//TODO: Check if value is worth storing, use it to inform routing, and compare it
103
103
//to the new HTLC max field in channel_update
104
- true
104
+ Some ( value )
105
105
} ,
106
106
Err ( ChainError :: NotSupported ) => {
107
107
// Tentatively accept, potentially exposing us to DoS attacks
108
- false
108
+ None
109
109
} ,
110
110
Err ( ChainError :: NotWatched ) => {
111
111
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
114
114
return Err ( LightningError { err : "Channel announced without corresponding UTXO entry" , action : ErrorAction :: IgnoreError } ) ;
115
115
} ,
116
116
} ;
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 ) ) ;
118
118
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 { "" } ) ;
119
119
result
120
120
}
@@ -256,6 +256,8 @@ pub struct ChannelInfo {
256
256
pub node_two : PublicKey ,
257
257
/// Details about the second direction of a channel
258
258
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 > ,
259
261
/// An initial announcement of the channel
260
262
/// Mostly redundant with the data we store in fields explicitly.
261
263
/// Everything else is useful only for sending out for initial routing sync.
@@ -277,6 +279,7 @@ impl_writeable!(ChannelInfo, 0, {
277
279
one_to_two,
278
280
node_two,
279
281
two_to_one,
282
+ capacity_sats,
280
283
announcement_message
281
284
} ) ;
282
285
@@ -554,7 +557,7 @@ impl NetworkGraph {
554
557
/// which is probably result of a reorg. In that case, we update channel info only if the
555
558
/// utxo was checked, otherwise stick to the existing update, to prevent DoS risks.
556
559
/// 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 > {
558
561
if let Some ( sig_verifier) = secp_ctx {
559
562
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
560
563
secp_verify_sig ! ( sig_verifier, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1) ;
@@ -571,6 +574,7 @@ impl NetworkGraph {
571
574
one_to_two : None ,
572
575
node_two : msg. contents . node_id_2 . clone ( ) ,
573
576
two_to_one : None ,
577
+ capacity_sats : utxo_value,
574
578
announcement_message : if should_relay { Some ( msg. clone ( ) ) } else { None } ,
575
579
} ;
576
580
@@ -579,7 +583,7 @@ impl NetworkGraph {
579
583
//TODO: because asking the blockchain if short_channel_id is valid is only optional
580
584
//in the blockchain API, we need to handle it smartly here, though it's unclear
581
585
//exactly how...
582
- if checked_utxo {
586
+ if utxo_value . is_some ( ) {
583
587
// Either our UTXO provider is busted, there was a reorg, or the UTXO provider
584
588
// only sometimes returns results. In any case remove the previous entry. Note
585
589
// that the spec expects us to "blacklist" the node_ids involved, but we can't
0 commit comments