@@ -73,7 +73,7 @@ macro_rules! secp_verify_sig {
73
73
74
74
impl RoutingMessageHandler for NetGraphMsgHandler {
75
75
fn handle_node_announcement ( & self , msg : & msgs:: NodeAnnouncement ) -> Result < bool , LightningError > {
76
- self . network_graph . write ( ) . unwrap ( ) . process_node_announcement ( msg, Some ( & self . secp_ctx ) )
76
+ self . network_graph . write ( ) . unwrap ( ) . update_node_from_announcement ( msg, Some ( & self . secp_ctx ) )
77
77
}
78
78
79
79
fn handle_channel_announcement ( & self , msg : & msgs:: ChannelAnnouncement ) -> Result < bool , LightningError > {
@@ -106,27 +106,27 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
106
106
return Err ( LightningError { err : "Channel announced without corresponding UTXO entry" , action : ErrorAction :: IgnoreError } ) ;
107
107
} ,
108
108
} ;
109
- let result = self . network_graph . write ( ) . unwrap ( ) . process_channel_announcement ( msg, checked_utxo, Some ( & self . secp_ctx ) ) ;
109
+ let result = self . network_graph . write ( ) . unwrap ( ) . update_channel_from_announcement ( msg, checked_utxo, Some ( & self . secp_ctx ) ) ;
110
110
log_trace ! ( self , "Added channel_announcement for {}{}" , msg. contents. short_channel_id, if !msg. contents. excess_data. is_empty( ) { " with excess uninterpreted data!" } else { "" } ) ;
111
111
result
112
112
}
113
113
114
114
fn handle_htlc_fail_channel_update ( & self , update : & msgs:: HTLCFailChannelUpdate ) {
115
115
match update {
116
116
& msgs:: HTLCFailChannelUpdate :: ChannelUpdateMessage { ref msg } => {
117
- let _ = self . network_graph . write ( ) . unwrap ( ) . process_channel_update ( msg, Some ( & self . secp_ctx ) ) ;
117
+ let _ = self . network_graph . write ( ) . unwrap ( ) . update_channel ( msg, Some ( & self . secp_ctx ) ) ;
118
118
} ,
119
119
& msgs:: HTLCFailChannelUpdate :: ChannelClosed { ref short_channel_id, ref is_permanent } => {
120
- self . network_graph . write ( ) . unwrap ( ) . process_channel_closing ( short_channel_id, & is_permanent) ;
120
+ self . network_graph . write ( ) . unwrap ( ) . close_channel_from_update ( short_channel_id, & is_permanent) ;
121
121
} ,
122
122
& msgs:: HTLCFailChannelUpdate :: NodeFailure { ref node_id, ref is_permanent } => {
123
- self . network_graph . write ( ) . unwrap ( ) . process_node_failure ( node_id, & is_permanent) ;
123
+ self . network_graph . write ( ) . unwrap ( ) . fail_node ( node_id, & is_permanent) ;
124
124
} ,
125
125
}
126
126
}
127
127
128
128
fn handle_channel_update ( & self , msg : & msgs:: ChannelUpdate ) -> Result < bool , LightningError > {
129
- self . network_graph . write ( ) . unwrap ( ) . process_channel_update ( msg, Some ( & self . secp_ctx ) )
129
+ self . network_graph . write ( ) . unwrap ( ) . update_channel ( msg, Some ( & self . secp_ctx ) )
130
130
}
131
131
132
132
fn get_next_channel_announcements ( & self , starting_point : u64 , batch_amount : u8 ) -> Vec < ( msgs:: ChannelAnnouncement , Option < msgs:: ChannelUpdate > , Option < msgs:: ChannelUpdate > ) > {
@@ -483,7 +483,9 @@ impl NetworkGraph {
483
483
/// Returns all known nodes
484
484
pub fn get_nodes < ' a > ( & ' a self ) -> & ' a BTreeMap < PublicKey , NodeInfo > { & self . nodes }
485
485
486
- fn process_node_announcement ( & mut self , msg : & msgs:: NodeAnnouncement , secp_ctx : Option < & Secp256k1 < secp256k1:: VerifyOnly > > ) -> Result < bool , LightningError > {
486
+ /// For an already known node (from channel announcements), update its stored properties from a given node announcement
487
+ /// Announcement signatures are checked here only if Secp256k1 object is provided.
488
+ fn update_node_from_announcement ( & mut self , msg : & msgs:: NodeAnnouncement , secp_ctx : Option < & Secp256k1 < secp256k1:: VerifyOnly > > ) -> Result < bool , LightningError > {
487
489
if let Some ( sig_verifier) = secp_ctx {
488
490
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
489
491
secp_verify_sig ! ( sig_verifier, & msg_hash, & msg. signature, & msg. contents. node_id) ;
@@ -512,7 +514,11 @@ impl NetworkGraph {
512
514
}
513
515
}
514
516
515
- fn process_channel_announcement ( & mut self , msg : & msgs:: ChannelAnnouncement , checked_utxo : bool , secp_ctx : Option < & Secp256k1 < secp256k1:: VerifyOnly > > ) -> Result < bool , LightningError > {
517
+ /// For a new or already known (from previous announcement) channel, store or update channel info,
518
+ /// after making sure it corresponds to a real transaction on-chain.
519
+ /// Also store nodes (if not stored yet) the channel is between, and make node aware of this channel.
520
+ /// Announcement signatures are checked here only if Secp256k1 object is provided.
521
+ fn update_channel_from_announcement ( & mut self , msg : & msgs:: ChannelAnnouncement , checked_utxo : bool , secp_ctx : Option < & Secp256k1 < secp256k1:: VerifyOnly > > ) -> Result < bool , LightningError > {
516
522
if let Some ( sig_verifier) = secp_ctx {
517
523
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
518
524
secp_verify_sig ! ( sig_verifier, & msg_hash, & msg. node_signature_1, & msg. contents. node_id_1) ;
@@ -605,7 +611,11 @@ impl NetworkGraph {
605
611
Ok ( should_relay)
606
612
}
607
613
608
- fn process_channel_closing ( & mut self , short_channel_id : & u64 , is_permanent : & bool ) {
614
+ /// Close a channel if a corresponding HTLC fail was sent.
615
+ /// If permanent, removes a channel from the local storage.
616
+ /// May cause the removal of nodes too, if this was their last channel.
617
+ /// If not permanent, makes channels unavailable for routing.
618
+ pub fn close_channel_from_update ( & mut self , short_channel_id : & u64 , is_permanent : & bool ) {
609
619
if * is_permanent {
610
620
if let Some ( chan) = self . channels . remove ( short_channel_id) {
611
621
Self :: remove_channel_in_nodes ( & mut self . nodes , & chan, * short_channel_id) ;
@@ -618,15 +628,17 @@ impl NetworkGraph {
618
628
}
619
629
}
620
630
621
- fn process_node_failure ( & mut self , _node_id : & PublicKey , is_permanent : & bool ) {
631
+ fn fail_node ( & mut self , _node_id : & PublicKey , is_permanent : & bool ) {
622
632
if * is_permanent {
623
633
// TODO: Wholly remove the node
624
634
} else {
625
635
// TODO: downgrade the node
626
636
}
627
637
}
628
638
629
- fn process_channel_update ( & mut self , msg : & msgs:: ChannelUpdate , secp_ctx : Option < & Secp256k1 < secp256k1:: VerifyOnly > > ) -> Result < bool , LightningError > {
639
+ /// For an already known (from announcement) channel, update info regarding one of the directions of a channel.
640
+ /// Announcement signatures are checked here only if Secp256k1 object is provided.
641
+ fn update_channel ( & mut self , msg : & msgs:: ChannelUpdate , secp_ctx : Option < & Secp256k1 < secp256k1:: VerifyOnly > > ) -> Result < bool , LightningError > {
630
642
let dest_node_id;
631
643
let chan_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
632
644
let chan_was_enabled;
0 commit comments