@@ -75,7 +75,7 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
75
75
fn handle_node_announcement ( & self , msg : & msgs:: NodeAnnouncement ) -> Result < bool , LightningError > {
76
76
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. contents. encode( ) [ ..] ) [ ..] ) ;
77
77
secp_verify_sig ! ( self . secp_ctx, & msg_hash, & msg. signature, & msg. contents. node_id) ;
78
- self . network_graph . write ( ) . unwrap ( ) . process_node_announcement ( msg)
78
+ self . network_graph . write ( ) . unwrap ( ) . update_node_from_announcement ( msg)
79
79
}
80
80
81
81
fn handle_channel_announcement ( & self , msg : & msgs:: ChannelAnnouncement ) -> Result < bool , LightningError > {
@@ -114,27 +114,27 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
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 ( ) . process_channel_announcement ( msg, checked_utxo) ;
117
+ let result = self . network_graph . write ( ) . unwrap ( ) . update_channel_from_announcement ( msg, checked_utxo) ;
118
118
log_trace ! ( self , "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
}
121
121
122
122
fn handle_htlc_fail_channel_update ( & self , update : & msgs:: HTLCFailChannelUpdate ) {
123
123
match update {
124
124
& msgs:: HTLCFailChannelUpdate :: ChannelUpdateMessage { ref msg } => {
125
- let _ = self . network_graph . write ( ) . unwrap ( ) . process_channel_update ( msg, & self . secp_ctx ) ;
125
+ let _ = self . network_graph . write ( ) . unwrap ( ) . update_channel ( msg, & self . secp_ctx ) ;
126
126
} ,
127
127
& msgs:: HTLCFailChannelUpdate :: ChannelClosed { ref short_channel_id, ref is_permanent } => {
128
- self . network_graph . write ( ) . unwrap ( ) . process_channel_closing ( short_channel_id, & is_permanent) ;
128
+ self . network_graph . write ( ) . unwrap ( ) . close_channel_from_update ( short_channel_id, & is_permanent) ;
129
129
} ,
130
130
& msgs:: HTLCFailChannelUpdate :: NodeFailure { ref node_id, ref is_permanent } => {
131
- self . network_graph . write ( ) . unwrap ( ) . process_node_failure ( node_id, & is_permanent) ;
131
+ self . network_graph . write ( ) . unwrap ( ) . fail_node ( node_id, & is_permanent) ;
132
132
} ,
133
133
}
134
134
}
135
135
136
136
fn handle_channel_update ( & self , msg : & msgs:: ChannelUpdate ) -> Result < bool , LightningError > {
137
- self . network_graph . write ( ) . unwrap ( ) . process_channel_update ( msg, & self . secp_ctx )
137
+ self . network_graph . write ( ) . unwrap ( ) . update_channel ( msg, & self . secp_ctx )
138
138
}
139
139
140
140
fn get_next_channel_announcements ( & self , starting_point : u64 , batch_amount : u8 ) -> Vec < ( msgs:: ChannelAnnouncement , Option < msgs:: ChannelUpdate > , Option < msgs:: ChannelUpdate > ) > {
@@ -491,7 +491,9 @@ impl NetworkGraph {
491
491
/// Returns all known nodes
492
492
pub fn get_nodes < ' a > ( & ' a self ) -> & ' a BTreeMap < PublicKey , NodeInfo > { & self . nodes }
493
493
494
- fn process_node_announcement ( & mut self , msg : & msgs:: NodeAnnouncement ) -> Result < bool , LightningError > {
494
+ /// For an already known node (from channel announcements), update its stored properties from a given node announcement
495
+ /// Announcement signatures *are not checked* here and should be checked by a caller beforehand.
496
+ pub fn update_node_from_announcement ( & mut self , msg : & msgs:: NodeAnnouncement ) -> Result < bool , LightningError > {
495
497
match self . nodes . get_mut ( & msg. contents . node_id ) {
496
498
None => Err ( LightningError { err : "No existing channels for node_announcement" , action : ErrorAction :: IgnoreError } ) ,
497
499
Some ( node) => {
@@ -515,7 +517,11 @@ impl NetworkGraph {
515
517
}
516
518
}
517
519
518
- fn process_channel_announcement ( & mut self , msg : & msgs:: ChannelAnnouncement , checked_utxo : bool ) -> Result < bool , LightningError > {
520
+ /// For a new or already known (from previous announcement) channel, store or update channel info,
521
+ /// after making sure it corresponds to a real transaction on-chain.
522
+ /// Also store nodes (if not stored yet) the channel is between, and make node aware of this channel.
523
+ /// Announcement signatures *are not checked* here and should be checked by a caller beforehand.
524
+ pub fn update_channel_from_announcement ( & mut self , msg : & msgs:: ChannelAnnouncement , checked_utxo : bool ) -> Result < bool , LightningError > {
519
525
let should_relay = msg. contents . excess_data . is_empty ( ) ;
520
526
521
527
let chan_info = ChannelInfo {
@@ -600,7 +606,11 @@ impl NetworkGraph {
600
606
Ok ( should_relay)
601
607
}
602
608
603
- fn process_channel_closing ( & mut self , short_channel_id : & u64 , is_permanent : & bool ) {
609
+ /// Close a channel if a corresponding HTLC fail was sent.
610
+ /// If permanent, removes a channel from the local storage.
611
+ /// May cause the removal of nodes too, if this was their last channel.
612
+ /// If not permanent, makes channels unavailable for routing.
613
+ pub fn close_channel_from_update ( & mut self , short_channel_id : & u64 , is_permanent : & bool ) {
604
614
if * is_permanent {
605
615
if let Some ( chan) = self . channels . remove ( short_channel_id) {
606
616
Self :: remove_channel_in_nodes ( & mut self . nodes , & chan, * short_channel_id) ;
@@ -613,15 +623,17 @@ impl NetworkGraph {
613
623
}
614
624
}
615
625
616
- fn process_node_failure ( & mut self , _node_id : & PublicKey , is_permanent : & bool ) {
626
+ fn fail_node ( & mut self , _node_id : & PublicKey , is_permanent : & bool ) {
617
627
if * is_permanent {
618
628
// TODO: Wholly remove the node
619
629
} else {
620
630
// TODO: downgrade the node
621
631
}
622
632
}
623
633
624
- fn process_channel_update ( & mut self , msg : & msgs:: ChannelUpdate , secp_ctx : & Secp256k1 < secp256k1:: VerifyOnly > ) -> Result < bool , LightningError > {
634
+ /// For an already known (from announcement) channel, update info regarding one of the directions of a channel.
635
+ /// Announcement signatures *are checked* here and should be checked by a caller beforehand.
636
+ fn update_channel ( & mut self , msg : & msgs:: ChannelUpdate , secp_ctx : & Secp256k1 < secp256k1:: VerifyOnly > ) -> Result < bool , LightningError > {
625
637
let dest_node_id;
626
638
let chan_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
627
639
let chan_was_enabled;
0 commit comments